From 9fe3995e8e2f9f4159c693663b9cc08dc37ff3f1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 2 Dec 2017 12:59:21 +0100 Subject: [PATCH] user-util: add new uid_is_system() helper This adds uid_is_system() and gid_is_system(), similar in style to uid_is_dynamic(). That a helper like this is useful is illustrated by the fact that test-condition.c didn't get the check right so far, which this patch fixes. --- src/basic/user-util.h | 8 ++++++++ src/login/logind-user.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/basic/user-util.h b/src/basic/user-util.h index f60166f79..b619239b8 100644 --- a/src/basic/user-util.h +++ b/src/basic/user-util.h @@ -71,6 +71,14 @@ static inline bool uid_is_dynamic(uid_t uid) { return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX; } +static inline bool uid_is_system(uid_t uid) { + return uid <= SYSTEM_UID_MAX; +} + +static inline bool gid_is_system(gid_t gid) { + return gid <= SYSTEM_GID_MAX; +} + /* The following macros add 1 when converting things, since UID 0 is a valid UID, while the pointer * NULL is special */ #define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1)) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 00cb8bf3a..3bbd9644c 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -645,7 +645,7 @@ int user_finalize(User *u) { * cases, as we shouldn't accidentally remove a system service's IPC objects while it is running, just because * a cronjob running as the same user just finished. Hence: exclude system users generally from IPC clean-up, * and do it only for normal users. */ - if (u->manager->remove_ipc && u->uid > SYSTEM_UID_MAX) { + if (u->manager->remove_ipc && !uid_is_system(u->uid)) { k = clean_ipc_by_uid(u->uid); if (k < 0) r = k; -- 2.30.2