]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
subid: Move linear allocation into its own function
authorPat Riehecky <riehecky@fnal.gov>
Mon, 16 Mar 2026 13:18:36 +0000 (08:18 -0500)
committerSerge Hallyn <serge@hallyn.com>
Fri, 10 Apr 2026 03:20:34 +0000 (22:20 -0500)
Signed-off-by: Pat Riehecky <riehecky@fnal.gov>
lib/find_new_sub_gids.c
lib/find_new_sub_uids.c

index b5304d980fa491315afc910c883bc7a42d99e2d2..3e6cc2d64dbe207f7ed44931845bf7f9012c4127 100644 (file)
 
 
 /*
- * find_new_sub_gids - Find a new unused range of GIDs.
+ * find_new_sub_gids_linear - Find an unused subordinate GID range via
+ * linear search.
  *
- * If successful, find_new_sub_gids provides a range of unused
- * user IDs in the [SUB_GID_MIN:SUB_GID_MAX] range.
+ * Loads SUB_GID_COUNT from login.defs and writes the allocated count back
+ * to *range_count on success.
  *
  * Return 0 on success, -1 if no unused GIDs are available.
  */
-int find_new_sub_gids (id_t *range_start, unsigned long *range_count)
+static int
+find_new_sub_gids_linear(id_t *range_start, unsigned long *range_count)
 {
        unsigned long min, max;
        unsigned long count;
@@ -46,7 +48,18 @@ int find_new_sub_gids (id_t *range_start, unsigned long *range_count)
        *range_count = count;
        return 0;
 }
+
+/*
+ * find_new_sub_gids - Find a new unused range of subordinate GIDs.
+ *
+ * Return 0 on success, -1 if no unused GIDs are available.
+ */
+int
+find_new_sub_gids(id_t *range_start, unsigned long *range_count)
+{
+       return find_new_sub_gids_linear(range_start, range_count);
+}
+
 #else                          /* !ENABLE_SUBIDS */
 extern int ISO_C_forbids_an_empty_translation_unit;
 #endif                         /* !ENABLE_SUBIDS */
-
index 30e9c46c2b3cfe7be250bde4ff5d44d545e72cb7..662ed7def5c713f132086fe884ec325b73990054 100644 (file)
 
 
 /*
- * find_new_sub_uids - Find a new unused range of UIDs.
+ * find_new_sub_uids_linear - Find an unused subordinate UID range via
+ * linear search.
  *
- * If successful, find_new_sub_uids provides a range of unused
- * user IDs in the [SUB_UID_MIN:SUB_UID_MAX] range.
+ * Loads SUB_UID_COUNT from login.defs and writes the allocated count back
+ * to *range_count on success.
  *
  * Return 0 on success, -1 if no unused UIDs are available.
  */
-int find_new_sub_uids (id_t *range_start, unsigned long *range_count)
+static int
+find_new_sub_uids_linear(id_t *range_start, unsigned long *range_count)
 {
        unsigned long min, max;
        unsigned long count;
@@ -46,7 +48,18 @@ int find_new_sub_uids (id_t *range_start, unsigned long *range_count)
        *range_count = count;
        return 0;
 }
+
+/*
+ * find_new_sub_uids - Find a new unused range of subordinate UIDs.
+ *
+ * Return 0 on success, -1 if no unused UIDs are available.
+ */
+int
+find_new_sub_uids(id_t *range_start, unsigned long *range_count)
+{
+       return find_new_sub_uids_linear(range_start, range_count);
+}
+
 #else                          /* !ENABLE_SUBIDS */
 extern int ISO_C_forbids_an_empty_translation_unit;
 #endif                         /* !ENABLE_SUBIDS */
-