chiark / gitweb /
user-util: add new uid_is_system() helper
authorLennart Poettering <lennart@poettering.net>
Sat, 2 Dec 2017 11:59:21 +0000 (12:59 +0100)
committerSven Eden <yamakuzure@gmx.net>
Sat, 2 Dec 2017 11:59:21 +0000 (12:59 +0100)
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
src/login/logind-user.c

index f60166f79a0f460632221ca667c870bfcd6abd03..b619239b8acbbb109b009ed05f088994f8eb6422 100644 (file)
@@ -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))
index 00cb8bf3a85b8ce6a7de109fa9c5445cb1cbf5ba..3bbd9644c947fa2f07784b96c5f21c402330eb39 100644 (file)
@@ -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;