Blame SOURCES/shadow-4.6-use-lckpwdf.patch

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