[Pkg-shadow-commits] r2248 - in upstream/trunk: . src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Thu Aug 7 08:03:14 UTC 2008


Author: nekral-guest
Date: 2008-08-07 08:03:13 +0000 (Thu, 07 Aug 2008)
New Revision: 2248

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/newusers.c
Log:
	* 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.

Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-08-07 08:02:52 UTC (rev 2247)
+++ upstream/trunk/ChangeLog	2008-08-07 08:03:13 UTC (rev 2248)
@@ -1,3 +1,12 @@
+2008-08-07  Nicolas François  <nicolas.francois at 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 at centraliens.net>
 
 	* src/chage.c: Report failure to unlock the passwd or shadow file

Modified: upstream/trunk/src/newusers.c
===================================================================
--- upstream/trunk/src/newusers.c	2008-08-07 08:02:52 UTC (rev 2247)
+++ upstream/trunk/src/newusers.c	2008-08-07 08:03:13 UTC (rev 2248)
@@ -129,17 +129,33 @@
 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 @@
 	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 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 @@
 	if (0 != errors) {
 		fprintf (stderr,
 		         _("%s: error detected, changes ignored\n"), Prog);
-		gr_unlock ();
-		if (is_shadow) {
-			spw_unlock ();
-		}
-		pw_unlock ();
 		fail_exit (1);
 	}
 




More information about the Pkg-shadow-commits mailing list