uid_t uid;
char name[NAME_MAX];
char home[PATH_MAX];
+ struct pakfire_subid subuids;
} user;
struct pakfire_group {
gid_t gid;
char name[NAME_MAX];
+ struct pakfire_subid subgids;
} group;
- // Mapped UID/GID
- struct pakfire_subid subuid;
- struct pakfire_subid subgid;
-
// Pool
Pool* pool;
}
const struct pakfire_subid* pakfire_subuid(struct pakfire* pakfire) {
- return &pakfire->subuid;
+ return &pakfire->user.subuids;
}
const struct pakfire_subid* pakfire_subgid(struct pakfire* pakfire) {
- return &pakfire->subgid;
+ return &pakfire->group.subgids;
}
/*
if (r)
goto ERROR;
+ // Fetch sub UID/GIDs
+ if (!pakfire_on_root(pakfire)) {
+ r = pakfire_getsubuid(pakfire, pakfire->user.name, &pakfire->user.subuids);
+ if (r)
+ goto ERROR;
+
+ r = pakfire_getsubgid(pakfire, pakfire->user.name, &pakfire->group.subgids);
+ if (r)
+ goto ERROR;
+ }
+
ERROR:
return r;
}
pakfire_log_set_priority(p, log_priority(env));
}
- // Setup user/group
- r = pakfire_setup_user(p);
- if (r)
- goto ERROR;
-
- // Initialise configuration
- r = pakfire_config_create(&p->config);
- if (r)
- goto ERROR;
-
// Generate a random path if none is set
if (!path) {
path = pakfire_mkdtemp(tempdir);
// Set path
pakfire_string_set(p->path, path);
+ // Setup user/group
+ r = pakfire_setup_user(p);
+ if (r)
+ goto ERROR;
+
+ // Initialise configuration
+ r = pakfire_config_create(&p->config);
+ if (r)
+ goto ERROR;
+
// Read /etc/os-release
r = pakfire_read_os_release(p);
if (r && errno != ENOENT)
DEBUG(p, " arch = %s\n", pakfire_get_arch(p));
DEBUG(p, " path = %s\n", pakfire_get_path(p));
- // Fetch sub UID/GIDs
- if (!pakfire_on_root(p)) {
- // UID
- r = pakfire_getsubid(p, "/etc/subuid", p->user.uid, &p->subuid);
- if (r) {
- ERROR(p, "Could not fetch subuid: %m\n");
- goto ERROR;
- }
-
- // GID
- r = pakfire_getsubid(p, "/etc/subgid", p->user.uid, &p->subgid);
- if (r) {
- ERROR(p, "Could not fetch subgid: %m\n");
- goto ERROR;
- }
-
- // Log
- DEBUG(p, " subuid = %u - %zu\n", p->subuid.id, p->subuid.id + p->subuid.length);
- DEBUG(p, " subgid = %u - %zu\n", p->subgid.id, p->subgid.id + p->subgid.length);
- }
-
// Perform some safety checks
r = pakfire_safety_checks(p);
if (r)
DEBUG(pakfire, "Looking up name for UID %ld\n", uid);
// Unmap the UID first
- uid = pakfire_unmap_id(pakfire, &pakfire->subuid, uid);
+ uid = pakfire_unmap_id(pakfire, &pakfire->user.subuids, uid);
// Fast path for "root"
if (uid == 0)
DEBUG(pakfire, "Looking up name for GID %ld\n", gid);
// Unmap the GID first
- gid = pakfire_unmap_id(pakfire, &pakfire->subgid, gid);
+ gid = pakfire_unmap_id(pakfire, &pakfire->group.subgids, gid);
// Fast path for "root"
if (gid == 0)
// Fast path for "root"
if (strcmp(name, "root") == 0)
- return pakfire_map_id(pakfire, &pakfire->subuid, 0);
+ return pakfire_map_id(pakfire, &pakfire->user.subuids, 0);
// Find a matching entry in /etc/passwd
struct passwd* entry = pakfire_getpwnam(pakfire, name);
if (!entry) {
ERROR(pakfire, "Could not retrieve UID for '%s': %m\n", name);
- return pakfire_map_id(pakfire, &pakfire->subuid, 0);
+ return pakfire_map_id(pakfire, &pakfire->user.subuids, 0);
}
DEBUG(pakfire, "Mapping %s to UID %d\n", name, entry->pw_uid);
- return pakfire_map_id(pakfire, &pakfire->subuid, entry->pw_uid);
+ return pakfire_map_id(pakfire, &pakfire->user.subuids, entry->pw_uid);
}
static la_int64_t pakfire_gid_lookup(void* data, const char* name, la_int64_t gid) {
// Fast path for "root"
if (strcmp(name, "root") == 0)
- return pakfire_map_id(pakfire, &pakfire->subgid, 0);
+ return pakfire_map_id(pakfire, &pakfire->group.subgids, 0);
// Find a matching entry in /etc/group
struct group* entry = pakfire_getgrnam(pakfire, name);
if (!entry) {
ERROR(pakfire, "Could not retrieve GID for '%s': %m\n", name);
- return pakfire_map_id(pakfire, &pakfire->subgid, 0);
+ return pakfire_map_id(pakfire, &pakfire->group.subgids, 0);
}
DEBUG(pakfire, "Mapping %s to GID %d\n", name, entry->gr_gid);
- return pakfire_map_id(pakfire, &pakfire->subgid, entry->gr_gid);
+ return pakfire_map_id(pakfire, &pakfire->group.subgids, entry->gr_gid);
}
struct archive* pakfire_make_archive_disk_writer(struct pakfire* pakfire, int internal) {
return r;
}
-int pakfire_getsubid(struct pakfire* pakfire, const char* path, const uid_t uid,
+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 (uid == 0) {
+ if (!owner) {
subid->id = 0;
subid->length = 0xffffffff - 1;
return 0;
}
- // Fetch information about the running user
- struct passwd* passwd = getpwuid(uid);
- if (!passwd) {
- ERROR(pakfire, "Could not fetch passwd entry for UID %d: %m\n", uid);
- return 1;
- }
-
- DEBUG(pakfire, "Fetching SUBID from %s for %s (%d)\n", path, passwd->pw_name, uid);
+ 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", ETC_SUBUID);
+ ERROR(pakfire, "Could not open %s: %m\n", path);
r = 1;
goto END;
}
if (r)
goto END;
- // TODO Check if name matches UID
-
// Check for match
- if (strcmp(entry.name, passwd->pw_name) == 0) {
+ if (strcmp(entry.name, owner) == 0) {
subid->id = entry.id;
subid->length = entry.length;
r = 0;
}
// No match found
- ERROR(pakfire, "No match found for %s\n", passwd->pw_name);
+ ERROR(pakfire, "No match found for %s\n", owner);
errno = ENOENT;
r = 1;
return r;
}
+
+int pakfire_getsubuid(struct pakfire* pakfire, const char* owner, struct pakfire_subid* subid) {
+ return pakfire_getsubid(pakfire, ETC_SUBUID, owner, subid);
+}
+
+int pakfire_getsubgid(struct pakfire* pakfire, const char* owner, struct pakfire_subid* subid) {
+ return pakfire_getsubid(pakfire, ETC_SUBGID, owner, subid);
+}
+
+#endif