aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-07-21 12:27:54 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2016-07-21 12:28:37 +0200
commit6aa08601e7964ae4a124367b7be00f1865fd08c4 (patch)
tree013fdce2f2433ec7b2095688bf672174de98092c /src/tools
parentKconfig: select IP6_NF_IPTABLES if using IPV6 (diff)
downloadwireguard-monolithic-historical-6aa08601e7964ae4a124367b7be00f1865fd08c4.tar.xz
wireguard-monolithic-historical-6aa08601e7964ae4a124367b7be00f1865fd08c4.zip
tools: abstract sockets are dangerous
They have no permissions, so we're probably better off just creating a socket file with the umask set, as we do in BSD.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/ipc.c29
1 files changed, 1 insertions, 28 deletions
diff --git a/src/tools/ipc.c b/src/tools/ipc.c
index 3243fcb..2fb1246 100644
--- a/src/tools/ipc.c
+++ b/src/tools/ipc.c
@@ -80,7 +80,6 @@ static int add_next_to_inflatable_buffer(struct inflatable_buffer *buffer)
return 0;
}
-#ifndef __linux__
static void close_and_unlink(int fd)
{
struct sockaddr_un addr;
@@ -90,16 +89,12 @@ static void close_and_unlink(int fd)
unlink(addr.sun_path);
close(fd);
}
-#endif
static int userspace_interface_fd(const char *interface)
{
struct stat sbuf;
- struct sockaddr_un addr = { .sun_family = AF_UNIX };
-#ifndef __linux__
- struct sockaddr_un bind_addr = { .sun_family = AF_UNIX };
+ struct sockaddr_un addr = { .sun_family = AF_UNIX }, bind_addr = { .sun_family = AF_UNIX };
mode_t old_umask;
-#endif
int fd = -1, ret;
ret = -EINVAL;
@@ -108,12 +103,10 @@ static int userspace_interface_fd(const char *interface)
ret = snprintf(addr.sun_path, sizeof(addr.sun_path) - 1, SOCK_PATH "%s" SOCK_SUFFIX, interface);
if (ret < 0)
goto out;
-#ifndef __linux__
ret = snprintf(bind_addr.sun_path, sizeof(bind_addr.sun_path) - 1, SOCK_PATH ".wg-tool-%s-%d.client", interface, getpid());
if (ret < 0)
goto out;
unlink(bind_addr.sun_path);
-#endif
ret = stat(addr.sun_path, &sbuf);
if (ret < 0)
goto out;
@@ -124,13 +117,9 @@ static int userspace_interface_fd(const char *interface)
ret = fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (ret < 0)
goto out;
-#ifdef __linux__
- ret = bind(fd, (struct sockaddr *)&addr, sizeof(sa_family_t));
-#else
old_umask = umask(0077);
ret = bind(fd, (struct sockaddr *)&bind_addr, sizeof(bind_addr));
umask(old_umask);
-#endif
if (ret < 0)
goto out;
@@ -142,11 +131,7 @@ static int userspace_interface_fd(const char *interface)
}
out:
if (ret && fd >= 0)
-#ifdef __linux__
- close(fd);
-#else
close_and_unlink(fd);
-#endif
if (!ret)
ret = fd;
return ret;
@@ -157,11 +142,7 @@ static bool userspace_has_wireguard_interface(const char *interface)
int fd = userspace_interface_fd(interface);
if (fd < 0)
return false;
-#ifdef __linux__
- close(fd);
-#else
close_and_unlink(fd);
-#endif
return true;
}
@@ -219,11 +200,7 @@ static int userspace_set_device(struct wgdevice *dev)
goto out;
ret = ret_code;
out:
-#ifdef __linux__
- close(fd);
-#else
close_and_unlink(fd);
-#endif
return (int)ret;
}
@@ -273,11 +250,7 @@ static int userspace_get_device(struct wgdevice **dev, const char *interface)
out:
if (*dev && ret)
free(*dev);
-#ifdef __linux__
- close(fd);
-#else
close_and_unlink(fd);
-#endif
errno = -ret;
return ret;
}