0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-17 08:38:42 +00:00

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.
This commit is contained in:
Ondrej Zajicek 2010-03-17 12:19:22 +01:00
parent 4e3bfd9006
commit 97e46d28ff
4 changed files with 15 additions and 16 deletions

View File

@ -114,6 +114,8 @@ config_parse(struct config *c)
rt_preconfig(c); rt_preconfig(c);
cf_parse(); cf_parse();
protos_postconfig(c); protos_postconfig(c);
if (EMPTY_LIST(c->protos))
cf_error("No protocol is specified in the config file");
#ifdef IPV6 #ifdef IPV6
if (!c->router_id) if (!c->router_id)
cf_error("Router ID must be configured manually on IPv6 routers"); cf_error("Router ID must be configured manually on IPv6 routers");

View File

@ -1075,7 +1075,7 @@ bad_no_log:
return -1; return -1;
} }
int void
sk_open_unix(sock *s, char *name) sk_open_unix(sock *s, char *name)
{ {
int fd; int fd;
@ -1084,15 +1084,13 @@ sk_open_unix(sock *s, char *name)
fd = socket(AF_UNIX, SOCK_STREAM, 0); fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) if (fd < 0)
die("sk_open_unix: socket: %m"); ERR("socket");
s->fd = fd; s->fd = fd;
if (err = sk_setup(s)) if (err = sk_setup(s))
goto bad; goto bad;
unlink(name); unlink(name);
if (strlen(name) >= sizeof(sa.sun_path)) /* Path length checked in test_old_bird() */
die("sk_open_unix: path too long");
sa.sun_family = AF_UNIX; sa.sun_family = AF_UNIX;
strcpy(sa.sun_path, name); strcpy(sa.sun_path, name);
if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0) 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)) if (listen(fd, 8))
ERR("listen"); ERR("listen");
sk_insert(s); sk_insert(s);
return 0; return;
bad: bad:
log(L_ERR "sk_open_unix: %s: %m", err); log(L_ERR "sk_open_unix: %s: %m", err);
close(fd); die("Unable to create control socket %s", name);
s->fd = -1;
return -1;
} }
static int static int
@ -1519,9 +1515,10 @@ test_old_bird(char *path)
struct sockaddr_un sa; struct sockaddr_un sa;
fd = socket(AF_UNIX, SOCK_STREAM, 0); fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) if (fd < 0)
die("Cannot create socket: %m"); die("Cannot create socket: %m");
if (strlen(path) >= sizeof(sa.sun_path))
die("Socket path too long");
bzero(&sa, sizeof(sa)); bzero(&sa, sizeof(sa));
sa.sun_family = AF_UNIX; sa.sun_family = AF_UNIX;
strcpy(sa.sun_path, path); strcpy(sa.sun_path, path);

View File

@ -298,8 +298,7 @@ cli_init_unix(void)
s->type = SK_UNIX_PASSIVE; s->type = SK_UNIX_PASSIVE;
s->rx_hook = cli_connect; s->rx_hook = cli_connect;
s->rbsize = 1024; s->rbsize = 1024;
if (sk_open_unix(s, path_control_socket) < 0) sk_open_unix(s, path_control_socket);
die("Unable to create control socket %s", path_control_socket);
} }
/* /*
@ -457,6 +456,9 @@ main(int argc, char **argv)
rt_init(); rt_init();
if_init(); if_init();
if (!parse_and_exit)
cli_init_unix();
protos_build(); protos_build();
proto_build(&proto_unix_kernel); proto_build(&proto_unix_kernel);
proto_build(&proto_unix_iface); proto_build(&proto_unix_iface);
@ -483,8 +485,6 @@ main(int argc, char **argv)
signal_init(); signal_init();
cli_init_unix();
#ifdef LOCAL_DEBUG #ifdef LOCAL_DEBUG
async_dump_flag = 1; async_dump_flag = 1;
#endif #endif

View File

@ -49,7 +49,7 @@ void io_init(void);
void io_loop(void); void io_loop(void);
void fill_in_sockaddr(sockaddr *sa, ip_addr a, unsigned port); void fill_in_sockaddr(sockaddr *sa, ip_addr a, unsigned port);
void get_sockaddr(sockaddr *sa, ip_addr *a, unsigned *port, int check); void get_sockaddr(sockaddr *sa, ip_addr *a, unsigned *port, int check);
int sk_open_unix(struct birdsock *s, char *name); void sk_open_unix(struct birdsock *s, char *name);
void *tracked_fopen(struct pool *, char *name, char *mode); void *tracked_fopen(struct pool *, char *name, char *mode);
void test_old_bird(char *path); void test_old_bird(char *path);