From d51420bb010a57f127ce3b1c12fdabcea66cddca Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Thu, 14 Jul 2011 13:29:05 +0000 Subject: [PATCH] * src/usermod.c (move_home): It is always an error to use -m if the new home directory already exist (independently from the existence of the old home directory did not exist) --- ChangeLog | 3 +++ src/usermod.c | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index cef066fa..1329c268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2011-07-14 Nicolas François * src/usermod.c: Fix typo in comment. + * src/usermod.c (move_home): It is always an error to use -m if + the new home directory already exist (independently from the + existence of the old home directory did not exist) 2011-07-08 Nicolas François diff --git a/src/usermod.c b/src/usermod.c index cd63089a..eaf578a4 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -1408,18 +1408,18 @@ static void move_home (void) { struct stat sb; - if (stat (user_home, &sb) == 0) { + if (access (user_newhome, F_OK) == 0) { /* * If the new home directory already exist, the user * should not use -m. */ - if (access (user_newhome, F_OK) == 0) { - fprintf (stderr, - _("%s: directory %s exists\n"), - Prog, user_newhome); - fail_exit (E_HOMEDIR); - } + fprintf (stderr, + _("%s: directory %s exists\n"), + Prog, user_newhome); + fail_exit (E_HOMEDIR); + } + if (stat (user_home, &sb) == 0) { /* * Don't try to move it if it is not a directory * (but /dev/null for example). --marekm