9f13c6
commit 408b8a548243aebaa6d773beeae8ddf4bb6100f0
9f13c6
Author: Tomas Mraz <tmraz@fedoraproject.org>
9f13c6
Date:   Thu May 2 14:33:06 2019 +0200
9f13c6
9f13c6
    Use the lckpwdf() again if prefix is not set
9f13c6
    
9f13c6
    The implementation of prefix option dropped the use of lckpwdf().
9f13c6
    However that is incorrect as other tools manipulating the shadow passwords
9f13c6
    such as PAM use lckpwdf() and do not know anything about the
9f13c6
    shadow's own locking mechanism.
9f13c6
    
9f13c6
    This reverts the implementation to use lckpwdf() if prefix option
9f13c6
    is not used.
9f13c6
9f13c6
diff --git a/lib/commonio.c b/lib/commonio.c
9f13c6
index 26e518f2..94dda779 100644
9f13c6
--- a/lib/commonio.c
9f13c6
+++ b/lib/commonio.c
9f13c6
@@ -364,6 +364,7 @@ static void free_linked_list (struct commonio_db *db)
9f13c6
 int commonio_setname (struct commonio_db *db, const char *name)
9f13c6
 {
9f13c6
 	snprintf (db->filename, sizeof (db->filename), "%s", name);
9f13c6
+	db->setname = true;
9f13c6
 	return 1;
9f13c6
 }
9f13c6
 
9f13c6
@@ -414,37 +415,39 @@ cleanup_ENOMEM:
9f13c6
 
9f13c6
 int commonio_lock (struct commonio_db *db)
