Make the socketfile accessible by clients

This commit is contained in:
Quentin Rameau 2017-07-09 12:09:13 +02:00 committed by Laslo Hunhold
parent 3b3fdd00e2
commit 260ef0a988

15
quark.c
View file

@ -878,11 +878,11 @@ getipsock(void)
} }
static int static int
getusock(char *udsname) getusock(char *udsname, uid_t uid, gid_t gid)
{ {
struct sockaddr_un addr; struct sockaddr_un addr;
size_t udsnamelen; 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) { if ((insock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
die("%s: socket: %s\n", argv0, strerror(errno)); die("%s: socket: %s\n", argv0, strerror(errno));
@ -906,6 +906,14 @@ getusock(char *udsname)
die("%s: listen: %s\n", argv0, strerror(errno)); 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; return insock;
} }
@ -1000,7 +1008,8 @@ main(int argc, char *argv[])
} }
/* bind socket */ /* bind socket */
insock = udsname ? getusock(udsname) : getipsock(); insock = udsname ? getusock(udsname, pwd->pw_uid, grp->gr_gid) :
getipsock();
/* chroot */ /* chroot */
if (chdir(servedir) < 0) { if (chdir(servedir) < 0) {