quark

quark web server
git clone git://git.suckless.org/quark
Log | Files | Refs | LICENSE

commit 260ef0a988309bbaa1fcf96733fe1170ca738173
parent 3b3fdd00e2558ad5e794cc87b1cf5109bc7e6ac9
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sun,  9 Jul 2017 12:09:13 +0200

Make the socketfile accessible by clients

Diffstat:
quark.c | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/quark.c b/quark.c @@ -878,11 +878,11 @@ getipsock(void) } static int -getusock(char *udsname) +getusock(char *udsname, uid_t uid, gid_t gid) { struct sockaddr_un addr; size_t udsnamelen; - int insock; + int insock, sockmode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; if ((insock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { die("%s: socket: %s\n", argv0, strerror(errno)); @@ -906,6 +906,14 @@ getusock(char *udsname) die("%s: listen: %s\n", argv0, strerror(errno)); } + if (chmod(udsname, sockmode) < 0) { + die("%s: chmod: %s\n", argv0, strerror(errno)); + } + + if (chown(udsname, uid, gid) < 0) { + die("%s: chown: %s\n", argv0, strerror(errno)); + } + return insock; } @@ -1000,7 +1008,8 @@ main(int argc, char *argv[]) } /* bind socket */ - insock = udsname ? getusock(udsname) : getipsock(); + insock = udsname ? getusock(udsname, pwd->pw_uid, grp->gr_gid) : + getipsock(); /* chroot */ if (chdir(servedir) < 0) {