summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-02-12 14:54:23 +0100
committerSander Vrijders <sander@ouroboros.rocks>2026-02-13 09:22:29 +0100
commit86dba5441c686d037c493e5b498e27249aa6bd9d (patch)
treed0916720c68b193b8a8e5bae7dce5de55121f081
parent4c73ee20024e1d1272a979574438749cfcd61426 (diff)
downloadouroboros-86dba5441c686d037c493e5b498e27249aa6bd9d.tar.gz
ouroboros-86dba5441c686d037c493e5b498e27249aa6bd9d.zip
lib: Fix SSM PUP creation on OS Xbe
OS X doesn't support chmod on shm files after creation. Since we already set the mode at creation, that call was redundant. Fixed the getpeereid() function was not accessible because of the guards. Fixed some differences between macOS and Linux with gid_t vs int usage. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
-rw-r--r--src/irmd/main.c13
-rw-r--r--src/lib/ssm/pool.c10
-rw-r--r--src/lib/ssm/tests/pool_test.c57
-rw-r--r--src/lib/utils.c9
4 files changed, 62 insertions, 27 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index ccb16017..196c4b11 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -24,7 +24,8 @@
#define _DEFAULT_SOURCE
#define _GNU_SOURCE
#else
-#define _POSIX_C_SOURCE 200809L
+#define _DEFAULT_SOURCE
+#define _BSD_SOURCE
#endif
#include "config.h"
@@ -60,15 +61,19 @@
#include <dirent.h>
#include <grp.h>
#include <pwd.h>
-#include <sys/socket.h>
-#include <sys/un.h>
#include <signal.h>
+#include <spawn.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
-#include <spawn.h>
+#include <sys/un.h>
+#ifdef __APPLE__
+#include <sys/types.h>
+#include <unistd.h>
+#endif
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
diff --git a/src/lib/ssm/pool.c b/src/lib/ssm/pool.c
index a388742d..5537d723 100644
--- a/src/lib/ssm/pool.c
+++ b/src/lib/ssm/pool.c
@@ -476,7 +476,6 @@ static ssize_t alloc_from_sc_b(struct ssm_pool * pool,
/* Generate pool filename: uid=0 for GSPP, uid>0 for PUP */
static char * pool_filename(uid_t uid)
{
- char * str;
char base[64];
if (IS_GSPP(uid))
@@ -484,9 +483,7 @@ static char * pool_filename(uid_t uid)
else
snprintf(base, sizeof(base), SSM_PUP_NAME_FMT, (int) uid);
- str = strdup(base);
-
- return str;
+ return strdup(base);
}
void ssm_pool_close(struct ssm_pool * pool)
@@ -527,7 +524,6 @@ void ssm_pool_destroy(struct ssm_pool * pool)
}
#define MM_FLAGS (PROT_READ | PROT_WRITE)
-
static struct ssm_pool * __pool_create(const char * name,
int flags,
uid_t uid,
@@ -554,9 +550,7 @@ static struct ssm_pool * __pool_create(const char * name,
if (flags & O_CREAT) {
if (ftruncate(fd, (off_t) file_size) < 0)
goto fail_truncate;
- if (uid != geteuid())
- (void) fchown(fd, uid, gid);
- if (fchmod(fd, mode) < 0)
+ if (uid != geteuid() && fchown(fd, uid, gid) < 0)
goto fail_truncate;
}
diff --git a/src/lib/ssm/tests/pool_test.c b/src/lib/ssm/tests/pool_test.c
index 87d4d71c..ce0c30c2 100644
--- a/src/lib/ssm/tests/pool_test.c
+++ b/src/lib/ssm/tests/pool_test.c
@@ -62,9 +62,10 @@ static int test_ssm_pool_basic_allocation(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
-
+ }
ret = ssm_pool_alloc(pool, POOL_256, &ptr, &spb);
if (ret < 0) {
printf("Alloc failed: %zd.\n", ret);
@@ -120,8 +121,10 @@ static int test_ssm_pool_multiple_allocations(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret1 = ssm_pool_alloc(pool, POOL_256, &ptr1, &spb1);
ret2 = ssm_pool_alloc(pool, POOL_256, &ptr2, &spb2);
@@ -213,8 +216,10 @@ static int test_ssm_pool_no_fallback_for_large(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(pool, POOL_2M, &ptr, &spb);
if (ret >= 0) {
@@ -249,8 +254,10 @@ static int test_ssm_pool_blocking_vs_nonblocking(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(pool, POOL_2M, &ptr, &spb);
if (ret != -EMSGSIZE) {
@@ -296,8 +303,10 @@ static int test_ssm_pool_stress_test(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
indices = malloc(100 * sizeof(*indices));
if (indices == NULL) {
@@ -393,8 +402,10 @@ static int test_ssm_pool_open_initializes_ssm(void)
TEST_START();
creator = ssm_pool_create(getuid(), getgid());
- if (creator == NULL)
+ if (creator == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(creator, POOL_256, &ptr, &spb);
if (ret < 0) {
@@ -440,8 +451,10 @@ static int test_ssm_pool_bounds_checking(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_alloc(pool, POOL_256, NULL, &spb);
if (ret < 0) {
@@ -503,8 +516,10 @@ static int test_ssm_pool_inter_process_communication(void)
len = strlen(msg) + 1;
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
rb = ssm_rbuff_create(getpid(), 1);
if (rb == NULL) {
@@ -607,8 +622,10 @@ static int test_ssm_pool_read_operation(void)
len = strlen(data) + 1;
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
idx = ssm_pool_alloc(pool, len, &wptr, &spb);
if (idx < 0) {
@@ -657,8 +674,10 @@ static int test_ssm_pool_mlock_operation(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
ret = ssm_pool_mlock(pool);
if (ret < 0)
@@ -691,8 +710,10 @@ static int test_ssm_pk_buff_operations(void)
dlen = strlen(data);
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
idx = ssm_pool_alloc(pool, POOL_256, &ptr, &spb);
if (idx < 0) {
@@ -796,8 +817,10 @@ static int test_ssm_pool_size_class_boundaries(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
for (i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
struct ssm_pk_buff * hdr;
@@ -857,8 +880,10 @@ static int test_ssm_pool_exhaustion(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
indices = malloc(2048 * sizeof(*indices));
if (indices == NULL) {
@@ -935,8 +960,10 @@ static int test_ssm_pool_reclaim_orphans(void)
TEST_START();
pool = ssm_pool_create(getuid(), getgid());
- if (pool == NULL)
+ if (pool == NULL) {
+ printf("Failed to create pool.\n");
goto fail_create;
+ }
my_pid = getpid();
diff --git a/src/lib/utils.c b/src/lib/utils.c
index cfddec62..dffd35f3 100644
--- a/src/lib/utils.c
+++ b/src/lib/utils.c
@@ -150,8 +150,13 @@ bool is_ouroboros_member_uid(uid_t uid)
{
struct group * grp;
struct passwd * pw;
+#ifdef __APPLE__
+ unsigned int gid;
+ int * groups = NULL;
+#else
gid_t gid;
gid_t * groups = NULL;
+#endif
int ngroups;
int i;
@@ -187,7 +192,11 @@ bool is_ouroboros_member_uid(uid_t uid)
}
for (i = 0; i < ngroups; i++) {
+#ifdef __APPLE__
+ if (groups[i] == (int) gid) {
+#else
if (groups[i] == gid) {
+#endif
free(groups);
return true;
}