]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
user-record: add some helpers for working with UserDBMatch
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Jan 2025 15:26:53 +0000 (16:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 27 Jan 2025 22:42:06 +0000 (23:42 +0100)
src/shared/user-record.h

index 0040451ecc0280a1d588d3e9cf466069dd424773..d1b9fefa3230c792970c719d2d7f9ef5c3477919 100644 (file)
@@ -9,7 +9,9 @@
 
 #include "hashmap.h"
 #include "missing_resource.h"
+#include "strv.h"
 #include "time-util.h"
+#include "user-util.h"
 
 typedef enum UserDisposition {
         USER_INTRINSIC,   /* root and nobody */
@@ -505,6 +507,28 @@ typedef struct UserDBMatch {
 
 #define USER_DISPOSITION_MASK_ALL ((UINT64_C(1) << _USER_DISPOSITION_MAX) - UINT64_C(1))
 
+#define USERDB_MATCH_NULL                                       \
+        (UserDBMatch) {                                         \
+                .disposition_mask = USER_DISPOSITION_MASK_ALL,  \
+                .uid_min = 0,                                   \
+                .uid_max = UID_INVALID-1,                       \
+       }
+
+static inline bool userdb_match_is_set(const UserDBMatch *match) {
+        if (!match)
+                return false;
+
+        return !strv_isempty(match->fuzzy_names) ||
+                !FLAGS_SET(match->disposition_mask, USER_DISPOSITION_MASK_ALL) ||
+                match->uid_min > 0 ||
+                match->uid_max < UID_INVALID-1;
+}
+
+static inline void userdb_match_done(UserDBMatch *match) {
+        assert(match);
+        strv_free(match->fuzzy_names);
+}
+
 bool user_name_fuzzy_match(const char *names[], size_t n_names, char **matches);
 int user_record_match(UserRecord *u, const UserDBMatch *match);