Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (1.19 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 1a2ded45 Pavel Machek
14
struct password_item *last_password_item = NULL;
15 900d5470 Pavel Machek
16
struct password_item *
17 b21f68b4 Ondrej Zajicek
password_find(list *l, int first_fit)
18 900d5470 Pavel Machek
{
19 5236fb03 Ondrej Filip
  struct password_item *pi;
20 b21f68b4 Ondrej Zajicek
  struct password_item *pf = NULL;
21 900d5470 Pavel Machek
22 02ad2737 Ondrej Filip
  if (l)
23 5236fb03 Ondrej Filip
  {
24 02ad2737 Ondrej Filip
    WALK_LIST(pi, *l)
25
    {
26 fd91ae33 Ondrej Zajicek
      if ((pi->genfrom < now_real) && (pi->gento > now_real))
27 b21f68b4 Ondrej Zajicek
      {
28
        if (first_fit)
29
          return pi;
30
31
        if (!pf || pf->genfrom < pi->genfrom)
32
          pf = pi;
33
      }
34 02ad2737 Ondrej Filip
    }
35 900d5470 Pavel Machek
  }
36 b21f68b4 Ondrej Zajicek
  return pf;
37 900d5470 Pavel Machek
}
38 2e6197d6 Pavel Machek
39 f8fefde3 Ondrej Zajicek
struct password_item *
40
password_find_by_id(list *l, int id)
41 2e6197d6 Pavel Machek
{
42 f8fefde3 Ondrej Zajicek
  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 2e6197d6 Pavel Machek
}
53
54 8465dccb Ondrej Zajicek (work)
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
}