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;
}
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;
}
// 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: