static la_int64_t pakfire_uid_lookup(void* data, const char* name, la_int64_t uid) {
struct pakfire* pakfire = (struct pakfire*)data;
+ // Cannot handle empty names
+ if (!*name)
+ goto ERROR;
+
// Fast path for "root"
if (strcmp(name, "root") == 0)
- return pakfire_map_id(pakfire, &pakfire->user.subuids, 0);
+ goto ERROR;
CTX_DEBUG(pakfire->ctx, "Looking up UID for '%s' (%ld)\n", name, uid);
struct passwd* entry = pakfire_getpwnam(pakfire, name);
if (!entry) {
CTX_ERROR(pakfire->ctx, "Could not retrieve UID for '%s': %m\n", name);
- return pakfire_map_id(pakfire, &pakfire->user.subuids, 0);
+ goto ERROR;
}
CTX_DEBUG(pakfire->ctx, "Mapping %s to UID %u\n", name, entry->pw_uid);
return pakfire_map_id(pakfire, &pakfire->user.subuids, entry->pw_uid);
+
+ERROR:
+ // Return root on error
+ return pakfire_map_id(pakfire, &pakfire->user.subuids, 0);
}
static la_int64_t pakfire_gid_lookup(void* data, const char* name, la_int64_t gid) {
struct pakfire* pakfire = (struct pakfire*)data;
+ // Cannot handle empty names
+ if (!*name)
+ goto ERROR;
+
// Fast path for "root"
if (strcmp(name, "root") == 0)
- return pakfire_map_id(pakfire, &pakfire->group.subgids, 0);
+ goto ERROR;
CTX_DEBUG(pakfire->ctx, "Looking up GID for '%s' (%ld)\n", name, gid);
struct group* entry = pakfire_getgrnam(pakfire, name);
if (!entry) {
CTX_ERROR(pakfire->ctx, "Could not retrieve GID for '%s': %m\n", name);
- return pakfire_map_id(pakfire, &pakfire->group.subgids, 0);
+ goto ERROR;
}
CTX_DEBUG(pakfire->ctx, "Mapping %s to GID %u\n", name, entry->gr_gid);
return pakfire_map_id(pakfire, &pakfire->group.subgids, entry->gr_gid);
+
+ERROR:
+ // Return root on error
+ return pakfire_map_id(pakfire, &pakfire->group.subgids, 0);
}
struct archive* pakfire_make_archive_disk_writer(struct pakfire* pakfire, int internal) {