]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
user-record: introduce USERDB_MATCH_ROOT_AND_SYSTEM
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Apr 2025 14:27:59 +0000 (23:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 May 2025 03:10:28 +0000 (12:10 +0900)
It may be useful when we want to resolve root and system user/group
but want to refuse nobody user/group.

src/shared/user-record.h

index 246d02f062d8ac04bba11478499a9c0c344053f1..32c8e38d04b9a50e436283801ad989da5070e275 100644 (file)
@@ -7,6 +7,7 @@
 #include "sd-id128.h"
 #include "sd-json.h"
 
+#include "bitfield.h"
 #include "hashmap.h"
 #include "rlimit-util.h"
 #include "strv.h"
@@ -527,12 +528,21 @@ typedef struct UserDBMatch {
 #define USER_DISPOSITION_MASK_ALL ((UINT64_C(1) << _USER_DISPOSITION_MAX) - UINT64_C(1))
 
 #define USERDB_MATCH_NULL                                       \
-        (UserDBMatch) {                                         \
+        (const UserDBMatch) {                                   \
                 .disposition_mask = USER_DISPOSITION_MASK_ALL,  \
                 .uid_min = 0,                                   \
                 .uid_max = UID_INVALID-1,                       \
        }
 
+/* Maybe useful when we want to resolve root and system user/group but want to refuse nobody user/group. */
+#define USERDB_MATCH_ROOT_AND_SYSTEM                            \
+        (const UserDBMatch) {                                   \
+                .disposition_mask =                             \
+                        INDEXES_TO_MASK(uint64_t, USER_INTRINSIC, USER_SYSTEM), \
+                .uid_min = 0,                                   \
+                .uid_max = UID_NOBODY - 1,                      \
+       }
+
 static inline bool userdb_match_is_set(const UserDBMatch *match) {
         if (!match)
                 return false;