1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#include <stdio.h>
#include "memory.h"
#include "vector.h"
#include "util.h"
#include "debug.h"
#include "regex.h"
#include "blacklist.h"
static int
store_ble (vector blist, char * str)
{
struct blentry * ble;
if (!str)
return 0;
ble = (struct blentry *)MALLOC(sizeof(struct blentry));
if (!ble)
goto out;
ble->preg = MALLOC(sizeof(regex_t));
if (!ble->preg)
goto out1;
ble->str = (char *)MALLOC(strlen(str) + 1);
if (!ble->str)
goto out2;
strcpy(ble->str, str);
if (regcomp((regex_t *)ble->preg, ble->str, REG_EXTENDED|REG_NOSUB))
goto out3;
if (!vector_alloc_slot(blist))
goto out3;
vector_set_slot(blist, ble);
return 0;
out3:
FREE(ble->str);
out2:
FREE(ble->preg);
out1:
FREE(ble);
out:
return 1;
}
int
setup_default_blist (vector blist)
{
int r = 0;
r += store_ble(blist, "(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*");
r += store_ble(blist, "hd[a-z]");
r += store_ble(blist, "cciss!c[0-9]d[0-9]*");
return r;
}
int
blacklist (vector blist, char * dev)
{
int i;
struct blentry *ble;
vector_foreach_slot (blist, ble, i) {
if (!regexec(ble->preg, dev, 0, NULL, 0)) {
condlog(3, "%s blacklisted", dev);
return 1;
}
}
return 0;
}
int
store_regex (vector blist, char * regex)
{
if (!blist)
return 1;
if (!regex)
return 1;
return store_ble(blist, regex);
}
void
free_blacklist (vector blist)
{
struct blentry * ble;
int i;
if (!blist)
return;
vector_foreach_slot (blist, ble, i) {
if (ble->str)
FREE(ble->str);
if (ble->preg)
FREE(ble->preg);
FREE(ble);
}
vector_free(blist);
}
|