From 76ef5d0493ed03499a06b1aa3e46a39fe58f288c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Feb 2022 14:53:57 +0100 Subject: [PATCH] user-util: move homed/nspawn map UID_MIN/UID_MAX define into user-util.h Let's have them at a common place, so that we have the ranges altogether at a minimal set of places. --- src/basic/user-util.h | 8 ++++++++ src/home/home-util.h | 4 ---- src/nspawn/nspawn-bind-user.c | 9 +++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/basic/user-util.h b/src/basic/user-util.h index bc76de6b411..40979d10801 100644 --- a/src/basic/user-util.h +++ b/src/basic/user-util.h @@ -12,6 +12,14 @@ #include #include +/* Users managed by systemd-homed. See https://systemd.io/UIDS-GIDS for details how this range fits into the rest of the world */ +#define HOME_UID_MIN 60001 +#define HOME_UID_MAX 60513 + +/* Users mapped from host into a container */ +#define MAP_UID_MIN 60514 +#define MAP_UID_MAX 60577 + bool uid_is_valid(uid_t uid); static inline bool gid_is_valid(gid_t gid) { diff --git a/src/home/home-util.h b/src/home/home-util.h index 69a88000f84..36b301d2360 100644 --- a/src/home/home-util.h +++ b/src/home/home-util.h @@ -8,10 +8,6 @@ #include "time-util.h" #include "user-record.h" -/* See https://systemd.io/UIDS-GIDS for details how this range fits into the rest of the world */ -#define HOME_UID_MIN 60001 -#define HOME_UID_MAX 60513 - /* Put some limits on disk sizes: not less than 5M, not more than 5T */ #define USER_DISK_SIZE_MIN (UINT64_C(5)*1024*1024) #define USER_DISK_SIZE_MAX (UINT64_C(5)*1024*1024*1024*1024) diff --git a/src/nspawn/nspawn-bind-user.c b/src/nspawn/nspawn-bind-user.c index d3113c303e6..97761cb6f0b 100644 --- a/src/nspawn/nspawn-bind-user.c +++ b/src/nspawn/nspawn-bind-user.c @@ -10,9 +10,6 @@ #include "user-util.h" #include "userdb.h" -#define MAP_UID_START 60514 -#define MAP_UID_END 60577 - static int check_etc_passwd_collisions( const char *directory, const char *name, @@ -157,11 +154,11 @@ static int find_free_uid(const char *directory, uid_t max_uid, uid_t *current_ui assert(current_uid); for (;; (*current_uid) ++) { - if (*current_uid > MAP_UID_END || *current_uid > max_uid) + if (*current_uid > MAP_UID_MAX || *current_uid > max_uid) return log_error_errno( SYNTHETIC_ERRNO(EBUSY), "No suitable available UID in range " UID_FMT "…" UID_FMT " in container detected, can't map user.", - MAP_UID_START, MAP_UID_END); + MAP_UID_MIN, MAP_UID_MAX); r = check_etc_passwd_collisions(directory, NULL, *current_uid); if (r < 0) @@ -202,7 +199,7 @@ int bind_user_prepare( BindUserContext **ret) { _cleanup_(bind_user_context_freep) BindUserContext *c = NULL; - uid_t current_uid = MAP_UID_START; + uid_t current_uid = MAP_UID_MIN; char **n; int r; -- 2.39.5