From: Anders Blomdell Date: Tue, 2 Sep 2025 09:45:37 +0000 (+0200) Subject: Factor out 'want_sub[ug]ids' and rename to 'want_sub[ug]id_file' X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15540c0d1fca58175327aff7b020cb68579a7802;p=thirdparty%2Fshadow.git Factor out 'want_sub[ug]ids' and rename to 'want_sub[ug]id_file' 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. --- diff --git a/lib/subordinateio.c b/lib/subordinateio.c index dc585f78b..9fc53f004 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -11,6 +11,7 @@ #include #include "commonio.h" #include "subordinateio.h" +#include "getdef.h" #include "../libsubid/subid.h" #include #include @@ -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 */ diff --git a/lib/subordinateio.h b/lib/subordinateio.h index 51d54cdf8..e0aa99d9f 100644 --- a/lib/subordinateio.h +++ b/lib/subordinateio.h @@ -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); diff --git a/src/newusers.c b/src/newusers.c index 6748036f2..f7ba15ddd 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -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) {