diff options
Diffstat (limited to 'usr.sbin/lpr/common_source')
-rw-r--r-- | usr.sbin/lpr/common_source/common.c | 5 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/displayq.c | 14 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/lp.h | 22 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/net.c | 12 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/rmjob.c | 23 |
5 files changed, 49 insertions, 27 deletions
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index 8e705db..8c434b0 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -553,8 +553,9 @@ fatal(pp, msg, va_alist) #else va_start(ap); #endif - if (from != host) - (void)printf("%s: ", host); + /* this error message is being sent to the 'from_host' */ + if (from_host != local_host) + (void)printf("%s: ", local_host); (void)printf("%s: ", progname); if (pp && pp->printer) (void)printf("%s: ", pp->printer); diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c index df82d56..7eef91e 100644 --- a/usr.sbin/lpr/common_source/displayq.c +++ b/usr.sbin/lpr/common_source/displayq.c @@ -127,7 +127,7 @@ displayq(struct printer *pp, int format) if (ret >= 0) { if (statb.st_mode & LFM_PRINT_DIS) { if (pp->remote) - printf("%s: ", host); + printf("%s: ", local_host); printf("Warning: %s is down: ", pp->printer); seteuid(euid); fd = open(pp->status_file, O_RDONLY|O_SHLOCK); @@ -141,7 +141,7 @@ displayq(struct printer *pp, int format) } if (statb.st_mode & LFM_QUEUE_DIS) { if (pp->remote) - printf("%s: ", host); + printf("%s: ", local_host); printf("Warning: %s queue is turned off\n", pp->printer); } @@ -179,7 +179,7 @@ displayq(struct printer *pp, int format) * Print the status file. */ if (pp->remote) - printf("%s: ", host); + printf("%s: ", local_host); seteuid(euid); fd = open(pp->status_file, O_RDONLY|O_SHLOCK); seteuid(uid); @@ -238,8 +238,8 @@ displayq(struct printer *pp, int format) alarm(0); (void)signal(SIGALRM, savealrm); if (fd < 0) { - if (from != host) - printf("%s: ", host); + if (from_host != local_host) + printf("%s: ", local_host); printf("connection to %s is down\n", pp->remote_host); } else { @@ -259,7 +259,7 @@ static void warn(const struct printer *pp) { if (pp->remote) - printf("%s: ", host); + printf("%s: ", local_host); puts("Warning: no daemon present"); current[0] = '\0'; } @@ -396,7 +396,7 @@ inlist(char *uname, char *cfile) for (n = 0, cp = cfile+3; isdigit(*cp); ) n = n * 10 + (*cp++ - '0'); for (r = requ; r < &requ[requests]; r++) - if (*r == n && !strcmp(cp, from)) + if (*r == n && !strcmp(cp, from_host)) return(1); return(0); } diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h index 3cee695..9ca0612 100644 --- a/usr.sbin/lpr/common_source/lp.h +++ b/usr.sbin/lpr/common_source/lp.h @@ -154,10 +154,24 @@ struct request { */ extern char line[BUFSIZ]; extern const char *progname; /* program name (lpr, lpq, etc) */ - /* host machine name */ -extern char host[MAXHOSTNAMELEN]; -extern char *from; /* client's machine name */ -extern char from_ip[NI_MAXHOST]; /* client machine's IP address */ + + /* + * 'local_host' is the name of the machine that lpd (lpr, whatever) + * is actually running on. + * + * 'from_host' will point to the 'host' variable when receiving a job + * from a user on the same host, or "somewhere else" when receiving a + * job from a remote host. If 'from_host != local_host', then 'from_ip' + * is the character representation of the IP address of from_host (note + * that string could be an IPv6 address). + * + * Also note that when 'from_host' is not pointing at 'local_host', the + * string it is pointing at may be as long as NI_MAXHOST (which is very + * likely to be much longer than MAXHOSTNAMELEN). + */ +extern char local_host[MAXHOSTNAMELEN]; +extern const char *from_host; /* client's machine name */ +extern const char *from_ip; /* client machine's IP address */ extern int requ[]; /* job number of spool entries */ extern int requests; /* # of spool requests */ diff --git a/usr.sbin/lpr/common_source/net.c b/usr.sbin/lpr/common_source/net.c index 619c253..df70ef4 100644 --- a/usr.sbin/lpr/common_source/net.c +++ b/usr.sbin/lpr/common_source/net.c @@ -65,9 +65,15 @@ static const char rcsid[] = #include "lp.local.h" #include "pathnames.h" -char host[MAXHOSTNAMELEN]; /* host machine name */ -char *from = host; /* client's machine name */ -char from_ip[NI_MAXHOST] = ""; /* client machine's IP address */ +/* + * 'local_host' is always the hostname of the machine which is running + * lpr (lpd, whatever), while 'from_host' either points at 'local_host' + * or points at a different buffer when receiving a job from a remote + * machine (and that buffer has the hostname of that remote machine). + */ +char local_host[MAXHOSTNAMELEN]; /* host running lpd/lpr */ +const char *from_host = local_host; /* client's machine name */ +const char *from_ip = ""; /* client machine's IP address */ #ifdef INET6 u_char family = PF_UNSPEC; diff --git a/usr.sbin/lpr/common_source/rmjob.c b/usr.sbin/lpr/common_source/rmjob.c index 39a7d0f..3a60efb 100644 --- a/usr.sbin/lpr/common_source/rmjob.c +++ b/usr.sbin/lpr/common_source/rmjob.c @@ -106,9 +106,9 @@ rmjob(const char *printer) } } if (!strcmp(person, "-all")) { - if (from == host) + if (from_host == local_host) fatal(pp, "The login name \"-all\" is reserved"); - all = 1; /* all those from 'from' */ + all = 1; /* all those from 'from_host' */ person = root; } @@ -218,8 +218,8 @@ do_unlink(char *file) { int ret; - if (from != host) - printf("%s: ", host); + if (from_host != local_host) + printf("%s: ", local_host); seteuid(euid); ret = unlink(file); seteuid(uid); @@ -242,7 +242,7 @@ chk(char *file) if (strlen(file) < 7 || file[0] != 'c' || file[1] != 'f') return(0); - if (all && (from == host || !strcmp(from, file+6))) + if (all && (from_host == local_host || !strcmp(from_host, file+6))) return(1); /* @@ -288,12 +288,13 @@ chk(char *file) int isowner(char *owner, char *file) { - if (!strcmp(person, root) && (from == host || !strcmp(from, file+6))) + if (!strcmp(person, root) && (from_host == local_host || + !strcmp(from_host, file+6))) return (1); - if (!strcmp(person, owner) && !strcmp(from, file+6)) + if (!strcmp(person, owner) && !strcmp(from_host, file+6)) return (1); - if (from != host) - printf("%s: ", host); + if (from_host != local_host) + printf("%s: ", local_host); printf("%s: Permission denied\n", file); return(0); } @@ -362,8 +363,8 @@ rmremote(const struct printer *pp) rem = getport(pp, pp->remote_host, 0); (void)signal(SIGALRM, savealrm); if (rem < 0) { - if (from != host) - printf("%s: ", host); + if (from_host != local_host) + printf("%s: ", local_host); printf("connection to %s is down\n", pp->remote_host); } else { if (writev(rem, iov, niov) != totlen) |