Statistics
| Branch: | Revision:

iof-bird-daemon / nest / password.c @ 62e64905

History | View | Annotate | Download (1.39 KB)

1
/*
2
 *        BIRD -- Password handling
3
 *
4
 *        (c) 1999 Pavel Machek <pavel@ucw.cz>
5
 *        (c) 2004 Ondrej Filip <feela@network.cz>
6
 *
7
 *        Can be freely distributed and used under the terms of the GNU GPL.
8
 */
9

    
10
#include "nest/bird.h"
11
#include "nest/password.h"
12
#include "lib/string.h"
13
#include "lib/mac.h"
14

    
15
struct password_item *last_password_item = NULL;
16

    
17
struct password_item *
18
password_find(list *l, int first_fit)
19
{
20
  struct password_item *pi;
21
  struct password_item *pf = NULL;
22

    
23
  if (l)
24
  {
25
    WALK_LIST(pi, *l)
26
    {
27
      if ((pi->genfrom < now_real) && (pi->gento > now_real))
28
      {
29
        if (first_fit)
30
          return pi;
31

    
32
        if (!pf || pf->genfrom < pi->genfrom)
33
          pf = pi;
34
      }
35
    }
36
  }
37
  return pf;
38
}
39

    
40
struct password_item *
41
password_find_by_id(list *l, uint id)
42
{
43
  struct password_item *pi;
44

    
45
  if (!l)
46
    return NULL;
47

    
48
  WALK_LIST(pi, *l)
49
    if ((pi->id == id) && (pi->accfrom <= now_real) && (now_real < pi->accto))
50
      return pi;
51

    
52
  return NULL;
53
}
54

    
55
struct password_item *
56
password_find_by_value(list *l, char *pass, uint size)
57
{
58
  struct password_item *pi;
59

    
60
  if (!l)
61
    return NULL;
62

    
63
  WALK_LIST(pi, *l)
64
    if (password_verify(pi, pass, size) && (pi->accfrom <= now_real) && (now_real < pi->accto))
65
      return pi;
66

    
67
  return NULL;
68
}
69

    
70
uint
71
max_mac_length(list *l)
72
{
73
  struct password_item *pi;
74
  uint val = 0;
75

    
76
  if (!l)
77
    return 0;
78

    
79
  WALK_LIST(pi, *l)
80
    val = MAX(val, mac_type_length(pi->alg));
81

    
82
  return val;
83
}