[Pkg-shadow-devel] patch for usermod

Nicolas François nicolas.francois@centraliens.net
Thu, 16 Jun 2005 01:18:46 +0200


--KFztAG8eRSV9hGtP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello Tomasz,

Here is a patch for usermod.

When the home directory is changed, if the old directory was copied
successfully, it is removed with remove_tree(old_home) and rmdir(oldname).
But if one of them (remove_tree or rmdir) fails, the new home directory is
removed.

This can lead to an inconsistent user entry (no more valid old or new home
directory).

This patch should avoid this and issue an additional warning in the worst
case.

more info at: http://bugs.debian.org/166369

This patch adds a new message, so if you already sent translation
requests, you can delay it for 4.0.11. (just say if you will include it)

Kind regards,
-- 
Nekral

--KFztAG8eRSV9hGtP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=008_usermod_warn_old_home_not_removed

Goal: When relocating a user's home directory, don't fail and remove the new
      home directory if we can't remove the old home directory for some
      reason; the results can be spectularly poort if, for instance, only
      the rmdir() fails.
Fixes: #166369

Status wrt upstream: It could certainly be submitted to upstream.

Index: src/usermod.c
===================================================================
RCS file: /cvsroot/shadow/src/usermod.c,v
retrieving revision 1.39
diff -u -r1.39 usermod.c
--- src/usermod.c	25 May 2005 19:31:51 -0000	1.39
+++ src/usermod.c	15 Jun 2005 17:48:19 -0000
@@ -1071,9 +1071,14 @@
 				if (copy_tree (user_home, user_newhome,
 					       uflg ? user_newid : -1,
 					       gflg ? user_newgid : -1) ==
-				    0 && remove_tree (user_home) == 0
-				    && rmdir (user_home) == 0)
-					return;
+				    0) {
+				  if (remove_tree (user_home) != 0 ||
+				    rmdir (user_home) != 0)
+				    fprintf (stderr,
+					     _("%s: warning: failed to completely remove old home directory %s"),
+					     Prog, user_home);
+				  return;
+				}
 
 				(void) remove_tree (user_newhome);
 				(void) rmdir (user_newhome);

--KFztAG8eRSV9hGtP--