Date: Thu, 22 May 2014 01:10:00 GMT From: Wim Lewis <wiml@omnigroup.com> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/181636: mtree(8): mtree -U does not fix ownership of symbolic links Message-ID: <201405220110.s4M1A0oC000742@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/181636; it has been noted by GNATS. From: Wim Lewis <wiml@omnigroup.com> To: bug-followup@FreeBSD.org Cc: Subject: Re: bin/181636: mtree(8): mtree -U does not fix ownership of symbolic links Date: Wed, 21 May 2014 18:03:13 -0700 I've encountered this as well. I think the fix would be to change the = miss() function in verify.c to use lchown (and possibly = lchmod/lchflags?) instead of chown/chmod/chflags when p->type =3D=3D = F_LINK. It already uses lchown when *creating* the symlink, so this = would be a sensible symmetry. Something along the lines of the following = patch maybe: --- /usr/src/usr.sbin/mtree/verify.c 2012-12-03 13:22:44.000000000 = -0800 +++ verify.c 2014-05-21 18:00:04.000000000 -0700 @@ -155,6 +155,32 @@ return (rval); } =20 + +static void +pchown(NODE *p) +{ + if ((p->type =3D=3D F_LINK ? lchown : chown)(path, p->st_uid, = p->st_gid) =3D=3D -1) { + serr =3D errno; + if (p->st_uid =3D=3D (uid_t)-1) + what =3D "group"; + else if ((p->type =3D=3D F_LINK ? lchown : chown)(path, = (uid_t)-1, p->st_gid) =3D=3D -1) + what =3D "user & group"; + else { + what =3D "user"; + errno =3D serr; + } + (void)printf("%s: %s not modified: %s" + "\n", path, what, strerror(errno)); + } + if (p->type !=3D F_LINK && chmod(path, p->st_mode)) + (void)printf("%s: permissions not set: %s\n", + path, strerror(errno)); + if ((p->flags & F_FLAGS) && p->st_flags && + (p->type =3D=3D F_LINK ? lchflags : chflags)(path, = p->st_flags)) + (void)printf("%s: file flags not set: %s\n", + path, strerror(errno)); +} + static void miss(NODE *p, char *tail) { @@ -200,20 +226,7 @@ strerror(errno)); else (void)printf(" (created)\n"); - if (lchown(path, p->st_uid, p->st_gid) = =3D=3D -1) { - serr =3D errno; - if (p->st_uid =3D=3D (uid_t)-1) - what =3D "group"; - else if (lchown(path, (uid_t)-1, - p->st_gid) =3D=3D -1) - what =3D "user & group"; - else { - what =3D "user"; - errno =3D serr; - } - (void)printf("%s: %s not = modified: %s" - "\n", path, what, = strerror(errno)); - } + pchown(p); continue; } else if (!(p->flags & F_MODE)) (void)printf(" (directory not created: mode = not specified)"); @@ -235,25 +248,6 @@ =20 if (!create) continue; - if (chown(path, p->st_uid, p->st_gid) =3D=3D -1) { - serr =3D errno; - if (p->st_uid =3D=3D (uid_t)-1) - what =3D "group"; - else if (chown(path, (uid_t)-1, p->st_gid) =3D=3D = -1) - what =3D "user & group"; - else { - what =3D "user"; - errno =3D serr; - } - (void)printf("%s: %s not modified: %s\n", - path, what, 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)); + pchown(p); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405220110.s4M1A0oC000742>