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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sun Jun 15 18:33:54 UTC 2008


Author: nekral-guest
Date: 2008-06-15 18:33:52 +0000 (Sun, 15 Jun 2008)
New Revision: 2185

Added:
   upstream/trunk/libmisc/find_new_gid.c
   upstream/trunk/libmisc/find_new_uid.c
Removed:
   upstream/trunk/libmisc/find_new_ids.c
Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/lib/prototypes.h
   upstream/trunk/libmisc/Makefile.am
Log:
	* libmisc/find_new_ids.c, libmisc/find_new_gid.c,
	libmisc/find_new_uid.c, libmisc/Makefile.am, lib/prototypes.h:
	Split find_new_ids.c into find_new_gid.c and find_new_uid.c to
	ease the description of login.defs variables in the different
	tools.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-06-15 00:01:46 UTC (rev 2184)
+++ upstream/trunk/ChangeLog	2008-06-15 18:33:52 UTC (rev 2185)
@@ -1,5 +1,13 @@
 2008-06-15  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* libmisc/find_new_ids.c, libmisc/find_new_gid.c,
+	libmisc/find_new_uid.c, libmisc/Makefile.am, lib/prototypes.h:
+	Split find_new_ids.c into find_new_gid.c and find_new_uid.c to
+	ease the description of login.defs variables in the different
+	tools.
+
+2008-06-15  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* libmisc/failure.c: Ignore the return value of strftime() and
 	printf().
 	* libmisc/failure.c: Fix syslog call. The UID is not available.

Modified: upstream/trunk/lib/prototypes.h
===================================================================
--- upstream/trunk/lib/prototypes.h	2008-06-15 00:01:46 UTC (rev 2184)
+++ upstream/trunk/lib/prototypes.h	2008-06-15 18:33:52 UTC (rev 2185)
@@ -99,10 +99,12 @@
 extern void change_field (char *, size_t, const char *);
 extern int valid_field (const char *, const char *);
 
-/* find_new_ids.c */
-extern int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid);
+/* find_new_gid.c */
 extern int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid);
 
+/* find_new_uid.c */
+extern int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid);
+
 /* getlong.c */
 extern int getlong(const char *numstr, long int *result);
 

Modified: upstream/trunk/libmisc/Makefile.am
===================================================================
--- upstream/trunk/libmisc/Makefile.am	2008-06-15 00:01:46 UTC (rev 2184)
+++ upstream/trunk/libmisc/Makefile.am	2008-06-15 18:33:52 UTC (rev 2185)
@@ -21,7 +21,8 @@
 	failure.c \
 	failure.h \
 	fields.c \
-	find_new_ids.c \
+	find_new_gid.c \
+	find_new_uid.c \
 	getdate.h \
 	getdate.y \
 	getlong.c \

