]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
user-record: Make user and group matching functions total
authorMichal Koutný <mkoutny@suse.com>
Fri, 28 Feb 2025 14:28:04 +0000 (15:28 +0100)
committerMichal Koutný <mkoutny@suse.com>
Mon, 3 Mar 2025 18:27:12 +0000 (19:27 +0100)
Since we can evaluate even the case with invalid ids (non-matching) we
can switch the function to pure boolean with no error cases and simpler
(none) return error handling.

src/shared/group-record.c
src/shared/group-record.h
src/shared/user-record.c
src/shared/user-record.h
src/shared/userdb.c

index 76d23259ce6520ae030b521427458499384e31a3..04989eb63aa5e0971ea7270cac2f419cf33ed782 100644 (file)
@@ -344,7 +344,7 @@ bool group_record_matches_group_name(const GroupRecord *g, const char *group_nam
         return false;
 }
 
-int group_record_match(GroupRecord *h, const UserDBMatch *match) {
+bool group_record_match(GroupRecord *h, const UserDBMatch *match) {
         assert(h);
 
         if (!match)
index 5705fe25116c831bece7caa85685ca8c5de5a6e6..ee8d39957798b7c48f3414fd52026b502f28e44e 100644 (file)
@@ -43,7 +43,7 @@ int group_record_load(GroupRecord *h, sd_json_variant *v, UserRecordLoadFlags fl
 int group_record_build(GroupRecord **ret, ...);
 int group_record_clone(GroupRecord *g, UserRecordLoadFlags flags, GroupRecord **ret);
 
-int group_record_match(GroupRecord *h, const UserDBMatch *match);
+bool group_record_match(GroupRecord *h, const UserDBMatch *match);
 
 const char* group_record_group_name_and_realm(GroupRecord *h);
 UserDisposition group_record_disposition(GroupRecord *h);
index 4c8e41cd8953887d324870a55091c1d367576ac0..89ba2fbef4c7ba3d1bacaf249fa8624b610195fa 100644 (file)
@@ -2769,7 +2769,7 @@ bool user_name_fuzzy_match(const char *names[], size_t n_names, char **matches)
         return false;
 }
 
-int user_record_match(UserRecord *u, const UserDBMatch *match) {
+bool user_record_match(UserRecord *u, const UserDBMatch *match) {
         assert(u);
 
         if (!match)
index 8f58c5ca93d84bbc8315d595a93b78f798d3dca3..fcd26855548191c6037184d0fa2d28bc52d9f62e 100644 (file)
@@ -532,7 +532,7 @@ static inline void userdb_match_done(UserDBMatch *match) {
 }
 
 bool user_name_fuzzy_match(const char *names[], size_t n_names, char **matches);
-int user_record_match(UserRecord *u, const UserDBMatch *match);
+bool user_record_match(UserRecord *u, const UserDBMatch *match);
 
 bool user_record_matches_user_name(const UserRecord *u, const char *username);
 
index 18b98685dbd6f1687aa4dfc7455b5642da43d81c..a420504b0c07f8cdc75994b260d7f3db02b69c30 100644 (file)
@@ -915,10 +915,7 @@ int userdb_by_name(const char *name, const UserDBMatch *match, UserDBFlags flags
         /* NB: we always apply our own filtering here, explicitly, regardless if the server supported it or
          * not. It's more robust this way, we never know how carefully the server is written, and whether it
          * properly implements all details of the filtering logic. */
-        r = user_record_match(ur, match);
-        if (r < 0)
-                return r;
-        if (r == 0)
+        if (!user_record_match(ur, match))
                 return -ENOEXEC;
 
         if (ret)
@@ -1001,10 +998,7 @@ int userdb_by_uid(uid_t uid, const UserDBMatch *match, UserDBFlags flags, UserRe
                         return r;
         }
 
-        r = user_record_match(ur, match);
-        if (r < 0)
-                return r;
-        if (r == 0)
+        if (!user_record_match(ur, match))
                 return -ENOEXEC;
 
         if (ret)
@@ -1347,10 +1341,7 @@ int groupdb_by_name(const char *name, const UserDBMatch *match, UserDBFlags flag
         }
 
         /* As above, we apply our own client-side filtering even if server-side filtering worked, for robustness and simplicity reasons. */
-        r = group_record_match(gr, match);
-        if (r < 0)
-                return r;
-        if (r == 0)
+        if (!group_record_match(gr, match))
                 return -ENOEXEC;
 
         if (ret)
@@ -1432,10 +1423,7 @@ int groupdb_by_gid(gid_t gid, const UserDBMatch *match, UserDBFlags flags, Group
                         return r;
         }
 
-        r = group_record_match(gr, match);
-        if (r < 0)
-                return r;
-        if (r == 0)
+        if (!group_record_match(gr, match))
                 return -ENOEXEC;
 
         if (ret)