From 1a7960421eb52ba19a0756b2b96fa134e3e259a4 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Fri, 18 May 2012 20:28:16 +0000 Subject: [PATCH] * src/useradd.c: Keep the default file as much as possible to avoid issue in case of crash. Use link instead of rename. --- ChangeLog | 5 +++++ src/useradd.c | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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; } -- 2.40.0