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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Fri Aug 22 02:24:30 UTC 2008


Author: nekral-guest
Date: 2008-08-22 02:24:29 +0000 (Fri, 22 Aug 2008)
New Revision: 2277

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/passwd.c
Log:
	* src/passwd.c: Check failure to unlock files. Report errors to
	stderr and syslog, but continue.

Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-08-22 02:22:34 UTC (rev 2276)
+++ upstream/trunk/ChangeLog	2008-08-22 02:24:29 UTC (rev 2277)
@@ -1,3 +1,8 @@
+2008-08-18  Nicolas François  <nicolas.francois at centraliens.net>
+
+	* src/passwd.c: Check failure to unlock files. Report errors to
+	stderr and syslog, but continue.
+
 2008-08-17  Nicolas François  <nicolas.francois at centraliens.net>
 
 	* src/chfn.c, src/chgpasswd.c, src/chpasswd.c, src/gpasswd.c,

Modified: upstream/trunk/src/passwd.c
===================================================================
--- upstream/trunk/src/passwd.c	2008-08-22 02:22:34 UTC (rev 2276)
+++ upstream/trunk/src/passwd.c	2008-08-22 02:24:29 UTC (rev 2277)
@@ -100,6 +100,9 @@
 
 static bool do_update_age = false;
 
+static bool pw_locked = false;
+static bool spw_locked = false;
+
 #ifndef USE_PAM
 /*
  * Size of the biggest passwd:
@@ -461,8 +464,22 @@
 
 static void fail_exit (int status)
 {
-	pw_unlock ();
-	spw_unlock ();
+	if (pw_locked) {
+		if (pw_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
+			/* continue */
+		}
+	}
+
+	if (spw_locked) {
+		if (spw_unlock () == 0) {
+			fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ());
+			SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ()));
+			/* continue */
+		}
+	}
+
 	exit (status);
 }
 
@@ -517,6 +534,7 @@
 		         Prog, pw_dbname ());
 		exit (E_PWDBUSY);
 	}
+	pw_locked = true;
 	if (pw_open (O_RDWR) == 0) {
 		fprintf (stderr,
 		         _("%s: cannot open %s\n"),
@@ -548,7 +566,12 @@
 		SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
 		fail_exit (E_FAILURE);
 	}
-	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 */
+	}
+	pw_locked = false;
 }
 
 static void update_shadow (void)
@@ -562,6 +585,7 @@
 		         Prog, spw_dbname ());
 		exit (E_PWDBUSY);
 	}
+	spw_locked = true;
 	if (spw_open (O_RDWR) == 0) {
 		fprintf (stderr, _("%s: cannot open %s\n"), Prog, spw_dbname ());
 		SYSLOG ((LOG_ERR, "cannot open %s", spw_dbname ()));
@@ -570,9 +594,14 @@
 	sp = spw_locate (name);
 	if (NULL == sp) {
 		/* Try to update the password in /etc/passwd instead. */
-		spw_close ();
+		(void) spw_close ();
 		update_noshadow ();
-		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 */
+		}
+		spw_locked = false;
 		return;
 	}
 	nsp = __spw_dup (sp);
@@ -616,7 +645,12 @@
 		SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
 		fail_exit (E_FAILURE);
 	}
-	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 */
+	}
+	spw_locked = false;
 }
 
 static long getnumber (const char *numstr)




More information about the Pkg-shadow-commits mailing list