From fd4b6cc52a88b848600db13fb4284e84fcf2442b Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Thu, 7 Aug 2008 08:02:34 +0000 Subject: [PATCH] * src/pwconv.c: Report failure to unlock the passwd or shadow file to stderr and syslog. * src/pwconv.c: Report failure to chmod the backup file. --- ChangeLog | 6 ++++++ src/pwconv.c | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4dd47de..84bcb145 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-08-06 Nicolas François + + * src/pwconv.c: Report failure to unlock the passwd or shadow file + to stderr and syslog. + * src/pwconv.c: Report failure to chmod the backup file. + 2008-08-06 Nicolas François * src/grpunconv.c: Report failure to unlock the group or gshadow diff --git a/src/pwconv.c b/src/pwconv.c index ac09f33c..bd31160e 100644 --- a/src/pwconv.c +++ b/src/pwconv.c @@ -87,16 +87,26 @@ static bool shadow_locked = false; static bool passwd_locked = false; /* local function prototypes */ -static void fail_exit (int); +static void fail_exit (int status); static void fail_exit (int status) { - if (shadow_locked) { - spw_unlock (); - } if (passwd_locked) { - pw_unlock (); + if (pw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); + /* continue */ + } } + + if (shadow_locked) { + if (spw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ())); + /* continue */ + } + } + exit (status); } @@ -207,17 +217,41 @@ int main (int argc, char **argv) fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ())); fail_exit (E_FAILURE); } if (pw_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ())); fail_exit (E_FAILURE); } - chmod (PASSWD_FILE "-", 0600); /* /etc/passwd- (backup file) */ - spw_unlock (); - pw_unlock (); + + /* /etc/passwd- (backup file) */ + if (chmod (PASSWD_FILE "-", 0600) != 0) { + fprintf (stderr, + _("%s: failed to change the mode of %s to 0600\n"), + Prog, PASSWD_FILE "-"); + SYSLOG ((LOG_ERR, "failed to change the mode of %s to 0600", PASSWD_FILE "-")); + /* continue */ + } + + if (passwd_locked) { + if (pw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); + /* continue */ + } + } + + if (shadow_locked) { + if (spw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ())); + /* continue */ + } + } nscd_flush_cache ("passwd");