user-record: Make user and group matching functions total

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.
This commit is contained in:
Michal Koutný
2025-03-03 19:27:12 +01:00
parent eaeb96125a
commit 75e2d70eef
5 changed files with 8 additions and 20 deletions
+4 -16
View 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)