]> git.ipfire.org Git - pakfire.git/commitdiff
pwd: Don't fail if we cannot read SUBUID/SUBGID from configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 1 Sep 2023 14:35:03 +0000 (14:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 1 Sep 2023 14:35:03 +0000 (14:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c
src/libpakfire/pwd.c

index 7406f0178465f31300cdc2fc68faab36002da53a..90683b62f792c09483993e55733c8ae29f3da9ff 100644 (file)
@@ -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;
 }
index 4cc154246bd8dd0527737f78fb7191641d93cc31..4178c04a90757b48e423db907db7960f87590dbc 100644 (file)
@@ -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: