aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--thing.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/thing.c b/thing.c
index e7c0f53..b3854ae 100644
--- a/thing.c
+++ b/thing.c
@@ -19,10 +19,12 @@
#define REALNAME ",flappy fly bird man?"
#define CHANNEL "#a"
+#define SOCKETGROUP "apionet"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <grp.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
@@ -183,6 +185,43 @@ int unix_setup() {
perror("(unix) bind");
return -1;
}
+
+ // set group and permissions on socket
+ long buflen = sysconf(_SC_GETGR_R_SIZE_MAX);
+ buflen = (buflen == -1) ? 1024 : buflen;
+ char *buf = malloc(buflen);
+ struct group grp;
+ struct group *res;
+ errno = 0;
+ // get group gid from name
+ getgrnam_r(SOCKETGROUP,&grp,buf,buflen,&res);
+ if (res == NULL) {
+ if (errno != 0)
+ perror("getgrnam_r");
+ else
+ fprintf(stderr,"group %s does not exist",SOCKETGROUP);
+ free(buf);
+ return -1;
+ }
+ free(buf);
+
+ // set socket's group
+ if (chown(SOCKETNAME,-1,grp.gr_gid) == -1) {
+ perror("chown");
+ return -1;
+ }
+
+ struct stat sb;
+ if (stat(SOCKETNAME,&sb) == -1) {
+ perror("stat");
+ return -1;
+ }
+ if (chmod(SOCKETNAME,sb.st_mode|S_IWGRP) == -1) {
+ perror("chmod");
+ return -1;
+ }
+
+
return sock;
}