#include <stdio.h>
#include "commonio.h"
#include "subordinateio.h"
+#include "getdef.h"
#include "../libsubid/subid.h"
#include <sys/types.h>
#include <pwd.h>
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 */
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);
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);
#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];
/*
* 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)
/*
* 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) {