diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index b3beca431b..d532d0bc6d 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -989,7 +989,7 @@ static int uid_is_ok(uid_t uid, const char *name, bool check_with_gid) { if (p) return 0; if (!IN_SET(errno, 0, ENOENT)) - return -errno; + log_warning_errno(errno, "Unexpected failure while looking up UID '" UID_FMT "' via NSS, assuming it doesn't exist: %m", uid); if (check_with_gid) { errno = 0; @@ -998,7 +998,7 @@ static int uid_is_ok(uid_t uid, const char *name, bool check_with_gid) { if (!streq(g->gr_name, name)) return 0; } else if (!IN_SET(errno, 0, ENOENT)) - return -errno; + log_warning_errno(errno, "Unexpected failure while looking up GID '" GID_FMT "' via NSS, assuming it doesn't exist: %m", uid); } } @@ -1103,7 +1103,7 @@ static int add_user(Item *i) { return 0; } if (!errno_is_not_exists(errno)) - return log_error_errno(errno, "Failed to check if user %s already exists: %m", i->name); + log_warning_errno(errno, "Unexpected failure while looking up user '%s' via NSS, assuming it doesn't exist: %m", i->name); } /* Try to use the suggested numeric UID */ @@ -1219,7 +1219,7 @@ static int gid_is_ok(gid_t gid, const char *groupname, bool check_with_uid) { if (g) return 0; if (!IN_SET(errno, 0, ENOENT)) - return -errno; + log_warning_errno(errno, "Unexpected failure while looking up GID '" GID_FMT "' via NSS, assuming it doesn't exist: %m", gid); if (check_with_uid) { errno = 0; @@ -1227,7 +1227,7 @@ static int gid_is_ok(gid_t gid, const char *groupname, bool check_with_uid) { if (p) return 0; if (!IN_SET(errno, 0, ENOENT)) - return -errno; + log_warning_errno(errno, "Unexpected failure while looking up GID '" GID_FMT "' via NSS, assuming it doesn't exist: %m", gid); } } @@ -1257,7 +1257,7 @@ static int get_gid_by_name(const char *name, gid_t *gid) { return 0; } if (!errno_is_not_exists(errno)) - return log_error_errno(errno, "Failed to check if group %s already exists: %m", name); + log_warning_errno(errno, "Unexpected failure while looking up group '%s' via NSS, assuming it doesn't exist: %m", name); } return -ENOENT; diff --git a/test/units/TEST-74-AUX-UTILS.sysusers.sh b/test/units/TEST-74-AUX-UTILS.sysusers.sh new file mode 100755 index 0000000000..dcd29938b5 --- /dev/null +++ b/test/units/TEST-74-AUX-UTILS.sysusers.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later +set -eux +set -o pipefail + +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + +at_exit() { + set +e + userdel -r foobarbaz + umount /run/systemd/userdb/ +} + +# Check that we indeed run under root to make the rest of the test work +[[ "$(id -u)" -eq 0 ]] + +trap at_exit EXIT + +# Ensure that a non-responsive NSS socket doesn't make sysusers fail +mount -t tmpfs tmpfs /run/systemd/userdb/ +touch /run/systemd/userdb/io.systemd.DynamicUser +echo 'u foobarbaz' | SYSTEMD_LOG_LEVEL=debug systemd-sysusers - +grep -q foobarbaz /etc/passwd