* src/useradd.c: Keep the default file as much as possible to

avoid issue in case of crash. Use link instead of rename.
This commit is contained in:
nekral-guest 2012-05-18 20:28:16 +00:00
parent 56845ad1c1
commit 1a7960421e
2 changed files with 9 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2012-05-18 Nicolas François <nicolas.francois@centraliens.net>
* 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 <pvrabec@redhat.com>
* lib/commonio.c: Fix labeling of /etc/{passwd,shadow,group,gshadow}.

View File

@ -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;
}