]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nss: when we encounter an invalid user/group name or UID/GID, don't return EINVAL 4989/head
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Dec 2016 16:59:38 +0000 (17:59 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Dec 2016 17:09:58 +0000 (18:09 +0100)
It's not our business to validate invalid user/group names or UID/GID.
Ideally, libc would filter these out, but they don't, hence we have to
filter, but let's not propagate this as error, but simply as "not found"
to the caller.

User name rules are pretty vaguely defined, and the rules defined by
POSIX clash with reality quite heavily (for example, utmp doesn't offer
enough room for user name length, and /usr/bin/chown permits separating
user/group names by a single dot, even though POSIX allows dots being
used in user/group names themselves.) We enforce stricter rules than
POSIX for good reason, and hence in doing so we should not categorically
return EINVAL on stuff we don't consider valid, but other components
might.

Fixes: #4983
src/nss-mymachines/nss-mymachines.c
src/nss-systemd/nss-systemd.c

index 895f61c46296344965a89d7cb34f4553d036917e..fac37faea5ef7cebde5c280a08de5b190c3082ce 100644 (file)
@@ -512,10 +512,8 @@ enum nss_status _nss_mymachines_getpwuid_r(
 
         BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
 
-        if (!uid_is_valid(uid)) {
-                r = -EINVAL;
-                goto fail;
-        }
+        if (!uid_is_valid(uid))
+                goto not_found;
 
         /* We consider all uids < 65536 host uids */
         if (uid < HOST_UID_LIMIT)
@@ -686,10 +684,8 @@ enum nss_status _nss_mymachines_getgrgid_r(
 
         BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
 
-        if (!gid_is_valid(gid)) {
-                r = -EINVAL;
-                goto fail;
-        }
+        if (!gid_is_valid(gid))
+                goto not_found;
 
         /* We consider all gids < 65536 host gids */
         if (gid < HOST_GID_LIMIT)
index c80972742b2b5374418df9452bd1a6c26663a2ca..fd5064c9379f4b47d63b279df794d0b789b4574a 100644 (file)
@@ -123,10 +123,10 @@ enum nss_status _nss_systemd_getpwnam_r(
         assert(name);
         assert(pwd);
 
-        if (!valid_user_group_name(name)) {
-                r = -EINVAL;
-                goto fail;
-        }
+        /* If the username is not valid, then we don't know it. Ideally libc would filter these for us anyway. We don't
+         * generate EINVAL here, because it isn't really out business to complain about invalid user names. */
+        if (!valid_user_group_name(name))
+                goto not_found;
 
         /* Synthesize entries for the root and nobody users, in case they are missing in /etc/passwd */
         if (streq(name, root_passwd.pw_name)) {
@@ -227,10 +227,8 @@ enum nss_status _nss_systemd_getpwuid_r(
 
         BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
 
-        if (!uid_is_valid(uid)) {
-                r = -EINVAL;
-                goto fail;
-        }
+        if (!uid_is_valid(uid))
+                goto not_found;
 
         /* Synthesize data for the root user and for nobody in case they are missing from /etc/passwd */
         if (uid == root_passwd.pw_uid) {
@@ -329,10 +327,8 @@ enum nss_status _nss_systemd_getgrnam_r(
         assert(name);
         assert(gr);
 
-        if (!valid_user_group_name(name)) {
-                r = -EINVAL;
-                goto fail;
-        }
+        if (!valid_user_group_name(name))
+                goto not_found;
 
         /* Synthesize records for root and nobody, in case they are missing form /etc/group */
         if (streq(name, root_group.gr_name)) {
@@ -430,10 +426,8 @@ enum nss_status _nss_systemd_getgrgid_r(
 
         BLOCK_SIGNALS(NSS_SIGNALS_BLOCK);
 
-        if (!gid_is_valid(gid)) {
-                r = -EINVAL;
-                goto fail;
-        }
+        if (!gid_is_valid(gid))
+                goto not_found;
 
         /* Synthesize records for root and nobody, in case they are missing from /etc/group */
         if (gid == root_group.gr_gid) {