diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c index 38c214499e..3ac57441d9 100644 --- a/src/nss-systemd/nss-systemd.c +++ b/src/nss-systemd/nss-systemd.c @@ -348,7 +348,7 @@ enum nss_status _nss_systemd_setgrent(int stayopen) { _l = pthread_mutex_lock_assert(&getgrent_data.mutex); getgrent_data.iterator = userdb_iterator_free(getgrent_data.iterator); - getpwent_data.by_membership = false; + getgrent_data.by_membership = false; /* See _nss_systemd_setpwent() for an explanation why we use USERDB_DONT_SYNTHESIZE here */ r = groupdb_all(nss_glue_userdb_flags() | USERDB_DONT_SYNTHESIZE, &getgrent_data.iterator); @@ -441,7 +441,7 @@ enum nss_status _nss_systemd_getgrent_r( getgrent_data.iterator = userdb_iterator_free(getgrent_data.iterator); r = membershipdb_all(nss_glue_userdb_flags(), &getgrent_data.iterator); - if (r < 0) { + if (r < 0 && r != -ESRCH) { UNPROTECT_ERRNO; *errnop = -r; return NSS_STATUS_UNAVAIL; @@ -454,7 +454,7 @@ enum nss_status _nss_systemd_getgrent_r( return NSS_STATUS_UNAVAIL; } else if (!STR_IN_SET(gr->group_name, root_group.gr_name, nobody_group.gr_name)) { r = membershipdb_by_group_strv(gr->group_name, nss_glue_userdb_flags(), &members); - if (r < 0) { + if (r < 0 && r != -ESRCH) { UNPROTECT_ERRNO; *errnop = -r; return NSS_STATUS_UNAVAIL; @@ -465,6 +465,9 @@ enum nss_status _nss_systemd_getgrent_r( if (getgrent_data.by_membership) { _cleanup_(_nss_systemd_unblockp) bool blocked = false; + if (!getgrent_data.iterator) + return NSS_STATUS_NOTFOUND; + for (;;) { _cleanup_free_ char *user_name = NULL, *group_name = NULL; diff --git a/src/nss-systemd/userdb-glue.c b/src/nss-systemd/userdb-glue.c index 0cc84bfac7..8f8988579b 100644 --- a/src/nss-systemd/userdb-glue.c +++ b/src/nss-systemd/userdb-glue.c @@ -216,7 +216,7 @@ enum nss_status userdb_getgrnam( } r = membershipdb_by_group_strv(name, nss_glue_userdb_flags(), &members); - if (r < 0) { + if (r < 0 && r != -ESRCH) { *errnop = -r; return NSS_STATUS_UNAVAIL; } @@ -309,7 +309,7 @@ enum nss_status userdb_getgrgid( from_nss = false; r = membershipdb_by_group_strv(g->group_name, nss_glue_userdb_flags(), &members); - if (r < 0) { + if (r < 0 && r != -ESRCH) { *errnop = -r; return NSS_STATUS_UNAVAIL; }