From nobody@FreeBSD.org  Thu Aug 29 03:02:33 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id BB4961DE
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 29 Aug 2013 03:02:33 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 90D462C39
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 29 Aug 2013 03:02:33 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r7T32W0A012448
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 29 Aug 2013 03:02:32 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r7T32WTV012445;
	Thu, 29 Aug 2013 03:02:32 GMT
	(envelope-from nobody)
Message-Id: <201308290302.r7T32WTV012445@oldred.freebsd.org>
Date: Thu, 29 Aug 2013 03:02:32 GMT
From: Olivier <olivier.nicole@cs.ait.ac.th>
To: freebsd-gnats-submit@FreeBSD.org
Subject: mtree -U does not fix ownership of symbolic links
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181636
>Category:       bin
>Synopsis:       [patch] mtree(8): mtree -U does not fix ownership of symbolic links
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 29 03:10:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Thu May 22 03:37:17 UTC 2014
>Originator:     Olivier
>Release:        9.1-RELEASE-p4
>Organization:
Asian Institute of Technology
>Environment:
FreeBSD banyan.cs.ait.ac.th 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #2: Fri Aug 23 10:03:44 ICT 2013     root@banyan.cs.ait.ac.th:/usr/obj/usr/src/sys/CSIM  amd64
>Description:
When using mtree -U to change the ownership and group of a hierarchy of users files, I found that symbolic links are not updated.

In the following example, I tried various combination of -L and -P for mtree.

206:30 are the old ownership and group; 4096:5030 (on:csimstaff) are the new ones.


>How-To-Repeat:
# ls -lisag
total 24
209553013 8 drwxr-xr-x  3 206  30         512 Aug 29 09:57 .
209553011 8 drwxr-xr-x  3 on   csimstaff  512 Aug 29 09:40 ..
209553068 8 drwxr-xr-x  2 206  30         512 Aug 29 09:57 dir
209553074 0 lrwxr-xr-x  1 206  30           3 Aug 29 09:57 dirlink -> dir
209553065 0 -rw-r--r--  1 206  30           0 Aug 29 09:37 file
209553067 0 lrwxr-xr-x  1 206  30           4 Aug 29 09:38 filelink -> file
# mtree -U -f ../mtree.file
. changed
        user expected 4096 found 206 modified
        gid expected 5030 found 30 modified
dir changed
        user expected 4096 found 206 modified
        gid expected 5030 found 30 modified
dirlink changed
        user expected 4096 found 206 modified
        gid expected 5030 found 30 modified
file changed
        user expected 4096 found 206 modified
        gid expected 5030 found 30 modified
# ls -lisag
total 24
209553013 8 drwxr-xr-x  3 on   csimstaff  512 Aug 29 09:57 .
209553011 8 drwxr-xr-x  3 on   csimstaff  512 Aug 29 09:40 ..
209553068 8 drwxr-xr-x  2 on   csimstaff  512 Aug 29 09:57 dir
209553074 0 lrwxr-xr-x  1 206  30           3 Aug 29 09:57 dirlink -> dir
209553065 0 -rw-r--r--  1 on   csimstaff    0 Aug 29 09:37 file
209553067 0 lrwxr-xr-x  1 206  30           4 Aug 29 09:38 filelink -> file
# more ../mtree.file
#          user: on
#       machine: banyan.cs.ait.ac.th
#          tree: /home/java/on/Mtree/dir
#          date: Thu Aug 29 09:58:26 2013

# .
/set type=file uid=4096 gid=30 mode=0755 nlink=1 flags=none
.               type=dir gid=5030 nlink=3 size=512 \
                time=1377745075.000000000
    dirlink     type=link gid=5030 size=3 time=1377745073.000000000 \
                link=dir
    file        gid=5030 mode=0644 size=0 time=1377743843.000000000
    filelink    type=link uid=206 size=4 time=1377743896.000000000 \
                link=file

# ./dir
dir             type=dir gid=5030 nlink=2 size=512 \
                time=1377745068.000000000
# ./dir
.

.

# 
>Fix:


>Release-Note:
>Audit-Trail:

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);
  	}
  }
 
 
 
>Unformatted:
