0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-13 22:58:42 +00:00
bird/nest/password.c

66 lines
1.1 KiB
C
Raw Normal View History

/*
* 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"
struct password_item *last_password_item = NULL;
1999-05-31 17:12:00 +00: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 *
get_best_password(struct password_item *head, int flags)
{
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 10:44:48 +00:00
head=head->next;
1999-05-31 17:12:00 +00:00
}
return best;
}
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 13:42:46 +00:00
int
password_same(struct password_item *old, struct password_item *new)
{
2000-05-16 15:00:15 +00:00
if (old == new)
return 1;
if ((!old) || (!new))
return 0;
2000-05-10 13:42:46 +00:00
return ((old->from == new->from) &&
(old->to == new->to) &&
(old->passive == new->passive) &&
password_same(old, new));
}