Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.39 KB)

1 1a2ded45 Pavel Machek
/*
2
 *        BIRD -- Password handling
3
 *
4 5236fb03 Ondrej Filip
 *        (c) 1999 Pavel Machek <pavel@ucw.cz>
5
 *        (c) 2004 Ondrej Filip <feela@network.cz>
6 1a2ded45 Pavel Machek
 *
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 7d875e09 Martin Mares
#include "lib/string.h"
13 390601f0 Ondrej Zajicek (work)
#include "lib/mac.h"
14 1a2ded45 Pavel Machek
15
struct password_item *last_password_item = NULL;
16 900d5470 Pavel Machek
17
struct password_item *
18 b21f68b4 Ondrej Zajicek
password_find(list *l, int first_fit)
19 900d5470 Pavel Machek
{
20 5236fb03 Ondrej Filip
  struct password_item *pi;
21 b21f68b4 Ondrej Zajicek
  struct password_item *pf = NULL;
22 900d5470 Pavel Machek
23 02ad2737 Ondrej Filip
  if (l)
24 5236fb03 Ondrej Filip
  {
25 02ad2737 Ondrej Filip
    WALK_LIST(pi, *l)
26
    {
27 fd91ae33 Ondrej Zajicek
      if ((pi->genfrom < now_real) && (pi->gento > now_real))
28 b21f68b4 Ondrej Zajicek
      {
29
        if (first_fit)
30
          return pi;
31
32
        if (!pf || pf->genfrom < pi->genfrom)
33
          pf = pi;
34
      }
35 02ad2737 Ondrej Filip
    }
36 900d5470 Pavel Machek
  }
37 b21f68b4 Ondrej Zajicek
  return pf;
38 900d5470 Pavel Machek
}
39 2e6197d6 Pavel Machek
40 f8fefde3 Ondrej Zajicek
struct password_item *
41 de2a27e2 Ondrej Zajicek (work)
password_find_by_id(list *l, uint id)
42 2e6197d6 Pavel Machek
{
43 f8fefde3 Ondrej Zajicek
  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 2e6197d6 Pavel Machek
}
54
55 8465dccb Ondrej Zajicek (work)
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 390601f0 Ondrej Zajicek (work)
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
}