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

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