[Pkg-shadow-commits] r3026 - in upstream/trunk: . libmisc

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Fri Jul 17 22:54:23 UTC 2009


Author: nekral-guest
Date: 2009-07-17 22:54:23 +0000 (Fri, 17 Jul 2009)
New Revision: 3026

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/NEWS
   upstream/trunk/libmisc/find_new_gid.c
   upstream/trunk/libmisc/find_new_uid.c
Log:
	* NEWS, libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not use
	getpwent / getgrent for system accounts. Trying the low-IDs with
	getpwuid / getgrgid should be more efficient on LDAP configured
	systems with many accounts.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-07-05 20:13:41 UTC (rev 3025)
+++ upstream/trunk/ChangeLog	2009-07-17 22:54:23 UTC (rev 3026)
@@ -1,3 +1,10 @@
+2009-07-18  Peter Vrabec  <pvrabec at redhat.com>
+
+	* NEWS, libmisc/find_new_gid.c, libmisc/find_new_uid.c: Do not use
+	getpwent / getgrent for system accounts. Trying the low-IDs with
+	getpwuid / getgrgid should be more efficient on LDAP configured
+	systems with many accounts.
+
 2009-07-05  Piarres Beobide  <pi+debian at beobide.net>
 
 	* po/eu.po: Updated Basque translation.

Modified: upstream/trunk/NEWS
===================================================================
--- upstream/trunk/NEWS	2009-07-05 20:13:41 UTC (rev 3025)
+++ upstream/trunk/NEWS	2009-07-17 22:54:23 UTC (rev 3026)
@@ -5,6 +5,10 @@
 - general
   * Improved support for large groups (impacts most tools).
 
+- addition of system users or groups
+  * Speed improvement. This should be noticeable in case of LDAP configured
+    systems. This should impact useradd, groupadd, and newusers
+
 - su
   * Preserve the DISPLAY and XAUTHORITY environment variables. This was
     only the case in the non PAM enabled versions.

Modified: upstream/trunk/libmisc/find_new_gid.c
===================================================================
--- upstream/trunk/libmisc/find_new_gid.c	2009-07-05 20:13:41 UTC (rev 3025)
+++ upstream/trunk/libmisc/find_new_gid.c	2009-07-17 22:54:23 UTC (rev 3026)
@@ -90,17 +90,31 @@
 	 * but we also check the local database (gr_rewind/gr_next) in case
 	 * some groups were created but the changes were not committed yet.
 	 */
-	setgrent ();
-	while ((grp = getgrent ()) != NULL) {
-		if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {
-			group_id = grp->gr_gid + 1;
+	if (sys_group ) {
+		/* setgrent / getgrent / endgrent can be very slow with
+		 * LDAP configurations (and many accounts).
+		 * Since there is a limited amount of IDs to be tested
+		 * for system accounts, we just check the existence
+		 * of IDs with getgrgid.
+		 */
+		for (group_id = gid_min; group_id <= gid_max; group_id++) {
+			if (getgrgid (group_id) != NULL) {
+				used_gids[grp->gr_gid] = true;
+			}
 		}
-		/* create index of used GIDs */
-		if (grp->gr_gid <= gid_max) {
-			used_gids[grp->gr_gid] = true;
+	} else {
+		setgrent ();
+		while ((grp = getgrent ()) != NULL) {
+			if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {
+				group_id = grp->gr_gid + 1;
+			}
+			/* create index of used GIDs */
+			if (grp->gr_gid <= gid_max) {
+				used_gids[grp->gr_gid] = true;
+			}
 		}
+		endgrent ();
 	}
-	endgrent ();
 	gr_rewind ();
 	while ((grp = gr_next ()) != NULL) {
 		if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {

Modified: upstream/trunk/libmisc/find_new_uid.c
===================================================================
--- upstream/trunk/libmisc/find_new_uid.c	2009-07-05 20:13:41 UTC (rev 3025)
+++ upstream/trunk/libmisc/find_new_uid.c	2009-07-17 22:54:23 UTC (rev 3026)
@@ -80,7 +80,6 @@
 		return 0;
 	}
 
-
 	user_id = uid_min;
 
 	/*
@@ -91,17 +90,31 @@
 	 * but we also check the local database (pw_rewind/pw_next) in case
 	 * some users were created but the changes were not committed yet.
 	 */
-	setpwent ();
-	while ((pwd = getpwent ()) != NULL) {
-		if ((pwd->pw_uid >= user_id) && (pwd->pw_uid <= uid_max)) {
-			user_id = pwd->pw_uid + 1;
+	if (sys_user) {
+		/* setpwent / getpwent / endpwent can be very slow with
+		 * LDAP configurations (and many accounts).
+		 * Since there is a limited amount of IDs to be tested
+		 * for system accounts, we just check the existence
+		 * of IDs with getpwuid.
+		 */
+		for (user_id = uid_min; user_id <= uid_max; user_id++) {
+			if (getpwuid (user_id) != NULL) {
+				used_uids[user_id] = true;
+			}
 		}
-		/* create index of used UIDs */
-		if (pwd->pw_uid <= uid_max) {
-			used_uids[pwd->pw_uid] = true;
+	} else {
+		setpwent ();
+		while ((pwd = getpwent ()) != NULL) {
+			if ((pwd->pw_uid >= user_id) && (pwd->pw_uid <= uid_max)) {
+				user_id = pwd->pw_uid + 1;
+			}
+			/* create index of used UIDs */
+			if (pwd->pw_uid <= uid_max) {
+				used_uids[pwd->pw_uid] = true;
+			}
 		}
+		endpwent ();
 	}
-	endpwent ();
 	pw_rewind ();
 	while ((pwd = pw_next ()) != NULL) {
 		if ((pwd->pw_uid >= user_id) && (pwd->pw_uid <= uid_max)) {




More information about the Pkg-shadow-commits mailing list