diff options
-rw-r--r-- | usr.sbin/lpr/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/common.c | 8 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/lp.h | 3 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/startdaemon.c | 21 | ||||
-rw-r--r-- | usr.sbin/lpr/lpc/lpc.c | 5 | ||||
-rw-r--r-- | usr.sbin/lpr/lpd/lpd.c | 6 | ||||
-rw-r--r-- | usr.sbin/lpr/lpq/lpq.c | 6 | ||||
-rw-r--r-- | usr.sbin/lpr/lpr/lpr.c | 107 | ||||
-rw-r--r-- | usr.sbin/lpr/lprm/lprm.c | 6 |
9 files changed, 58 insertions, 107 deletions
diff --git a/usr.sbin/lpr/Makefile b/usr.sbin/lpr/Makefile index 67eb7e48cb5..d9e6a50cff7 100644 --- a/usr.sbin/lpr/Makefile +++ b/usr.sbin/lpr/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.3 1997/09/21 11:43:51 deraadt Exp $ +# $OpenBSD: Makefile,v 1.4 2001/12/06 03:12:30 ericj Exp $ SUBDIR= lpc lpd lpq lpr lprm lptest pac filters @@ -6,4 +6,5 @@ SUBDIR= lpc lpd lpq lpr lprm lptest pac filters SUBDIR+= SMM.doc .endif +CFLAGS+= -Wall .include <bsd.subdir.mk> diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index 592f4eef608..bb1468459e4 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.13 2001/11/23 03:58:17 deraadt Exp $ */ +/* $OpenBSD: common.c,v 1.14 2001/12/06 03:12:30 ericj Exp $ */ /* * Copyright (c) 1983, 1993 @@ -42,7 +42,7 @@ #if 0 static const char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; #else -static const char rcsid[] = "$OpenBSD: common.c,v 1.13 2001/11/23 03:58:17 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: common.c,v 1.14 2001/12/06 03:12:30 ericj Exp $"; #endif #endif /* not lint */ @@ -112,7 +112,6 @@ long XS; /* flags to set for local mode */ char line[BUFSIZ]; char *bp; /* pointer into printcap buffer. */ -char *name; /* program name */ char *printer; /* printer name */ /* host machine name */ char host[MAXHOSTNAMELEN]; @@ -421,6 +420,7 @@ fatal(msg, va_alist) va_dcl #endif { + extern char *__progname; va_list ap; #ifdef __STDC__ va_start(ap, msg); @@ -429,7 +429,7 @@ fatal(msg, va_alist) #endif if (from != host) (void)printf("%s: ", host); - (void)printf("%s: ", name); + (void)printf("%s: ", __progname); if (printer) (void)printf("%s: ", printer); (void)vprintf(msg, ap); diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h index b46c0eac9c2..01f0a3c599c 100644 --- a/usr.sbin/lpr/common_source/lp.h +++ b/usr.sbin/lpr/common_source/lp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lp.h,v 1.5 2001/11/23 03:58:17 deraadt Exp $ */ +/* $OpenBSD: lp.h,v 1.6 2001/12/06 03:12:30 ericj Exp $ */ /* * Copyright (c) 1983, 1993 @@ -83,7 +83,6 @@ extern long XS; /* flags to set for local mode */ extern char line[BUFSIZ]; extern char *bp; /* pointer into printcap buffer */ -extern char *name; /* program name */ extern char *printer; /* printer name */ /* host machine name */ extern char host[MAXHOSTNAMELEN]; diff --git a/usr.sbin/lpr/common_source/startdaemon.c b/usr.sbin/lpr/common_source/startdaemon.c index 07c376943a2..971c6482a9a 100644 --- a/usr.sbin/lpr/common_source/startdaemon.c +++ b/usr.sbin/lpr/common_source/startdaemon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: startdaemon.c,v 1.5 2001/11/23 03:58:17 deraadt Exp $ */ +/* $OpenBSD: startdaemon.c,v 1.6 2001/12/06 03:12:30 ericj Exp $ */ /* * Copyright (c) 1983, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static const char sccsid[] = "@(#)startdaemon.c 8.2 (Berkeley) 4/17/94"; #else -static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.5 2001/11/23 03:58:17 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.6 2001/12/06 03:12:30 ericj Exp $"; #endif #endif /* not lint */ @@ -55,8 +55,6 @@ static const char rcsid[] = "$OpenBSD: startdaemon.c,v 1.5 2001/11/23 03:58:17 d extern uid_t uid, euid; -static void perr __P((char *)); - /* * Tell the printer daemon that there are new files in the spool directory. */ @@ -71,7 +69,7 @@ startdaemon(printer) s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) { - perr("socket"); + perror("socket"); return(0); } memset(&un, 0, sizeof(un)); @@ -91,7 +89,7 @@ startdaemon(printer) } siginterrupt(SIGINT, 0); seteuid(uid); - perr("connect"); + perror("connect"); (void) close(s); return(0); } @@ -105,7 +103,7 @@ startdaemon(printer) /* XXX atomicio inside siginterrupt? */ if (write(s, buf, n) != n) { - perr("write"); + perror("write"); (void) close(s); return(0); } @@ -122,12 +120,3 @@ startdaemon(printer) (void) close(s); return(0); } - -static void -perr(msg) - char *msg; -{ - extern char *name; - - (void)printf("%s: %s: %s\n", name, msg, strerror(errno)); -} diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c index 42b23fde8d7..3c3ffe04331 100644 --- a/usr.sbin/lpr/lpc/lpc.c +++ b/usr.sbin/lpr/lpc/lpc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpc.c,v 1.10 2001/11/23 03:58:18 deraadt Exp $ */ +/* $OpenBSD: lpc.c,v 1.11 2001/12/06 03:12:30 ericj Exp $ */ /* * Copyright (c) 1983, 1993 @@ -44,7 +44,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95"; #else -static const char rcsid[] = "$OpenBSD: lpc.c,v 1.10 2001/11/23 03:58:18 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: lpc.c,v 1.11 2001/12/06 03:12:30 ericj Exp $"; #endif #endif /* not lint */ @@ -98,7 +98,6 @@ main(argc, argv) euid = geteuid(); uid = getuid(); seteuid(uid); - name = argv[0]; openlog("lpd", 0, LOG_LPR); if (--argc > 0) { diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index 1da204184b5..6d38a974c54 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpd.c,v 1.23 2001/11/23 03:58:18 deraadt Exp $ */ +/* $OpenBSD: lpd.c,v 1.24 2001/12/06 03:12:30 ericj Exp $ */ /* $NetBSD: lpd.c,v 1.7 1996/04/24 14:54:06 mrg Exp $ */ /* @@ -45,7 +45,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpd.c,v 1.23 2001/11/23 03:58:18 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: lpd.c,v 1.24 2001/12/06 03:12:30 ericj Exp $"; #endif #endif /* not lint */ @@ -138,8 +138,6 @@ main(argc, argv) options = 0; gethostname(host, sizeof(host)); - name = "lpd"; - if (euid != 0) { fprintf(stderr,"lpd: must run as root\n"); exit(1); diff --git a/usr.sbin/lpr/lpq/lpq.c b/usr.sbin/lpr/lpq/lpq.c index 4b2c9b2ab48..6e2b09ec64a 100644 --- a/usr.sbin/lpr/lpq/lpq.c +++ b/usr.sbin/lpr/lpq/lpq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpq.c,v 1.9 2001/11/23 03:58:18 deraadt Exp $ */ +/* $OpenBSD: lpq.c,v 1.10 2001/12/06 03:12:31 ericj Exp $ */ /* * Copyright (c) 1983, 1993 @@ -44,7 +44,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpq.c,v 1.9 2001/11/23 03:58:18 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: lpq.c,v 1.10 2001/12/06 03:12:31 ericj Exp $"; #endif #endif /* not lint */ @@ -95,7 +95,7 @@ main(argc, argv) euid = geteuid(); uid = getuid(); seteuid(uid); - name = *argv; + if (gethostname(host, sizeof(host))) { perror("lpq: gethostname"); exit(1); diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c index eac99c57038..71054fe86b6 100644 --- a/usr.sbin/lpr/lpr/lpr.c +++ b/usr.sbin/lpr/lpr/lpr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpr.c,v 1.22 2001/11/23 03:58:18 deraadt Exp $ */ +/* $OpenBSD: lpr.c,v 1.23 2001/12/06 03:12:31 ericj Exp $ */ /* $NetBSD: lpr.c,v 1.10 1996/03/21 18:12:25 jtc Exp $ */ /* @@ -50,7 +50,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpr.c 8.4 (Berkeley) 4/28/95"; #else -static const char rcsid[] = "$OpenBSD: lpr.c,v 1.22 2001/11/23 03:58:18 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: lpr.c,v 1.23 2001/12/06 03:12:31 ericj Exp $"; #endif #endif /* not lint */ @@ -112,7 +112,6 @@ static void card __P((int, char *)); static void chkprinter __P((char *)); static void cleanup __P((int)); static void copy __P((int, char [])); -static void fatal2 __P((const char *, ...)); static char *linked __P((char *)); static char *lmktemp __P((char *, int, int)); static void mktemps __P((void)); @@ -146,7 +145,6 @@ main(argc, argv) if (signal(SIGTERM, SIG_IGN) != SIG_IGN) signal(SIGTERM, cleanup); - name = argv[0]; gethostname(host, sizeof (host)); openlog("lpd", 0, LOG_LPR); @@ -275,9 +273,9 @@ main(argc, argv) } chkprinter(printer); if (SC && ncopies > 1) - fatal2("multiple copies are not allowed"); + errx(1, "multiple copies are not allowed"); if (MC > 0 && ncopies > MC) - fatal2("only %d copies are allowed", MC); + errx(1, "only %d copies are allowed", MC); /* * Get the identity of the person doing the lpr using the same * algorithm as lprm. @@ -285,7 +283,7 @@ main(argc, argv) userid = getuid(); if (userid != DU || person == 0) { if ((pw = getpwuid(userid)) == NULL) - fatal2("Who are you?"); + errx(1, "Who are you?"); person = pw->pw_name; } /* @@ -293,7 +291,7 @@ main(argc, argv) */ if (RG != NULL && userid != DU) { if ((gptr = getgrnam(RG)) == NULL) - fatal2("Restricted group specified incorrectly"); + errx(1, "Restricted group specified incorrectly"); if (gptr->gr_gid != getgid()) { while (*gptr->gr_mem != NULL) { if ((strcmp(person, *gptr->gr_mem)) == 0) @@ -301,7 +299,7 @@ main(argc, argv) gptr->gr_mem++; } if (*gptr->gr_mem == NULL) - fatal2("Not a member of the restricted group"); + errx(1, "Not a member of the restricted group"); } } /* @@ -309,7 +307,7 @@ main(argc, argv) */ (void) snprintf(buf, sizeof(buf), "%s/%s", SD, LO); if (userid && stat(buf, &stb) == 0 && (stb.st_mode & 010)) - fatal2("Printer queue is disabled"); + errx(1, "Printer queue is disabled"); /* * Initialize the control file. */ @@ -368,14 +366,14 @@ main(argc, argv) continue; } if (sflag) - printf("%s: %s: not linked, copying instead\n", name, arg); - if ((i = open(arg, O_RDONLY)) < 0) { - printf("%s: cannot open %s\n", name, arg); - } else { + warnx("%s: not linked, copying instead", arg); + if ((i = open(arg, O_RDONLY)) < 0) + warn("%s", arg); + else { copy(i, arg); (void) close(i); if (f && unlink(arg) < 0) - printf("%s: %s: not removed\n", name, arg); + warnx("%s: not removed", arg); } } @@ -392,14 +390,14 @@ main(argc, argv) if (read(tfd, &c, 1) == 1 && lseek(tfd, (off_t)0, 0) == 0 && write(tfd, &c, 1) != 1) { - printf("%s: cannot touch %s\n", name, tfname); + warn("%s", tfname); tfname[inchar]++; cleanup(0); } (void) close(tfd); } if (link(tfname, cfname) < 0) { - printf("%s: cannot rename %s\n", name, cfname); + warn("cannot rename %s", cfname); tfname[inchar]++; cleanup(0); } @@ -437,7 +435,7 @@ copy(f, n) nr = nc = 0; while ((i = read(f, buf, BUFSIZ)) > 0) { if (write(fd, buf, i) != i) { - printf("%s: %s: temp file write error\n", name, n); + warn("%s", n); break; } nc += i; @@ -445,15 +443,14 @@ copy(f, n) nc -= BUFSIZ; nr++; if (MX > 0 && nr > MX) { - printf("%s: %s: copy file is too large\n", - name, n); + warnx("%s: copy file is too large", n); break; } } } (void) close(fd); if (nc==0 && nr==0) - printf("%s: %s: empty input file\n", name, f ? n : "stdin"); + warnx("%s: empty input file", f ? n : "stdin"); else nact++; } @@ -534,23 +531,23 @@ nfile(n) f = open(n, O_WRONLY | O_EXCL | O_CREAT, FILMOD); (void) umask(oldumask); if (f < 0) { - printf("%s: cannot create %s\n", name, n); + warn("%s", n); cleanup(0); } if (fchown(f, userid, -1) < 0) { - printf("%s: cannot chown %s\n", name, n); + warn("cannot chown %s", n); cleanup(0); /* cleanup does exit */ } seteuid(uid); if (++n[inchar] > 'z') { if (++n[inchar-2] == 't') { - printf("too many files - break up the job\n"); + warnx("too many files - break up the job"); cleanup(0); } n[inchar] = 'A'; } else if (n[inchar] == '[') n[inchar] = 'a'; - return(f); + return (f); } /* @@ -600,25 +597,25 @@ test(file) char *cp; if ((fd = open(file, O_RDONLY)) < 0) { - printf("%s: cannot open %s\n", name, file); + warn("cannot open %s\n", file); goto bad; } if (fstat(fd, &statb) < 0) { - printf("%s: cannot stat %s\n", name, file); + warn("cannot stat %s\n", file); goto bad; } if ((statb.st_mode & S_IFMT) == S_IFDIR) { - printf("%s: %s is a directory\n", name, file); + warnx("%s is a directory\n", file); goto bad; } if (statb.st_size == 0) { - printf("%s: %s is an empty file\n", name, file); + warnx("%s is an empty file\n", file); goto bad; } if (read(fd, &execb, sizeof(execb)) == sizeof(execb) && !N_BADMAG(execb)) { - printf("%s: %s is an executable program and is unprintable", - name, file); + warnx("%s is an executable program and is unprintable", + file); (void) close(fd); goto bad; } @@ -638,7 +635,7 @@ test(file) if (fd == 0) return(1); } - printf("%s: %s: is not removable by you\n", name, file); + warnx("%s is not removable by you", file); } return(0); bad: @@ -672,9 +669,9 @@ chkprinter(s) int status; if ((status = cgetent(&bp, printcapdb, s)) == -2) - fatal2("cannot open printer description file"); + errx(1, "cannot open printer description file"); else if (status == -1) - fatal2("%s: unknown printer", s); + errx(1, "%s: unknown printer", s); if (cgetstr(bp, "sd", &SD) == -1) SD = _PATH_DEFSPOOL; if (cgetstr(bp, "lo", &LO) == -1) @@ -702,14 +699,10 @@ mktemps() (void) snprintf(buf, sizeof(buf), "%s/.seq", SD); seteuid(euid); - if ((fd = open(buf, O_RDWR|O_CREAT, 0661)) < 0) { - printf("%s: cannot create %s\n", name, buf); - exit(1); - } - if (flock(fd, LOCK_EX)) { - printf("%s: cannot lock %s\n", name, buf); - exit(1); - } + if ((fd = open(buf, O_RDWR|O_CREAT, 0661)) < 0) + err(1, "cannot create %s", buf); + if (flock(fd, LOCK_EX)) + err(1, "cannot lock %s", buf); seteuid(uid); n = 0; if ((len = read(fd, buf, sizeof(buf))) > 0) { @@ -742,35 +735,7 @@ lmktemp(id, num, len) char *s; if ((s = malloc(len)) == NULL) - fatal2("out of memory"); + err(1, NULL); (void) snprintf(s, len, "%s/%sA%03d%s", SD, id, num, host); return(s); } - -#ifdef __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -static void -#ifdef __STDC__ -fatal2(const char *msg, ...) -#else -fatal2(msg, va_alist) - char *msg; - va_dcl -#endif -{ - va_list ap; -#ifdef __STDC__ - va_start(ap, msg); -#else - va_start(ap); -#endif - printf("%s: ", name); - vprintf(msg, ap); - putchar('\n'); - va_end(ap); - exit(1); -} diff --git a/usr.sbin/lpr/lprm/lprm.c b/usr.sbin/lpr/lprm/lprm.c index 838224a29ef..e94c43a0974 100644 --- a/usr.sbin/lpr/lprm/lprm.c +++ b/usr.sbin/lpr/lprm/lprm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lprm.c,v 1.8 2001/11/23 03:58:18 deraadt Exp $ */ +/* $OpenBSD: lprm.c,v 1.9 2001/12/06 03:12:31 ericj Exp $ */ /* * Copyright (c) 1983, 1993 @@ -44,7 +44,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lprm.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: lprm.c,v 1.8 2001/11/23 03:58:18 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: lprm.c,v 1.9 2001/12/06 03:12:31 ericj Exp $"; #endif #endif /* not lint */ @@ -99,7 +99,7 @@ main(argc, argv) uid = getuid(); euid = geteuid(); seteuid(uid); /* be safe */ - name = argv[0]; + gethostname(host, sizeof(host)); openlog("lpd", 0, LOG_LPR); if ((p = getpwuid(getuid())) == NULL) |