From: nekral-guest Date: Fri, 18 May 2012 20:28:16 +0000 (+0000) Subject: * src/useradd.c: Keep the default file as much as possible to X-Git-Tag: 4.1.5.1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a7960421eb52ba19a0756b2b96fa134e3e259a4;p=shadow * src/useradd.c: Keep the default file as much as possible to avoid issue in case of crash. Use link instead of rename. --- diff --git a/ChangeLog b/ChangeLog index 98f1a27f..fab7ad3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-05-18 Nicolas François + + * src/useradd.c: Keep the default file as much as possible to + avoid issue in case of crash. Use link instead of rename. + 2012-05-18 Peter Vrabec * lib/commonio.c: Fix labeling of /etc/{passwd,shadow,group,gshadow}. diff --git a/src/useradd.c b/src/useradd.c index f1b2fa81..fcffd129 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -557,11 +557,12 @@ static int set_defaults (void) */ wlen = snprintf (buf, sizeof buf, "%s-", USER_DEFAULTS_FILE); assert (wlen < (int) sizeof buf); - if ((rename (USER_DEFAULTS_FILE, buf) != 0) && (ENOENT != errno)) { + unlink (buf); + if ((link (USER_DEFAULTS_FILE, buf) != 0) && (ENOENT != errno)) { int err = errno; fprintf (stderr, - _("%s: rename: %s: %s\n"), - Prog, USER_DEFAULTS_FILE, strerror (err)); + _("%s: Cannot create backup file (%s): %s\n"), + Prog, buf, strerror (err)); unlink (new_file); return -1; }