]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 6 Aug 2008 15:57:31 +0000 (15:57 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 6 Aug 2008 15:57:31 +0000 (15:57 +0000)
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.

29 files changed:
ChangeLog
lib/groupio.c
lib/groupio.h
lib/pwio.c
lib/pwio.h
lib/sgroupio.c
lib/sgroupio.h
lib/shadowio.c
lib/shadowio.h
src/chage.c
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

index 1e7cb1537201ac7e95dd871bb6cff584ca3f9ea9..623d53f3a6b55492909e1dec73216e01ea16cc8e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2008-08-06  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * 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  <nicolas.francois@centraliens.net>
 
        * src/groupadd.c: Harmonize error & syslog messages.
index 702fa7f99fef4a15c759d253abbc4613b55fa2a2..6ca720d8ba4f88630c93e9e859c78978425eba1c 100644 (file)
@@ -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);
index ba708940b3224905e0637005ac01f23e2522c229..9f2984c995975bfc670247056c4be33544273b8f 100644 (file)
 #include <grp.h>
 
 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
index f36fec227e60c698eaaaac159d3f6169fdffa4bf..63cdc51145701974ee24c5d395fa01926768f6ee 100644 (file)
@@ -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);
index 12a0e63f0bd5a8433d5e53023f59fe0d84660784..28f8bbd5284dc4b6be9ebb554c3899d51aa17e9f 100644 (file)
 
 #include <pwd.h>
 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
index af644a5ef5163c658ddceadb64faecbf8c63d551..1454bc55246912c7a4878dfcb705dae5b3cd9f59 100644 (file)
@@ -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);
index 01954f11a30c702581c0601fbe142826a2ba1007..c030afedf114975e5193731cdf704f291ed9e9db 100644 (file)
 
 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
index 4e1208f9f083b896a268be6d70d3270d291ac32a..810a6d43ebe5e1a55b4301f0cc2b79823576c85b 100644 (file)
@@ -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);
index b10f51e0b79aca3306a6fccfc1142f3568946537..c7db66b3615b2dcb60ad4284ebf2300057ac05bb 100644 (file)
 
 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
index 2810194a90b454baffba206c14c4a6d01a801bed..2f7a859b33b9262ea683d70e40d099008810d890 100644 (file)
@@ -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);
        }
index 3a45603bb125821ca56aa3f51d5957f20a945fce..cc4d9313400eaebecbbf7742d62bbe7f60d8fee1 100644 (file)
@@ -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);
                }
index 409b80d9a3494654a560d2d391f3117ab9d70656..f8a81272c2c0a9b67094b06425c7b1b78a8ae871 100644 (file)
@@ -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;
index b6cb0a2a5961cd24fac642c7c87f9be2805b9881..ac8ba50bb778f404c7588cd83d5e7d67a8c9c5f8 100644 (file)
@@ -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;
index 3dca9978d99b42aa3920599d5a4acc46f2d04f15..361f6b38a7d69b8561b33e3cb7d8992a65ee6808 100644 (file)
@@ -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 {
index f76672036c2538646c77b5a31c313956506e5120..d4dd16bcdf1695e52edc31240c544903851c983a 100644 (file)
@@ -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",
index a9962ebfe86418469027e75755aab6ec1151deb1..4bc7b8107c023f8719be3dace075a1f96c18e23b 100644 (file)
@@ -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);
                }
        }
index d84806aec568540024ca23594f2c23b842d698f0..3866b40ada318a867295572be2ceb4f794d8151f 100644 (file)
@@ -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);
                }
        }
index bfdb468b9d2349bb786f56da3a95aba04a20095d..49ade1e8b37010ce525775dae394a946bfc68f2a 100644 (file)
@@ -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;
index 2b83332d0268081d7194c0b9c1a2833872c0079b..d0619108a4a2ebc5211cf02f69442ba927354bbd 100644 (file)
@@ -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);
                }
index 6472c245df75c5940ca46e0477acab5c1ee17f6c..5b7ef05614b6d23e15ab7126216ddb0885ca041c 100644 (file)
@@ -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 ();
index 6fdc8b953bf203bf59d25e4d1dde42982e36e35c..b29a9ee2a0e2c28a1faf2c7a602b8b6aa2232954 100644 (file)
@@ -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 */
+
index 88f21f4bba55d4b59e4f9fd2ee775c9b778991b4..1dcd2804a57d31e151462989695ca7b19c50e52c 100644 (file)
@@ -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;
                }
index b2730b915d50847d643c918b249efbd49079a8a5..ff3dea408e784224f18d855a66a5f5917c23ddd3 100644 (file)
@@ -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));
index 96a390d74e3eea816a4df028965dbbaf327bee5a..803d98fbe8ead2779ac89ff8a3b3df1a555360d0 100644 (file)
@@ -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);
                }
index 79853341b57eb6ff0624bfad1677724f732d7088..ac09f33c242779af4b6969fe172d5bd7dffeca1d 100644 (file)
@@ -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) */
index f1169441ac4732f24c5b0d7b9344de04cc3fb9f6..e38097b44a5e24704d92f153d3befbe50bc9ce1a 100644 (file)
@@ -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);
        }
 
index 272181e8437b303ccfd0e0f50d8bfa3601025933..4d81f6d48a572024557862e07a7932a5d4ae1376 100644 (file)
@@ -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;
index f402c0585e8f3bb20d7db276c046c4e833838e42..7e7e15dad190d007569d9867b10d9773b06c3f58 100644 (file)
@@ -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) {
index 223f5946a8f8a91d39db313e57e3f25603fd0148..aee90f8cfacdd9ca1d4541643a6b12153fbdff17 100644 (file)
@@ -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);