diff options
author | charnier <charnier@FreeBSD.org> | 1997-10-01 06:30:02 +0000 |
---|---|---|
committer | charnier <charnier@FreeBSD.org> | 1997-10-01 06:30:02 +0000 |
commit | c8ef4a7a48d8f5d12953d95267505428c7f529f0 (patch) | |
tree | 652d4b08e3d4b8184e9130c4f56d427b5c60029c /usr.sbin | |
parent | 9e9c06cc6a32be0e300ed8612438b503e0b8998e (diff) | |
download | FreeBSD-src-c8ef4a7a48d8f5d12953d95267505428c7f529f0.zip FreeBSD-src-c8ef4a7a48d8f5d12953d95267505428c7f529f0.tar.gz |
Use err(3) instead of local redefinition.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/mtree/compare.c | 12 | ||||
-rw-r--r-- | usr.sbin/mtree/create.c | 48 | ||||
-rw-r--r-- | usr.sbin/mtree/extern.h | 1 | ||||
-rw-r--r-- | usr.sbin/mtree/misc.c | 46 | ||||
-rw-r--r-- | usr.sbin/mtree/mtree.8 | 34 | ||||
-rw-r--r-- | usr.sbin/mtree/mtree.c | 21 | ||||
-rw-r--r-- | usr.sbin/mtree/spec.c | 59 | ||||
-rw-r--r-- | usr.sbin/mtree/verify.c | 18 |
8 files changed, 125 insertions, 114 deletions
diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index efe2429..72b00b9 100644 --- a/usr.sbin/mtree/compare.c +++ b/usr.sbin/mtree/compare.c @@ -32,22 +32,28 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> +#include <err.h> +#include <errno.h> #include <fcntl.h> #include <fts.h> -#include <errno.h> +#include <md5.h> #include <stdio.h> #include <time.h> #include <unistd.h> -#include <md5.h> #include "mtree.h" #include "extern.h" extern int uflag; +extern int lineno; static char *ftype __P((u_int)); @@ -283,7 +289,7 @@ rlink(name) register int len; if ((len = readlink(name, lbuf, sizeof(lbuf))) == -1) - err("%s: %s", name, strerror(errno)); + err(1, "line %d: %s", lineno, name); lbuf[len] = '\0'; return (lbuf); } diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c index 44ee411..2638e2a 100644 --- a/usr.sbin/mtree/create.c +++ b/usr.sbin/mtree/create.c @@ -32,21 +32,26 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> -#include <time.h> +#include <dirent.h> +#include <err.h> +#include <errno.h> #include <fcntl.h> #include <fts.h> -#include <dirent.h> #include <grp.h> +#include <md5.h> #include <pwd.h> -#include <errno.h> -#include <unistd.h> #include <stdio.h> -#include <md5.h> +#include <time.h> +#include <unistd.h> #include "mtree.h" #include "extern.h" @@ -58,6 +63,7 @@ extern int ftsoptions; extern int dflag, iflag, nflag, sflag; extern u_short keys; extern char fullpath[MAXPATHLEN]; +extern int lineno; static gid_t gid; static uid_t uid; @@ -86,7 +92,7 @@ cwalk() argv[0] = "."; argv[1] = NULL; if ((t = fts_open(argv, ftsoptions, dsort)) == NULL) - err("fts_open: %s", strerror(errno)); + err(1, "line %d: fts_open", lineno); while ((p = fts_read(t))) { if (iflag) indent = p->fts_level * 4; @@ -109,8 +115,7 @@ cwalk() case FTS_DNR: case FTS_ERR: case FTS_NS: - (void)fprintf(stderr, "mtree: %s: %s\n", - p->fts_path, strerror(p->fts_errno)); + warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); break; default: if (!dflag) @@ -121,8 +126,7 @@ cwalk() } (void)fts_close(t); if (sflag && keys & F_CKSUM) - (void)fprintf(stderr, - "mtree: %s checksum: %lu\n", fullpath, crc_total); + warnx("%s checksum: %lu", fullpath, crc_total); } static void @@ -152,8 +156,9 @@ statf(indent, p) if ((pw = getpwuid(p->fts_statp->st_uid)) != NULL) { output(indent, &offset, "uname=%s", pw->pw_name); } else { - err("could not get uname for uid=%u", - p->fts_statp->st_uid); + errx(1, + "line %d: could not get uname for uid=%u", + lineno, p->fts_statp->st_uid); } } if (keys & F_UID) @@ -164,8 +169,9 @@ statf(indent, p) if ((gr = getgrgid(p->fts_statp->st_gid)) != NULL) { output(indent, &offset, "gname=%s", gr->gr_name); } else { - err("could not get gname for gid=%u", - p->fts_statp->st_gid); + errx(1, + "line %d: could not get gname for gid=%u", + lineno, p->fts_statp->st_gid); } } if (keys & F_GID) @@ -184,7 +190,7 @@ statf(indent, p) if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) - err("%s: %s", p->fts_accpath, strerror(errno)); + err(1, "line %d: %s", lineno, p->fts_accpath); (void)close(fd); output(indent, &offset, "cksum=%lu", val); } @@ -193,7 +199,7 @@ statf(indent, p) md5digest = MD5File(p->fts_accpath,buf); if (!md5digest) { - err("%s: %s", p->fts_accpath, strerror(errno)); + err(1, "line %d: %s", lineno, p->fts_accpath); } else { output(indent, &offset, "md5digest=%s", md5digest); } @@ -230,7 +236,7 @@ statd(t, parent, puid, pgid, pmode) if ((p = fts_children(t, 0)) == NULL) { if (errno) - err("%s: %s", RP(parent), strerror(errno)); + err(1, "line %d: %s", lineno, RP(parent)); return (1); } @@ -275,14 +281,18 @@ statd(t, parent, puid, pgid, pmode) if ((pw = getpwuid(saveuid)) != NULL) (void)printf(" uname=%s", pw->pw_name); else - err("could not get uname for uid=%u", saveuid); + errx(1, + "line %d: could not get uname for uid=%u", + lineno, saveuid); if (keys & F_UID) (void)printf(" uid=%lu", saveuid); if (keys & F_GNAME) if ((gr = getgrgid(savegid)) != NULL) (void)printf(" gname=%s", gr->gr_name); else - err("could not get gname for gid=%u", savegid); + errx(1, + "line %d: could not get gname for gid=%u", + lineno, savegid); if (keys & F_GID) (void)printf(" gid=%lu", savegid); if (keys & F_MODE) diff --git a/usr.sbin/mtree/extern.h b/usr.sbin/mtree/extern.h index 72c5dbc..f3b6230 100644 --- a/usr.sbin/mtree/extern.h +++ b/usr.sbin/mtree/extern.h @@ -36,7 +36,6 @@ int compare __P((char *, NODE *, FTSENT *)); int crc __P((int, u_long *, u_long *)); void cwalk __P((void)); -void err __P((const char *, ...)); char *inotype __P((u_int)); u_int parsekey __P((char *, int *)); char *rlink __P((char *)); diff --git a/usr.sbin/mtree/misc.c b/usr.sbin/mtree/misc.c index b40df49..093265c 100644 --- a/usr.sbin/mtree/misc.c +++ b/usr.sbin/mtree/misc.c @@ -29,12 +29,19 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)misc.c 8.1 (Berkeley) 6/6/93 */ +#ifndef lint +#if 0 +static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; +#endif /*not lint */ + #include <sys/types.h> #include <sys/stat.h> +#include <err.h> #include <fts.h> #include <stdio.h> #include "mtree.h" @@ -79,7 +86,7 @@ parsekey(name, needvaluep) k = (KEY *)bsearch(&tmp, keylist, sizeof(keylist) / sizeof(KEY), sizeof(KEY), keycompare); if (k == NULL) - err("unknown keyword %s", name); + errx(1, "line %d: unknown keyword %s", lineno, name); if (needvaluep) *needvaluep = k->flags & NEEDVALUE ? 1 : 0; @@ -92,36 +99,3 @@ keycompare(a, b) { return (strcmp(((KEY *)a)->name, ((KEY *)b)->name)); } - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -void -#if __STDC__ -err(const char *fmt, ...) -#else -err(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fflush(NULL); - (void)fprintf(stderr, "\nmtree: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - if (lineno) - (void)fprintf(stderr, - "mtree: failed at line %d of the specification\n", lineno); - exit(1); - /* NOTREACHED */ -} diff --git a/usr.sbin/mtree/mtree.8 b/usr.sbin/mtree/mtree.8 index dcc8370..8fedd94 100644 --- a/usr.sbin/mtree/mtree.8 +++ b/usr.sbin/mtree/mtree.8 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)mtree.8 8.2 (Berkeley) 12/11/93 -.\" $Id$ +.\" $Id: mtree.8,v 1.10 1997/02/22 16:07:52 peter Exp $ .\" .Dd February 9, 1995 .Dt MTREE 8 @@ -64,38 +64,40 @@ Ignore everything except directory type files. .It Fl e Don't complain about files that are in the file hierarchy, but not in the specification. -.It Fl f +.It Fl f Ar file Read the specification from .Ar file , instead of from the standard input. .It Fl i -Indents the output 4 spaces each time a directory level is descended when +Indent the output 4 spaces each time a directory level is descended when create a specification with the .Fl c option. This does not effect either the /set statements or the comment before each directory. It does however effect the comment before the close of each directory. -.It Fl K -Add the specified (whitespace or comma separated) keywords to the current -set of keywords. -.It Fl k +.It Fl K Ar keywords +Add the specified (whitespace or comma separated) +.Ar keywords +to the current set of keywords. +.It Fl k Ar keywords Use the ``type'' keyword plus the specified (whitespace or comma separated) -keywords instead of the current set of keywords. +.Ar keywords +instead of the current set of keywords. .It Fl n Do not emit pathname comments when creating a specification. Normally a comment is emitted before each directory and before the close of that directory when using the .Fl c option. -.It Fl p +.It Fl p Ar path Use the file hierarchy rooted in .Ar path , instead of the current directory. .It Fl r Remove any files in the file hierarchy that are not described in the specification. -.It Fl s +.It Fl s Ar seed Display a single checksum to the standard error output that represents all of the files for which the keyword .Cm cksum @@ -225,7 +227,7 @@ Empty lines and lines whose first non-whitespace character is a hash mark (``#'') are ignored. .Pp The -.Nm mtree +.Nm utility exits with a status of 0 on success, 1 if any error occurred, and 2 if the file hierarchy did not match the specification. A status of 2 is converted to a status of 0 if the @@ -234,7 +236,7 @@ option is used. .Sh EXAMPLES To detect system binaries that have been ``trojan horsed'', it is recommended that -.Nm mtree +.Nm .Fl K .Cm md5digest be run on the file systems, and a copy of the results stored on a different @@ -243,7 +245,7 @@ The output file itself should be digested using the .Xr md5 1 utility. Then, periodically, -.Nm mtree +.Nm and .Xr md5 1 should be run against the on-line specifications. @@ -278,11 +280,11 @@ system specification directory .Xr chown 8 .Sh HISTORY The -.Nm mtree +.Nm utility appeared in .Bx 4.3 Reno . The MD5 digest capability was added in -.Tn FreeBSD -2.1, in response to the widespread use of programs which can spoof +.Fx 2.1 , +in response to the widespread use of programs which can spoof .Xr cksum 1 . diff --git a/usr.sbin/mtree/mtree.c b/usr.sbin/mtree/mtree.c index 67e476c..cf61a9b 100644 --- a/usr.sbin/mtree/mtree.c +++ b/usr.sbin/mtree/mtree.c @@ -32,21 +32,26 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1989, 1990, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> +#include <err.h> #include <errno.h> -#include <unistd.h> -#include <stdio.h> #include <fts.h> +#include <stdio.h> +#include <unistd.h> #include "mtree.h" #include "extern.h" @@ -64,8 +69,6 @@ main(argc, argv) int argc; char *argv[]; { - extern int optind; - extern char *optarg; int ch; char *dir, *p; int status; @@ -85,7 +88,7 @@ main(argc, argv) break; case 'f': if (!(freopen(optarg, "r", stdin))) - err("%s: %s", optarg, strerror(errno)); + err(1, "%s", optarg); break; case 'i': iflag = 1; @@ -114,7 +117,7 @@ main(argc, argv) sflag = 1; crc_total = ~strtol(optarg, &p, 0); if (*p) - err("illegal seed value -- %s", optarg); + errx(1, "illegal seed value -- %s", optarg); case 'U': Uflag = 1; uflag = 1; @@ -136,10 +139,10 @@ main(argc, argv) usage(); if (dir && chdir(dir)) - err("%s: %s", dir, strerror(errno)); + err(1, "%s", dir); if ((cflag || sflag) && !getwd(fullpath)) - err("%s", fullpath); + errx(1, "%s", fullpath); if (cflag) { cwalk(); diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 7ab6cf8..77f54b1 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -32,18 +32,23 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/types.h> #include <sys/stat.h> +#include <ctype.h> +#include <err.h> +#include <errno.h> #include <fts.h> -#include <pwd.h> #include <grp.h> -#include <errno.h> -#include <unistd.h> +#include <pwd.h> #include <stdio.h> -#include <ctype.h> +#include <unistd.h> #include "mtree.h" #include "extern.h" @@ -72,7 +77,7 @@ spec() /* Find end of line. */ if ((p = index(buf, '\n')) == NULL) - err("line %d too long", lineno); + errx(1, "line %d too long", lineno); /* See if next line is continuation line. */ if (p[-1] == '\\') { @@ -100,7 +105,7 @@ spec() /* Grab file name, "$", "set", or "unset". */ if ((p = strtok(p, "\n\t ")) == NULL) - err("missing field"); + errx(1, "line %d: missing field", lineno); if (p[0] == '/') switch(p[1]) { @@ -117,7 +122,8 @@ spec() } if (index(p, '/')) - err("slash character in file name"); + errx(1, "line %d: slash character in file name", + lineno); if (!strcmp(p, "..")) { /* Don't go up, if haven't gone down. */ @@ -131,11 +137,11 @@ spec() last->flags |= F_DONE; continue; -noparent: err("no parent node"); +noparent: errx(1, "line %d: no parent node", lineno); } if ((centry = calloc(1, sizeof(NODE) + strlen(p))) == NULL) - err("%s", strerror(errno)); + errx(1, "calloc"); *centry = ginfo; (void)strcpy(centry->name, p); #define MAGIC "?*[" @@ -174,27 +180,28 @@ set(t, ip) for (; (kw = strtok(t, "= \t\n")); t = NULL) { ip->flags |= type = parsekey(kw, &value); if (value && (val = strtok(NULL, " \t\n")) == NULL) - err("missing value"); + errx(1, "line %d: missing value", lineno); switch(type) { case F_CKSUM: ip->cksum = strtoul(val, &ep, 10); if (*ep) - err("invalid checksum %s", val); + errx(1, "line %d: invalid checksum %s", + lineno, val); break; case F_MD5: ip->md5digest = strdup(val); if(!ip->md5digest) { - err("%s", strerror(errno)); + errx(1, "strdup"); } break; case F_GID: ip->st_gid = strtoul(val, &ep, 10); if (*ep) - err("invalid gid %s", val); + errx(1, "line %d: invalid gid %s", lineno, val); break; case F_GNAME: if ((gr = getgrnam(val)) == NULL) - err("unknown group %s", val); + errx(1, "line %d: unknown group %s", lineno, val); ip->st_gid = gr->gr_gid; break; case F_IGN: @@ -202,31 +209,36 @@ set(t, ip) break; case F_MODE: if ((m = setmode(val)) == NULL) - err("invalid file mode %s", val); + errx(1, "line %d: invalid file mode %s", + lineno, val); ip->st_mode = getmode(m, 0); break; case F_NLINK: ip->st_nlink = strtoul(val, &ep, 10); if (*ep) - err("invalid link count %s", val); + errx(1, "line %d: invalid link count %s", + lineno, val); break; case F_SIZE: ip->st_size = strtoq(val, &ep, 10); if (*ep) - err("invalid size %s", val); + errx(1, "line %d: invalid size %s", + lineno, val); break; case F_SLINK: if ((ip->slink = strdup(val)) == NULL) - err("%s", strerror(errno)); + errx(1, "strdup"); break; case F_TIME: ip->st_mtimespec.tv_sec = strtoul(val, &ep, 10); if (*ep != '.') - err("invalid time %s", val); + errx(1, "line %d: invalid time %s", + lineno, val); val = ep + 1; ip->st_mtimespec.tv_nsec = strtoul(val, &ep, 10); if (*ep) - err("invalid time %s", val); + errx(1, "line %d: invalid time %s", + lineno, val); break; case F_TYPE: switch(*val) { @@ -257,17 +269,18 @@ set(t, ip) ip->type = F_SOCK; break; default: - err("unknown file type %s", val); + errx(1, "line %d: unknown file type %s", + lineno, val); } break; case F_UID: ip->st_uid = strtoul(val, &ep, 10); if (*ep) - err("invalid uid %s", val); + errx(1, "line %d: invalid uid %s", lineno, val); break; case F_UNAME: if ((pw = getpwnam(val)) == NULL) - err("unknown user %s", val); + errx(1, "line %d: unknown user %s", lineno, val); ip->st_uid = pw->pw_uid; break; } diff --git a/usr.sbin/mtree/verify.c b/usr.sbin/mtree/verify.c index e435eb0..6610d3a 100644 --- a/usr.sbin/mtree/verify.c +++ b/usr.sbin/mtree/verify.c @@ -32,17 +32,22 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> #include <dirent.h> +#include <err.h> +#include <errno.h> #include <fts.h> #include <fnmatch.h> -#include <unistd.h> -#include <errno.h> #include <stdio.h> +#include <unistd.h> #include "mtree.h" #include "extern.h" @@ -50,6 +55,7 @@ extern long int crc_total; extern int ftsoptions; extern int dflag, eflag, rflag, sflag, uflag; extern char fullpath[MAXPATHLEN]; +extern int lineno; static NODE *root; static char path[MAXPATHLEN]; @@ -80,7 +86,7 @@ vwalk() argv[0] = "."; argv[1] = NULL; if ((t = fts_open(argv, ftsoptions, NULL)) == NULL) - err("fts_open: %s", strerror(errno)); + err(1, "line %d: fts_open", lineno); level = root; specdepth = rval = 0; while ((p = fts_read(t))) { @@ -97,8 +103,7 @@ vwalk() case FTS_DNR: case FTS_ERR: case FTS_NS: - (void)fprintf(stderr, "mtree: %s: %s\n", - RP(p), strerror(p->fts_errno)); + warnx("%s: %s", RP(p), strerror(p->fts_errno)); continue; default: if (dflag) @@ -143,8 +148,7 @@ extra: } (void)fts_close(t); if (sflag) - (void)fprintf(stderr, - "mtree: %s checksum: %lu\n", fullpath, crc_total); + warnx("%s checksum: %lu", fullpath, crc_total); return (rval); } |