check whether local machine is same as remote machine (a la printjob.c)
authorThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Tue, 21 Feb 1989 06:48:09 +0000 (22:48 -0800)
committerThomas Ferrin <tef@ucbvax.Berkeley.EDU>
Tue, 21 Feb 1989 06:48:09 +0000 (22:48 -0800)
SCCS-vsn: usr.sbin/lpr/common_source/rmjob.c 5.4

usr/src/usr.sbin/lpr/common_source/rmjob.c

index d43eac2..178e9d1 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)rmjob.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)rmjob.c    5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -60,6 +60,36 @@ rmjob()
        if ((RP = pgetstr("rp", &bp)) == NULL)
                RP = DEFLP;
        RM = pgetstr("rm", &bp);
        if ((RP = pgetstr("rp", &bp)) == NULL)
                RP = DEFLP;
        RM = pgetstr("rm", &bp);
+       /*
+        * Figure out whether the local machine is the same as the remote 
+        * machine entry (if it exists).  If not, then ignore the local
+        * queue information.
+        */
+        if (RM != (char *) NULL) {
+               char name[256];
+               struct hostent *hp;
+
+               /* get the standard network name of the local host */
+               gethostname(name, sizeof(name));
+               name[sizeof(name)-1] = '\0';
+               hp = gethostbyname(name);
+               if (hp == (struct hostent *) NULL) {
+                   printf("unable to get network name for local machine %s",
+                       name);
+                   goto localcheck_done;
+               } else strcpy(name, hp->h_name);
+
+               /* get the standard network name of RM */
+               hp = gethostbyname(RM);
+               if (hp == (struct hostent *) NULL) {
+                   printf("unable to get hostname for remote machine %s", RM);
+                   goto localcheck_done;
+               }
+
+               /* if printer is not on local machine, ignore LP */
+               if (strcmp(name, hp->h_name) != 0) *LP = '\0';
+       }
+localcheck_done:
 
        /*
         * If the format was `lprm -' and the user isn't the super-user,
 
        /*
         * If the format was `lprm -' and the user isn't the super-user,