summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2021-12-13 12:19:05 -0600
committerAriadne Conill <ariadne@dereferenced.org>2021-12-14 12:57:47 -0600
commitbaf4dc327b0627bc190b0fe452b08d2d6b05a010 (patch)
treed568ea278b7f6ce8f63516a70968f5e385d745f0
parent8e5f4910f8ae653f4ff30c0b3c23a4b659036f9b (diff)
downloadapk-tools-baf4dc327b0627bc190b0fe452b08d2d6b05a010.tar.gz
apk-tools-baf4dc327b0627bc190b0fe452b08d2d6b05a010.tar.bz2
apk-tools-baf4dc327b0627bc190b0fe452b08d2d6b05a010.tar.xz
apk-tools-baf4dc327b0627bc190b0fe452b08d2d6b05a010.zip
io: use opendirectory for UID/GID lookups on macOS
macOS has no concept of a chroot-specific UID/GID database, as the database is actually LDAP. ref #10794
-rw-r--r--src/io.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/io.c b/src/io.c
index 498ba71..3e91fd5 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1098,7 +1098,6 @@ static void idhash_reset(struct apk_id_hash *idh)
idhash_init(idh);
}
-#ifndef __APPLE__
static void idcache_add(struct apk_id_hash *hash, apk_blob_t name, unsigned long id)
{
struct cache_item *ci;
@@ -1115,7 +1114,6 @@ static void idcache_add(struct apk_id_hash *hash, apk_blob_t name, unsigned long
hlist_add_head(&ci->by_id, &hash->by_id[id % ARRAY_SIZE(hash->by_id)]);
hlist_add_head(&ci->by_name, &hash->by_name[h % ARRAY_SIZE(hash->by_name)]);
}
-#endif
static struct cache_item *idcache_by_name(struct apk_id_hash *hash, apk_blob_t name)
{
@@ -1158,7 +1156,6 @@ void apk_id_cache_free(struct apk_id_cache *idc)
idc->root_fd = 0;
}
-#ifndef __APPLE__
static FILE *fopenat(int dirfd, const char *pathname)
{
FILE *f;
@@ -1171,11 +1168,9 @@ static FILE *fopenat(int dirfd, const char *pathname)
if (!f) close(fd);
return f;
}
-#endif
static void idcache_load_users(int root_fd, struct apk_id_hash *idh)
{
-#ifndef __APPLE__
#ifdef HAVE_FGETPWENT_R
char buf[1024];
struct passwd pwent;
@@ -1192,8 +1187,11 @@ static void idcache_load_users(int root_fd, struct apk_id_hash *idh)
do {
#ifdef HAVE_FGETPWENT_R
fgetpwent_r(in, &pwent, buf, sizeof(buf), &pwd);
-#else
+#elif !defined(__APPLE__)
pwd = fgetpwent(in);
+#else
+# warning macOS does not support nested /etc/passwd databases, using system one.
+ pwd = getpwent();
#endif
if (!pwd) break;
idcache_add(idh, APK_BLOB_STR(pwd->pw_name), pwd->pw_uid);
@@ -1202,12 +1200,10 @@ static void idcache_load_users(int root_fd, struct apk_id_hash *idh)
#ifndef HAVE_FGETPWENT_R
endpwent();
#endif
-#endif
}
static void idcache_load_groups(int root_fd, struct apk_id_hash *idh)
{
-#ifndef __APPLE__
#ifdef HAVE_FGETGRENT_R
char buf[1024];
struct group grent;
@@ -1224,8 +1220,11 @@ static void idcache_load_groups(int root_fd, struct apk_id_hash *idh)
do {
#ifdef HAVE_FGETGRENT_R
fgetgrent_r(in, &grent, buf, sizeof(buf), &grp);
-#else
+#elif !defined(__APPLE__)
grp = fgetgrent(in);
+#else
+# warning macOS does not support nested /etc/group databases, using system one.
+ grp = getgrent();
#endif
if (!grp) break;
idcache_add(idh, APK_BLOB_STR(grp->gr_name), grp->gr_gid);
@@ -1234,7 +1233,6 @@ static void idcache_load_groups(int root_fd, struct apk_id_hash *idh)
#ifndef HAVE_FGETGRENT_R
endgrent();
#endif
-#endif
}
uid_t apk_id_cache_resolve_uid(struct apk_id_cache *idc, apk_blob_t username, uid_t default_uid)