Statistics
| Branch: | Revision:

iof-bird-daemon / nest / password.c @ 8c6ce98b

History | View | Annotate | Download (1.26 KB)

1
/*
2
 *        BIRD -- Password handling
3
 *
4
 *        Copyright 1999 Pavel Machek <pavel@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include "nest/bird.h"
10
#include "nest/password.h"
11

    
12
struct password_item *last_password_item = NULL;
13

    
14
static int
15
password_goodness(struct password_item *i)
16
{
17
  if (i->from > now)
18
    return 0;
19
  if (i->to < now)
20
    return 0;
21
  if (i->passive < now)
22
    return 1;
23
  return 2;
24
}
25

    
26
struct password_item *
27
get_best_password(struct password_item *head, int flags)
28
{
29
  int good = -1;
30
  struct password_item *best = NULL;
31

    
32
  while (head) {
33
    int cur = password_goodness(head);
34
    if (cur > good) {
35
      good = cur;
36
      best = head;
37
    }
38
    head=head->next;
39
  }
40
  return best;
41
}
42

    
43
void
44
password_strncpy(char *to, char *from, int len)
45
{
46
  int i;
47
  for (i=0; i<len; i++) {
48
    *to++ = *from;
49
    if (*from)
50
      from++;
51
  }
52
}
53

    
54
int
55
password_same(struct password_item *old, struct password_item *new)
56
{
57
  for(;;)
58
    {
59
      if (old == new)
60
        return 1;
61
      if (!old || !new)
62
        return 0;
63
      if (old->from    != new->from    ||
64
          old->to      != new->to      ||
65
          old->passive != new->passive ||
66
          old->id      != new->id      ||
67
          strcmp(old->password, new->password))
68
        return 0;
69
      old = old->next;
70
      new = new->next;
71
    }
72
}