rpms/shadow-utils/FC-6 shadow-4.0.17-findNewUIDOnce.patch, NONE, 1.1 shadow-utils.spec, 1.90, 1.91

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Wed May 23 15:08:53 UTC 2007


Author: pvrabec

Update of /cvs/dist/rpms/shadow-utils/FC-6
In directory cvs.devel.redhat.com:/tmp/cvs-serv2997

Modified Files:
	shadow-utils.spec 
Added Files:
	shadow-4.0.17-findNewUIDOnce.patch 
Log Message:
- do not run find_new_uid() twice and use getpwuid() to check
  UID uniqueness (#236871


shadow-4.0.17-findNewUIDOnce.patch:
 useradd.c |   49 +++++++++++++++++--------------------------------
 1 files changed, 17 insertions(+), 32 deletions(-)

--- NEW FILE shadow-4.0.17-findNewUIDOnce.patch ---
--- shadow-4.0.17/src/useradd.c.findNewUidOnce	2007-05-16 14:42:55.000000000 +0200
+++ shadow-4.0.17/src/useradd.c	2007-05-16 14:53:24.000000000 +0200
@@ -854,8 +854,9 @@
  * find_new_uid - find the next available UID
  *
  *	find_new_uid() locates the next highest unused UID in the password
- *	file, or checks the given user ID against the existing ones for
- *	uniqueness.
+ *	file.
+ *	It doesn't make sense to use find_new_uid(), if UID is specified 
+ * 	via "-u" option.
  */
 static void find_new_uid (void)
 {
@@ -871,12 +872,7 @@
                 uid_max = getdef_unum ("UID_MIN", 500) - 1;
         }
 
-	/*
-	 * Start with some UID value if the user didn't provide us with
-	 * one already.
-	 */
-	if (!uflg)
-		user_id = uid_min;
+	user_id = uid_min;
 
 	/*
 	 * Search the entire password file, either looking for this
@@ -890,25 +886,7 @@
 	setpwent ();
 	while ((pwd = getpwent ())) {
 #endif
-		if (strcmp (user_name, pwd->pw_name) == 0) {
-			fprintf (stderr, _("%s: name %s is not unique\n"),
-				 Prog, user_name);
-#ifdef WITH_AUDIT
-			audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding user",
-				      user_name, user_id, 0);
-#endif
-			exit (E_NAME_IN_USE);
-		}
-		if (!oflg && uflg && user_id == pwd->pw_uid) {
-			fprintf (stderr, _("%s: UID %u is not unique\n"),
-				 Prog, (unsigned int) user_id);
-#ifdef WITH_AUDIT
-			audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding user",
-				      user_name, user_id, 0);
-#endif
-			exit (E_UID_IN_USE);
-		}
-		if (!uflg && pwd->pw_uid >= user_id) {
+		if (pwd->pw_uid >= user_id) {
 			if (pwd->pw_uid > uid_max)
 				continue;
 			user_id = pwd->pw_uid + 1;
@@ -921,7 +899,7 @@
 	 * free UID starting with UID_MIN (it's O(n*n) but can be avoided
 	 * by not having users with UID equal to UID_MAX).  --marekm
 	 */
-	if (!uflg && user_id == uid_max + 1) {
+	if (user_id == uid_max + 1) {
 		for (user_id = uid_min; user_id < uid_max; user_id++) {
 #ifdef NO_GETPWENT
 			pw_rewind ();
@@ -1562,9 +1540,6 @@
 	struct passwd pwent;
 	struct spwd spent;
 
-	if (!oflg)
-		find_new_uid ();
-
 	/*
 	 * Fill in the password structure with any new fields, making
 	 * copies of strings.
@@ -1883,7 +1858,17 @@
 		/* first, seek for a valid uid to use for this user.
 		 * We do this because later we can use the uid we found as
 		 * gid too ... --gafton */
-		find_new_uid ();
+		if (!uflg)
+			find_new_uid ();
+		else {
+			if (getpwuid (user_id)) {
+	                        fprintf (stderr, _("%s: UID %u is not unique\n"), Prog, (unsigned int) user_id);
+#ifdef WITH_AUDIT
+        	                audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding user", user_name, user_id, 0);
+#endif
+                        	exit (E_UID_IN_USE);
+			}
+		}
 	}
 
 	/* do we have to add a group for that user? This is why we need to


Index: shadow-utils.spec
===================================================================
RCS file: /cvs/dist/rpms/shadow-utils/FC-6/shadow-utils.spec,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- shadow-utils.spec	14 Jan 2007 13:22:52 -0000	1.90
+++ shadow-utils.spec	23 May 2007 15:08:51 -0000	1.91
@@ -5,7 +5,7 @@
 Summary: Utilities for managing accounts and shadow password files.
 Name: shadow-utils
 Version: 4.0.17
-Release: 12%{?dist}
+Release: 13%{?dist}
 Epoch: 2
 URL: http://shadow.pld.org.pl/
 Source0: ftp://ftp.pld.org.pl/software/shadow/shadow-%{version}.tar.bz2
@@ -25,6 +25,7 @@
 Patch10: shadow-4.0.17-auditLogging.patch
 Patch11: shadow-4.0.17-overflow.patch
 Patch12: shadow-4.0.17-appendOption.patch
+Patch13: shadow-4.0.17-findNewUIDOnce.patch
 License: BSD
 Group: System Environment/Base
 BuildRequires: autoconf, automake, libtool, gettext-devel
@@ -66,6 +67,7 @@
 %patch10 -p1 -b .auditLogging
 %patch11 -p1 -b .overflow
 %patch12 -p1 -b .appendOption
+%patch13 -p1 -b .findNewUID
 
 rm po/*.gmo
 rm po/stamp-po
@@ -220,6 +222,10 @@
 %{_mandir}/*/man8/faillog.8*
 
 %changelog
+* Wed May 23 2007 Peter Vrabec <pvrabec at redhat.com> 2:4.0.17-13
+- do not run find_new_uid() twice and use getpwuid() to check
+  UID uniqueness (#236871)
+
 * Sun Jan 14 2007 Peter Vrabec <pvrabec at redhat.com> 2:4.0.17-12
 - fix append option in usermod (#222540).
 




More information about the fedora-cvs-commits mailing list