1999-05-26 22:24:57 +08:00
|
|
|
/*
|
|
|
|
* BIRD -- Password handling
|
|
|
|
*
|
|
|
|
* Copyright 1999 Pavel Machek <pavel@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/password.h"
|
2002-11-13 16:47:06 +08:00
|
|
|
#include "lib/string.h"
|
1999-05-26 22:24:57 +08:00
|
|
|
|
|
|
|
struct password_item *last_password_item = NULL;
|
1999-06-01 01:12:00 +08:00
|
|
|
|
|
|
|
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 *
|
2004-06-05 17:10:56 +08:00
|
|
|
get_best_password(struct password_item *head, int flags UNUSED)
|
1999-06-01 01:12:00 +08:00
|
|
|
{
|
|
|
|
int good = -1;
|
|
|
|
struct password_item *best = NULL;
|
|
|
|
|
|
|
|
while (head) {
|
|
|
|
int cur = password_goodness(head);
|
|
|
|
if (cur > good) {
|
|
|
|
good = cur;
|
|
|
|
best = head;
|
|
|
|
}
|
1999-10-02 18:44:48 +08:00
|
|
|
head=head->next;
|
1999-06-01 01:12:00 +08:00
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
1999-06-01 03:15:52 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
password_strncpy(char *to, char *from, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<len; i++) {
|
|
|
|
*to++ = *from;
|
|
|
|
if (*from)
|
|
|
|
from++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-10 21:42:46 +08:00
|
|
|
int
|
|
|
|
password_same(struct password_item *old, struct password_item *new)
|
|
|
|
{
|
2001-01-08 19:13:01 +08:00
|
|
|
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;
|
|
|
|
}
|
2000-05-10 21:42:46 +08:00
|
|
|
}
|