From 7fc596fb8a389f23fa469b3b2ab1b791adb549f7 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Wed, 6 Aug 2008 15:57:31 +0000 Subject: [PATCH] * lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h, lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h: Added *_dbname() functions to retrieve the name of the databases. * lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h, lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h: *_name() functions renamed *setname(). * src/grpck.c, src/pwck.c: Likewise. * lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added the name of the arguments to the prototypes. * src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c, src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c, src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c, src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c: Harmonize the erro & syslog messages in case of failure of the *_lock(), *_open(), *_close(), *_unlock(), *_remove() functions. * src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid capitalized messages. * src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages in case of inexistent entries. * src/usermod.c: Harmonize messages in case of already existing entries. * src/newusers.c, src/useradd.c: Simplify PAM error handling. * src/useradd.c: Report failures to unlock files (stderr, syslog, and audit). But do not fail (continue). * src/useradd.c (open_files): Do not report to syslog & audit failures to lock or open the databases. This might be harmless, and the logs were not already informed that a change was requested. * src/usermod.c: It's not the account which is unlocked, but its password. --- ChangeLog | 34 ++++++ lib/groupio.c | 7 +- lib/groupio.h | 11 +- lib/pwio.c | 7 +- lib/pwio.h | 11 +- lib/sgroupio.c | 7 +- lib/sgroupio.h | 11 +- lib/shadowio.c | 7 +- lib/shadowio.h | 11 +- src/chage.c | 36 +++--- src/chfn.c | 28 ++--- src/chgpasswd.c | 25 +++-- src/chpasswd.c | 30 +++-- src/chsh.c | 24 ++-- src/gpasswd.c | 68 +++++------ src/groupadd.c | 55 +++++---- src/groupdel.c | 52 +++++---- src/groupmod.c | 94 +++++++++------- src/grpck.c | 16 +-- src/grpconv.c | 21 ++-- src/grpunconv.c | 28 +++-- src/newusers.c | 31 +++-- src/passwd.c | 51 +++++---- src/pwck.c | 20 ++-- src/pwconv.c | 25 +++-- src/pwunconv.c | 25 +++-- src/useradd.c | 292 +++++++++++++++++++++++++++++------------------- src/userdel.c | 82 +++++++------- src/usermod.c | 122 ++++++++++---------- 29 files changed, 703 insertions(+), 528 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e7cb153..623d53f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2008-08-06 Nicolas François + + * lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h, + lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h: + Added *_dbname() functions to retrieve the name of the databases. + * lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h, + lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h: + *_name() functions renamed *setname(). + * src/grpck.c, src/pwck.c: Likewise. + * lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added + the name of the arguments to the prototypes. + * src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c, + src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c, + src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c, + src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c, + src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c: + Harmonize the erro & syslog messages in case of failure of the + *_lock(), *_open(), *_close(), *_unlock(), *_remove() functions. + * src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid + capitalized messages. + * src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages + in case of inexistent entries. + * src/usermod.c: Harmonize messages in case of already existing + entries. + * src/newusers.c, src/useradd.c: Simplify PAM error handling. + * src/useradd.c: Report failures to unlock files (stderr, syslog, + and audit). But do not fail (continue). + * src/useradd.c (open_files): Do not report to syslog & audit + failures to lock or open the databases. This might be harmless, + and the logs were not already informed that a change was + requested. + * src/usermod.c: It's not the account which is unlocked, but its + password. + 2008-08-02 Nicolas François * src/groupadd.c: Harmonize error & syslog messages. diff --git a/lib/groupio.c b/lib/groupio.c index 702fa7f9..6ca720d8 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -126,11 +126,16 @@ static struct commonio_db group_db = { false /* readonly */ }; -int gr_name (const char *filename) +int gr_setdbname (const char *filename) { return commonio_setname (&group_db, filename); } +const char *gr_dbname (void) +{ + return group_db.filename; +} + int gr_lock (void) { return commonio_lock (&group_db); diff --git a/lib/groupio.h b/lib/groupio.h index ba708940..9f2984c9 100644 --- a/lib/groupio.h +++ b/lib/groupio.h @@ -38,16 +38,17 @@ #include extern int gr_close (void); -extern const struct group *gr_locate (const char *); +extern const struct group *gr_locate (const char *name); extern const struct group *gr_locate_gid (gid_t gid); extern int gr_lock (void); -extern int gr_name (const char *); +extern int gr_setdbname (const char *filename); +extern const char *gr_dbname (void); extern const struct group *gr_next (void); -extern int gr_open (int); -extern int gr_remove (const char *); +extern int gr_open (int mode); +extern int gr_remove (const char *name); extern int gr_rewind (void); extern int gr_unlock (void); -extern int gr_update (const struct group *); +extern int gr_update (const struct group *gr); extern int gr_sort (void); #endif diff --git a/lib/pwio.c b/lib/pwio.c index f36fec22..63cdc511 100644 --- a/lib/pwio.c +++ b/lib/pwio.c @@ -108,11 +108,16 @@ static struct commonio_db passwd_db = { false /* readonly */ }; -int pw_name (const char *filename) +int pw_setdbname (const char *filename) { return commonio_setname (&passwd_db, filename); } +const char *pw_dbname (void) +{ + return passwd_db.filename; +} + int pw_lock (void) { return commonio_lock (&passwd_db); diff --git a/lib/pwio.h b/lib/pwio.h index 12a0e63f..28f8bbd5 100644 --- a/lib/pwio.h +++ b/lib/pwio.h @@ -37,16 +37,17 @@ #include extern int pw_close (void); -extern const struct passwd *pw_locate (const char *); +extern const struct passwd *pw_locate (const char *name); extern const struct passwd *pw_locate_uid (uid_t uid); extern int pw_lock (void); -extern int pw_name (const char *); +extern int pw_setdbname (const char *filename); +extern const char *pw_dbname (void); extern const struct passwd *pw_next (void); -extern int pw_open (int); -extern int pw_remove (const char *); +extern int pw_open (int mode); +extern int pw_remove (const char *name); extern int pw_rewind (void); extern int pw_unlock (void); -extern int pw_update (const struct passwd *); +extern int pw_update (const struct passwd *pw); extern int pw_sort (void); #endif diff --git a/lib/sgroupio.c b/lib/sgroupio.c index af644a5e..1454bc55 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -161,11 +161,16 @@ static struct commonio_db gshadow_db = { false /* readonly */ }; -int sgr_name (const char *filename) +int sgr_setdbname (const char *filename) { return commonio_setname (&gshadow_db, filename); } +const char *sgr_dbname (void) +{ + return gshadow_db.filename; +} + bool sgr_file_present (void) { return commonio_present (&gshadow_db); diff --git a/lib/sgroupio.h b/lib/sgroupio.h index 01954f11..c030afed 100644 --- a/lib/sgroupio.h +++ b/lib/sgroupio.h @@ -37,15 +37,16 @@ extern int sgr_close (void); extern bool sgr_file_present (void); -extern const struct sgrp *sgr_locate (const char *); +extern const struct sgrp *sgr_locate (const char *name); extern int sgr_lock (void); -extern int sgr_name (const char *); +extern int sgr_setdbname (const char *filename); +extern const char *sgr_dbname (void); extern const struct sgrp *sgr_next (void); -extern int sgr_open (int); -extern int sgr_remove (const char *); +extern int sgr_open (int mode); +extern int sgr_remove (const char *name); extern int sgr_rewind (void); extern int sgr_unlock (void); -extern int sgr_update (const struct sgrp *); +extern int sgr_update (const struct sgrp *sg); extern int sgr_sort (void); #endif diff --git a/lib/shadowio.c b/lib/shadowio.c index 4e1208f9..810a6d43 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -105,11 +105,16 @@ static struct commonio_db shadow_db = { false /* readonly */ }; -int spw_name (const char *filename) +int spw_setdbname (const char *filename) { return commonio_setname (&shadow_db, filename); } +const char *spw_dbname (void) +{ + return shadow_db.filename; +} + bool spw_file_present (void) { return commonio_present (&shadow_db); diff --git a/lib/shadowio.h b/lib/shadowio.h index b10f51e0..c7db66b3 100644 --- a/lib/shadowio.h +++ b/lib/shadowio.h @@ -38,15 +38,16 @@ extern int spw_close (void); extern bool spw_file_present (void); -extern const struct spwd *spw_locate (const char *); +extern const struct spwd *spw_locate (const char *name); extern int spw_lock (void); -extern int spw_name (const char *); +extern int spw_setdbname (const char *filename); +extern const char *spw_dbname (void); extern const struct spwd *spw_next (void); -extern int spw_open (int); -extern int spw_remove (const char *); +extern int spw_open (int mode); +extern int spw_remove (const char *name); extern int spw_rewind (void); extern int spw_unlock (void); -extern int spw_update (const struct spwd *); +extern int spw_update (const struct spwd *sp); extern int spw_sort (void); #endif diff --git a/src/chage.c b/src/chage.c index 2810194a..2f7a859b 100644 --- a/src/chage.c +++ b/src/chage.c @@ -555,16 +555,16 @@ static void open_files (bool readonly) */ if (!readonly && (pw_lock () == 0)) { fprintf (stderr, - _("%s: can't lock password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed locking %s", PASSWD_FILE)); + _("%s: cannot lock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "cannot lock %s", pw_dbname ())); fail_exit (E_NOPERM); } if (!readonly) { pw_locked = true; } if (pw_open (readonly ? O_RDONLY: O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed opening %s", PASSWD_FILE)); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ())); fail_exit (E_NOPERM); } @@ -576,8 +576,8 @@ static void open_files (bool readonly) */ if (!readonly && (spw_lock () == 0)) { fprintf (stderr, - _("%s: can't lock shadow password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed locking %s", SHADOW_FILE)); + _("%s: cannot lock %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "cannot lock %s", spw_dbname ())); fail_exit (E_NOPERM); } if (!readonly) { @@ -585,8 +585,8 @@ static void open_files (bool readonly) } if (spw_open (readonly ? O_RDONLY: O_RDWR) == 0) { fprintf (stderr, - _("%s: can't open shadow password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed opening %s", SHADOW_FILE)); + _("%s: cannot open %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "cannot open %s", spw_dbname ())); fail_exit (E_NOPERM); } } @@ -602,8 +602,8 @@ static void close_files (void) */ if (spw_close () == 0) { fprintf (stderr, - _("%s: can't rewrite shadow password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed rewriting %s", SHADOW_FILE)); + _("%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_NOPERM); } @@ -612,8 +612,8 @@ static void close_files (void) * will be re-written. */ if (pw_close () == 0) { - fprintf (stderr, _("%s: can't rewrite password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed rewriting %s", PASSWD_FILE)); + 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_NOPERM); } spw_unlock (); @@ -647,8 +647,8 @@ static void update_age (const struct spwd *sp, const struct passwd *pw) pwent.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ if (pw_update (&pwent) == 0) { fprintf (stderr, - _("%s: can't update password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed updating %s", PASSWD_FILE)); + _("%s: cannot update %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "cannot update %s", pw_dbname ())); fail_exit (E_NOPERM); } } else { @@ -671,8 +671,8 @@ static void update_age (const struct spwd *sp, const struct passwd *pw) if (spw_update (&spwent) == 0) { fprintf (stderr, - _("%s: can't update shadow password file\n"), Prog); - SYSLOG ((LOG_ERR, "failed updating %s", SHADOW_FILE)); + _("%s: cannot update %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "cannot update %s", spw_dbname ())); fail_exit (E_NOPERM); } @@ -808,8 +808,8 @@ int main (int argc, char **argv) pw = pw_locate (argv[optind]); if (NULL == pw) { - fprintf (stderr, _("%s: unknown user %s\n"), Prog, - argv[optind]); + fprintf (stderr, _("%s: user '%s' does not exist in %s\n"), + Prog, argv[optind], pw_dbname ()); closelog (); exit (E_NOPERM); } diff --git a/src/chfn.c b/src/chfn.c index 3a45603b..cc4d9313 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -417,16 +417,18 @@ static void update_gecos (const char *user, char *gecos) * password file. Get a lock on the file and open it. */ if (pw_lock () == 0) { - fputs (_("Cannot lock the password file; try again later.\n"), - stderr); - SYSLOG ((LOG_WARN, "can't lock /etc/passwd")); + fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ())); closelog (); exit (E_NOPERM); } if (pw_open (O_RDWR) == 0) { - fputs (_("Cannot open the password file.\n"), stderr); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname ()); pw_unlock (); - SYSLOG ((LOG_ERR, "can't open /etc/passwd")); + SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ())); closelog (); exit (E_NOPERM); } @@ -441,7 +443,8 @@ static void update_gecos (const char *user, char *gecos) if (NULL == pw) { pw_unlock (); fprintf (stderr, - _("%s: %s not found in /etc/passwd\n"), Prog, user); + _("%s: user '%s' does not exist in %s\n"), + Prog, user, pw_dbname ()); exit (E_NOPERM); } @@ -468,15 +471,15 @@ static void update_gecos (const char *user, char *gecos) * Changes have all been made, so commit them and unlock the file. */ if (pw_close () == 0) { - fputs (_("Cannot commit password file changes.\n"), stderr); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); pw_unlock (); - SYSLOG ((LOG_ERR, "can't rewrite /etc/passwd")); + SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ())); closelog (); exit (E_NOPERM); } if (pw_unlock () == 0) { - fputs (_("Cannot unlock the password file.\n"), stderr); - SYSLOG ((LOG_ERR, "can't unlock /etc/passwd")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); closelog (); exit (E_NOPERM); } @@ -633,7 +636,7 @@ int main (int argc, char **argv) user = argv[optind]; pw = xgetpwnam (user); if (NULL == pw) { - fprintf (stderr, _("%s: unknown user %s\n"), Prog, + fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, user); exit (E_NOPERM); } @@ -641,8 +644,7 @@ int main (int argc, char **argv) pw = get_my_pwent (); if (NULL == pw) { fprintf (stderr, - _ - ("%s: Cannot determine your user name.\n"), + _("%s: Cannot determine your user name.\n"), Prog); exit (E_NOPERM); } diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 409b80d9..f8a81272 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -178,7 +178,7 @@ static void check_flags (void) { if (sflg && !cflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-s", "-c"); usage (); } @@ -264,11 +264,13 @@ static void open_files (void) * bring all of the entries into memory where they may be updated. */ if (gr_lock () == 0) { - fprintf (stderr, _("%s: can't lock group file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, gr_dbname ()); exit (1); } if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open group file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, gr_dbname ()); gr_unlock (); exit (1); } @@ -277,14 +279,14 @@ static void open_files (void) /* Do the same for the shadowed database, if it exist */ if (is_shadow_grp) { if (sgr_lock () == 0) { - fprintf (stderr, _("%s: can't lock gshadow file\n"), - Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), + Prog, sgr_dbname ()); gr_unlock (); exit (1); } if (sgr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open shadow file\n"), - Prog); + fprintf (stderr, _("%s: cannot open %s\n"), + Prog, sgr_dbname ()); gr_unlock (); sgr_unlock (); exit (1); @@ -302,7 +304,8 @@ static void close_files (void) if (is_shadow_grp) { if (sgr_close () == 0) { fprintf (stderr, - _("%s: error updating gshadow file\n"), Prog); + _("%s: failure while writing changes to %s\n"), + Prog, sgr_dbname ()); gr_unlock (); exit (1); } @@ -311,7 +314,9 @@ static void close_files (void) #endif if (gr_close () == 0) { - fprintf (stderr, _("%s: error updating group file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, gr_dbname ()); exit (1); } gr_unlock (); @@ -414,7 +419,7 @@ int main (int argc, char **argv) gr = gr_locate (name); if (NULL == gr) { fprintf (stderr, - _("%s: line %d: unknown group %s\n"), Prog, + _("%s: line %d: group '%s' does not exist\n"), Prog, line, name); errors++; continue; diff --git a/src/chpasswd.c b/src/chpasswd.c index b6cb0a2a..ac8ba50b 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -175,7 +175,7 @@ static void check_flags (void) { if (sflg && !cflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-s", "-c"); usage (); } @@ -261,11 +261,13 @@ static void open_files (void) * will bring all of the entries into memory where they may be updated. */ if (pw_lock () == 0) { - fprintf (stderr, _("%s: can't lock password file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, pw_dbname ()); exit (1); } if (pw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open password file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname ()); pw_unlock (); exit (1); } @@ -273,14 +275,16 @@ static void open_files (void) /* Do the same for the shadowed database, if it exist */ if (is_shadow_pwd) { if (spw_lock () == 0) { - fprintf (stderr, _("%s: can't lock shadow file\n"), - Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), + Prog, spw_dbname ()); pw_unlock (); exit (1); } if (spw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open shadow file\n"), - Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), + Prog, spw_dbname ()); pw_unlock (); spw_unlock (); exit (1); @@ -296,7 +300,8 @@ static void close_files (void) if (is_shadow_pwd) { if (spw_close () == 0) { fprintf (stderr, - _("%s: error updating shadow file\n"), Prog); + _("%s: failure while writing changes to %s\n"), + Prog, spw_dbname ()); pw_unlock (); exit (1); } @@ -304,7 +309,9 @@ static void close_files (void) } if (pw_close () == 0) { - fprintf (stderr, _("%s: error updating password file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, pw_dbname ()); exit (1); } pw_unlock (); @@ -407,7 +414,7 @@ int main (int argc, char **argv) pw = pw_locate (name); if (NULL == pw) { fprintf (stderr, - _("%s: line %d: unknown user %s\n"), Prog, + _("%s: line %d: user '%s' does not exist\n"), Prog, line, name); errors++; continue; @@ -445,8 +452,7 @@ int main (int argc, char **argv) if (0 == ok) { fprintf (stderr, - _ - ("%s: line %d: cannot update password entry\n"), + _("%s: line %d: cannot update password entry\n"), Prog, line); errors++; continue; diff --git a/src/chsh.c b/src/chsh.c index 3dca9978..361f6b38 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -352,16 +352,16 @@ static void update_shell (const char *user, char *newshell) * the password file. Get a lock on the file and open it. */ if (pw_lock () == 0) { - SYSLOG ((LOG_WARN, "can't lock /etc/passwd")); + SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ())); closelog (); - fputs (_("Cannot lock the password file; try again later.\n"), - stderr); + fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), + Prog, pw_dbname ()); exit (1); } if (pw_open (O_RDWR) == 0) { - SYSLOG ((LOG_ERR, "can't open /etc/passwd")); + SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ())); closelog (); - fputs (_("Cannot open the password file.\n"), stderr); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); pw_unlock (); exit (1); } @@ -376,7 +376,8 @@ static void update_shell (const char *user, char *newshell) if (NULL == pw) { pw_unlock (); fprintf (stderr, - _("%s: %s not found in /etc/passwd\n"), Prog, user); + _("%s: user '%s' does not exist in %s\n"), + Prog, user, pw_dbname ()); exit (1); } @@ -403,16 +404,17 @@ static void update_shell (const char *user, char *newshell) * Changes have all been made, so commit them and unlock the file. */ if (pw_close () == 0) { - SYSLOG ((LOG_ERR, "can't rewrite /etc/passwd")); + SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ())); closelog (); - fputs (_("Cannot commit password file changes.\n"), stderr); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); pw_unlock (); exit (1); } if (pw_unlock () == 0) { - SYSLOG ((LOG_ERR, "can't unlock /etc/passwd")); + SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); closelog (); - fputs (_("Cannot unlock the password file.\n"), stderr); + fprintf (stderr, + _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); exit (1); } } @@ -459,7 +461,7 @@ int main (int argc, char **argv) pw = xgetpwnam (user); if (NULL == pw) { fprintf (stderr, - _("%s: unknown user %s\n"), Prog, user); + _("%s: user '%s' does not exist\n"), Prog, user); exit (1); } } else { diff --git a/src/gpasswd.c b/src/gpasswd.c index f7667203..d4dd16bc 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -162,8 +162,8 @@ static void fail_exit (int status) { if (group_locked) { if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -174,8 +174,8 @@ static void fail_exit (int status) #ifdef SHADOWGRP if (gshadow_locked) { if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -368,8 +368,8 @@ static void check_flags (int argc, int opt_index) static void open_files (void) { if (gr_lock () == 0) { - fprintf (stderr, _("%s: cannot lock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the group file")); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking /etc/group", @@ -382,8 +382,8 @@ static void open_files (void) if (is_shadowgrp) { if (sgr_lock () == 0) { fprintf (stderr, - _("%s: cannot lock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the shadow group file")); + _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking /etc/gshadow", @@ -395,8 +395,8 @@ static void open_files (void) } #endif if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the group file")); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening /etc/group", @@ -406,8 +406,8 @@ static void open_files (void) } #ifdef SHADOWGRP if (is_shadowgrp && (sgr_open (O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the shadow group file")); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening /etc/gshadow", @@ -428,8 +428,8 @@ static void open_files (void) static void close_files (void) { if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the group file")); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "rewriting /etc/group", @@ -440,8 +440,8 @@ static void close_files (void) #ifdef SHADOWGRP if (is_shadowgrp) { if (sgr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file")); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "rewriting /etc/gshadow", @@ -450,8 +450,8 @@ static void close_files (void) fail_exit (1); } if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -463,8 +463,8 @@ static void close_files (void) } #endif if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -564,8 +564,10 @@ static void update_group (struct group *gr) #endif { if (gr_update (gr) == 0) { - fprintf (stderr, _("%s: cannot update the entry of '%s' in the group file\n"), Prog, gr->gr_name); - SYSLOG ((LOG_WARN, "cannot update the entry of '%s' in the group file", gr->gr_name)); + fprintf (stderr, + _("%s: cannot update entry '%s' in %s\n"), + Prog, gr->gr_name, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot update entry '%s' in %s", gr->gr_name, gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating /etc/group", @@ -575,8 +577,8 @@ static void update_group (struct group *gr) } #ifdef SHADOWGRP if (is_shadowgrp && (sgr_update (sg) == 0)) { - fprintf (stderr, _("%s: cannot update the entry of '%s' in the shadow group file\n"), Prog, sg->sg_name); - SYSLOG ((LOG_WARN, "cannot update the entry of '%s' in the shadow group file", sg->sg_name)); + fprintf (stderr, _("%s: cannot update entry '%s' in %s\n"), Prog, sg->sg_name, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot update entry '%s' in %s", sg->sg_name, sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating /etc/gshadow", @@ -605,8 +607,8 @@ static void get_group (struct group *gr) struct sgrp const*tmpsg = NULL; if (gr_open (O_RDONLY) == 0) { - fprintf (stderr, _("%s: cannot open the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the group file")); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening /etc/group", @@ -617,7 +619,7 @@ static void get_group (struct group *gr) tmpgr = gr_locate (group); if (NULL == tmpgr) { - fprintf (stderr, _("%s: group '%s' does not exist in the group file\n"), Prog, group); + fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), Prog, group, gr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "group lookup", @@ -632,8 +634,8 @@ static void get_group (struct group *gr) gr->gr_mem = dup_list (tmpgr->gr_mem); if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the group file")); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "closing /etc/group", @@ -646,8 +648,8 @@ static void get_group (struct group *gr) if (is_shadowgrp) { if (sgr_open (O_RDONLY) == 0) { fprintf (stderr, - _("%s: cannot open the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the shadow group file")); + _("%s: cannot open %s\n"), Prog, sgr_dbmane ()); + SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening /etc/gshadow", @@ -684,8 +686,8 @@ static void get_group (struct group *gr) } if (sgr_close () == 0) { fprintf (stderr, - _("%s: cannot rewrite the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file")); + _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "closing /etc/gshadow", diff --git a/src/groupadd.c b/src/groupadd.c index a9962ebf..4bc7b810 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -198,8 +198,8 @@ static void grp_update (void) * Write out the new group file entry. */ if (gr_update (&grp) == 0) { - fprintf (stderr, _("%s: error adding new entry '%s' in the group file\n"), Prog, grp.gr_name); - SYSLOG ((LOG_WARN, "error adding new entry '%s' in the group file", grp.gr_name)); + fprintf (stderr, _("%s: error adding new entry '%s' in %s\n"), Prog, grp.gr_name, gr_dbname ()); + SYSLOG ((LOG_WARN, "error adding new entry '%s' in %s", grp.gr_name, gr_dbname ())); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP @@ -207,8 +207,8 @@ static void grp_update (void) * Write out the new shadow group entries as well. */ if (is_shadow_grp && (sgr_update (&sgrp) == 0)) { - fprintf (stderr, _("%s: error adding new entry '%s' in the shadow group file\n"), Prog, sgrp.sg_name); - SYSLOG ((LOG_WARN, "error adding new entry '%s' in the shadow group file", sgrp.sg_name)); + fprintf (stderr, _("%s: error adding new entry '%s' in %s\n"), Prog, sgrp.sg_name, sgr_dbname ()); + SYSLOG ((LOG_WARN, "error adding new entry '%s' in %s", sgrp.sg_name, sgr_dbname ())); fail_exit (E_GRP_UPDATE); } #endif /* SHADOWGRP */ @@ -252,13 +252,13 @@ static void check_new_name (void) static void close_files (void) { if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the group file")); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -271,13 +271,13 @@ static void close_files (void) if (is_shadow_grp) { if (sgr_close () == 0) { fprintf (stderr, - _("%s: cannot rewrite the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file")); + _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -298,8 +298,8 @@ static void close_files (void) static void open_files (void) { if (gr_lock () == 0) { - fprintf (stderr, _("%s: cannot lock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the group file")); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking group file", @@ -309,8 +309,8 @@ static void open_files (void) } group_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the group file")); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening group file", @@ -322,8 +322,8 @@ static void open_files (void) if (is_shadow_grp) { if (sgr_lock () == 0) { fprintf (stderr, - _("%s: cannot lock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the shadow group file")); + _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking gshadow file", @@ -334,8 +334,8 @@ static void open_files (void) gshadow_locked = true; if (sgr_open (O_RDWR) == 0) { fprintf (stderr, - _("%s: cannot open the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the shadow group file")); + _("%s: cannot open %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening gshadow file", @@ -354,8 +354,8 @@ static void fail_exit (int code) { if (group_locked) { if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -367,8 +367,8 @@ static void fail_exit (int code) #ifdef SHADOWGRP if (gshadow_locked) { if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -469,8 +469,7 @@ static void process_flags (int argc, char **argv) cp = strchr (optarg, '='); if (NULL == cp) { fprintf (stderr, - _ - ("%s: -K requires KEY=VALUE\n"), + _("%s: -K requires KEY=VALUE\n"), Prog); exit (E_BAD_ARG); } @@ -547,8 +546,8 @@ static void check_flags (void) /* Turn off -g, we can use any GID */ gflg = false; } else { - fprintf (stderr, _("%s: GID '%u' already exists\n"), - Prog, (unsigned int) group_id); + fprintf (stderr, _("%s: GID '%lu' already exists\n"), + Prog, (unsigned long int) group_id); fail_exit (E_GID_IN_USE); } } diff --git a/src/groupdel.c b/src/groupdel.c index d84806ae..3866b40a 100644 --- a/src/groupdel.c +++ b/src/groupdel.c @@ -96,8 +96,8 @@ static void fail_exit (int code) { if (group_locked) { if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -109,8 +109,8 @@ static void fail_exit (int code) #ifdef SHADOWGRP if (gshadow_locked) { if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -138,7 +138,9 @@ static void fail_exit (int code) static void grp_update (void) { if (gr_remove (group_name) == 0) { - fprintf (stderr, _("%s: cannot remove group '%s' from the group database\n"), Prog, group_name); + fprintf (stderr, + _("%s: cannot remove entry '%s' from %s\n"), + Prog, group_name, gr_dbname ()); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP @@ -148,8 +150,8 @@ static void grp_update (void) if (is_shadow_grp && (sgr_locate (group_name) != NULL)) { if (sgr_remove (group_name) == 0) { fprintf (stderr, - _("%s: cannot remove group '%s' from the shadow group database\n"), - Prog, group_name); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, group_name, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } } @@ -173,13 +175,13 @@ static void close_files (void) SYSLOG ((LOG_INFO, "remove group '%s'\n", group_name)); if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the group file")); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -192,13 +194,13 @@ static void close_files (void) if (is_shadow_grp) { if (sgr_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file")); + _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -219,29 +221,33 @@ static void close_files (void) static void open_files (void) { if (gr_lock () == 0) { - fprintf (stderr, _("%s: cannot lock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the group file")); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s",gr_dbname ())); fail_exit (E_GRP_UPDATE); } group_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the group file")); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP if (is_shadow_grp) { if (sgr_lock () == 0)) { fprintf (stderr, - _("%s: cannot lock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the shadow group file")); + _("%s: cannot lock %s\n"), + Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } gshadow_locked = true; if (sgr_open (O_RDWR) == 0)) { fprintf (stderr, - _("%s: cannot open the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the shadow group file")); + _("%s: cannot open %s\n"), + Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } } diff --git a/src/groupmod.c b/src/groupmod.c index bfdb468b..49ade1e8 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -125,8 +125,8 @@ static void fail_exit (int status) { if (group_locked) { if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -138,8 +138,8 @@ static void fail_exit (int status) #ifdef SHADOWGRP if (gshadow_locked) { if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -151,8 +151,8 @@ static void fail_exit (int status) #endif /* SHADOWGRP */ if (passwd_locked) { if (pw_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the passwd file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the passwd file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking passwd file", @@ -225,8 +225,8 @@ static void grp_update (void) ogrp = gr_locate (group_name); if (!ogrp) { fprintf (stderr, - _("%s: group '%s' does not exist in the group file\n"), - Prog, group_name); + _("%s: group '%s' does not exist in %s\n"), + Prog, group_name, gr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modifying group", @@ -257,7 +257,9 @@ static void grp_update (void) * Write out the new group file entry. */ if (gr_update (&grp) == 0) { - fprintf (stderr, _("%s: cannot add entry '%s' to the group database\n"), Prog, grp.gr_name); + fprintf (stderr, + _("%s: cannot add entry '%s' to %s\n"), + Prog, grp.gr_name, gr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding group", @@ -266,7 +268,9 @@ static void grp_update (void) fail_exit (E_GRP_UPDATE); } if (nflg && (gr_remove (group_name) == 0)) { - fprintf (stderr, _("%s: cannot remove the entry of '%s' from the group database\n"), Prog, grp.gr_name); + fprintf (stderr, + _("%s: cannot remove entry '%s' from %s\n"), + Prog, grp.gr_name, gr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting group", @@ -281,14 +285,15 @@ static void grp_update (void) * "out" if there wasn't. Can't just return because there might be * some syslogging to do. */ - if (NULL == osgrp) + if (NULL == osgrp) { goto out; + } /* * Write out the new shadow group entries as well. */ if (is_shadow_grp && (sgr_update (&sgrp) == 0)) { - fprintf (stderr, _("%s: cannot add entry '%s' to the shadow group database\n"), Prog, sgrp.sg_name); + fprintf (stderr, _("%s: cannot add entry '%s' to %s\n"), Prog, sgrp.sg_name, sgr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding group", @@ -297,7 +302,9 @@ static void grp_update (void) fail_exit (E_GRP_UPDATE); } if (is_shadow_grp && nflg && (sgr_remove (group_name) == 0)) { - fprintf (stderr, _("%s: cannot remove the entry of '%s' from the shadow group database\n"), Prog); + fprintf (stderr, + _("%s: cannot remove entry '%s' from %s\n"), + Prog, sgr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting group", @@ -499,8 +506,8 @@ static void process_flags (int argc, char **argv) static void close_files (void) { if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the group file")); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "rewrite group file", @@ -509,8 +516,8 @@ static void close_files (void) fail_exit (E_GRP_UPDATE); } if (gr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking group file", @@ -523,8 +530,8 @@ static void close_files (void) if (is_shadow_grp) { if (sgr_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the shadow group file")); + _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "rewrite gshadow file", @@ -533,8 +540,8 @@ static void close_files (void) fail_exit (E_GRP_UPDATE); } if (sgr_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the shadow group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the shadow group file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking gshadow file", @@ -548,8 +555,8 @@ static void close_files (void) if (gflg) { if (pw_close () == 0) { fprintf (stderr, - _("%s: cannot rewrite the passwd file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot rewrite the passwd file")); + _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", pw_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "rewrite passwd file", @@ -558,8 +565,8 @@ static void close_files (void) fail_exit (E_GRP_UPDATE); } if (pw_unlock () == 0) { - fprintf (stderr, _("%s: cannot unlock the passwd file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot unlock the passwd file")); + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ())); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "unlocking passwd file", @@ -579,31 +586,31 @@ static void close_files (void) static void open_files (void) { if (gr_lock () == 0) { - fprintf (stderr, _("%s: cannot lock the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot lock the group file")); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } group_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open the group file\n"), Prog); - SYSLOG ((LOG_WARN, "cannot open the group file")); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP if (is_shadow_grp) { if (sgr_lock () == 0) { fprintf (stderr, - _("%s: cannot lock the shadow group file\n"), - Prog); - SYSLOG ((LOG_WARN, "cannot lock the shadow group file")); + _("%s: cannot lock %s\n"), + Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } gshadow_locked = true; if (sgr_open (O_RDWR) == 0) { fprintf (stderr, - _("%s: cannot open the shadow group file\n"), - Prog); - SYSLOG ((LOG_WARN, "cannot open the shadow group file")); + _("%s: cannot open %s\n"), + Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } } @@ -611,17 +618,17 @@ static void open_files (void) if (gflg) { if (pw_lock () == 0) { fprintf (stderr, - _("%s: cannot lock the passwd file\n"), - Prog); - SYSLOG ((LOG_WARN, "cannot lock the passwd file")); + _("%s: cannot lock %s\n"), + Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ())); fail_exit (E_GRP_UPDATE); } passwd_locked = true; if (pw_open (O_RDWR) == 0) { fprintf (stderr, - _("%s: cannot open the passwd file\n"), - Prog); - SYSLOG ((LOG_WARN, "cannot open the passwd file")); + _("%s: cannot open %s\n"), + Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } } @@ -639,10 +646,11 @@ void update_primary_groups (gid_t ogid, gid_t ngid) lpwd = pw_locate (pwd->pw_name); if (NULL == lpwd) { fprintf (stderr, - _("%s: cannot change the primary group of user '%s' from %lu to %lu, since it is not in the passwd file.\n"), + _("%s: cannot change the primary group of user '%s' from %lu to %lu, since it is not in %s.\n"), Prog, pwd->pw_name, (unsigned long) ogid, - (unsigned long) ngid); + (unsigned long) ngid, + pw_dbname ()); fail_exit (E_GRP_UPDATE); } else { npwd = *lpwd; diff --git a/src/grpck.c b/src/grpck.c index 2b83332d..d0619108 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -183,13 +183,13 @@ static void process_flags (int argc, char **argv) */ if (optind != argc) { grp_file = argv[optind]; - gr_name (grp_file); + gr_setdbname (grp_file); use_system_grp_file = false; } #ifdef SHADOWGRP if ((optind + 2) == argc) { sgr_file = argv[optind + 1]; - sgr_name (sgr_file); + sgr_setdbname (sgr_file); is_shadow = true; use_system_sgr_file = false; } else if (optind == argc) { @@ -211,7 +211,7 @@ static void open_files (void) */ if (!read_only) { if (gr_lock () == 0) { - fprintf (stderr, _("%s: cannot lock file %s\n"), + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, grp_file); if (use_system_grp_file) { SYSLOG ((LOG_WARN, "cannot lock %s", grp_file)); @@ -221,7 +221,7 @@ static void open_files (void) } #ifdef SHADOWGRP if (is_shadow && (sgr_lock () == 0)) { - fprintf (stderr, _("%s: cannot lock file %s\n"), + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, sgr_file); if (use_system_sgr_file) { SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file)); @@ -237,7 +237,7 @@ static void open_files (void) * O_RDWR otherwise. */ if (gr_open (read_only ? O_RDONLY : O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open file %s\n"), Prog, + fprintf (stderr, _("%s: cannot open %s\n"), Prog, grp_file); if (use_system_grp_file) { SYSLOG ((LOG_WARN, "cannot open %s", grp_file)); @@ -247,7 +247,7 @@ static void open_files (void) } #ifdef SHADOWGRP if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open file %s\n"), Prog, + fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_file); if (use_system_sgr_file) { SYSLOG ((LOG_WARN, "cannot open %s", sgr_file)); @@ -273,13 +273,13 @@ static void close_files (bool changed) */ if (changed) { if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot update file %s\n"), + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, grp_file); exit (E_CANT_UPDATE); } #ifdef SHADOWGRP if (is_shadow && (sgr_close () == 0)) { - fprintf (stderr, _("%s: cannot update file %s\n"), + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_file); exit (E_CANT_UPDATE); } diff --git a/src/grpconv.c b/src/grpconv.c index 6472c245..5b7ef056 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -83,22 +83,22 @@ int main (int argc, char **argv) (void) textdomain (PACKAGE); if (gr_lock () == 0) { - fprintf (stderr, _("%s: can't lock group file\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ()); fail_exit (5); } group_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open group file\n"), Prog); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (1); } if (sgr_lock () == 0) { - fprintf (stderr, _("%s: can't lock shadow group file\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); fail_exit (5); } gshadow_locked = true; if (sgr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open shadow group file\n"), Prog); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); fail_exit (1); } @@ -116,8 +116,8 @@ int main (int argc, char **argv) * This shouldn't happen (the entry exists) but... */ fprintf (stderr, - _("%s: can't remove shadow group %s\n"), - Prog, sg->sg_name); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, sg->sg_name, sgr_dbname ()); fail_exit (3); } } @@ -171,12 +171,15 @@ int main (int argc, char **argv) } if (sgr_close () == 0) { - fprintf (stderr, _("%s: can't update shadow group file\n"), - Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, sgr_dbname ()); fail_exit (3); } if (gr_close () == 0) { - fprintf (stderr, _("%s: can't update group file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, gr_dbname ()); fail_exit (3); } sgr_unlock (); diff --git a/src/grpunconv.c b/src/grpunconv.c index 6fdc8b95..b29a9ee2 100644 --- a/src/grpunconv.c +++ b/src/grpunconv.c @@ -2,6 +2,7 @@ * Copyright (c) 1996 , Michael Meskes * Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 2002 - 2006, Tomasz Kłoczko + * Copyright (c) 2008 , Nicolas François * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -86,22 +87,26 @@ int main (int argc, char **argv) } if (gr_lock () == 0) { - fprintf (stderr, _("%s: can't lock group file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, gr_dbname ()); fail_exit (5); } group_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open group file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (1); } if (sgr_lock () == 0) { - fprintf (stderr, _("%s: can't lock shadow group file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); fail_exit (5); } gshadow_locked = true; if (sgr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open shadow group file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, sgr_dbname ()); fail_exit (1); } @@ -127,19 +132,23 @@ int main (int argc, char **argv) } if (sgr_close () == 0) { - fprintf (stderr, _("%s: can't update shadow group file\n"), - Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, sgr_dbname ()); fail_exit (3); } if (gr_close () == 0) { - fprintf (stderr, _("%s: can't update group file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, gr_dbname ()); fail_exit (3); } if (unlink (SGROUP_FILE) != 0) { - fprintf (stderr, _("%s: can't delete shadow group file\n"), - Prog); + fprintf (stderr, + _("%s: cannot delete %s\n"), + Prog, SGROUP_FILE); fail_exit (3); } @@ -158,3 +167,4 @@ int main (int argc, char **argv) exit (1); } #endif /* !SHADOWGRP */ + diff --git a/src/newusers.c b/src/newusers.c index 88f21f4b..1dcd2804 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -517,7 +517,7 @@ static void check_flags (void) { if (sflg && !cflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-s", "-c"); usage (); } @@ -556,29 +556,24 @@ static void check_perms (void) struct passwd *pampw; pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */ - if (pampw == NULL) { + if (NULL == pampw) { retval = PAM_USER_UNKNOWN; } - if (retval == PAM_SUCCESS) { + if (PAM_SUCCESS == retval) { retval = pam_start ("newusers", pampw->pw_name, &conv, &pamh); } - if (retval == PAM_SUCCESS) { + if (PAM_SUCCESS == retval) { retval = pam_authenticate (pamh, 0); - if (retval != PAM_SUCCESS) { - (void) pam_end (pamh, retval); - } } - if (retval == PAM_SUCCESS) { + if (PAM_SUCCESS == retval) { retval = pam_acct_mgmt (pamh, 0); - if (retval != PAM_SUCCESS) { - (void) pam_end (pamh, retval); - } } - if (retval != PAM_SUCCESS) { + if (PAM_SUCCESS != retval) { + (void) pam_end (pamh, retval); fprintf (stderr, _("%s: PAM authentication failed\n"), Prog); fail_exit (1); } @@ -597,23 +592,23 @@ static void open_files (void) * it gets locked, assume the others can be locked right away. */ if (pw_lock () == 0) { - fprintf (stderr, _("%s: can't lock /etc/passwd.\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pw_dbname ()); fail_exit (1); } passwd_locked = true; if (is_shadow && (spw_lock () == 0)) { - fprintf (stderr, _("%s: can't lock /etc/shadow.\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, spw_dbname ()); fail_exit (1); } shadow_locked = true; if (gr_lock () == 0) { - fprintf (stderr, _("%s: can't lock /etc/group.\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ()); fail_exit (1); } group_locked = true; #ifdef SHADOWGRP if (is_shadow_grp && (sgr_lock () == 0)) { - fprintf (stderr, _("%s: can't lock /etc/gshadow.\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); fail_exit (1); } gshadow_locked = true; @@ -800,8 +795,8 @@ int main (int argc, char **argv) pw = pw_locate (fields[0]); if (NULL == pw) { fprintf (stderr, - _("%s: line %d: cannot find user %s\n"), - Prog, line, fields[0]); + _("%s: line %d: user '%s' does not exist in %s\n"), + Prog, line, fields[0], pw_dbname ()); errors++; continue; } diff --git a/src/passwd.c b/src/passwd.c index b2730b91..ff3dea40 100644 --- a/src/passwd.c +++ b/src/passwd.c @@ -512,20 +512,24 @@ static void update_noshadow (void) struct passwd *npw; if (pw_lock () == 0) { - fputs (_("Cannot lock the password file; try again later.\n"), - stderr); - SYSLOG ((LOG_WARN, "can't lock password file")); + fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", pw_dbname ())); exit (E_PWDBUSY); } if (pw_open (O_RDWR) == 0) { - fputs (_("Cannot open the password file.\n"), stderr); - SYSLOG ((LOG_ERR, "can't open password file")); + fprintf (stderr, + _("%s: cannot open %s\n"), + Prog, pw_dbname ()); + SYSLOG ((LOG_ERR, "cannot open %s", pw_dbname ())); fail_exit (E_MISSING); } pw = pw_locate (name); if (NULL == pw) { - fprintf (stderr, _("%s: %s not found in /etc/passwd\n"), - Prog, name); + fprintf (stderr, + _("%s: user '%s' does not exist in %s\n"), + Prog, name, pw_dbname ()); fail_exit (E_NOPERM); } npw = __pw_dup (pw); @@ -539,8 +543,10 @@ static void update_noshadow (void) fail_exit (E_FAILURE); } if (pw_close () == 0) { - fputs (_("Cannot commit password file changes.\n"), stderr); - SYSLOG ((LOG_ERR, "can't rewrite password file")); + 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); } pw_unlock (); @@ -552,14 +558,15 @@ static void update_shadow (void) struct spwd *nsp; if (spw_lock () == 0) { - fputs (_("Cannot lock the password file; try again later.\n"), - stderr); - SYSLOG ((LOG_WARN, "can't lock password file")); + fprintf (stderr, + _("%s: cannot lock %s; try again later.\n"), + Prog, spw_dbname ()); + SYSLOG ((LOG_WARN, "cannot lock %s", spw_dbname ())); exit (E_PWDBUSY); } if (spw_open (O_RDWR) == 0) { - fputs (_("Cannot open the password file.\n"), stderr); - SYSLOG ((LOG_ERR, "can't open password file")); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_ERR, "cannot open %s", spw_dbname ())); fail_exit (E_FAILURE); } sp = spw_locate (name); @@ -614,8 +621,10 @@ static void update_shadow (void) fail_exit (E_FAILURE); } if (spw_close () == 0) { - fputs (_("Cannot commit password file changes.\n"), stderr); - SYSLOG ((LOG_ERR, "can't rewrite password file")); + 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); } spw_unlock (); @@ -809,8 +818,7 @@ int main (int argc, char **argv) /* only "files" supported for now */ if (strcmp (optarg, "files") != 0) { fprintf (stderr, - _ - ("%s: repository %s not supported\n"), + _("%s: repository %s not supported\n"), Prog, optarg); exit (E_BAD_ARG); } @@ -920,7 +928,7 @@ int main (int argc, char **argv) pw = xgetpwnam (name); if (NULL == pw) { - fprintf (stderr, _("%s: unknown user %s\n"), Prog, name); + fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, name); exit (E_NOPERM); } #ifdef WITH_SELINUX @@ -949,9 +957,8 @@ int main (int argc, char **argv) */ if (!amroot && (pw->pw_uid != getuid ())) { fprintf (stderr, - _ - ("%s: You may not view or modify password information for %s.\n"), - Prog, name); + _("%s: You may not view or modify password information for %s.\n"), + Prog, name); SYSLOG ((LOG_WARN, "%s: can't view or modify password information for %s", Prog, name)); diff --git a/src/pwck.c b/src/pwck.c index 96a390d7..803d98fb 100644 --- a/src/pwck.c +++ b/src/pwck.c @@ -141,12 +141,12 @@ static void process_flags (int argc, char **argv) */ if (optind != argc) { pwd_file = argv[optind]; - pw_name (pwd_file); + pw_setdbname (pwd_file); use_system_pw_file = false; } if ((optind + 2) == argc) { spw_file = argv[optind + 1]; - spw_name (spw_file); + spw_setdbname (spw_file); is_shadow = true; use_system_spw_file = false; } else if (optind == argc) { @@ -167,7 +167,7 @@ static void open_files (void) */ if (!read_only) { if (pw_lock () == 0) { - fprintf (stderr, _("%s: cannot lock file %s\n"), + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pwd_file); if (use_system_pw_file) { SYSLOG ((LOG_WARN, "cannot lock %s", pwd_file)); @@ -176,7 +176,7 @@ static void open_files (void) exit (E_CANTLOCK); } if (is_shadow && (spw_lock () == 0)) { - fprintf (stderr, _("%s: cannot lock file %s\n"), + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, spw_file); if (use_system_spw_file) { SYSLOG ((LOG_WARN, "cannot lock %s", spw_file)); @@ -191,7 +191,7 @@ static void open_files (void) * otherwise. */ if (pw_open (read_only ? O_RDONLY : O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open file %s\n"), + fprintf (stderr, _("%s: cannot open %s\n"), Prog, pwd_file); if (use_system_pw_file) { SYSLOG ((LOG_WARN, "cannot open %s", pwd_file)); @@ -200,7 +200,7 @@ static void open_files (void) exit (E_CANTOPEN); } if (is_shadow && (spw_open (read_only ? O_RDONLY : O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open file %s\n"), + fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_file); if (use_system_spw_file) { SYSLOG ((LOG_WARN, "cannot open %s", spw_file)); @@ -225,16 +225,16 @@ static void close_files (bool changed) */ if (changed) { if (pw_close () == 0) { - fprintf (stderr, _("%s: cannot update file %s\n"), + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pwd_file); - SYSLOG ((LOG_WARN, "cannot update %s", pwd_file)); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", pwd_file)); closelog (); exit (E_CANTUPDATE); } if (is_shadow && (spw_close () == 0)) { - fprintf (stderr, _("%s: cannot update file %s\n"), + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, spw_file); - SYSLOG ((LOG_WARN, "cannot update %s", spw_file)); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_file)); closelog (); exit (E_CANTUPDATE); } diff --git a/src/pwconv.c b/src/pwconv.c index 79853341..ac09f33c 100644 --- a/src/pwconv.c +++ b/src/pwconv.c @@ -113,22 +113,26 @@ int main (int argc, char **argv) (void) textdomain (PACKAGE); if (pw_lock () == 0) { - fprintf (stderr, _("%s: can't lock passwd file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, pw_dbname ()); fail_exit (E_PWDBUSY); } passwd_locked = true; if (pw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open passwd file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname ()); fail_exit (E_MISSING); } if (spw_lock () == 0) { - fprintf (stderr, _("%s: can't lock shadow file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, spw_dbname ()); fail_exit (E_PWDBUSY); } shadow_locked = true; if (spw_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open shadow file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, spw_dbname ()); fail_exit (E_FAILURE); } @@ -146,9 +150,8 @@ int main (int argc, char **argv) * This shouldn't happen (the entry exists) but... */ fprintf (stderr, - _ - ("%s: can't remove shadow entry for %s\n"), - Prog, sp->sp_namp); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, sp->sp_namp, spw_dbname ()); fail_exit (E_FAILURE); } } @@ -201,11 +204,15 @@ int main (int argc, char **argv) } if (spw_close () == 0) { - fprintf (stderr, _("%s: can't update shadow file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, spw_dbname ()); fail_exit (E_FAILURE); } if (pw_close () == 0) { - fprintf (stderr, _("%s: can't update passwd file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, pw_dbname ()); fail_exit (E_FAILURE); } chmod (PASSWD_FILE "-", 0600); /* /etc/passwd- (backup file) */ diff --git a/src/pwunconv.c b/src/pwunconv.c index f1169441..e38097b4 100644 --- a/src/pwunconv.c +++ b/src/pwunconv.c @@ -83,22 +83,30 @@ int main (int argc, char **argv) } if (pw_lock () == 0) { - fprintf (stderr, _("%s: can't lock passwd file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), + Prog, pw_dbname ()); fail_exit (5); } passwd_locked = true; if (pw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open passwd file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), + Prog, pw_dbname ()); fail_exit (1); } if (spw_lock () == 0) { - fprintf (stderr, _("%s: can't lock shadow file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), + Prog, spw_dbname ()); fail_exit (5); } shadow_locked = true; if (spw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: can't open shadow file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), + Prog, spw_dbname ()); fail_exit (1); } @@ -138,18 +146,21 @@ int main (int argc, char **argv) if (spw_close () == 0) { fprintf (stderr, - _("%s: can't update shadow password file\n"), Prog); + _("%s: failure while writing changes to %s\n"), + Prog, spw_dbname ()); fail_exit (3); } if (pw_close () == 0) { - fprintf (stderr, _("%s: can't update password file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, pw_dbname ()); fail_exit (3); } if (unlink (SHADOW) != 0) { fprintf (stderr, - _("%s: can't delete shadow password file\n"), Prog); + _("%s: cannot delete %s\n"), Prog, SHADOW); fail_exit (3); } diff --git a/src/useradd.c b/src/useradd.c index 272181e8..4d81f6d4 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -194,21 +194,58 @@ static void create_mail (void); */ static void fail_exit (int code) { - if (home_added) + if (home_added) { rmdir (user_home); + } if (shadow_locked) { - spw_unlock (); + if (spw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", spw_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking shadow file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } } if (passwd_locked) { - pw_unlock (); + if (pw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking passwd file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } } if (group_locked) { - gr_unlock (); + if (gr_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking group file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } } #ifdef SHADOWGRP if (gshadow_locked) { - sgr_unlock (); + if (sgr_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking gshadow file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } } #endif @@ -318,7 +355,7 @@ static void get_defaults (void) def_gname = xstrdup (grp->gr_name); } else { fprintf (stderr, - _("%s: unknown GID %s\n"), + _("%s: GID '%s' does not exist\n"), Prog, cp); } /* local, no need for xgetgrnam */ @@ -327,7 +364,7 @@ static void get_defaults (void) def_gname = xstrdup (cp); } else { fprintf (stderr, - _("%s: unknown group %s\n"), Prog, cp); + _("%s: group '%s' does not exist\n"), Prog, cp); } } @@ -599,7 +636,7 @@ static int get_groups (char *list) * string name. */ if (NULL == grp) { - fprintf (stderr, _("%s: unknown group %s\n"), + fprintf (stderr, _("%s: group '%s' does not exist\n"), Prog, list); errors++; } @@ -703,10 +740,11 @@ static void new_pwent (struct passwd *pwent) { memzero (pwent, sizeof *pwent); pwent->pw_name = (char *) user_name; - if (is_shadow_pwd) + if (is_shadow_pwd) { pwent->pw_passwd = (char *) SHADOW_PASSWD_STRING; - else + } else { pwent->pw_passwd = (char *) user_pass; + } pwent->pw_uid = user_id; pwent->pw_gid = user_gid; @@ -717,8 +755,9 @@ static void new_pwent (struct passwd *pwent) static long scale_age (long x) { - if (x <= 0) + if (x <= 0) { return x; + } return x * (DAY / SCALE); } @@ -776,14 +815,15 @@ static void grp_update (void) * Scan through the entire group file looking for the groups that * the user is a member of. */ - for (gr_rewind (), grp = gr_next (); grp; grp = gr_next ()) { + for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) { /* * See if the user specified this group as one of their * concurrent groups. */ - if (!is_on_list (user_groups, grp->gr_name)) + if (!is_on_list (user_groups, grp->gr_name)) { continue; + } /* * Make a copy - gr_update() will free() everything @@ -831,11 +871,13 @@ static void grp_update (void) * See if the user specified this group as one of their * concurrent groups. */ - if (gr_locate (sgrp->sg_name) == NULL) + if (gr_locate (sgrp->sg_name) == NULL) { continue; + } - if (!is_on_list (user_groups, sgrp->sg_name)) + if (!is_on_list (user_groups, sgrp->sg_name)) { continue; + } /* * Make a copy - sgr_update() will free() everything @@ -844,8 +886,8 @@ static void grp_update (void) nsgrp = __sgr_dup (sgrp); if (NULL == nsgrp) { fprintf (stderr, - _("%s: Out of memory. Cannot update the shadow group database.\n"), - Prog); + _("%s: Out of memory. Cannot update %s.\n"), + Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); /* XXX */ } @@ -856,7 +898,7 @@ static void grp_update (void) nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_name); if (sgr_update (nsgrp) == 0) { fprintf (stderr, - _("%s: error adding new group entry\n"), Prog); + _("%s: error adding new entry to %s\n"), Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT @@ -915,12 +957,11 @@ static void process_flags (int argc, char **argv) long_options, NULL)) != -1) { switch (c) { case 'b': - if (!VALID (optarg) - || optarg[0] != '/') { + if ( ( !VALID (optarg) ) + || ( optarg[0] != '/' )) { fprintf (stderr, - _ - ("%s: invalid base directory '%s'\n"), - Prog, optarg); + _("%s: invalid base directory '%s'\n"), + Prog, optarg); exit (E_BAD_ARG); } def_home = optarg; @@ -929,29 +970,28 @@ static void process_flags (int argc, char **argv) case 'c': if (!VALID (optarg)) { fprintf (stderr, - _ - ("%s: invalid comment '%s'\n"), - Prog, optarg); + _("%s: invalid comment '%s'\n"), + Prog, optarg); exit (E_BAD_ARG); } user_comment = optarg; cflg = true; break; case 'd': - if (!VALID (optarg) - || optarg[0] != '/') { + if ( ( !VALID (optarg) ) + || ( optarg[0] != '/' )) { fprintf (stderr, - _ - ("%s: invalid home directory '%s'\n"), - Prog, optarg); + _("%s: invalid home directory '%s'\n"), + Prog, optarg); exit (E_BAD_ARG); } user_home = optarg; dflg = true; break; case 'D': - if (anyflag) + if (anyflag) { usage (); + } Dflg = true; break; case 'e': @@ -959,26 +999,26 @@ static void process_flags (int argc, char **argv) user_expire = strtoday (optarg); if (user_expire == -1) { fprintf (stderr, - _ - ("%s: invalid date '%s'\n"), - Prog, optarg); + _("%s: invalid date '%s'\n"), + Prog, optarg); exit (E_BAD_ARG); } - } else + } else { user_expire = -1; + } /* * -e "" is allowed - it's a no-op without /etc/shadow */ if (('\0' != *optarg) && !is_shadow_pwd) { fprintf (stderr, - _ - ("%s: shadow passwords required for -e\n"), - Prog); + _("%s: shadow passwords required for -e\n"), + Prog); exit (E_USAGE); } - if (Dflg) + if (Dflg) { def_expire = optarg; + } eflg = true; break; case 'f': @@ -1037,16 +1077,16 @@ static void process_flags (int argc, char **argv) cp = strchr (optarg, '='); if (NULL == cp) { fprintf (stderr, - _ - ("%s: -K requires KEY=VALUE\n"), - Prog); + _("%s: -K requires KEY=VALUE\n"), + Prog); exit (E_BAD_ARG); } /* terminate name, point to value */ *cp = '\0'; cp++; - if (putdef_str (optarg, cp) < 0) + if (putdef_str (optarg, cp) < 0) { exit (E_BAD_ARG); + } break; case 'l': lflg = true; @@ -1063,9 +1103,8 @@ static void process_flags (int argc, char **argv) case 'p': /* set encrypted password */ if (!VALID (optarg)) { fprintf (stderr, - _ - ("%s: invalid field '%s'\n"), - Prog, optarg); + _("%s: invalid field '%s'\n"), + Prog, optarg); exit (E_BAD_ARG); } user_pass = optarg; @@ -1074,14 +1113,13 @@ static void process_flags (int argc, char **argv) rflg = true; break; case 's': - if (!VALID (optarg) + if ( ( !VALID (optarg) ) || ( ('\0' != optarg[0]) && ('/' != optarg[0]) - && ('*' != optarg[0]))) { + && ('*' != optarg[0]) )) { fprintf (stderr, - _ - ("%s: invalid shell '%s'\n"), - Prog, optarg); + _("%s: invalid shell '%s'\n"), + Prog, optarg); exit (E_BAD_ARG); } user_shell = optarg; @@ -1113,13 +1151,13 @@ static void process_flags (int argc, char **argv) */ if (oflg && !uflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-o", "-u"); usage (); } if (kflg && !mflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-k", "-m"); usage (); } @@ -1141,21 +1179,23 @@ static void process_flags (int argc, char **argv) * for the -b, -e, -f, -g, -s options only. */ if (Dflg) { - if (optind != argc) + if (optind != argc) { usage (); + } - if (uflg || oflg || Gflg || dflg || cflg || mflg) + if (uflg || oflg || Gflg || dflg || cflg || mflg) { usage (); + } } else { - if (optind != argc - 1) + if (optind != argc - 1) { usage (); + } user_name = argv[optind]; if (!is_valid_user_name (user_name)) { fprintf (stderr, - _ - ("%s: invalid user name '%s'\n"), - Prog, user_name); + _("%s: invalid user name '%s'\n"), + Prog, user_name); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding user", @@ -1173,14 +1213,17 @@ static void process_flags (int argc, char **argv) } } - if (!eflg) + if (!eflg) { user_expire = strtoday (def_expire); + } - if (!gflg) + if (!gflg) { user_gid = def_group; + } - if (!sflg) + if (!sflg) { user_shell = def_shell; + } /* TODO: add handle change default spool mail creation by -K CREATE_MAIL_SPOOL={yes,no}. It need rewrite internal API for handle @@ -1197,41 +1240,80 @@ static void process_flags (int argc, char **argv) static void close_files (void) { if (pw_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog); + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", pw_dbname ())); fail_exit (E_PW_UPDATE); } if (is_shadow_pwd && (spw_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite shadow password file\n"), Prog); + _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", spw_dbname ())); fail_exit (E_PW_UPDATE); } if (do_grp_update) { if (gr_close () == 0) { fprintf (stderr, - _("%s: cannot rewrite group file\n"), Prog); + _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", gr_dbname ())); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP if (is_shadow_grp && (sgr_close () == 0)) { fprintf (stderr, - _ - ("%s: cannot rewrite shadow group file\n"), - Prog); + _("%s: failure while writing changes to %s\n"), + Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failure while writing changes to %s", sgr_dbname ())); fail_exit (E_GRP_UPDATE); } #endif } if (is_shadow_pwd) { - spw_unlock (); + if (spw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", spw_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking shadow file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } shadow_locked = false; } - pw_unlock (); + if (pw_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", pw_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking passwd file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } passwd_locked = false; - gr_unlock (); + if (gr_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", gr_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking group file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } group_locked = false; #ifdef SHADOWGRP if (is_shadow_grp) { - sgr_unlock (); + if (sgr_unlock () == 0) { + fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); + SYSLOG ((LOG_WARN, "failed to unlock %s", sgr_dbname ())); +#ifdef WITH_AUDIT + audit_logger (AUDIT_USER_CHAUTHTOK, Prog, + "unlocking gshadow file", + user_name, AUDIT_NO_ID, 0); +#endif + /* continue */ + } gshadow_locked = false; } #endif @@ -1245,46 +1327,26 @@ static void close_files (void) static void open_files (void) { if (pw_lock () == 0) { - fprintf (stderr, _("%s: unable to lock password file\n"), Prog); -#ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, Prog, - "locking password file", - user_name, (unsigned int) user_id, 0); -#endif + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pw_dbname ()); exit (E_PW_UPDATE); } passwd_locked = true; if (pw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: unable to open password file\n"), Prog); -#ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, Prog, - "opening password file", - user_name, (unsigned int) user_id, 0); -#endif + fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ()); fail_exit (E_PW_UPDATE); } if (is_shadow_pwd) { if (spw_lock () == 0) { fprintf (stderr, - _("%s: cannot lock shadow password file\n"), - Prog); -#ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, Prog, - "locking shadow password file", - user_name, (unsigned int) user_id, 0); -#endif + _("%s: cannot lock %s\n"), + Prog, spw_dbname ()); fail_exit (E_PW_UPDATE); } shadow_locked = true; if (spw_open (O_RDWR) == 0) { fprintf (stderr, - _("%s: cannot open shadow password file\n"), - Prog); -#ifdef WITH_AUDIT - audit_logger (AUDIT_USER_CHAUTHTOK, Prog, - "opening shadow password file", - user_name, (unsigned int) user_id, 0); -#endif + _("%s: cannot open %s\n"), + Prog, spw_dbname ()); fail_exit (E_PW_UPDATE); } } @@ -1293,27 +1355,27 @@ static void open_files (void) * Lock and open the group file. */ if (gr_lock () == 0) { - fprintf (stderr, _("%s: error locking group file\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, gr_dbname ()); fail_exit (E_GRP_UPDATE); } group_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: error opening group file\n"), Prog); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP if (is_shadow_grp) { if (sgr_lock () == 0) { fprintf (stderr, - _("%s: error locking shadow group file\n"), - Prog); + _("%s: cannot lock %s\n"), + Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } gshadow_locked = true; if (sgr_open (O_RDWR) == 0) { fprintf (stderr, - _("%s: error opening shadow group file\n"), - Prog); + _("%s: cannot open %s\n"), + Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } } @@ -1419,6 +1481,8 @@ static void faillog_reset (uid_t uid) fprintf (stderr, _("%s: failed to reset the faillog entry of UID %lu: %s\n"), Prog, (unsigned long) uid, strerror (errno)); + SYSLOG ((LOG_WARN, "failed to reset the faillog entry of UID %lu", (unsigned long) uid)); + /* continue */ } } @@ -1442,6 +1506,8 @@ static void lastlog_reset (uid_t uid) fprintf (stderr, _("%s: failed to reset the lastlog entry of UID %lu: %s\n"), Prog, (unsigned long) uid, strerror (errno)); + SYSLOG ((LOG_WARN, "failed to reset the lastlog entry of UID %lu", (unsigned long) uid)); + /* continue */ } } @@ -1665,19 +1731,14 @@ int main (int argc, char **argv) if (PAM_SUCCESS == retval) { retval = pam_authenticate (pamh, 0); - if (PAM_SUCCESS != retval) { - (void) pam_end (pamh, retval); - } } if (PAM_SUCCESS == retval) { retval = pam_acct_mgmt (pamh, 0); - if (PAM_SUCCESS != retval) { - (void) pam_end (pamh, retval); - } } if (PAM_SUCCESS != retval) { + (void) pam_end (pamh, retval); fprintf (stderr, _("%s: PAM authentication failed\n"), Prog); fail_exit (1); } @@ -1700,7 +1761,7 @@ int main (int argc, char **argv) * Start with a quick check to see if the user exists. */ if (getpwnam (user_name) != NULL) { /* local, no need for xgetpwnam */ - fprintf (stderr, _("%s: user %s exists\n"), Prog, user_name); + fprintf (stderr, _("%s: user '%s' already exists\n"), Prog, user_name); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding user", @@ -1719,8 +1780,7 @@ int main (int argc, char **argv) /* local, no need for xgetgrnam */ if (getgrnam (user_name) != NULL) { fprintf (stderr, - _ - ("%s: group %s exists - if you want to add this user to that group, use -g.\n"), + _("%s: group %s exists - if you want to add this user to that group, use -g.\n"), Prog, user_name); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, @@ -1818,9 +1878,7 @@ int main (int argc, char **argv) nscd_flush_cache ("group"); #ifdef USE_PAM - if (PAM_SUCCESS == retval) { - (void) pam_end (pamh, PAM_SUCCESS); - } + (void) pam_end (pamh, PAM_SUCCESS); #endif /* USE_PAM */ return E_SUCCESS; diff --git a/src/userdel.c b/src/userdel.c index f402c058..7e7e15da 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -146,8 +146,9 @@ static void update_groups (void) * See if the user specified this group as one of their * concurrent groups. */ - if (!is_on_list (grp->gr_mem, user_name)) + if (!is_on_list (grp->gr_mem, user_name)) { continue; + } /* * Delete the username from the list of group members and @@ -156,8 +157,8 @@ static void update_groups (void) ngrp = __gr_dup (grp); if (NULL == ngrp) { fprintf (stderr, - _("%s: Out of memory. Cannot update the group database.\n"), - Prog); + _("%s: Out of memory. Cannot update %s.\n"), + Prog, gr_dbname ()); exit (13); /* XXX */ } ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); @@ -202,9 +203,8 @@ static void update_groups (void) } if (pwd->pw_gid == grp->gr_gid) { fprintf (stderr, - _ - ("%s: Cannot remove group %s which is a primary group for another user.\n"), - Prog, grp->gr_name); + _("%s: Cannot remove group %s which is a primary group for another user.\n"), + Prog, grp->gr_name); break; } } @@ -261,8 +261,8 @@ static void update_groups (void) nsgrp = __sgr_dup (sgrp); if (NULL == nsgrp) { fprintf (stderr, - _("%s: Out of memory. Cannot update the shadow group database.\n"), - Prog); + _("%s: Out of memory. Cannot update %s.\n"), + Prog, sgr_dbname ()); exit (13); /* XXX */ } @@ -288,8 +288,9 @@ static void update_groups (void) user_name, nsgrp->sg_name)); } - if (deleted_user_group) + if (deleted_user_group) { sgr_remove (user_name); + } #endif /* SHADOWGRP */ } @@ -301,19 +302,23 @@ static void update_groups (void) */ static void close_files (void) { - if (pw_close () == 0) - fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog); - if (is_shadow_pwd && (spw_close () == 0)) + if (pw_close () == 0) { + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); + } + if (is_shadow_pwd && (spw_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite shadow password file\n"), Prog); - if (gr_close () == 0) - fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog); + _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); + } + if (gr_close () == 0) { + fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); + } gr_unlock (); #ifdef SHADOWGRP - if (is_shadow_grp && (sgr_close () == 0)) + if (is_shadow_grp && (sgr_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite shadow group file\n"), Prog); + _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); + } if (is_shadow_grp) { sgr_unlock (); @@ -357,7 +362,7 @@ static void fail_exit (int code) static void open_files (void) { if (pw_lock () == 0) { - fprintf (stderr, _("%s: unable to lock password file\n"), Prog); + fprintf (stderr, _("%s: cannot lock %s\n"), Prog, pw_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking password file", @@ -366,7 +371,8 @@ static void open_files (void) exit (E_PW_UPDATE); } if (pw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: unable to open password file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening password file", @@ -376,7 +382,7 @@ static void open_files (void) } if (is_shadow_pwd && (spw_lock () == 0)) { fprintf (stderr, - _("%s: cannot lock shadow password file\n"), Prog); + _("%s: cannot lock %s\n"), Prog, spw_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking shadow password file", @@ -386,7 +392,7 @@ static void open_files (void) } if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) { fprintf (stderr, - _("%s: cannot open shadow password file\n"), Prog); + _("%s: cannot open %s\n"), Prog, spw_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening shadow password file", @@ -395,7 +401,8 @@ static void open_files (void) fail_exit (E_PW_UPDATE); } if (gr_lock () == 0) { - fprintf (stderr, _("%s: unable to lock group file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, gr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking group file", @@ -404,7 +411,7 @@ static void open_files (void) fail_exit (E_GRP_UPDATE); } if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open group file\n"), Prog); + fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening group file", @@ -415,7 +422,7 @@ static void open_files (void) #ifdef SHADOWGRP if (is_shadow_grp && (sgr_lock () == 0)) { fprintf (stderr, - _("%s: unable to lock shadow group file\n"), Prog); + _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking shadow group file", @@ -424,8 +431,8 @@ static void open_files (void) fail_exit (E_GRP_UPDATE); } if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) { - fprintf (stderr, _("%s: cannot open shadow group file\n"), - Prog); + fprintf (stderr, _("%s: cannot open %s\n"), + Prog, sgr_dbname ()); #ifdef WITH_AUDIT audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening shadow group file", @@ -446,12 +453,14 @@ static void update_user (void) { if (pw_remove (user_name) == 0) { fprintf (stderr, - _("%s: error deleting password entry\n"), Prog); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, user_name, pw_dbname ()); fail_exit (E_PW_UPDATE); } if (is_shadow_pwd && (spw_remove (user_name) == 0)) { fprintf (stderr, - _("%s: error deleting shadow password entry\n"), Prog); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, user_name, spw_dbname ()); fail_exit (E_PW_UPDATE); } #ifdef WITH_AUDIT @@ -709,21 +718,16 @@ int main (int argc, char **argv) } } - if (retval == PAM_SUCCESS) { + if (PAM_SUCCESS == retval) { retval = pam_authenticate (pamh, 0); - if (retval != PAM_SUCCESS) { - (void) pam_end (pamh, retval); - } } - if (retval == PAM_SUCCESS) { + if (PAM_SUCCESS == retval) { retval = pam_acct_mgmt (pamh, 0); - if (retval != PAM_SUCCESS) { - (void) pam_end (pamh, retval); - } } - if (retval != PAM_SUCCESS) { + if (PAM_SUCCESS != retval) { + (void) pam_end (pamh, retval); fprintf (stderr, _("%s: PAM authentication failed\n"), Prog); exit (E_PW_UPDATE); } @@ -858,9 +862,7 @@ int main (int argc, char **argv) nscd_flush_cache ("group"); #ifdef USE_PAM - if (retval == PAM_SUCCESS) { - (void) pam_end (pamh, PAM_SUCCESS); - } + (void) pam_end (pamh, PAM_SUCCESS); #endif /* USE_PAM */ #ifdef WITH_AUDIT if (0 != errors) { diff --git a/src/usermod.c b/src/usermod.c index 223f5946..aee90f8c 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -279,9 +279,8 @@ static int get_groups (char *list) if (ngroups == sys_ngroups) { fprintf (stderr, - _ - ("%s: too many groups specified (max %d).\n"), - Prog, ngroups); + _("%s: too many groups specified (max %d).\n"), + Prog, ngroups); break; } @@ -358,8 +357,8 @@ static char *new_pw_passwd (char *pw_pass) if (pw_pass[1] == '\0') { fprintf (stderr, - _("%s: unlocking the user would result in a passwordless account.\n" - "You should set a password with usermod -p to unlock this user account.\n"), + _("%s: unlocking the user's password would result in a passwordless account.\n" + "You should set a password with usermod -p to unlock this user's password.\n"), Prog); return pw_pass; } @@ -569,8 +568,8 @@ static void update_group (void) ngrp = __gr_dup (grp); if (NULL == ngrp) { fprintf (stderr, - _("%s: Out of memory. Cannot update the group database.\n"), - Prog); + _("%s: Out of memory. Cannot update %s.\n"), + Prog, gr_dbname ()); fail_exit (E_GRP_UPDATE); } @@ -619,8 +618,9 @@ static void update_group (void) changed = false; if (gr_update (ngrp) == 0) { fprintf (stderr, - _("%s: error adding new group entry\n"), Prog); - SYSLOG ((LOG_ERR, "error adding new group entry")); + _("%s: error adding new entry '%s' in %s\n"), + Prog, ngrp->gr_name, gr_dbname ()); + SYSLOG ((LOG_ERR, "error adding new entry '%s' in %s", ngrp->gr_name, gr_dbname ())); fail_exit (E_GRP_UPDATE); } } @@ -669,8 +669,8 @@ static void update_gshadow (void) nsgrp = __sgr_dup (sgrp); if (NULL == nsgrp) { fprintf (stderr, - _("%s: Out of memory. Cannot update the shadow group database.\n"), - Prog); + _("%s: Out of memory. Cannot update %s.\n"), + Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } @@ -737,8 +737,10 @@ static void update_gshadow (void) */ if (sgr_update (nsgrp) == 0) { fprintf (stderr, - _("%s: error adding new shadow group entry\n"), Prog); - SYSLOG ((LOG_ERR, "error adding shadow group entry")); + _("%s: error adding new entry '%s' in '%s\n"), + Prog, nsgrp->sg_name, sgr_dbname ()); + SYSLOG ((LOG_ERR, "error adding new entry '%s' in %s", + nsgrp->sg_name, sgr_dbname ())); fail_exit (E_GRP_UPDATE); } } @@ -1048,7 +1050,7 @@ static void process_flags (int argc, char **argv) if (aflg && (!Gflg)) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-a", "-G"); usage (); exit (E_USAGE); @@ -1064,7 +1066,7 @@ static void process_flags (int argc, char **argv) if (oflg && !uflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-o", "-u"); usage (); exit (E_USAGE); @@ -1072,7 +1074,7 @@ static void process_flags (int argc, char **argv) if (mflg && !dflg) { fprintf (stderr, - _("%s: %s flag is ONLY allowed with the %s flag\n"), + _("%s: %s flag is only allowed with the %s flag\n"), Prog, "-m", "-d"); usage (); exit (E_USAGE); @@ -1080,13 +1082,13 @@ static void process_flags (int argc, char **argv) /* local, no need for xgetpwnam */ if (lflg && (getpwnam (user_newname) != NULL)) { - fprintf (stderr, _("%s: user %s exists\n"), Prog, user_newname); + fprintf (stderr, _("%s: user '%s' already exists\n"), Prog, user_newname); exit (E_NAME_IN_USE); } /* local, no need for xgetpwuid */ if (uflg && !oflg && (getpwuid (user_newid) != NULL)) { - fprintf (stderr, _("%s: uid %lu is not unique\n"), + fprintf (stderr, _("%s: UID '%lu' already exists\n"), Prog, (unsigned long) user_newid); exit (E_UID_IN_USE); } @@ -1101,26 +1103,28 @@ static void process_flags (int argc, char **argv) static void close_files (void) { if (pw_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); fail_exit (E_PW_UPDATE); } if (is_shadow_pwd && (spw_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite shadow password file\n"), Prog); + _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); fail_exit (E_PW_UPDATE); } if (Gflg || lflg) { if (gr_close () == 0) { - fprintf (stderr, _("%s: cannot rewrite group file\n"), - Prog); + fprintf (stderr, + _("%s: failure while writing changes to %s\n"), + Prog, gr_dbname ()); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP if (is_shadow_grp && (sgr_close () == 0)) { fprintf (stderr, - _("%s: cannot rewrite shadow group file\n"), - Prog); + _("%s: failure while writing changes to %s\n"), + Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } if (is_shadow_grp) { @@ -1161,23 +1165,25 @@ static void close_files (void) static void open_files (void) { if (pw_lock () == 0) { - fprintf (stderr, _("%s: unable to lock password file\n"), Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, pw_dbname ()); fail_exit (E_PW_UPDATE); } pw_locked = true; if (pw_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: unable to open password file\n"), Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, pw_dbname ()); fail_exit (E_PW_UPDATE); } if (is_shadow_pwd && (spw_lock () == 0)) { fprintf (stderr, - _("%s: cannot lock shadow password file\n"), Prog); + _("%s: cannot lock %s\n"), Prog, spw_dbname ()); fail_exit (E_PW_UPDATE); } spw_locked = true; if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) { fprintf (stderr, - _("%s: cannot open shadow password file\n"), Prog); + _("%s: cannot open %s\n"), Prog, spw_dbname ()); fail_exit (E_PW_UPDATE); } @@ -1187,28 +1193,26 @@ static void open_files (void) * group entries. */ if (gr_lock () == 0) { - fprintf (stderr, _("%s: error locking group file\n"), - Prog); + fprintf (stderr, + _("%s: cannot lock %s\n"), Prog, gr_dbname ()); fail_exit (E_GRP_UPDATE); } gr_locked = true; if (gr_open (O_RDWR) == 0) { - fprintf (stderr, _("%s: error opening group file\n"), - Prog); + fprintf (stderr, + _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP if (is_shadow_grp && (sgr_lock () == 0)) { fprintf (stderr, - _("%s: error locking shadow group file\n"), - Prog); + _("%s: cannot lock %s\n"), Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } sgr_locked = true; if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) { fprintf (stderr, - _("%s: error opening shadow group file\n"), - Prog); + _("%s: cannot open %s\n"), Prog, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } #endif @@ -1234,8 +1238,8 @@ static void usr_update (void) */ pwd = pw_locate (user_name); if (NULL == pwd) { - fprintf (stderr, _("%s: %s not found in /etc/passwd\n"), - Prog, user_name); + fprintf (stderr, _("%s: user '%s' does not exist in %s\n"), + Prog, user_name, pw_dbname ()); fail_exit (E_NOTFOUND); } pwent = *pwd; @@ -1255,30 +1259,28 @@ static void usr_update (void) || Lflg || Uflg) { if (pw_update (&pwent) == 0) { fprintf (stderr, - _("%s: error changing password entry\n"), - Prog); + _("%s: cannot add new entry '%s' in %s\n"), + Prog, pwent.pw_name, pw_dbname ()); fail_exit (E_PW_UPDATE); } if (lflg && (pw_remove (user_name) == 0)) { fprintf (stderr, - _("%s: error removing password entry\n"), - Prog); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, user_name, pw_dbname ()); fail_exit (E_PW_UPDATE); } } if ((NULL != spwd) && (lflg || eflg || fflg || pflg || Lflg || Uflg)) { if (spw_update (&spent) == 0) { fprintf (stderr, - _ - ("%s: error adding new shadow password entry\n"), - Prog); + _("%s: cannot add new entry '%s' in %s\n"), + Prog, spent.sp_namp, spw_dbname ()); fail_exit (E_PW_UPDATE); } if (lflg && (spw_remove (user_name) == 0)) { fprintf (stderr, - _ - ("%s: error removing shadow password entry\n"), - Prog); + _("%s: cannot remove entry '%s' from %s\n"), + Prog, user_name, spw_dbname ()); fail_exit (E_PW_UPDATE); } } @@ -1311,9 +1313,8 @@ static void move_home (void) if (errno == EXDEV) { if (mkdir (user_newhome, sb.st_mode & 0777) != 0) { fprintf (stderr, - _ - ("%s: can't create %s\n"), - Prog, user_newhome); + _("%s: can't create %s\n"), + Prog, user_newhome); } if (chown (user_newhome, sb.st_uid, sb.st_gid) != 0) { fprintf (stderr, @@ -1347,9 +1348,8 @@ static void move_home (void) (void) remove_tree (user_newhome); } fprintf (stderr, - _ - ("%s: cannot rename directory %s to %s\n"), - Prog, user_home, user_newhome); + _("%s: cannot rename directory %s to %s\n"), + Prog, user_home, user_newhome); fail_exit (E_HOMEDIR); } #ifdef WITH_AUDIT @@ -1523,8 +1523,9 @@ static void move_mailbox (void) fd = open (mailfile, O_RDONLY | O_NONBLOCK, 0); if (fd < 0) { /* no need for warnings if the mailbox doesn't exist */ - if (errno != ENOENT) + if (errno != ENOENT) { perror (mailfile); + } return; } if (fstat (fd, &st) < 0) { @@ -1626,19 +1627,14 @@ int main (int argc, char **argv) if (PAM_SUCCESS == retval) { retval = pam_authenticate (pamh, 0); - if (PAM_SUCCESS != retval) { - (void) pam_end (pamh, retval); - } } if (PAM_SUCCESS == retval) { retval = pam_acct_mgmt (pamh, 0); - if (PAM_SUCCESS != retval) { - (void) pam_end (pamh, retval); - } } if (PAM_SUCCESS != retval) { + (void) pam_end (pamh, retval); fprintf (stderr, _("%s: PAM authentication failed\n"), Prog); exit (1); } @@ -1685,9 +1681,7 @@ int main (int argc, char **argv) } #ifdef USE_PAM - if (PAM_SUCCESS == retval) { - (void) pam_end (pamh, PAM_SUCCESS); - } + (void) pam_end (pamh, PAM_SUCCESS); #endif /* USE_PAM */ exit (E_SUCCESS);