]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
userdb: return ESRCH if userdb service refuses a user/group name as invalid 34778/head
authorLennart Poettering <lennart@poettering.net>
Tue, 15 Oct 2024 11:59:57 +0000 (13:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 15 Oct 2024 12:15:21 +0000 (14:15 +0200)
if a userdb service refuse a user/group name as invalid, let's turn this
into ESRCH client-side following that there definitely is no user/group
record for a completely invalid user/group name.

Replaces: #34558

src/shared/userdb.c

index 557de70ea8042da5957bd0bf15ca4b8d6cbb4d02..ff83d4bf902683e0eef6ae2ebc1e884d07c111de 100644 (file)
@@ -171,9 +171,15 @@ static int userdb_on_query_reply(
         if (error_id) {
                 log_debug("Got lookup error: %s", error_id);
 
+                /* Convert various forms of record not found into -ESRCH, since NSS typically doesn't care,
+                 * about the details. Note that if a userName specification is refused as invalid parameter,
+                 * we also turn this into -ESRCH following the logic that there cannot be a user record for a
+                 * completely invalid user name. */
                 if (STR_IN_SET(error_id,
                                "io.systemd.UserDatabase.NoRecordFound",
-                               "io.systemd.UserDatabase.ConflictingRecordFound"))
+                               "io.systemd.UserDatabase.ConflictingRecordFound") ||
+                    sd_varlink_error_is_invalid_parameter(error_id, parameters, "userName") ||
+                    sd_varlink_error_is_invalid_parameter(error_id, parameters, "groupName"))
                         r = -ESRCH;
                 else if (streq(error_id, "io.systemd.UserDatabase.ServiceNotAvailable"))
                         r = -EHOSTDOWN;