diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-02 09:02:51 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-02 09:02:51 +0000 |
commit | 27eb3bc1668a32f200dacedea4b7206cf9f46735 (patch) | |
tree | e6ac3ebe0d59808be4b7e132ffe6dc7f8a97e58b /usr.sbin/bgpd/control.c | |
parent | 1bec981eaa9dd9aefd3538888fbb6a6b42c15dfa (diff) |
umask setting and unlink before bind() the unix socket, chmod and umask
restore afterwards
help & ok theo
Diffstat (limited to 'usr.sbin/bgpd/control.c')
-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); |