src/libpakfire/pakfire.c \
src/libpakfire/parser.c \
src/libpakfire/problem.c \
+ src/libpakfire/pwd.c \
src/libpakfire/relation.c \
src/libpakfire/relationlist.c \
src/libpakfire/repo.c \
src/libpakfire/include/pakfire/parser.h \
src/libpakfire/include/pakfire/private.h \
src/libpakfire/include/pakfire/problem.h \
+ src/libpakfire/include/pakfire/pwd.h \
src/libpakfire/include/pakfire/relation.h \
src/libpakfire/include/pakfire/relationlist.h \
src/libpakfire/include/pakfire/repo.h \
#include <pakfire/pakfire.h>
#include <pakfire/parser.h>
#include <pakfire/private.h>
+#include <pakfire/pwd.h>
#include <pakfire/repo.h>
#include <pakfire/scriptlet.h>
#include <pakfire/util.h>
return 0;
}
+static la_int64_t archive_user_lookup(void* data, const char* name, la_int64_t uid) {
+ Pakfire pakfire = (Pakfire)data;
+
+ // Fast path for "root"
+ if (strcmp(name, "root") == 0)
+ return 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': %s\n", name, strerror(errno));
+ return 0;
+ }
+
+ DEBUG(pakfire, "Mapping %s to UID %d\n", name, entry->pw_uid);
+
+ return entry->pw_uid;
+}
+
static int archive_extract(PakfireArchive archive, struct archive* a, const char* prefix) {
struct archive_entry* entry;
int r;
archive_write_disk_set_options(ext, flags);
archive_write_disk_set_standard_lookup(ext);
+ // Install our own routine for user lookups
+ archive_write_disk_set_user_lookup(ext, archive->pakfire, archive_user_lookup, NULL);
+
for (;;) {
r = archive_read_next_header(a, &entry);
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef PAKFIRE_PWD_H
+#define PAKFIRE_PWD_H
+
+#ifdef PAKFIRE_PRIVATE
+
+#include <pwd.h>
+
+#include <pakfire/types.h>
+
+struct passwd* pakfire_getpwnam(Pakfire pakfire, const char* name);
+struct passwd* pakfire_getpwuid(Pakfire pakfire, uid_t uid);
+
+#endif
+
+#endif /* PAKFIRE_PWD_H */
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2021 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <pakfire/pakfire.h>
+#include <pakfire/pwd.h>
+
+static struct passwd* pakfire_getpwent(Pakfire pakfire,
+ int(*cmp)(struct passwd* entry, const void* value), const void* value) {
+ struct passwd* entry = NULL;
+
+ // Get path to /etc/passwd
+ char* path = pakfire_make_path(pakfire, "/etc/passwd");
+ if (!path)
+ return NULL;
+
+ FILE* f = fopen(path, "r");
+ if (!f)
+ goto END;
+
+ for (;;) {
+ // Parse entry
+ entry = fgetpwent(f);
+ if (!entry)
+ goto END;
+
+ // Check if this is what we are looking for
+ if (cmp(entry, value))
+ break;
+ else
+ entry = NULL;
+ }
+
+END:
+ free(path);
+
+ if (f)
+ fclose(f);
+
+ return entry;
+}
+
+static int __pakfire_getpwnam(struct passwd* entry, const void* value) {
+ const char* name = (const char*)value;
+
+ if (strcmp(entry->pw_name, name) == 0)
+ return 1;
+
+ return 0;
+}
+
+struct passwd* pakfire_getpwnam(Pakfire pakfire, const char* name) {
+ return pakfire_getpwent(pakfire, __pakfire_getpwnam, name);
+}
+
+static int __pakfire_getpwuid(struct passwd* entry, const void* value) {
+ uid_t* uid = (uid_t*)value;
+
+ if (entry->pw_uid == *uid)
+ return 1;
+
+ return 0;
+}
+
+struct passwd* pakfire_getpwuid(Pakfire pakfire, uid_t uid) {
+ return pakfire_getpwent(pakfire, __pakfire_getpwuid, &uid);
+}