9f13c6
 {
9f13c6
-/*#ifdef HAVE_LCKPWDF*/ /* not compatible with prefix option*/
9f13c6
-#if 0
9f13c6
-	/*
9f13c6
-	 * only if the system libc has a real lckpwdf() - the one from
9f13c6
-	 * lockpw.c calls us and would cause infinite recursion!
9f13c6
-	 */
9f13c6
+	int i;
9f13c6
 
9f13c6
+#ifdef HAVE_LCKPWDF
9f13c6
 	/*
9f13c6
-	 * Call lckpwdf() on the first lock.
9f13c6
-	 * If it succeeds, call *_lock() only once
9f13c6
-	 * (no retries, it should always succeed).
9f13c6
+	 * Only if the system libc has a real lckpwdf() - the one from
9f13c6
+	 * lockpw.c calls us and would cause infinite recursion!
9f13c6
+	 * It is also not used with the prefix option.
9f13c6
 	 */
9f13c6
-	if (0 == lock_count) {
9f13c6
-		if (lckpwdf () == -1) {
9f13c6
-			if (geteuid () != 0) {
9f13c6
-				(void) fprintf (stderr,
9f13c6
-				                "%s: Permission denied.\n",
9f13c6
-				                Prog);
9f13c6
+	if (!db->setname) {
9f13c6
+		/*
9f13c6
+		 * Call lckpwdf() on the first lock.
9f13c6
+		 * If it succeeds, call *_lock() only once
9f13c6
+		 * (no retries, it should always succeed).
9f13c6
+		 */
9f13c6
+		if (0 == lock_count) {
9f13c6
+			if (lckpwdf () == -1) {
9f13c6
+				if (geteuid () != 0) {
9f13c6
+					(void) fprintf (stderr,
9f13c6
+					                "%s: Permission denied.\n",
9f13c6
+					                Prog);
9f13c6
+				}
9f13c6
+				return 0;	/* failure */
9f13c6
 			}
9f13c6
-			return 0;	/* failure */
9f13c6
 		}
9f13c6
-	}
9f13c6
 
9f13c6
-	if (commonio_lock_nowait (db, true) != 0) {
9f13c6
-		return 1;	/* success */
9f13c6
-	}
9f13c6
+		if (commonio_lock_nowait (db, true) != 0) {
9f13c6
+			return 1;	/* success */
9f13c6
+		}
9f13c6
 
9f13c6
-	ulckpwdf ();
9f13c6
-	return 0;		/* failure */
9f13c6
-#else				/* !HAVE_LCKPWDF */
9f13c6
-	int i;
9f13c6
+		ulckpwdf ();
9f13c6
+		return 0;		/* failure */
9f13c6
+	}
9f13c6
+#endif				/* !HAVE_LCKPWDF */
9f13c6
 
9f13c6
 	/*
9f13c6
 	 * lckpwdf() not used - do it the old way.
9f13c6
@@ -471,7 +474,6 @@ int commonio_lock (struct commonio_db *db)
9f13c6
 		}
9f13c6
 	}
9f13c6
 	return 0;		/* failure */
9f13c6
-#endif				/* !HAVE_LCKPWDF */
9f13c6
 }
9f13c6
 
9f13c6
 static void dec_lock_count (void)
9f13c6
diff --git a/lib/commonio.h b/lib/commonio.h
9f13c6
index 40e5708f..64e83073 100644
9f13c6
--- a/lib/commonio.h
9f13c6
+++ b/lib/commonio.h
9f13c6
@@ -143,6 +143,7 @@ struct commonio_db {
9f13c6
 	bool isopen:1;
9f13c6
 	bool locked:1;
9f13c6
 	bool readonly:1;
9f13c6
+	bool setname:1;
9f13c6
 };
9f13c6
 
9f13c6
 extern int commonio_setname (struct commonio_db *, const char *);
9f13c6
diff --git a/lib/groupio.c b/lib/groupio.c
9f13c6
index ae2302b5..bffb06e0 100644
9f13c6
--- a/lib/groupio.c
9f13c6
+++ b/lib/groupio.c
9f13c6
@@ -139,7 +139,8 @@ static /*@owned@*/struct commonio_db group_db = {
9f13c6
 	false,			/* changed */
9f13c6
 	false,			/* isopen */
9f13c6
 	false,			/* locked */
9f13c6
-	false			/* readonly */
9f13c6
+	false,			/* readonly */
9f13c6
+	false			/* setname */
9f13c6
 };
9f13c6
 
9f13c6
 int gr_setdbname (const char *filename)
9f13c6
diff --git a/lib/pwio.c b/lib/pwio.c
9f13c6
index 7ee85377..127719cb 100644
9f13c6
--- a/lib/pwio.c
9f13c6
+++ b/lib/pwio.c
9f13c6
@@ -114,7 +114,8 @@ static struct commonio_db passwd_db = {
9f13c6
 	false,			/* changed */
9f13c6
 	false,			/* isopen */
9f13c6
 	false,			/* locked */
9f13c6
-	false			/* readonly */
9f13c6
+	false,			/* readonly */
9f13c6
+	false			/* setname */
9f13c6
 };
9f13c6
 
9f13c6
 int pw_setdbname (const char *filename)
9f13c6
diff --git a/lib/sgroupio.c b/lib/sgroupio.c
9f13c6
index 5423626a..ffbdb263 100644
9f13c6
--- a/lib/sgroupio.c
9f13c6
+++ b/lib/sgroupio.c
9f13c6
@@ -238,7 +238,8 @@ static struct commonio_db gshadow_db = {
9f13c6
 	false,			/* changed */
9f13c6
 	false,			/* isopen */
9f13c6
 	false,			/* locked */
9f13c6
-	false			/* readonly */
9f13c6
+	false,			/* readonly */
9f13c6
+	false			/* setname */
9f13c6
 };
9f13c6
 
9f13c6
 int sgr_setdbname (const char *filename)
9f13c6
diff --git a/lib/shadowio.c b/lib/shadowio.c
9f13c6
index 5fa3d312..676b1f1a 100644
9f13c6
--- a/lib/shadowio.c
9f13c6
+++ b/lib/shadowio.c
9f13c6
@@ -114,7 +114,8 @@ static struct commonio_db shadow_db = {
9f13c6
 	false,			/* changed */
9f13c6
 	false,			/* isopen */
9f13c6
 	false,			/* locked */
9f13c6
-	false			/* readonly */
9f13c6
+	false,			/* readonly */
9f13c6
+	false			/* setname */
9f13c6
 };
9f13c6
 
9f13c6
 int spw_setdbname (const char *filename)
9f13c6
diff --git a/lib/subordinateio.c b/lib/subordinateio.c
9f13c6
index a662e67e..dd779c59 100644
9f13c6
--- a/lib/subordinateio.c
9f13c6
+++ b/lib/subordinateio.c
9f13c6
@@ -550,7 +550,8 @@ static struct commonio_db subordinate_uid_db = {
9f13c6
 	false,			/* changed */
9f13c6
 	false,			/* isopen */
9f13c6
 	false,			/* locked */
9f13c6
-	false			/* readonly */
9f13c6
+	false,			/* readonly */
9f13c6
+	false			/* setname */
9f13c6
 };
9f13c6
 
9f13c6
 int sub_uid_setdbname (const char *filename)
9f13c6
@@ -631,7 +632,8 @@ static struct commonio_db subordinate_gid_db = {
9f13c6
 	false,			/* changed */
9f13c6
 	false,			/* isopen */
9f13c6
 	false,			/* locked */
9f13c6
-	false			/* readonly */
9f13c6
+	false,			/* readonly */
9f13c6
+	false			/* setname */
9f13c6
 };
9f13c6
 
9f13c6
 int sub_gid_setdbname (const char *filename)