From d3a1c560e6a6f58d0159864f70ec75fb07ed1933 Mon Sep 17 00:00:00 2001 From: vg Date: Fri, 23 Feb 2024 15:55:08 +0100 Subject: add umask call to dictate rights for unix socket --- small-codes/syslog-listen.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/small-codes/syslog-listen.c b/small-codes/syslog-listen.c index e248608..4b58271 100644 --- a/small-codes/syslog-listen.c +++ b/small-codes/syslog-listen.c @@ -6,13 +6,14 @@ // compile with gcc/clang -o syslog-listen syslog-listen.c -#include +#include +#include #include #include -#include #include +#include #include -#include +#include #define PERROR(code, msg) { if ((code) == -1) { perror((msg)); exit(1); } } @@ -31,6 +32,7 @@ int main(int argc, const char** argv) int sock = socket(AF_UNIX, SOCK_DGRAM, 0); PERROR(sock, "socket"); unlink(argv[1]); // no need to test ret as bind will crash if needed + umask(0007); // by default allow user/group calling the program int ret = bind(sock, (struct sockaddr*)&sock_file, sizeof(sock_file)); PERROR(ret, "bind"); -- cgit v1.2.3