--- shadow-4.0.12/src/useradd.c.pix 2007-06-12 10:50:05.000000000 +0200 +++ shadow-4.0.12/src/useradd.c 2007-06-12 11:02:52.000000000 +0200 @@ -181,7 +181,7 @@ static void open_files (void); static void faillog_reset (uid_t); static void lastlog_reset (uid_t); static void usr_update (void); -static void create_home (void); +static int create_home (void); static void create_mail (void); /* @@ -1593,6 +1593,24 @@ static void grp_add() do_grp_update++; } +static int is_home_empty (void) +{ + struct dirent *ep; + int empty = 1; + DIR *dp = opendir(user_home); + + if (dp == NULL) return 0; /* gasp, it should not happen */ + + while (ep = readdir (dp)) + if (strcmp(ep->d_name, ".") != 0 && + strcmp(ep->d_name, "..") != 0 && + strcmp(ep->d_name, "lost+found") != 0) + empty = 0; + closedir(dp); + + return empty; +} + /* * create_home - create the user's home directory * @@ -1601,7 +1619,7 @@ static void grp_add() * with the user's default group. */ -static void create_home (void) +static int create_home (void) { if (access (user_home, F_OK)) { /* XXX - create missing parent directories. --marekm */ @@ -1615,6 +1633,12 @@ static void create_home (void) chown (user_home, user_id, user_gid); chmod (user_home, 0777 & ~getdef_num ("UMASK", 022)); home_added++; + return 0; + } else if (is_home_empty ()) { + (void) chown (user_home, user_id, user_gid); + return 0; + } else { + return -1; } } @@ -1818,8 +1842,7 @@ int main (int argc, char **argv) usr_update (); if (mflg) { - create_home (); - if (home_added) + if (create_home () == 0) copy_tree (def_template, user_home, user_id, user_gid); else fprintf (stderr,