#include <pakfire/pakfire.h>
#include <pakfire/parser.h>
#include <pakfire/private.h>
+#include <pakfire/pwd.h>
#include <pakfire/repo.h>
#include <pakfire/types.h>
#include <pakfire/util.h>
// Restore errno
errno = saved_errno;
}
+
+static const char* pakfire_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_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;
+}
+
+struct archive* pakfire_make_archive_disk_reader(Pakfire pakfire, int internal) {
+ struct archive* archive = archive_read_disk_new();
+ if (!archive)
+ return NULL;
+
+ // Do not read fflags
+ int r = archive_read_disk_set_behavior(archive, ARCHIVE_READDISK_NO_FFLAGS);
+ if (r) {
+ ERROR(pakfire, "Could not change behavior of reader: %s\n",
+ archive_error_string(archive));
+ archive_read_free(archive);
+ return NULL;
+ }
+
+ // Install user/group lookups
+ if (internal) {
+ archive_read_disk_set_uname_lookup(archive, pakfire, pakfire_user_lookup, NULL);
+ archive_read_disk_set_gname_lookup(archive, pakfire, pakfire_group_lookup, NULL);
+ } else {
+ archive_read_disk_set_standard_lookup(archive);
+ }
+
+ return archive;
+}