From: Michael Tremer Date: Mon, 31 Oct 2022 10:18:30 +0000 (+0000) Subject: pwd: Sum up reading subuid/subgid X-Git-Tag: 0.9.28~184 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74a3d0c73e022a23fa8743a23f7064db9240746e;p=pakfire.git pwd: Sum up reading subuid/subgid I misinterpreted the format of /etc/subgid and used the group name when instead it is the same format as /etc/subuid. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/pwd.h b/src/libpakfire/include/pakfire/pwd.h index dc8cdc686..b0468e769 100644 --- a/src/libpakfire/include/pakfire/pwd.h +++ b/src/libpakfire/include/pakfire/pwd.h @@ -38,10 +38,8 @@ struct passwd* pakfire_getpwuid(struct pakfire* pakfire, uid_t uid); struct group* pakfire_getgrnam(struct pakfire* pakfire, const char* name); struct group* pakfire_getgrgid(struct pakfire* pakfire, gid_t gid); -int pakfire_getsubuid(struct pakfire* pakfire, const uid_t uid, - struct pakfire_subid* subuid); -int pakfire_getsubgid(struct pakfire* pakfire, const gid_t gid, - struct pakfire_subid* subgid); +int pakfire_getsubid(struct pakfire* pakfire, const char* path, + const uid_t uid, struct pakfire_subid* subid); #endif diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 3ef63f34d..8c1223ae6 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -788,14 +788,14 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path, // Fetch sub UID/GIDs if (!pakfire_on_root(p)) { // UID - r = pakfire_getsubuid(p, p->uid, &p->subuid); + r = pakfire_getsubid(p, "/etc/subuid", p->uid, &p->subuid); if (r) { ERROR(p, "Could not fetch subuid: %m\n"); goto ERROR; } // GID - r = pakfire_getsubgid(p, p->gid, &p->subgid); + r = pakfire_getsubid(p, "/etc/subgid", p->uid, &p->subgid); if (r) { ERROR(p, "Could not fetch subgid: %m\n"); goto ERROR; diff --git a/src/libpakfire/pwd.c b/src/libpakfire/pwd.c index 3adef05e8..756339d0b 100644 --- a/src/libpakfire/pwd.c +++ b/src/libpakfire/pwd.c @@ -226,8 +226,8 @@ ERROR: return &subid; } -int pakfire_getsubuid(struct pakfire* pakfire, const uid_t uid, - struct pakfire_subid* subuid) { +int pakfire_getsubid(struct pakfire* pakfire, const char* path, const uid_t uid, + struct pakfire_subid* subid) { struct pakfire_subid* entry = NULL; int r = 1; @@ -238,10 +238,10 @@ int pakfire_getsubuid(struct pakfire* pakfire, const uid_t uid, return 1; } - DEBUG(pakfire, "Fetching SUBUID for %s (%d)\n", passwd->pw_name, uid); + DEBUG(pakfire, "Fetching SUBID from %s for %s (%d)\n", path, passwd->pw_name, uid); // Open /etc/subuid - FILE* f = fopen(ETC_SUBUID, "r"); + FILE* f = fopen(path, "r"); if (!f) { ERROR(pakfire, "Could not open %s: %m\n", ETC_SUBUID); goto ERROR; @@ -257,54 +257,8 @@ int pakfire_getsubuid(struct pakfire* pakfire, const uid_t uid, // Check for match if (strcmp(entry->name, passwd->pw_name) == 0) { - subuid->id = entry->id; - subuid->length = entry->length; - r = 0; - - break; - } - } - -ERROR: - if (f) - fclose(f); - - return r; -} - -int pakfire_getsubgid(struct pakfire* pakfire, const gid_t gid, - struct pakfire_subid* subgid) { - struct pakfire_subid* entry = NULL; - int r = 1; - - // Fetch information about the running user - struct group* group = getgrgid(gid); - if (!group) { - ERROR(pakfire, "Could not fetch group entry for GID %d: %m\n", gid); - return 1; - } - - DEBUG(pakfire, "Fetching SUBGID for %s (%d)\n", group->gr_name, gid); - - // Open /etc/subgid - FILE* f = fopen(ETC_SUBGID, "r"); - if (!f) { - ERROR(pakfire, "Could not open %s: %m\n", ETC_SUBGID); - goto ERROR; - } - - // Walk through all entries - while (1) { - entry = pakfire_fgetsubid(pakfire, f); - if (!entry) - break; - - // TODO Check if name matches GID - - // Check for match - if (strcmp(entry->name, group->gr_name) == 0) { - subgid->id = entry->id; - subgid->length = entry->length; + subid->id = entry->id; + subid->length = entry->length; r = 0; break;