]> granicus.if.org Git - shadow/commitdiff
* src/newusers.c: Report failure to unlock the passwd or shadow
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 7 Aug 2008 08:03:13 +0000 (08:03 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 7 Aug 2008 08:03:13 +0000 (08:03 +0000)
file to stderr and syslog.
* src/newusers.c: In case of error when files are open or closed,
indicate the failing file.
* src/newusers.c: Do not try to unlock the files manually since
this is done in fail_exit.

ChangeLog
src/newusers.c

index 5ef40352de577c344f9a20e61584cdce0e281745..4bb23bdb7d9dc62e7e20407d3da16d5a716f7a4c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-08-07  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * src/newusers.c: Report failure to unlock the passwd or shadow
+       file to stderr and syslog.
+       * src/newusers.c: In case of error when files are open or closed,
+       indicate the failing file.
+       * src/newusers.c: Do not try to unlock the files manually since
+       this is done in fail_exit.
+
 2008-08-06  Nicolas François  <nicolas.francois@centraliens.net>
 
        * src/chage.c: Report failure to unlock the passwd or shadow file
index 1dcd2804a57d31e151462989695ca7b19c50e52c..feda58dcc98adf0abe25082e402c53e2b30b5907 100644 (file)
@@ -129,17 +129,33 @@ static void usage (void)
 static void fail_exit (int code)
 {
        if (shadow_locked) {
-               spw_unlock ();
+               if (spw_unlock () == 0) {
+                       fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
+                       SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
+                       /* continue */
+               }
        }
        if (passwd_locked) {
-               pw_unlock ();
+               if (pw_unlock () == 0) {
+                       fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
+                       SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
+                       /* continue */
+               }
        }
        if (group_locked) {
-               gr_unlock ();
+               if (gr_unlock () == 0) {
+                       fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
+                       SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
+                       /* 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_ERR, "failed to unlock %s", sgr_dbname ()));
+                       /* continue */
+               }
        }
 #endif
 
@@ -614,16 +630,24 @@ static void open_files (void)
        gshadow_locked = true;
 #endif
 
-       if (   (pw_open (O_RDWR) == 0)
-           || (is_shadow && (spw_open (O_RDWR) == 0))
-           || (gr_open (O_RDWR) == 0)
+       if (pw_open () == 0) {
+               fprintf (stderr, _("%s: cannot open %s\n"), Prog, pw_dbname ());
+               fail_exit (1);
+       }
+       if (is_shadow && (spw_open () == 0)) {
+               fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_dbname ());
+               fail_exit (1);
+       }
+       if (gr_open () == 0) {
+               fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ());
+               fail_exit (1);
+       }
 #ifdef SHADOWGRP
-           || (is_shadow_grp && (sgr_open(O_RDWR) == 0))
-#endif
-          ) {
-               fprintf (stderr, _("%s: can't open files\n"), Prog);
+       if (is_shadow_grp && (sgr_open () == 0)) {
+               fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ());
                fail_exit (1);
        }
+#endif
 }
 
 /*
@@ -631,30 +655,71 @@ static void open_files (void)
  */
 static void close_files (void)
 {
-       if (   (pw_close () == 0)
-           || (is_shadow && (spw_close () == 0))
-           || (gr_close () == 0)
-#ifdef SHADOWGRP
-           || (is_shadow_grp && (sgr_close() == 0))
-#endif
-          ) {
-               fprintf (stderr, _("%s: error updating files\n"), Prog);
+       if (pw_close () == 0) {
+               fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
+               SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
+               fail_exit (1);
+       }
+       if (pw_unlock () == 0) {
+               fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
+               SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
+               /* continue */
+       }
+       passwd_locked = false;
+
+       if (is_shadow) {
+               if (spw_close () == 0) {
+                       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 (1);
+               }
+               if (spw_unlock () == 0) {
+                       fprintf (stderr,
+                                _("%s: failed to unlock %s\n"),
+                                Prog, spw_dbname ());
+                       SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
+                       /* continue */
+               }
+               shadow_locked = false;
+       }
+
+       if (gr_close () == 0) {
+               fprintf (stderr,
+                        _("%s: failure while writing changes to %s\n"),
+                        Prog, gr_dbname ());
+               SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ()));
                fail_exit (1);
        }
+       if (gr_unlock () == 0) {
+               fprintf (stderr,
+                        _("%s: failed to unlock %s\n"),
+                        Prog, gr_dbname ());
+               SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
+               /* continue */
+       }
+       group_locked = false;
+
 #ifdef SHADOWGRP
        if (is_shadow_grp) {
-               sgr_unlock();
+               if (sgr_close () == 0) {
+                       fprintf (stderr,
+                                _("%s: failure while writing changes to %s\n"),
+                                Prog, sgr_dbname ());
+                       SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ()));
+                       fail_exit (1);
+               }
+               if (sgr_unlock () == 0) {
+                       fprintf (stderr,
+                                _("%s: failed to unlock %s\n"),
+                                Prog, sgr_dbname ());
+                       SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
+                       /* continue */
+               }
                gshadow_locked = false;
        }
 #endif
-       gr_unlock ();
-       group_locked = false;
-       if (is_shadow) {
-               spw_unlock ();
-               shadow_locked = false;
-       }
-       pw_unlock ();
-       passwd_locked = false;
 }
 
 int main (int argc, char **argv)
@@ -860,11 +925,6 @@ int main (int argc, char **argv)
        if (0 != errors) {
                fprintf (stderr,
                         _("%s: error detected, changes ignored\n"), Prog);
-               gr_unlock ();
-               if (is_shadow) {
-                       spw_unlock ();
-               }
-               pw_unlock ();
                fail_exit (1);
        }