Statistics
| Branch: | Revision:

iof-bird-daemon / nest / password.c @ 7152e5ef

History | View | Annotate | Download (1.19 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

    
14
struct password_item *last_password_item = NULL;
15

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

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

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

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

    
44
  if (!l)
45
    return NULL;
46

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

    
51
  return NULL;
52
}
53

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

    
59
  if (!l)
60
    return NULL;
61

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

    
66
  return NULL;
67
}
68