From: Zbigniew Jędrzejewski-Szmek Date: Tue, 23 May 2023 10:07:13 +0000 (+0200) Subject: basic/user-util: return -ESRCH if passwd/group are missing X-Git-Tag: v254-rc1~411^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c42bac6a60ed40aeaa1e605d37990e20f52f6c26;p=thirdparty%2Fsystemd.git basic/user-util: return -ESRCH if passwd/group are missing --- diff --git a/src/basic/user-util.c b/src/basic/user-util.c index dd2642d214e..3325aabe4d5 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -287,7 +287,9 @@ int get_user_creds( p = getpwnam(*username); } if (!p) { - r = errno_or_else(ESRCH); + /* getpwnam() may fail with ENOENT if /etc/passwd is missing. + * For us that is equivalent to the name not being defined. */ + r = IN_SET(errno, 0, ENOENT) ? -ESRCH : -errno; /* If the user requested that we only synthesize as fallback, do so now */ if (FLAGS_SET(flags, USER_CREDS_PREFER_NSS)) { @@ -381,7 +383,9 @@ int get_group_creds(const char **groupname, gid_t *gid, UserCredsFlags flags) { } if (!g) - return errno_or_else(ESRCH); + /* getgrnam() may fail with ENOENT if /etc/group is missing. + * For us that is equivalent to the name not being defined. */ + return IN_SET(errno, 0, ENOENT) ? -ESRCH : -errno; if (gid) { if (!gid_is_valid(g->gr_gid))