#define ETC_SUBUID "/etc/subuid"
#define ETC_SUBGID "/etc/subgid"
-static struct passwd* pakfire_getpwent(pakfire_root* root,
+static struct passwd* pakfire_getpwent(pakfire_ctx* ctx, pakfire_root* root,
int(*cmp)(struct passwd* entry, const void* value), const void* value) {
struct passwd* entry = NULL;
char path[PATH_MAX];
return 0;
}
-struct passwd* pakfire_getpwnam(pakfire_root* root, const char* name) {
- return pakfire_getpwent(root, __pakfire_getpwnam, name);
+struct passwd* pakfire_getpwnam(pakfire_ctx* ctx, pakfire_root* root, const char* name) {
+ return pakfire_getpwent(ctx, root, __pakfire_getpwnam, name);
}
static int __pakfire_getpwuid(struct passwd* entry, const void* value) {
return 0;
}
-struct passwd* pakfire_getpwuid(pakfire_root* root, uid_t uid) {
- return pakfire_getpwent(root, __pakfire_getpwuid, &uid);
+struct passwd* pakfire_getpwuid(pakfire_ctx* ctx, pakfire_root* root, uid_t uid) {
+ return pakfire_getpwent(ctx, root, __pakfire_getpwuid, &uid);
}
-static struct group* pakfire_getgrent(pakfire_root* root,
+static struct group* pakfire_getgrent(pakfire_ctx* ctx, pakfire_root* root,
int(*cmp)(struct group* entry, const void* value), const void* value) {
struct group* entry = NULL;
char path[PATH_MAX];
return 0;
}
-struct group* pakfire_getgrnam(pakfire_root* root, const char* name) {
- return pakfire_getgrent(root, __pakfire_getgrnam, name);
+struct group* pakfire_getgrnam(pakfire_ctx* ctx, pakfire_root* root, const char* name) {
+ return pakfire_getgrent(ctx, root, __pakfire_getgrnam, name);
}
static int __pakfire_getgrgid(struct group* entry, const void* value) {
return 0;
}
-struct group* pakfire_getgrgid(pakfire_root* root, gid_t gid) {
- return pakfire_getgrent(root, __pakfire_getgrgid, &gid);
+struct group* pakfire_getgrgid(pakfire_ctx* ctx, pakfire_root* root, gid_t gid) {
+ return pakfire_getgrent(ctx, root, __pakfire_getgrgid, &gid);
}
// SUBUID/SUBGID
#ifdef HAVE_SUBID
-static int pakfire_getsubid(pakfire_root* root, const char* owner,
+static int pakfire_getsubid(pakfire_ctx* ctx, pakfire_root* root, const char* owner,
struct pakfire_subid* subid, int (callback)(const char* owner, struct subid_range** ranges)) {
struct subid_range* ranges = NULL;
int count;
int r = -1;
- pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
r = subid_init(PACKAGE_NAME, stderr);
if (r) {
ERROR(ctx, "Could not setup subid: %m\n");
ERROR:
if (ranges)
free(ranges);
- if (ctx)
- pakfire_ctx_unref(ctx);
return r;
}
-int pakfire_getsubuid(pakfire_root* root, const char* owner, struct pakfire_subid* subid) {
- return pakfire_getsubid(root, owner, subid, subid_get_uid_ranges);
+int pakfire_getsubuid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* owner, struct pakfire_subid* subid) {
+ return pakfire_getsubid(ctx, root, owner, subid, subid_get_uid_ranges);
}
-int pakfire_getsubgid(pakfire_root* root, const char* owner, struct pakfire_subid* subid) {
- return pakfire_getsubid(root, owner, subid, subid_get_gid_ranges);
+int pakfire_getsubgid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* owner, struct pakfire_subid* subid) {
+ return pakfire_getsubid(ctx, root, owner, subid, subid_get_gid_ranges);
}
# else /* Our own implementation */
-static int pakfire_fgetsubid(pakfire_root* root, struct pakfire_subid* subid, FILE* f) {
+static int pakfire_fgetsubid(pakfire_ctx* ctx, pakfire_root* root,
+ struct pakfire_subid* subid, FILE* f) {
int r;
char* line = NULL;
size_t length = 0;
char* p = NULL;
- pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
// Read the next line
while (1) {
r = getline(&line, &length, f);
DEBUG(ctx, "Parsed SUBID entry: name=%s, id=%u, length=%zu\n",
subid->name, subid->id, subid->length);
- if (ctx)
- pakfire_ctx_unref(ctx);
-
return r;
}
If nothing was found, the function returns 1.
If there was an error, the function may return something else.
*/
-static int pakfire_getsubid(pakfire_root* root, const char* path, const char* owner,
- struct pakfire_subid* subid) {
+static int pakfire_getsubid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* path, const char* owner, struct pakfire_subid* subid) {
struct pakfire_subid entry = {};
int r;
if (!owner)
return 1;
- pakfire_ctx* ctx = pakfire_root_get_ctx(root);
-
DEBUG(ctx, "Fetching SUBID from %s for %s\n", path, owner);
// Open /etc/subuid
// Walk through all entries
while (1) {
- r = pakfire_fgetsubid(root, &entry, f);
+ r = pakfire_fgetsubid(ctx, root, &entry, f);
switch (r) {
case 0:
break;
END:
if (f)
fclose(f);
- if (ctx)
- pakfire_ctx_unref(ctx);
return r;
}
-int pakfire_getsubuid(pakfire_root* root, const char* owner, struct pakfire_subid* subid) {
- return pakfire_getsubid(root, ETC_SUBUID, owner, subid);
+int pakfire_getsubuid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* owner, struct pakfire_subid* subid) {
+ return pakfire_getsubid(ctx, root, ETC_SUBUID, owner, subid);
}
-int pakfire_getsubgid(pakfire_root* root, const char* owner, struct pakfire_subid* subid) {
- return pakfire_getsubid(root, ETC_SUBGID, owner, subid);
+int pakfire_getsubgid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* owner, struct pakfire_subid* subid) {
+ return pakfire_getsubid(ctx, root, ETC_SUBGID, owner, subid);
}
#endif
size_t length;
};
-struct passwd* pakfire_getpwnam(pakfire_root* root, const char* name);
-struct passwd* pakfire_getpwuid(pakfire_root* root, uid_t uid);
+#include <pakfire/ctx.h>
-struct group* pakfire_getgrnam(pakfire_root* root, const char* name);
-struct group* pakfire_getgrgid(pakfire_root* root, gid_t gid);
+struct passwd* pakfire_getpwnam(pakfire_ctx* ctx, pakfire_root* root, const char* name);
+struct passwd* pakfire_getpwuid(pakfire_ctx* ctx, pakfire_root* root, uid_t uid);
-int pakfire_getsubuid(pakfire_root* root, const char* owner, struct pakfire_subid* subid);
-int pakfire_getsubgid(pakfire_root* root, const char* owner, struct pakfire_subid* subid);
+struct group* pakfire_getgrnam(pakfire_ctx* ctx, pakfire_root* root, const char* name);
+struct group* pakfire_getgrgid(pakfire_ctx* ctx, pakfire_root* root, gid_t gid);
+
+int pakfire_getsubuid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* owner, struct pakfire_subid* subid);
+int pakfire_getsubgid(pakfire_ctx* ctx, pakfire_root* root,
+ const char* owner, struct pakfire_subid* subid);
#endif /* PAKFIRE_PWD_H */
// Read SUBUID/SUBGIDs from file
if (!pakfire_root_on_root(self)) {
// Fetch SUBUIDs
- r = pakfire_getsubuid(self, self->user.name, &self->user.subuids);
+ r = pakfire_getsubuid(self->ctx, self, self->user.name, &self->user.subuids);
switch (r) {
case 0:
case 1:
}
// Fetch SUBGIDs
- r = pakfire_getsubgid(self, self->user.name, &self->group.subgids);
+ r = pakfire_getsubgid(self->ctx, self, self->user.name, &self->group.subgids);
switch (r) {
case 0:
case 1:
DEBUG(self->ctx, "Looking up name for UID %ld\n", uid);
// Find a matching entry in /etc/passwd
- struct passwd* entry = pakfire_getpwuid(self, uid);
+ struct passwd* entry = pakfire_getpwuid(self->ctx, self, uid);
if (!entry) {
ERROR(self->ctx, "Could not retrieve uname for %ld: %m\n", uid);
return 0;
DEBUG(self->ctx, "Looking up name for GID %ld\n", gid);
// Find a matching entry in /etc/group
- struct group* entry = pakfire_getgrgid(self, gid);
+ struct group* entry = pakfire_getgrgid(self->ctx, self, gid);
if (!entry) {
ERROR(self->ctx, "Could not retrieve gname for %ld: %m\n", gid);
return 0;
DEBUG(self->ctx, "Looking up UID for '%s' (%ld)\n", name, uid);
// Find a matching entry in /etc/passwd
- struct passwd* entry = pakfire_getpwnam(self, name);
+ struct passwd* entry = pakfire_getpwnam(self->ctx, self, name);
if (!entry) {
ERROR(self->ctx, "Could not retrieve UID for '%s': %m\n", name);
goto ERROR;
DEBUG(self->ctx, "Looking up GID for '%s' (%ld)\n", name, gid);
// Find a matching entry in /etc/group
- struct group* entry = pakfire_getgrnam(self, name);
+ struct group* entry = pakfire_getgrnam(self->ctx, self, name);
if (!entry) {
ERROR(self->ctx, "Could not retrieve GID for '%s': %m\n", name);
goto ERROR;