tlsgate

TLS reverse proxy
git clone git://git.akobets.xyz/tlsgate
Log | Files | Refs | README | LICENSE

commit e5f6df13fc86b62d4d691c3acfc212ad92e59549
parent ae9fc55fd7ce552e60175c47408f4e203c4a9827
Author: Artem Kobets <artem@akobets.xyz>
Date:   Wed, 23 Sep 2020 17:51:29 +0300

fix permissions on uds socket

Diffstat:
Msock.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/sock.c b/sock.c @@ -1,6 +1,7 @@ #include <fcntl.h> #include <errno.h> #include <stdio.h> +#include <sys/stat.h> #include <sys/time.h> #include <unistd.h> @@ -60,6 +61,8 @@ sock_proxy_uds(const char *file) int fd; struct sockaddr_un addr; int saved_errno; + // 0666 file permissions + int perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) err("socket"); @@ -70,6 +73,13 @@ sock_proxy_uds(const char *file) if (bind(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) == -1) err("bind"); + if (chmod(file, perms) == -1) { + saved_errno = errno; + sock_remove_uds(file); + errno = saved_errno; + err("chmod"); + } + if (listen(fd, SOMAXCONN) == -1) { saved_errno = errno; sock_remove_uds(file);