Bug 181636 - [patch] mtree(8): mtree -U does not fix ownership of symbolic links
Summary: [patch] mtree(8): mtree -U does not fix ownership of symbolic links
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.1-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-29 04:10 UTC by olivier.nicole
Modified: 2017-12-31 22:23 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description olivier.nicole 2013-08-29 04:10:00 UTC
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
.

.

#
Comment 1 wiml 2014-05-22 02:03:13 UTC
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);
 	}
 }
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:25 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped