[23720] trunk/base/src/pextlib1.0/Pextlib.c

source_changes at macosforge.org source_changes at macosforge.org
Sat Apr 7 11:52:48 PDT 2007


Revision: 23720
          http://trac.macosforge.org/projects/macports/changeset/23720
Author:   eridius at macports.org
Date:     2007-04-07 11:52:47 -0700 (Sat, 07 Apr 2007)

Log Message:
-----------
nextuid and nextgid now return the first uid/gid > 100 rather than the max + 1
This means that new users created with adduser are not visible on the login screen.
Also it was kinda silly to create a new user/group with id 502 when 100-499 were available

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/Pextlib.c

Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c	2007-04-07 17:45:21 UTC (rev 23719)
+++ trunk/base/src/pextlib1.0/Pextlib.c	2007-04-07 18:52:47 UTC (rev 23720)
@@ -941,36 +941,40 @@
 	return TCL_OK;
 }
 
+/* Find the first unused UID > 100
+   previously this would find the highest used UID and add 1
+   but UIDs > 500 are visible on the login screen of OS X */
 int NextuidCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
 {
 	Tcl_Obj *tcl_result;
-	struct passwd *pwent;
-	int max;
+	int cur;
 
-	max = 0;
-
-	while ((pwent = getpwent()) != NULL)
-		if ((int)pwent->pw_uid > max)
-			max = (int)pwent->pw_uid;
+	cur = 100;
 	
-	tcl_result = Tcl_NewIntObj(max + 1);
+	while (getpwuid(cur) != NULL) {
+        cur++;
+	}
+	
+	tcl_result = Tcl_NewIntObj(cur);
 	Tcl_SetObjResult(interp, tcl_result);
 	return TCL_OK;
 }
 
+/* Just as with NextuidCmd, return the first unused gid > 100
+   groups aren't visible on the login screen, but I see no reason
+   to create group 502 when I can create group 100 */
 int NextgidCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
 {
 	Tcl_Obj *tcl_result;
-	struct group *grent;
-	int max;
+	int cur;
 
-	max = 0;
+    cur = 100;
 
-	while ((grent = getgrent()) != NULL)
-		if ((int)grent->gr_gid > max)
-			max = (int)grent->gr_gid;
+    while (getgrgid(cur) != NULL) {
+        cur++;
+    }
 	
-	tcl_result = Tcl_NewIntObj(max + 1);
+	tcl_result = Tcl_NewIntObj(cur);
 	Tcl_SetObjResult(interp, tcl_result);
 	return TCL_OK;
 }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070407/8da1148b/attachment.html


More information about the macports-changes mailing list