From d6db229ffc94981339a6a6e41c2172b0f962c6f6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Jan 2025 16:26:53 +0100 Subject: [PATCH] user-record: add some helpers for working with UserDBMatch --- src/shared/user-record.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 0040451ecc..d1b9fefa32 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -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);