[hackers] [quark] Make the socketfile accessible by clients || Quentin Rameau

From: <git_AT_suckless.org>
Date: Tue, 11 Jul 2017 15:03:01 +0200 (CEST)

commit 260ef0a988309bbaa1fcf96733fe1170ca738173
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Sun Jul 9 12:09:13 2017 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Jul 11 14:09:27 2017 +0200

    Make the socketfile accessible by clients

diff --git a/quark.c b/quark.c
index 94532de..edf4103 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -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));
_AT_@ -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;
 }
 
_AT_@ -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) {
Received on Tue Jul 11 2017 - 15:03:01 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 11 2017 - 15:13:44 CEST