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