From 4ac2ef542b0092f13ae7e51a5f79917ae7026d85 Mon Sep 17 00:00:00 2001 From: "Rodney W. Grimes" Date: Sun, 9 Oct 1994 20:28:31 +0000 Subject: [PATCH] Add -U option which does the same things as -u except exits with 0 instead of 2 on MISMATCH. --- usr.sbin/mtree/mtree.8 | 14 ++++++++++++-- usr.sbin/mtree/mtree.c | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/usr.sbin/mtree/mtree.8 b/usr.sbin/mtree/mtree.8 index e8a4cb29a82..92c65a4cafc 100644 --- a/usr.sbin/mtree/mtree.8 +++ b/usr.sbin/mtree/mtree.8 @@ -39,7 +39,7 @@ .Nd map a directory hierarchy .Sh SYNOPSIS .Nm mtree -.Op Fl cdeinrux +.Op Fl cdeinrUux .Op Fl f Ar spec .Op Fl K Ar keywords .Op Fl k Ar keywords @@ -100,11 +100,18 @@ of the files for which the keyword .Cm cksum was specified. The checksum is seeded with the specified value. -.It Fl u +.It Fl U Modify the owner, group, and permissions of existing files to match the specification and create any missing directories. User, group, and permissions must all be specified for missing directories to be created. +Exit with a status of 0 on success, 1 if any error occurred, +a mismatch is not considered an error if it was corrected. +.It Fl u +Same as +.Fl U +except a status of 2 is returned if the file hierarchy did not match +the specification. .It Fl x Don't descend below mount points in the file hierarchy. .El @@ -218,6 +225,9 @@ The .Nm mtree 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 +.Fl U +option is used. .Sh EXAMPLES To detect system binaries that have been ``trojan horsed'', it is recommended that diff --git a/usr.sbin/mtree/mtree.c b/usr.sbin/mtree/mtree.c index 9f5aad68aeb..349dbb9d34f 100644 --- a/usr.sbin/mtree/mtree.c +++ b/usr.sbin/mtree/mtree.c @@ -53,7 +53,7 @@ static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93"; extern long int crc_total; int ftsoptions = FTS_PHYSICAL; -int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag; +int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag; u_short keys; char fullpath[MAXPATHLEN]; @@ -68,10 +68,11 @@ main(argc, argv) extern char *optarg; int ch; char *dir, *p; + int status; dir = NULL; keys = KEYDEFAULT; - while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:ux")) != EOF) + while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != EOF) switch((char)ch) { case 'c': cflag = 1; @@ -114,6 +115,10 @@ main(argc, argv) crc_total = ~strtol(optarg, &p, 0); if (*p) err("illegal seed value -- %s", optarg); + case 'U': + Uflag = 1; + uflag = 1; + break; case 'u': uflag = 1; break; @@ -140,13 +145,16 @@ main(argc, argv) cwalk(); exit(0); } - exit(verify()); + status = verify(); + if (Uflag & (status == MISMATCHEXIT)) + status = 0; + exit(status); } static void usage() { (void)fprintf(stderr, -"usage: mtree [-cdeinrux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); +"usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); exit(1); }