From 50b4f1e3bf55059f484bea537e93ad2b4bce151a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 22 Jun 2026 20:19:25 +0200 Subject: [PATCH] shared/creds-util: use getpwuid_malloc() Static linking, i.e. without dlopen, sometimes fails when getpwuid is used. I doesn't fail in all cases (glibc version?), so I didn't do this initially. --- src/shared/creds-util.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 739973aa46..a15fcfc6b2 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -768,6 +768,7 @@ static int mangle_uid_into_key( uid_t uid, uint8_t md[static SHA256_DIGEST_LENGTH]) { + _cleanup_free_ struct passwd *pw = NULL; sd_id128_t mid; int r; @@ -778,12 +779,9 @@ static int mangle_uid_into_key( * (specifically, UID, user name, machine ID) with the key we'd otherwise use for system credentials, * and use the resulting hash as actual encryption key. */ - errno = 0; - struct passwd *pw = getpwuid(uid); - if (!pw) - return log_error_errno( - IN_SET(errno, 0, ENOENT) ? SYNTHETIC_ERRNO(ESRCH) : errno, - "Failed to resolve UID " UID_FMT ": %m", uid); + r = getpwuid_malloc(uid, &pw); + if (r < 0) + return log_error_errno(r, "Failed to resolve UID "UID_FMT": %m", uid); r = sd_id128_get_machine(&mid); if (r < 0)