Copied: upstream/trunk/libmisc/find_new_gid.c (from rev 2172, upstream/trunk/libmisc/find_new_ids.c)
===================================================================
--- upstream/trunk/libmisc/find_new_gid.c	                        (rev 0)
+++ upstream/trunk/libmisc/find_new_gid.c	2008-06-15 18:33:52 UTC (rev 2185)
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 1991 - 1994, Julianne Frances Haugh
+ * Copyright (c) 2008       , Nicolas François
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the copyright holders or contributors may not be used to
+ *    endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "prototypes.h"
+#include "groupio.h"
+#include "getdef.h"
+
+/*
+ * find_new_gid - Find a new unused GID.
+ *
+ * If successful, find_new_gid provides an unused group ID in the
+ * [GID_MIN:GID_MAX] range.
+ * This ID should be higher than all the used GID, but if not possible,
+ * the lowest unused ID in the range will be returned.
+ * 
+ * Return 0 on success, -1 if no unused GIDs are available.
+ */
+int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
+{
+	const struct group *grp;
+	gid_t gid_min, gid_max, group_id;
+
+	assert (gid != NULL);
+
+	if (!sys_group) {
+		gid_min = getdef_ulong ("GID_MIN", 1000L);
+		gid_max = getdef_ulong ("GID_MAX", 60000L);
+	} else {
+		gid_min = getdef_ulong ("SYS_GID_MIN", 1L);
+		gid_max = getdef_ulong ("GID_MIN", 1000L) - 1;
+		gid_max = getdef_ulong ("SYS_GID_MAX", (unsigned long) gid_max);
+	}
+
+	if (   (NULL != preferred_gid)
+	    && (*preferred_gid >= gid_min)
+	    && (*preferred_gid <= gid_max)
+	    /* Check if the user exists according to NSS */
+	    && (getgrgid (*preferred_gid) == NULL)
+	    /* Check also the local database in case of uncommitted
+	     * changes */
+	    && (gr_locate_gid (*preferred_gid) == NULL)) {
+		*gid = *preferred_gid;
+		return 0;
+	}
+
+	group_id = gid_min;
+
+	/*
+	 * Search the entire group file,
+	 * looking for the largest unused value.
+	 *
+	 * We check the list of users according to NSS (setpwent/getpwent),
+	 * but we also check the local database (pw_rewind/pw_next) in case
+	 * some groups were created but the changes were not committed yet.
+	 */
+	setgrent ();
+	gr_rewind ();
+	while (   ((grp = getgrent ()) != NULL)
+	       || ((grp = gr_next ()) != NULL)) {
+		if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {
+			group_id = grp->gr_gid + 1;
+		}
+	}
+	endgrent ();
+
+	/*
+	 * If a group with GID equal to GID_MAX exists, the above algorithm
+	 * will give us GID_MAX+1 even if not unique. Search for the first
+	 * free GID starting with GID_MIN (it's O(n*n) but can be avoided
+	 * by not having users with GID equal to GID_MAX).  --marekm
+	 */
+	if (group_id == gid_max + 1) {
+		for (group_id = gid_min; group_id < gid_max; group_id++) {
+			/* local, no need for xgetgrgid */
+			if (   (getgrgid (group_id) == NULL)
+			    && (gr_locate_gid (group_id) == NULL)) {
+				break;
+			}
+		}
+		if (group_id == gid_max) {
+			fputs (_("Can't get unique GID (no more available GIDs)\n"), stderr);
+			return -1;
+		}
+	}
+
+	*gid = group_id;
+	return 0;
+}
+

