From b21f68b4cd4794c84e5f0eb2c34204c87ccf0e9a Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sat, 8 Nov 2008 17:24:23 +0100 Subject: Fix bugs in OSPF MD5 authentication. First bug is that default values for MD5 password ID changed during reconfigure, Second bug is that BIRD chooses password in first-fit manner, but RFC says that it should use the one with the latest generate-from. It also modifies the syntax for multiple passwords. Now it is possible to just add more 'password' statements to the interface section and it is not needed to use 'passwords' section. Old syntax can be used too. --- nest/config.Y | 54 +++++++++++++++++++++--------------------------------- nest/password.c | 13 ++++++++++--- nest/password.h | 2 +- 3 files changed, 32 insertions(+), 37 deletions(-) (limited to 'nest') diff --git a/nest/config.Y b/nest/config.Y index 91c3363..48940ff 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -20,6 +20,16 @@ static struct proto_config *this_proto; static struct iface_patt *this_ipatt; static list *this_p_list; static struct password_item *this_p_item; +static int password_id; + +static list * +get_passwords(void) +{ + list *rv = this_p_list; + this_p_list = NULL; + return rv; +} + CF_DECLS @@ -37,7 +47,6 @@ CF_ENUM(T_ENUM_RTD, RTD_, ROUTER, DEVICE, BLACKHOLE, UNREACHABLE, PROHIBIT) %type idval %type imexport %type rtable -%type

password_list password_begin password_begin_list %type optsym %type r_args %type echo_mask echo_size debug_mask debug_list debug_flag import_or_proto @@ -197,6 +206,11 @@ debug_flag: /* Password lists */ +password_list: + PASSWORDS '{' password_items '}' + | password_item +; + password_items: /* empty */ | password_item ';' password_items @@ -209,14 +223,18 @@ password_item: password_item_begin: PASSWORD TEXT { - static int id = 1; + if (!this_p_list) { + this_p_list = cfg_alloc(sizeof(list)); + init_list(this_p_list); + password_id = 1; + } this_p_item = cfg_alloc(sizeof (struct password_item)); this_p_item->password = $2; this_p_item->genfrom = 0; this_p_item->gento = TIME_INFINITY; this_p_item->accfrom = 0; this_p_item->accto = TIME_INFINITY; - this_p_item->id = id++; + this_p_item->id = password_id++; add_tail(this_p_list, &this_p_item->n); } ; @@ -230,36 +248,6 @@ password_item_params: | ID expr ';' password_item_params { this_p_item->id = $2; if ($2 <= 0) cf_error("Password ID has to be greated than zero."); } ; -password_list: - password_begin_list '{' password_items '}' { - $$ = $1; - } - | password_begin -; - -password_begin_list: - PASSWORDS { - this_p_list = cfg_alloc(sizeof(list)); - init_list(this_p_list); - $$ = (void *) this_p_list; - } -; - -password_begin: - PASSWORD TEXT { - this_p_list = cfg_alloc(sizeof(list)); - init_list(this_p_list); - this_p_item = cfg_alloc(sizeof (struct password_item)); - this_p_item->password = $2; - this_p_item->genfrom = 0; - this_p_item->gento = TIME_INFINITY; - this_p_item->accfrom = 0; - this_p_item->accto = TIME_INFINITY; - this_p_item->id = 1; - add_tail(this_p_list, &this_p_item->n); - $$ = (void *) this_p_list; - } -; /* Core commands */ CF_CLI_HELP(SHOW, ..., [[Show status information]]) diff --git a/nest/password.c b/nest/password.c index 80c4c7b..179939e 100644 --- a/nest/password.c +++ b/nest/password.c @@ -14,19 +14,26 @@ struct password_item *last_password_item = NULL; struct password_item * -password_find(list *l) +password_find(list *l, int first_fit) { struct password_item *pi; + struct password_item *pf = NULL; if (l) { WALK_LIST(pi, *l) { if ((pi->genfrom < now_real) && (pi->gento > now_real)) - return pi; + { + if (first_fit) + return pi; + + if (!pf || pf->genfrom < pi->genfrom) + pf = pi; + } } } - return NULL; + return pf; } void password_cpy(char *dst, char *src, int size) diff --git a/nest/password.h b/nest/password.h index 0c45383..726af73 100644 --- a/nest/password.h +++ b/nest/password.h @@ -22,7 +22,7 @@ struct password_item { extern struct password_item *last_password_item; -struct password_item *password_find(list *); +struct password_item *password_find(list *l, int first_fit); void password_cpy(char *dst, char *src, int size); #endif -- cgit v1.2.3