summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
Diffstat (limited to 'nest')
-rw-r--r--nest/config.Y82
-rw-r--r--nest/password.c63
-rw-r--r--nest/password.h15
3 files changed, 80 insertions, 80 deletions
diff --git a/nest/config.Y b/nest/config.Y
index 4f9b46b6..7a83a60a 100644
--- a/nest/config.Y
+++ b/nest/config.Y
@@ -11,18 +11,21 @@ CF_HDR
#include "nest/rt-dev.h"
#include "nest/password.h"
#include "nest/cmds.h"
+#include "lib/lists.h"
CF_DEFINES
static struct proto_config *this_proto;
static struct iface_patt *this_ipatt;
+static list *this_p_list;
+static struct password_item *this_p_item;
CF_DECLS
CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
-CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREIMPORT)
+CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREIMPORT, GENERATE)
CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIRECT,
RIP, OSPF, OSPF_IA, OSPF_EXT1, OSPF_EXT2, BGP, PIPE)
@@ -33,7 +36,7 @@ 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
+%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
@@ -193,36 +196,71 @@ debug_flag:
/* Password lists */
-password_begin:
+password_items:
+ /* empty */
+ | password_item ';' password_items
+;
+
+password_item:
+ password_item_begin '{' password_item_params '}'
+ | password_item_begin
+;
+
+password_item_begin:
PASSWORD TEXT {
- last_password_item = cfg_alloc(sizeof (struct password_item));
- last_password_item->password = $2;
- last_password_item->from = 0;
- last_password_item->to = TIME_INFINITY;
- last_password_item->id = 0;
- last_password_item->next = NULL;
- $$=last_password_item;
+ static int id = 0;
+ 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++;
+ add_tail(this_p_list, &this_p_item->n);
}
- ;
+;
-password_items:
+password_item_params:
/* empty */ { }
- | FROM datetime password_items { last_password_item->from = $2; }
- | TO datetime password_items { last_password_item->to = $2; }
- | PASSIVE datetime password_items { last_password_item->passive = $2; }
- | ID expr password_items { last_password_item->id = $2; }
+ | GENERATE FROM datetime ';' password_item_params { this_p_item->genfrom = $3; }
+ | GENERATE TO datetime ';' password_item_params { this_p_item->gento = $3; }
+ | ACCEPT FROM datetime ';' password_item_params { this_p_item->accfrom = $3; }
+ | ACCEPT TO datetime ';' password_item_params { this_p_item->accto = $3; }
+ | ID expr ';' password_item_params { this_p_item->id = $2; }
;
-password_list:
- /* empty */ { $$ = NULL; }
- | password_begin password_items ';' password_list {
- $1->next = $4;
+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);
+ $$ = 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 = 0;
+ add_tail(this_p_list, &this_p_item->n);
+ $$ = this_p_list;
+ }
+;
/* Core commands */
-
CF_CLI_HELP(SHOW, ..., [[Show status information]])
CF_CLI(SHOW STATUS,,, [[Show router status]])
diff --git a/nest/password.c b/nest/password.c
index 594569cc..63096023 100644
--- a/nest/password.c
+++ b/nest/password.c
@@ -1,7 +1,8 @@
/*
* BIRD -- Password handling
*
- * Copyright 1999 Pavel Machek <pavel@ucw.cz>
+ * (c) 1999 Pavel Machek <pavel@ucw.cz>
+ * (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@@ -12,62 +13,22 @@
struct password_item *last_password_item = NULL;
-static int
-password_goodness(struct password_item *i)
-{
- if (i->from > now)
- return 0;
- if (i->to < now)
- return 0;
- if (i->passive < now)
- return 1;
- return 2;
-}
-
struct password_item *
-get_best_password(struct password_item *head, int flags UNUSED)
+password_find(list *l)
{
- int good = -1;
- struct password_item *best = NULL;
+ struct password_item *pi;
- while (head) {
- int cur = password_goodness(head);
- if (cur > good) {
- good = cur;
- best = head;
- }
- head=head->next;
+ WALK_LIST(pi, *l)
+ {
+ if ((pi->genfrom > now) && (pi->gento < now))
+ return pi;
}
- return best;
+ return NULL;
}
-void
-password_strncpy(char *to, char *from, int len)
+void password_cpy(char *dst, char *src, int size)
{
- int i;
- for (i=0; i<len; i++) {
- *to++ = *from;
- if (*from)
- from++;
- }
+ bzero(dst, size);
+ memcpy(dst, src, strlen(src) < size ? strlen(src) : size);
}
-int
-password_same(struct password_item *old, struct password_item *new)
-{
- for(;;)
- {
- if (old == new)
- return 1;
- if (!old || !new)
- return 0;
- if (old->from != new->from ||
- old->to != new->to ||
- old->passive != new->passive ||
- old->id != new->id ||
- strcmp(old->password, new->password))
- return 0;
- old = old->next;
- new = new->next;
- }
-}
diff --git a/nest/password.h b/nest/password.h
index 481eeb61..0c453836 100644
--- a/nest/password.h
+++ b/nest/password.h
@@ -1,7 +1,8 @@
/*
* BIRD -- Password handling
*
- * Copyright 1999 Pavel Machek <pavel@ucw.cz>
+ * (c) 1999 Pavel Machek <pavel@ucw.cz>
+ * (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@@ -10,18 +11,18 @@
#define PASSWORD_H
#include "lib/timer.h"
+#define MD5_AUTH_SIZE 16
+
struct password_item {
- struct password_item *next;
+ node n;
char *password;
int id;
- bird_clock_t from, passive, to;
+ bird_clock_t accfrom, accto, genfrom, gento;
};
extern struct password_item *last_password_item;
-struct password_item *get_best_password(struct password_item *head, int flags);
-extern int password_same(struct password_item *, struct password_item *);
-extern void password_strncpy(char *to, char *from, int len);
-
+struct password_item *password_find(list *);
+void password_cpy(char *dst, char *src, int size);
#endif