Deleted: upstream/trunk/libmisc/find_new_ids.c
===================================================================
--- upstream/trunk/libmisc/find_new_ids.c	2008-06-15 00:01:46 UTC (rev 2184)
+++ upstream/trunk/libmisc/find_new_ids.c	2008-06-15 18:33:52 UTC (rev 2185)
@@ -1,205 +0,0 @@
-/*
- * Copyright (c) 1991 - 1994, Julianne Frances Haugh
- * Copyright (c) 2008       , Nicolas François
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the copyright holders or contributors may not be used to
- *    endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-
-#include <assert.h>
-#include <stdio.h>
-
-#include "prototypes.h"
-#include "pwio.h"
-#include "groupio.h"
-#include "getdef.h"
-
-/*
- * find_new_uid - Find a new unused UID.
- *
- * If successful, find_new_uid provides an unused user ID in the
- * [UID_MIN:UID_MAX] range.
- * This ID should be higher than all the used UID, but if not possible,
- * the lowest unused ID in the range will be returned.
- * 
- * Return 0 on success, -1 if no unused UIDs are available.
- */
-int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid)
-{
-	const struct passwd *pwd;
-	uid_t uid_min, uid_max, user_id;
-
-	assert (uid != NULL);
-
-	if (!sys_user) {
-		uid_min = getdef_ulong ("UID_MIN", 1000L);
-		uid_max = getdef_ulong ("UID_MAX", 60000L);
-	} else {
-		uid_min = getdef_ulong ("SYS_UID_MIN", 1L);
-		uid_max = getdef_ulong ("UID_MIN", 1000L) - 1;
-		uid_max = getdef_ulong ("SYS_UID_MAX", (unsigned long) uid_max);
-	}
-
-	if (   (NULL != preferred_uid)
-	    && (*preferred_uid >= uid_min)
-	    && (*preferred_uid <= uid_max)
-	    /* Check if the user exists according to NSS */
-	    && (getpwuid (*preferred_uid) == NULL)
-	    /* Check also the local database in case of uncommitted
-	     * changes */
-	    && (pw_locate_uid (*preferred_uid) == NULL)) {
-		*uid = *preferred_uid;
-		return 0;
-	}
-
-
-	user_id = uid_min;
-
-	/*
-	 * Search the entire password file,
-	 * looking for the largest unused value.
-	 *
-	 * We check the list of users according to NSS (setpwent/getpwent),
-	 * 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 ();
-	pw_rewind ();
-	while (   ((pwd = getpwent ()) != NULL)
-	       || ((pwd = pw_next ()) != NULL)) {
-		if ((pwd->pw_uid >= user_id) && (pwd->pw_uid <= uid_max)) {
-			user_id = pwd->pw_uid + 1;
-		}
-	}
-	endpwent ();
-
-	/*
-	 * If a user with UID equal to UID_MAX exists, the above algorithm
-	 * will give us UID_MAX+1 even if not unique. Search for the first
-	 * 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 (user_id == uid_max + 1) {
-		for (user_id = uid_min; user_id < uid_max; user_id++) {
-			/* local, no need for xgetpwuid */
-			if (   (getpwuid (user_id) == NULL)
-			    && (pw_locate_uid (user_id) == NULL)) {
-				break;
-			}
-		}
-		if (user_id == uid_max) {
-			fputs (_("Can't get unique UID (no more available UIDs)\n"), stderr);
-			return -1;
-		}
-	}
-
-	*uid = user_id;
-	return 0;
-}
-
-/*
- * find_new_gid - Find a new unused GID.
- *
- * If successful, find_new_gid provides an unused group ID in the
- * [GID_MIN:GID_MAX] range.
- * This ID should be higher than all the used GID, but if not possible,
- * the lowest unused ID in the range will be returned.
- * 
- * Return 0 on success, -1 if no unused GIDs are available.
- */
-int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
-{
-	const struct group *grp;
-	gid_t gid_min, gid_max, group_id;
-
-	assert (gid != NULL);
-
-	if (!sys_group) {
-		gid_min = getdef_ulong ("GID_MIN", 1000L);
-		gid_max = getdef_ulong ("GID_MAX", 60000L);
-	} else {
-		gid_min = getdef_ulong ("SYS_GID_MIN", 1L);
-		gid_max = getdef_ulong ("GID_MIN", 1000L) - 1;
-		gid_max = getdef_ulong ("SYS_GID_MAX", (unsigned long) gid_max);
-	}
-
-	if (   (NULL != preferred_gid)
-	    && (*preferred_gid >= gid_min)
-	    && (*preferred_gid <= gid_max)
-	    /* Check if the user exists according to NSS */
-	    && (getgrgid (*preferred_gid) == NULL)
-	    /* Check also the local database in case of uncommitted
-	     * changes */
-	    && (gr_locate_gid (*preferred_gid) == NULL)) {
-		*gid = *preferred_gid;
-		return 0;
-	}
-
-	group_id = gid_min;
-
-	/*
-	 * Search the entire group file,
-	 * looking for the largest unused value.
-	 *
-	 * We check the list of users according to NSS (setpwent/getpwent),
-	 * but we also check the local database (pw_rewind/pw_next) in case
-	 * some groups were created but the changes were not committed yet.
-	 */
-	setgrent ();
-	gr_rewind ();
-	while (   ((grp = getgrent ()) != NULL)
-	       || ((grp = gr_next ()) != NULL)) {
-		if ((grp->gr_gid >= group_id) && (grp->gr_gid <= gid_max)) {
-			group_id = grp->gr_gid + 1;
-		}
-	}
-	endgrent ();
-
-	/*
-	 * If a group with GID equal to GID_MAX exists, the above algorithm
-	 * will give us GID_MAX+1 even if not unique. Search for the first
-	 * free GID starting with GID_MIN (it's O(n*n) but can be avoided
-	 * by not having users with GID equal to GID_MAX).  --marekm
-	 */
-	if (group_id == gid_max + 1) {
-		for (group_id = gid_min; group_id < gid_max; group_id++) {
-			/* local, no need for xgetgrgid */
-			if (   (getgrgid (group_id) == NULL)
-			    && (gr_locate_gid (group_id) == NULL)) {
-				break;
-			}
-		}
-		if (group_id == gid_max) {
-			fputs (_("Can't get unique GID (no more available GIDs)\n"), stderr);
-			return -1;
-		}
-	}
-
-	*gid = group_id;
-	return 0;
-}
-

