From cb2327d8e42c8d52d3e5dc8dd8132cb2c0933c70 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 29 Oct 2022 04:00:50 +0100 Subject: use chmod and friends instead of fchmod and friends that way it actually works to set the permissions on the actual file. i don't know why it wasn't working. apparently fchmod etc on a socket is unspecified under posix as well --- unix.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/unix.c b/unix.c index 3228a0b..ac1d1fd 100644 --- a/unix.c +++ b/unix.c @@ -3,7 +3,7 @@ #include "conf.h" static int -sock_perms(int fd) +sock_perms(char fname[]) { // first get group by name struct group *group; @@ -12,18 +12,18 @@ sock_perms(int fd) return -1; } // set group on socket - if (fchown(fd, -1, group->gr_gid) == -1) { + if (chown(fname, -1, group->gr_gid) == -1) { perror("chown"); return -1; } // get current permissions, so we can modify them. struct stat sb; - if (fstat(fd, &sb) == -1) { + if (stat(fname, &sb) == -1) { perror("stat"); return -1; } - if (fchmod(fd, sb.st_mode|S_IWGRP) == -1) { + if (chmod(fname, sb.st_mode|S_IWGRP) == -1) { perror("chmod"); return -1; } @@ -34,9 +34,9 @@ sock_perms(int fd) // takes filename, returns socket fd // or -1 or whatever int -unix_setup(char sockname[]) +unix_setup(char filename[]) { - unlink(sockname); + unlink(filename); int sock = socket(AF_UNIX, SOCK_DGRAM, 0); if (sock == -1) { @@ -47,14 +47,14 @@ unix_setup(char sockname[]) struct sockaddr_un name; memset(&name, 0, sizeof name); name.sun_family = AF_UNIX; - strncpy(name.sun_path, sockname, (sizeof name.sun_path)-1); + strncpy(name.sun_path, filename, (sizeof name.sun_path)-1); if (bind(sock, (struct sockaddr *)&name, sizeof name) == -1) { perror("(unix) bind"); return -1; } - if (sock_perms(sock) == -1) { - fprintf(stderr,"warning: couldn't correctly set up permissions on %s\n",sockname); + if (sock_perms(filename) == -1) { + fprintf(stderr,"warning: couldn't correctly set up permissions on %s\n",filename); } return sock; -- cgit v1.2.3