From c54bafa7e74dbcb5b07bafe8fadf2ca830fd93d7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 1 Sep 2023 14:35:03 +0000 Subject: [PATCH] pwd: Don't fail if we cannot read SUBUID/SUBGID from configuration Signed-off-by: Michael Tremer --- src/libpakfire/pakfire.c | 23 +++++++++++++++---- src/libpakfire/pwd.c | 48 ++++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 7406f0178..90683b62f 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -824,15 +824,30 @@ static int pakfire_setup_user(struct pakfire* pakfire) { if (!pakfire_on_root(pakfire)) { // Fetch SUBUIDs r = pakfire_getsubuid(pakfire, pakfire->user.name, &pakfire->user.subuids); - if (r) - goto ERROR; + switch (r) { + case 0: + case 1: + break; + + default: + goto ERROR; + } // Fetch SUBGIDs r = pakfire_getsubgid(pakfire, pakfire->user.name, &pakfire->group.subgids); - if (r) - goto ERROR; + switch (r) { + case 0: + case 1: + break; + + default: + goto ERROR; + } } + // Success + r = 0; + ERROR: return r; } diff --git a/src/libpakfire/pwd.c b/src/libpakfire/pwd.c index 4cc154246..4178c04a9 100644 --- a/src/libpakfire/pwd.c +++ b/src/libpakfire/pwd.c @@ -273,25 +273,37 @@ ERROR: return r; } +/* + This function searches for a SUBUID/SUBGID entry for the given user. + + If something is found, subid is configured accordingly and the function returns 0. + If nothing was found, the function returns 1. + If there was an error, the function may return something else. +*/ static int pakfire_getsubid(struct pakfire* pakfire, const char* path, const char* owner, struct pakfire_subid* subid) { struct pakfire_subid entry; - int r = 1; - - // Do not lookup root user and set the entire available UID/GID range - if (!owner) { - subid->id = 0; - subid->length = 0xffffffff - 1; + int r; - return 0; - } + // Do not lookup root + if (!owner) + return 1; DEBUG(pakfire, "Fetching SUBID from %s for %s\n", path, owner); // Open /etc/subuid FILE* f = fopen(path, "r"); if (!f) { - ERROR(pakfire, "Could not open %s: %m\n", path); + switch (errno) { + case ENOENT: + break; + + default: + ERROR(pakfire, "Could not open %s: %m\n", path); + break; + } + + // Nothing found r = 1; goto END; } @@ -299,22 +311,30 @@ static int pakfire_getsubid(struct pakfire* pakfire, const char* path, const cha // Walk through all entries while (1) { r = pakfire_fgetsubid(pakfire, &entry, f); - if (r) - goto END; + switch (r) { + case 0: + break; + + case EOF: + r = 1; + goto END; + + default: + goto END; + } // Check for match if (strcmp(entry.name, owner) == 0) { subid->id = entry.id; subid->length = entry.length; - r = 0; + r = 0; goto END; } } // No match found - ERROR(pakfire, "No match found for %s\n", owner); - errno = ENOENT; + DEBUG(pakfire, "No match found for %s\n", owner); r = 1; END: -- 2.39.5