Date: Mon, 14 Apr 2003 17:41:26 +0200 (CEST) From: Rene de Vries <rene@tunix.nl> To: FreeBSD-gnats-submit@FreeBSD.org Cc: robert@FreeBSD.org Subject: bin/50949: BUG: mtree doesn't honor the -P when checking/changing ownership Message-ID: <200304141541.h3EFfQQZ072931@upsilix.tunix.nl> Resent-Message-ID: <200304141550.h3EFo1oj005227@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 50949 >Category: bin >Synopsis: BUG: mtree doesn't honor the -P when checking/changing ownership >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 14 08:50:01 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Rene de Vries >Release: FreeBSD 4.7-RELEASE-p3 i386/FreeBSD 5.0-20030401 i386 >Organization: Tunix Internet Security & Training >Environment: >Description: Symlinks are not always taken into account when -P is used. >How-To-Repeat: >Fix: Files: usr.sbin/mtree/compare.c usr.sbin/mtree/verify.c Diff against FreeBSD 5 (current as of 01 Apr 2003): Index: usr.sbin/mtree/compare.c =================================================================== RCS file: /home/fbsd-cvsrepo/src/usr.sbin/mtree/compare.c,v retrieving revision 1.25 diff -u -r1.25 compare.c --- usr.sbin/mtree/compare.c 13 Mar 2003 23:35:30 -0000 1.25 +++ usr.sbin/mtree/compare.c 1 Apr 2003 14:34:12 -0000 @@ -63,6 +63,7 @@ extern int uflag; extern int lineno; +extern int ftsoptions; static const char *ftype(u_int); @@ -127,11 +128,19 @@ (void)printf("%suser expected %lu found %lu", tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid); if (uflag) - if (chown(p->fts_accpath, s->st_uid, -1)) - (void)printf(" not modified: %s\n", - strerror(errno)); - else - (void)printf(" modified\n"); + if (ftsoptions & FTS_PHYSICAL) { + if (lchown(p->fts_accpath, s->st_uid, -1)) + (void)printf(" not modified: %s\n", + strerror(errno)); + else + (void)printf(" modified\n"); + } else { + if (chown(p->fts_accpath, s->st_uid, -1)) + (void)printf(" not modified: %s\n", + strerror(errno)); + else + (void)printf(" modified\n"); + } else (void)printf("\n"); tab = "\t"; @@ -141,11 +150,19 @@ (void)printf("%sgid expected %lu found %lu", tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid); if (uflag) - if (chown(p->fts_accpath, -1, s->st_gid)) - (void)printf(" not modified: %s\n", - strerror(errno)); - else - (void)printf(" modified\n"); + if (ftsoptions & FTS_PHYSICAL) { + if (lchown(p->fts_accpath, -1, s->st_gid)) + (void)printf(" not modified: %s\n", + strerror(errno)); + else + (void)printf(" modified\n"); + } else { + if (chown(p->fts_accpath, -1, s->st_gid)) + (void)printf(" not modified: %s\n", + strerror(errno)); + else + (void)printf(" modified\n"); + } else (void)printf("\n"); tab = "\t"; @@ -157,11 +174,19 @@ (void)printf("%spermissions expected %#o found %#o", tab, s->st_mode, p->fts_statp->st_mode & MBITS); if (uflag) - if (chmod(p->fts_accpath, s->st_mode)) - (void)printf(" not modified: %s\n", - strerror(errno)); - else - (void)printf(" modified\n"); + if (ftsoptions & FTS_PHYSICAL) { + if (lchmod(p->fts_accpath, s->st_mode)) + (void)printf(" not modified: %s\n", + strerror(errno)); + else + (void)printf(" modified\n"); + } else { + if (chmod(p->fts_accpath, s->st_mode)) + (void)printf(" not modified: %s\n", + strerror(errno)); + else + (void)printf(" modified\n"); + } else (void)printf("\n"); tab = "\t"; Index: usr.sbin/mtree/verify.c =================================================================== RCS file: /home/fbsd-cvsrepo/src/usr.sbin/mtree/verify.c,v retrieving revision 1.18 diff -u -r1.18 verify.c --- usr.sbin/mtree/verify.c 13 Mar 2003 23:35:30 -0000 1.18 +++ usr.sbin/mtree/verify.c 1 Apr 2003 14:34:12 -0000 @@ -226,19 +226,36 @@ if (!create) continue; - if (chown(path, p->st_uid, p->st_gid)) { - (void)printf("%s: user/group/mode not modified: %s\n", - path, strerror(errno)); - (void)printf("%s: warning: file mode %snot set\n", path, - (p->flags & F_FLAGS) ? "and file flags " : ""); - continue; + if (ftsoptions & FTS_PHYSICAL) { + if (lchown(path, p->st_uid, p->st_gid)) { + (void)printf("%s: user/group/mode not modified: %s\n", + path, strerror(errno)); + (void)printf("%s: warning: file mode %snot set\n", path, + (p->flags & F_FLAGS) ? "and file flags " : ""); + continue; + } + if (lchmod(path, p->st_mode)) + (void)printf("%s: permissions not set: %s\n", + path, strerror(errno)); + if ((p->flags & F_FLAGS) && p->st_flags && + chflags(path, p->st_flags)) + (void)printf("%s: file flags not set: %s\n", + path, strerror(errno)); + } else { + if (chown(path, p->st_uid, p->st_gid)) { + (void)printf("%s: user/group/mode not modified: %s\n", + path, strerror(errno)); + (void)printf("%s: warning: file mode %snot set\n", path, + (p->flags & F_FLAGS) ? "and file flags " : ""); + continue; + } + if (chmod(path, p->st_mode)) + (void)printf("%s: permissions not set: %s\n", + path, strerror(errno)); + if ((p->flags & F_FLAGS) && p->st_flags && + chflags(path, p->st_flags)) + (void)printf("%s: file flags not set: %s\n", + path, strerror(errno)); } - if (chmod(path, p->st_mode)) - (void)printf("%s: permissions not set: %s\n", - path, strerror(errno)); - if ((p->flags & F_FLAGS) && p->st_flags && - chflags(path, p->st_flags)) - (void)printf("%s: file flags not set: %s\n", - path, strerror(errno)); } } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304141541.h3EFfQQZ072931>