diff options
author | 2004-01-02 09:02:50 +0000 | |
---|---|---|
committer | 2004-01-02 09:02:50 +0000 | |
commit | 322c71cf30530b3a841814dcbef35d1b8bfd8dec (patch) | |
tree | af4ef6591f3a3c492868fce0758b9cb0e695bc57 | |
parent | Don't strip scripts; idea from mpech@; ok deraadt@ (diff) | |
download | wireguard-openbsd-322c71cf30530b3a841814dcbef35d1b8bfd8dec.tar.xz wireguard-openbsd-322c71cf30530b3a841814dcbef35d1b8bfd8dec.zip |
umask setting and unlink before bind() the unix socket, chmod and umask
restore afterwards
help & ok theo
-rw-r--r-- | usr.sbin/bgpd/control.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index 1ae375c1bdf..349db058783 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.2 2004/01/02 02:27:57 henning Exp $ */ +/* $OpenBSD: control.c,v 1.3 2004/01/02 09:02:50 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -17,6 +17,7 @@ */ #include <sys/types.h> +#include <sys/stat.h> #include <sys/socket.h> #include <sys/un.h> #include <errno.h> @@ -38,22 +39,38 @@ struct ctl_conn *control_connbyfd(int); int control_init(void) { - struct sockaddr_un sun; - int fd; + struct sockaddr_un sun; + int fd; + mode_t old_umask; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { log_err("control_init: socket"); return (-1); } + old_umask = umask(S_IWGRP|S_IWOTH|S_IROTH|S_IXOTH); bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; strlcpy(sun.sun_path, SOCKET_NAME, sizeof(sun.sun_path)); + + if (unlink(SOCKET_NAME) == -1) + if (errno != ENOENT) { + log_err("unlink %s", SOCKET_NAME); + return (-1); + } + if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) { log_err("control_init: bind: %s", SOCKET_NAME); return (-1); } + if (chmod(SOCKET_NAME, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) { + log_err("control_init chmod"); + return (-1); + } + + umask(old_umask); + control_state.fd = fd; return (fd); |