From 58dbf4c925aadf92a2de62943648b76ae1063c4a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 5 May 2021 22:06:34 +0200 Subject: [PATCH 1/2] userdb: return ESRCH if we didn't find a single varlink service Clearly communicate to callers that we didn't find a single varlink service, when a lookup is attempted. Note that the fallback's to NSS, drop-ins and synthesis might eat up this error again, but we should really make this case reasonably recognizable, in particular as our various tools already handle this condition correctly and print a nice message then. --- src/shared/userdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/userdb.c b/src/shared/userdb.c index 3e08b339f5..33a1442460 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -510,7 +510,7 @@ static int userdb_start_query( } if (set_isempty(iterator->links)) - return ret; /* propagate last error we saw if we couldn't connect to anything. */ + return ret < 0 ? ret : -ESRCH; /* propagate last error we saw if we couldn't connect to anything. */ /* We connected to some services, in this case, ignore the ones we failed on */ return 0; From 40fb3503f45447f37214fdd7f27946dc57a65925 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 5 May 2021 22:27:37 +0200 Subject: [PATCH 2/2] userdb: initialize .synthesize_root/.synthesize_nobody in generic code Let's initialize this at the same place for any iterator allocated. (Yes not all types of iterator objects need this, but it's still nice to share this trivial code at one place). --- src/shared/userdb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shared/userdb.c b/src/shared/userdb.c index 33a1442460..91ac7c3832 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -114,6 +114,8 @@ static UserDBIterator* userdb_iterator_new(LookupWhat what, UserDBFlags flags) { *i = (UserDBIterator) { .what = what, .flags = flags, + .synthesize_root = !FLAGS_SET(flags, USERDB_DONT_SYNTHESIZE), + .synthesize_nobody = !FLAGS_SET(flags, USERDB_DONT_SYNTHESIZE), }; return i; @@ -730,8 +732,6 @@ int userdb_all(UserDBFlags flags, UserDBIterator **ret) { if (!iterator) return -ENOMEM; - iterator->synthesize_root = iterator->synthesize_nobody = !FLAGS_SET(flags, USERDB_DONT_SYNTHESIZE); - qr = userdb_start_query(iterator, "io.systemd.UserDatabase.GetUserRecord", true, NULL, flags); if (!FLAGS_SET(flags, USERDB_EXCLUDE_NSS) && (qr < 0 || !iterator->nss_covered)) { @@ -1002,8 +1002,6 @@ int groupdb_all(UserDBFlags flags, UserDBIterator **ret) { if (!iterator) return -ENOMEM; - iterator->synthesize_root = iterator->synthesize_nobody = !FLAGS_SET(flags, USERDB_DONT_SYNTHESIZE); - qr = userdb_start_query(iterator, "io.systemd.UserDatabase.GetGroupRecord", true, NULL, flags); if (!FLAGS_SET(flags, USERDB_EXCLUDE_NSS) && (qr < 0 || !iterator->nss_covered)) {