summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
Diffstat (limited to 'nest')
-rw-r--r--nest/config.Y54
-rw-r--r--nest/password.c13
-rw-r--r--nest/password.h2
3 files changed, 32 insertions, 37 deletions
diff --git a/nest/config.Y b/nest/config.Y
index 91c3363b..48940ffd 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 <i32> idval
%type <f> imexport
%type <r> rtable
-%type <p> password_list password_begin password_begin_list
%type <s> optsym
%type <ra> r_args
%type <i> 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 80c4c7b4..179939e2 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 0c453836..726af733 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