#include <pakfire/packager.h>
#include <pakfire/pakfire.h>
#include <pakfire/private.h>
+#include <pakfire/pwd.h>
#include <pakfire/types.h>
#define BUFFER_SIZE 64 * 1024
pakfire_unref(packager->pakfire);
}
+static const char* pakfire_packager_user_lookup(void* data, la_int64_t uid) {
+ Pakfire pakfire = (Pakfire)data;
+
+ // Fast path for "root"
+ if (uid == 0)
+ return "root";
+
+ // Find a matching entry in /etc/passwd
+ struct passwd* entry = pakfire_getpwuid(pakfire, uid);
+ if (!entry) {
+ ERROR(pakfire, "Could not retrieve uname for %ld: %s\n", uid, strerror(errno));
+ return 0;
+ }
+
+ DEBUG(pakfire, "Mapping UID %ld to %s\n", uid, entry->pw_name);
+
+ return entry->pw_name;
+}
+
+static const char* pakfire_packager_group_lookup(void* data, la_int64_t gid) {
+ Pakfire pakfire = (Pakfire)data;
+
+ // Fast path for "root"
+ if (gid == 0)
+ return "root";
+
+ // Find a matching entry in /etc/group
+ struct group* entry = pakfire_getgrgid(pakfire, gid);
+ if (!entry) {
+ ERROR(pakfire, "Could not retrieve gname for %ld: %s\n", gid, strerror(errno));
+ return 0;
+ }
+
+ DEBUG(pakfire, "Mapping GID %ld to %s\n", gid, entry->gr_name);
+
+ return entry->gr_name;
+}
+
static int pakfire_packager_create_reader(struct pakfire_packager* p) {
// Open a reader
p->reader = archive_read_disk_new();
return 1;
}
+ // Install our own routine for user/group lookups
+ archive_read_disk_set_uname_lookup(p->reader, p->pakfire,
+ pakfire_packager_user_lookup, NULL);
+ archive_read_disk_set_gname_lookup(p->reader, p->pakfire,
+ pakfire_packager_group_lookup, NULL);
+
return 0;
}