From owner-freebsd-bugs@FreeBSD.ORG Thu May 22 01:10:01 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6CB6F7F8 for ; Thu, 22 May 2014 01:10:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4BC7D23E3 for ; Thu, 22 May 2014 01:10:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s4M1A0iQ000743 for ; Thu, 22 May 2014 01:10:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s4M1A0oC000742; Thu, 22 May 2014 01:10:00 GMT (envelope-from gnats) Date: Thu, 22 May 2014 01:10:00 GMT Message-Id: <201405220110.s4M1A0oC000742@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Wim Lewis Subject: Re: bin/181636: mtree(8): mtree -U does not fix ownership of symbolic links Reply-To: Wim Lewis X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 May 2014 01:10:01 -0000 The following reply was made to PR bin/181636; it has been noted by GNATS. From: Wim Lewis 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); } }