uid-classification: properly classify *all* container UIDs

A bit confusingly CONTAINER_UID_BASE_MAX is just the maximum *base* UID
for a container. Thus, with the usual 64K UID assignments, the last
actual container UID is CONTAINER_UID_BASE_MAX+0xFFFF.

To make this less confusing define CONTAINER_UID_MIN/MAX that add the
missing extra space.

Also adjust two uses where this was mishandled so far, due to this
confusion.

With this change the UID ranges we default to should properly match what
is documented on https://systemd.io/UIDS-GIDS/.
This commit is contained in:
Lennart Poettering
2024-11-08 23:18:39 +00:00
committed by Luca Boccassi
parent 347def981b
commit 56933f2073
3 changed files with 14 additions and 4 deletions
+9 -1
View File
@@ -4,6 +4,14 @@
#include <stdbool.h>
#include <sys/types.h>
/* The container base should have the last 16 bit set to zero */
assert_cc((CONTAINER_UID_BASE_MIN & 0xFFFFU) == 0);
assert_cc((CONTAINER_UID_BASE_MAX & 0xFFFFU) == 0);
/* Given we assign 64K UIDs to containers, the last container UID is 0xFFFF larger than the base */
#define CONTAINER_UID_MIN (CONTAINER_UID_BASE_MIN)
#define CONTAINER_UID_MAX (CONTAINER_UID_BASE_MAX + 0xFFFFU)
bool uid_is_system(uid_t uid);
bool gid_is_system(gid_t gid);
@@ -16,7 +24,7 @@ static inline bool gid_is_dynamic(gid_t gid) {
}
static inline bool uid_is_container(uid_t uid) {
return CONTAINER_UID_BASE_MIN <= uid && uid <= CONTAINER_UID_BASE_MAX;
return CONTAINER_UID_MIN <= uid && uid <= CONTAINER_UID_MAX;
}
static inline bool gid_is_container(gid_t gid) {