Blame SOURCES/shadow-4.1.5.1-chgrp-guard.patch

9b7f02
diff -up shadow-4.1.5.1/man/usermod.8.xml.chgrp-guard shadow-4.1.5.1/man/usermod.8.xml
9b7f02
--- shadow-4.1.5.1/man/usermod.8.xml.chgrp-guard	2016-05-04 13:44:17.267917583 +0200
9b7f02
+++ shadow-4.1.5.1/man/usermod.8.xml	2016-05-04 13:44:17.284917968 +0200
9b7f02
@@ -198,6 +198,12 @@
9b7f02
 	    The group ownership of files outside of the user's home directory
9b7f02
 	    must be fixed manually.
9b7f02
 	  </para>
9b7f02
+	  <para>
9b7f02
+	    The change of the group ownership of files inside of the user's
9b7f02
+	    home directory is also not done if the home dir owner uid is
9b7f02
+	    different from the current or new user id. This is safety measure
9b7f02
+	    for special home directories such as <filename>/</filename>.
9b7f02
+	  </para>
9b7f02
 	</listitem>
9b7f02
       </varlistentry>
9b7f02
       <varlistentry>
9b7f02
@@ -364,6 +370,12 @@
9b7f02
 	    must be fixed manually.
9b7f02
 	  </para>
9b7f02
 	  <para>
9b7f02
+	    The change of the user ownership of files inside of the user's
9b7f02
+	    home directory is also not done if the home dir owner uid is
9b7f02
+	    different from the current or new user id. This is safety measure
9b7f02
+	    for special home directories such as <filename>/</filename>.
9b7f02
+	  </para>
9b7f02
+	  <para>
9b7f02
 	    No checks will be performed with regard to the
9b7f02
 	    <option>UID_MIN</option>, <option>UID_MAX</option>,
9b7f02
 	    <option>SYS_UID_MIN</option>, or <option>SYS_UID_MAX</option>
9b7f02
diff -up shadow-4.1.5.1/src/usermod.c.chgrp-guard shadow-4.1.5.1/src/usermod.c
9b7f02
--- shadow-4.1.5.1/src/usermod.c.chgrp-guard	2016-05-04 13:44:17.280917877 +0200
9b7f02
+++ shadow-4.1.5.1/src/usermod.c	2016-05-04 13:44:17.285917991 +0200
9b7f02
@@ -1971,7 +1971,10 @@ int main (int argc, char **argv)
9b7f02
 	}
9b7f02
 
9b7f02
 	if (!mflg && (uflg || gflg)) {
9b7f02
-		if (access (dflg ? user_newhome : user_home, F_OK) == 0) {
9b7f02
+		struct stat sb;
9b7f02
+
9b7f02
+		if (stat (dflg ? user_newhome : user_home, &sb) == 0 &&
9b7f02
+			((uflg && sb.st_uid == user_newid) || sb.st_uid == user_id)) {
9b7f02
 			/*
9b7f02
 			 * Change the UID on all of the files owned by
9b7f02
 			 * `user_id' to `user_newid' in the user's home