From 97e46d28fff1aa27d7d15e113cc3a52ae20934c7 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Wed, 17 Mar 2010 12:19:22 +0100 Subject: Adds check for no protocol and some minor CLI fixes. - Adds check to deny config file with no specified protocol to prevent loading of empty config file. - Moves CLI init before config parse to receive immediate error message when cannot open control socket. - Fixes socket name path check and other error handling in CLI init. --- sysdep/unix/io.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'sysdep/unix/io.c') diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 02d59ab..d86c8cb 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1075,7 +1075,7 @@ bad_no_log: return -1; } -int +void sk_open_unix(sock *s, char *name) { int fd; @@ -1084,15 +1084,13 @@ sk_open_unix(sock *s, char *name) fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) - die("sk_open_unix: socket: %m"); + ERR("socket"); s->fd = fd; if (err = sk_setup(s)) goto bad; unlink(name); - - if (strlen(name) >= sizeof(sa.sun_path)) - die("sk_open_unix: path too long"); + /* Path length checked in test_old_bird() */ sa.sun_family = AF_UNIX; strcpy(sa.sun_path, name); if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0) @@ -1100,13 +1098,11 @@ sk_open_unix(sock *s, char *name) if (listen(fd, 8)) ERR("listen"); sk_insert(s); - return 0; + return; -bad: + bad: log(L_ERR "sk_open_unix: %s: %m", err); - close(fd); - s->fd = -1; - return -1; + die("Unable to create control socket %s", name); } static int @@ -1519,9 +1515,10 @@ test_old_bird(char *path) struct sockaddr_un sa; fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd < 0) die("Cannot create socket: %m"); + if (strlen(path) >= sizeof(sa.sun_path)) + die("Socket path too long"); bzero(&sa, sizeof(sa)); sa.sun_family = AF_UNIX; strcpy(sa.sun_path, path); -- cgit v1.2.3