Copied: upstream/trunk/libmisc/find_new_uid.c (from rev 2172, upstream/trunk/libmisc/find_new_ids.c)
===================================================================
--- upstream/trunk/libmisc/find_new_uid.c	                        (rev 0)
+++ upstream/trunk/libmisc/find_new_uid.c	2008-06-15 18:33:52 UTC (rev 2185)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 1991 - 1994, Julianne Frances Haugh
+ * Copyright (c) 2008       , Nicolas François
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the copyright holders or contributors may not be used to
+ *    endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "prototypes.h"
+#include "pwio.h"
+#include "getdef.h"
+
+/*
+ * find_new_uid - Find a new unused UID.
+ *
+ * If successful, find_new_uid provides an unused user ID in the
+ * [UID_MIN:UID_MAX] range.
+ * This ID should be higher than all the used UID, but if not possible,
+ * the lowest unused ID in the range will be returned.
+ * 
+ * Return 0 on success, -1 if no unused UIDs are available.
+ */
+int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid)
+{
+	const struct passwd *pwd;
+	uid_t uid_min, uid_max, user_id;
+
+	assert (uid != NULL);
+
+	if (!sys_user) {
+		uid_min = getdef_ulong ("UID_MIN", 1000L);
+		uid_max = getdef_ulong ("UID_MAX", 60000L);
+	} else {
+		uid_min = getdef_ulong ("SYS_UID_MIN", 1L);
+		uid_max = getdef_ulong ("UID_MIN", 1000L) - 1;
+		uid_max = getdef_ulong ("SYS_UID_MAX", (unsigned long) uid_max);
+	}
+
+	if (   (NULL != preferred_uid)
+	    && (*preferred_uid >= uid_min)
+	    && (*preferred_uid <= uid_max)
+	    /* Check if the user exists according to NSS */
+	    && (getpwuid (*preferred_uid) == NULL)
+	    /* Check also the local database in case of uncommitted
+	     * changes */
+	    && (pw_locate_uid (*preferred_uid) == NULL)) {
+		*uid = *preferred_uid;
+		return 0;
+	}
+
+
+	user_id = uid_min;
+
+	/*
+	 * Search the entire password file,
+	 * looking for the largest unused value.
+	 *
+	 * We check the list of users according to NSS (setpwent/getpwent),
+	 * 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 ();
+	pw_rewind ();
+	while (   ((pwd = getpwent ()) != NULL)
+	       || ((pwd = pw_next ()) != NULL)) {
+		if ((pwd->pw_uid >= user_id) && (pwd->pw_uid <= uid_max)) {
+			user_id = pwd->pw_uid + 1;
+		}
+	}
+	endpwent ();
+
+	/*
+	 * If a user with UID equal to UID_MAX exists, the above algorithm
+	 * will give us UID_MAX+1 even if not unique. Search for the first
+	 * 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 (user_id == uid_max + 1) {
+		for (user_id = uid_min; user_id < uid_max; user_id++) {
+			/* local, no need for xgetpwuid */
+			if (   (getpwuid (user_id) == NULL)
+			    && (pw_locate_uid (user_id) == NULL)) {
+				break;
+			}
+		}
+		if (user_id == uid_max) {
+			fputs (_("Can't get unique UID (no more available UIDs)\n"), stderr);
+			return -1;
+		}
+	}
+
+	*uid = user_id;
+	return 0;
+}
+




More information about the Pkg-shadow-commits mailing list