diff options
author | Balint Reczey <balint@balintreczey.hu> | 2022-08-20 18:17:16 +0200 |
---|---|---|
committer | Balint Reczey <balint@balintreczey.hu> | 2022-08-20 18:17:16 +0200 |
commit | 675b462b64b213647d0f5c56b1e8440be5890c8a (patch) | |
tree | 1cd63eec7594d03a622575136c61d8c813f59503 /lib/subordinateio.c | |
parent | 0c04b92a9afe5e09a20307d8a5ec98d97ed00f47 (diff) | |
download | shadow-675b462b64b213647d0f5c56b1e8440be5890c8a.tar.gz |
New upstream version 4.12.2+dfsg1
Diffstat (limited to 'lib/subordinateio.c')
-rw-r--r-- | lib/subordinateio.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/lib/subordinateio.c b/lib/subordinateio.c index 9ca70b8b..bd1af26b 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -17,6 +17,8 @@ #include <ctype.h> #include <fcntl.h> +#define ID_SIZE 31 + /* * subordinate_dup: create a duplicate range * @@ -155,7 +157,7 @@ static struct commonio_ops subordinate_ops = { * * Returns true if @owner owns any subuid ranges, false otherwise. */ -static const bool range_exists(struct commonio_db *db, const char *owner) +static bool range_exists(struct commonio_db *db, const char *owner) { const struct subordinate_range *range; commonio_rewind(db); @@ -745,6 +747,40 @@ gid_t sub_gid_find_free_range(gid_t min, gid_t max, unsigned long count) return start == ULONG_MAX ? (gid_t) -1 : start; } +static bool get_owner_id(const char *owner, enum subid_type id_type, char *id) +{ + struct passwd *pw; + struct group *gr; + int ret = 0; + + switch (id_type) { + case ID_TYPE_UID: + pw = getpwnam(owner); + if (pw == NULL) { + return false; + } + ret = snprintf(id, ID_SIZE, "%u", pw->pw_uid); + if (ret < 0 || ret >= ID_SIZE) { + return false; + } + break; + case ID_TYPE_GID: + gr = getgrnam(owner); + if (gr == NULL) { + return false; + } + ret = snprintf(id, ID_SIZE, "%u", gr->gr_gid); + if (ret < 0 || ret >= ID_SIZE) { + return false; + } + break; + default: + return false; + } + + return true; +} + /* * int list_owner_ranges(const char *owner, enum subid_type id_type, struct subordinate_range ***ranges) * @@ -770,6 +806,8 @@ int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_r enum subid_status status; int count = 0; struct subid_nss_ops *h; + char id[ID_SIZE]; + bool have_owner_id; *in_ranges = NULL; @@ -798,6 +836,8 @@ int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_r return -1; } + have_owner_id = get_owner_id(owner, id_type, id); + commonio_rewind(db); while ((range = commonio_next(db)) != NULL) { if (0 == strcmp(range->owner, owner)) { @@ -808,6 +848,16 @@ int list_owner_ranges(const char *owner, enum subid_type id_type, struct subid_r goto out; } } + + // Let's also compare with the ID + if (have_owner_id == true && 0 == strcmp(range->owner, id)) { + if (!append_range(&ranges, range, count++)) { + free(ranges); + ranges = NULL; + count = -1; + goto out; + } + } } out: |