diff options
author | Timo Teräs <timo.teras@iki.fi> | 2010-09-10 15:49:21 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2010-09-10 15:49:21 +0300 |
commit | 36a24c1ffd961b263e392d8167fa4799865c08f6 (patch) | |
tree | 0ffc80743f26ca2e5f5e97d68f611c8ce0429bfb | |
parent | 5d4deb7c304b860d7501b04cdf1185df274ab83c (diff) | |
download | squark-36a24c1ffd961b263e392d8167fa4799865c08f6.tar.bz2 squark-36a24c1ffd961b263e392d8167fa4799865c08f6.tar.xz |
authdb: use shared 'squark' group for shm areas
this way multiple users can access the shm areas (e.g. www-data
for captive portal, and proxy for squid). all system users needing
to use squark tools need to belong to this group.
-rw-r--r-- | authdb.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -4,6 +4,7 @@ #include <malloc.h> #include <sched.h> #include <fcntl.h> +#include <grp.h> #include "authdb.h" #include "addr.h" @@ -18,10 +19,11 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create) { int oflag, fd; - char name[64]; + char name[64], buf[256]; blob_t b = BLOB_BUF(name); void *base; struct authdb_map_entry *me; + struct group grp, *res; blob_push(&b, BLOB_STR("squark-auth-")); blob_push_hexdump(&b, addr_get_hostaddr_blob(addr)); @@ -31,15 +33,21 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create) if (create) oflag |= O_CREAT; - fd = shm_open(name, oflag, 0600); + fd = shm_open(name, oflag, 0660); if (fd < 0) return NULL; - if (create && ftruncate(fd, AUTHDB_SHM_SIZE) < 0) { + if (ftruncate(fd, AUTHDB_SHM_SIZE) < 0) { close(fd); return NULL; } + getgrnam_r("squark", &grp, buf, sizeof(buf), &res); + if (res != NULL) { + fchown(fd, -1, res->gr_gid); + fchmod(fd, 0660); + } + base = mmap(NULL, AUTHDB_SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); |