]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Factor out 'want_sub[ug]ids' and rename to 'want_sub[ug]id_file'
authorAnders Blomdell <anders.blomdell@control.lth.se>
Tue, 2 Sep 2025 09:45:37 +0000 (11:45 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 10 Sep 2025 13:28:13 +0000 (08:28 -0500)
Move 'want_sub[ug]ids' from 'src/newusers.c' to 'lib/subordinateio.[ch]'
and rename them to 'want_sub[ug]id_file' to clearly indicate that it
refers to the '/etc/sub[ug]id' and not to subids in general.

lib/subordinateio.c
lib/subordinateio.h
src/newusers.c

index dc585f78b56efd8a5ff008467c2dedd0a52cbc97..9fc53f004f85507f5bdf9cae772c71c657b8032e 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include "commonio.h"
 #include "subordinateio.h"
+#include "getdef.h"
 #include "../libsubid/subid.h"
 #include <sys/types.h>
 #include <pwd.h>
@@ -685,6 +686,37 @@ uid_t sub_uid_find_free_range(uid_t min, uid_t max, unsigned long count)
        return start == ULONG_MAX ? (uid_t) -1 : start;
 }
 
+
+/*
+ * want_subuid_file: check if /etc/subuid should be used.
+ *
+ * Returns true if /etc/subuid should be opened/created, if
+ * false is returned, /etc/subuid should not be accessed.
+ */
+bool want_subuid_file(void)
+{
+       if (get_subid_nss_handle() != NULL)
+               return false;
+       if (getdef_ulong("SUB_UID_COUNT", 65536) == 0)
+               return false;
+       return true;
+}
+
+/*
+ * want_subgid_file: check if /etc/subuid should be used.
+ *
+ * Returns true if /etc/subgid should be opened/created, if
+ * false is returned, /etc/subgid should not be accessed.
+ */
+bool want_subgid_file(void)
+{
+       if (get_subid_nss_handle() != NULL)
+               return false;
+       if (getdef_ulong("SUB_GID_COUNT", 65536) == 0)
+               return false;
+       return true;
+}
+
 static struct commonio_db subordinate_gid_db = {
        SUBGID_FILE,            /* filename */
        &subordinate_ops,       /* ops */
index 51d54cdf8dc4c93a76eb585d67a06f9ff967f485..e0aa99d9f1883bb112bbeac2e85787a958e667bb 100644 (file)
@@ -25,6 +25,7 @@ extern int sub_uid_unlock (void);
 extern int sub_uid_add (const char *owner, uid_t start, unsigned long count);
 extern int sub_uid_remove (const char *owner, uid_t start, unsigned long count);
 extern uid_t sub_uid_find_free_range(uid_t min, uid_t max, unsigned long count);
+extern bool want_subuid_file(void);
 extern int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_range **ranges);
 extern bool new_subid_range(struct subordinate_range *range, enum subid_type id_type, bool reuse);
 extern bool release_subid_range(struct subordinate_range *range, enum subid_type id_type);
@@ -43,6 +44,7 @@ extern int sub_gid_unlock (void);
 extern int sub_gid_add (const char *owner, gid_t start, unsigned long count);
 extern int sub_gid_remove (const char *owner, gid_t start, unsigned long count);
 extern uid_t sub_gid_find_free_range(gid_t min, gid_t max, unsigned long count);
+extern bool want_subgid_file(void);
 
 extern void free_subid_pointer(void *ptr);
 
index 6748036f2487df0bc9a460720760382a5383a6b1..f7ba15ddd1a181d97e22e3bf661154492a1fb609 100644 (file)
@@ -1039,24 +1039,6 @@ static void close_files (void)
 #endif                         /* ENABLE_SUBIDS */
 }
 
-static bool want_subuids(void)
-{
-       if (get_subid_nss_handle() != NULL)
-               return false;
-       if (getdef_ulong ("SUB_UID_COUNT", 65536) == 0)
-               return false;
-       return true;
-}
-
-static bool want_subgids(void)
-{
-       if (get_subid_nss_handle() != NULL)
-               return false;
-       if (getdef_ulong ("SUB_GID_COUNT", 65536) == 0)
-               return false;
-       return true;
-}
-
 int main (int argc, char **argv)
 {
        char buf[BUFSIZ];
@@ -1269,7 +1251,7 @@ int main (int argc, char **argv)
                /*
                 * Add subordinate uids if the user does not have them.
                 */
-               if (is_sub_uid && want_subuids() && !local_sub_uid_assigned(fields[0])) {
+               if (is_sub_uid && want_subuid_file() && !local_sub_uid_assigned(fields[0])) {
                        uid_t sub_uid_start = 0;
                        unsigned long sub_uid_count = 0;
                        if (find_new_sub_uids(&sub_uid_start, &sub_uid_count) != 0)
@@ -1291,7 +1273,7 @@ int main (int argc, char **argv)
                /*
                 * Add subordinate gids if the user does not have them.
                 */
-               if (is_sub_gid && want_subgids() && !local_sub_gid_assigned(fields[0])) {
+               if (is_sub_gid && want_subgid_file() && !local_sub_gid_assigned(fields[0])) {
                        gid_t sub_gid_start = 0;
                        unsigned long sub_gid_count = 0;
                        if (find_new_sub_gids(&sub_gid_start, &sub_gid_count) != 0) {