uid-range: make uid_map_search_root() take UIDRangeUsernsMode

This commit is contained in:
Mike Yuan
2025-01-11 15:53:15 +01:00
parent 8c2c8235a6
commit a0e3dbdef5
3 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -624,12 +624,12 @@ int userns_get_base_uid(int userns_fd, uid_t *ret_uid, gid_t *ret_gid) {
return r;
uid_t uid;
r = uid_map_search_root(pid, "uid_map", &uid);
r = uid_map_search_root(pid, UID_RANGE_USERNS_OUTSIDE, &uid);
if (r < 0)
return r;
gid_t gid;
r = uid_map_search_root(pid, "gid_map", &gid);
r = uid_map_search_root(pid, GID_RANGE_USERNS_OUTSIDE, &gid);
if (r < 0)
return r;
+3 -3
View File
@@ -324,13 +324,13 @@ bool uid_range_equal(const UIDRange *a, const UIDRange *b) {
return true;
}
int uid_map_search_root(pid_t pid, const char *filename, uid_t *ret) {
int uid_map_search_root(pid_t pid, UIDRangeUsernsMode mode, uid_t *ret) {
int r;
assert(pid_is_valid(pid));
assert(filename);
assert(IN_SET(mode, UID_RANGE_USERNS_OUTSIDE, GID_RANGE_USERNS_OUTSIDE));
const char *p = procfs_file_alloca(pid, filename);
const char *p = procfs_file_alloca(pid, mode == UID_RANGE_USERNS_OUTSIDE ? "uid_map" : "gid_map");
_cleanup_fclose_ FILE *f = fopen(p, "re");
if (!f) {
if (errno != ENOENT)
+2 -2
View File
@@ -15,7 +15,7 @@ typedef struct UIDRange {
size_t n_entries;
} UIDRange;
UIDRange *uid_range_free(UIDRange *range);
UIDRange* uid_range_free(UIDRange *range);
DEFINE_TRIVIAL_CLEANUP_FUNC(UIDRange*, uid_range_free);
int uid_range_add_internal(UIDRange **range, uid_t start, uid_t nr, bool coalesce);
@@ -77,4 +77,4 @@ int uid_range_load_userns_by_fd(int userns_fd, UIDRangeUsernsMode mode, UIDRange
bool uid_range_overlaps(const UIDRange *range, uid_t start, uid_t nr);
int uid_map_search_root(pid_t pid, const char *filename, uid_t *ret);
int uid_map_search_root(pid_t pid, UIDRangeUsernsMode mode, uid_t *ret);