From 165275fe803d0d001a0991014da928e44ed25941 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Jan 2025 11:55:24 +0100 Subject: [PATCH 1/2] userdbctl: don't expect argument to --fuzzy The getopt() parser was completely wrong, it expected an argument where wasn't expected or processes. The test cases only passed by accident because they use the "user" verb which is also the default verb. It would be accidently read as argument for --fuzzy and ignored. Fix that. --- src/userdb/userdbctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index e47c3761d0b..8a85778ef7d 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -1227,7 +1227,7 @@ static int parse_argv(int argc, char *argv[]) { { "chain", no_argument, NULL, ARG_CHAIN }, { "uid-min", required_argument, NULL, ARG_UID_MIN }, { "uid-max", required_argument, NULL, ARG_UID_MAX }, - { "fuzzy", required_argument, NULL, 'z' }, + { "fuzzy", no_argument, NULL, 'z' }, { "disposition", required_argument, NULL, ARG_DISPOSITION }, { "boundaries", required_argument, NULL, ARG_BOUNDARIES }, {} From 83e3b96d0a3b665b7b7a291500fa354a7760a917 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Jan 2025 16:44:12 +0100 Subject: [PATCH 2/2] userdb: reset errno before getpwent() errno handling for NSS is always a bit weird since NSS modules generally are not particularly careful with it. Hence let's initialize errno explicitly before we invoke getpwent() so that we know it's in a reasonable state afterwards on failure, or zero if not. We do this in most places we use NSS, including in userdb when it comes to getgrent(), just for getpwent() we don't so far. Address that. --- src/shared/userdb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/shared/userdb.c b/src/shared/userdb.c index be7c77d9503..a1da514884d 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -853,6 +853,7 @@ int userdb_iterator_get(UserDBIterator *iterator, UserRecord **ret) { /* If NSS isn't covered elsewhere, let's iterate through it first, since it probably contains * the more traditional sources, which are probably good to show first. */ + errno = 0; pw = getpwent(); if (pw) { _cleanup_free_ char *buffer = NULL;