12 |
|
|
13 |
|
|
14 |
account_data account; |
account_data account; |
15 |
filter_entry **filters; |
filter_entry **dfilters; /* Filters of DENY type. */ |
16 |
int fcnt = 0; /* Counter of how many filters were |
filter_entry **afilters; /* Filters of ALLOW type. */ |
17 |
found in configuration file. */ |
int dfcnt = 0; |
18 |
|
int afcnt = 0; /* DENY and ALLOW type filters found |
19 |
|
in the configuration file */ |
20 |
|
|
21 |
|
|
22 |
/* |
/* |
65 |
unsigned int row = 0; |
unsigned int row = 0; |
66 |
char line[LINE_MAX]; |
char line[LINE_MAX]; |
67 |
regex_t comreg[4]; |
regex_t comreg[4]; |
68 |
regmatch_t match[3]; |
regmatch_t match[4]; |
69 |
const char *reg[] = { |
const char *reg[] = { |
70 |
"^[[:blank:]]*(SERVER|PORT|USERNAME|PASSWORD|LOGFILE)[[:blank:]]*=[[:blank:]]*([[:graph:]]*)[[:blank:]]*", |
"^[[:blank:]]*(SERVER|PORT|USERNAME|PASSWORD|LOGFILE)[[:blank:]]*=[[:blank:]]*([[:graph:]]*)[[:blank:]]*", |
71 |
"^[[:blank:]]*DENY[[:blank:]]*=[[:blank:]]*(FROM|CC|BCC|SUBJECT|TO):? ([[:print:]]*)", |
"^[[:blank:]]*(DENY|ALLOW)[[:blank:]]*=[[:blank:]]*(FROM|CC|BCC|SUBJECT|TO):? ([[:print:]]*)", |
72 |
"^[[:blank:]]*DENY[[:blank:]]*=[[:blank:]]*([[:graph:]]+):? ([[:print:]]*)", |
"^[[:blank:]]*(DENY|ALLOW)[[:blank:]]*=[[:blank:]]*([[:graph:]]+):? ([[:print:]]*)", |
73 |
"^[[:blank:]]*#{0,1}.*" |
"^[[:blank:]]*#{0,1}.*" |
74 |
}; |
}; |
75 |
|
|
81 |
if (!regexec(&comreg[0], line, 3, match, 0)) { |
if (!regexec(&comreg[0], line, 3, match, 0)) { |
82 |
set_account(line, match); |
set_account(line, match); |
83 |
continue; |
continue; |
84 |
} else if (!regexec(&comreg[1], line, 3, match, 0)) { |
} else if (!regexec(&comreg[1], line, 4, match, 0)) { |
85 |
standard_filter(line, match); |
standard_filter(line, match); |
86 |
continue; |
continue; |
87 |
} else if (!regexec(&comreg[2], line, 3, match, 0)) { |
} else if (!regexec(&comreg[2], line, 4, match, 0)) { |
88 |
explicit_filter(line, match); |
custom_filter(line, match); |
89 |
continue; |
continue; |
90 |
} else if (!regexec(&comreg[3], line, 1, match, 0)) |
} else if (!regexec(&comreg[3], line, 1, match, 0)) |
91 |
continue; |
continue; |
148 |
void set_filters(char *line, regmatch_t * match, int expl) |
void set_filters(char *line, regmatch_t * match, int expl) |
149 |
{ |
{ |
150 |
int s; |
int s; |
151 |
|
int *fcnt; |
152 |
|
filter_entry ***filters; |
153 |
|
|
154 |
|
if (!(strncmp(line + match[1].rm_so, "DENY", 4))) { |
155 |
|
#ifdef DEBUG |
156 |
|
printf("debug: filter entry: DENY"); |
157 |
|
#endif |
158 |
|
fcnt = &dfcnt; |
159 |
|
filters = &dfilters; |
160 |
|
} else { |
161 |
|
#ifdef DEBUG |
162 |
|
printf("debug: filter entry: ALLOW"); |
163 |
|
#endif |
164 |
|
fcnt = &afcnt; |
165 |
|
filters = &afilters; |
166 |
|
} |
167 |
|
|
168 |
/* Every FILTER_ENTRIES_MAX, space for more filters is realloc() -ed. */ |
/* Every FILTER_ENTRIES_MAX, space for more filters is realloc() -ed. */ |
169 |
if (!fcnt) |
if (!*fcnt) |
170 |
filters = |
*filters = |
171 |
(filter_entry **) malloc(FILTER_ENTRIES_MAX * |
(filter_entry **) malloc(FILTER_ENTRIES_MAX * |
172 |
sizeof(filter_entry *)); |
sizeof(filter_entry *)); |
173 |
else if (!(fcnt % FILTER_ENTRIES_MAX)) |
else if (!(*fcnt % FILTER_ENTRIES_MAX)) |
174 |
filters = (filter_entry **) realloc(filters, |
*filters = (filter_entry **) realloc(*filters, |
175 |
(((fcnt / FILTER_ENTRIES_MAX) + |
(((*fcnt / |
176 |
1) * FILTER_ENTRIES_MAX) * |
FILTER_ENTRIES_MAX) + |
177 |
sizeof(filter_entry *)); |
1) * FILTER_ENTRIES_MAX) * |
178 |
|
sizeof(filter_entry *)); |
179 |
filters[fcnt] = (filter_entry *) malloc(sizeof(filter_entry)); |
|
180 |
|
(*filters)[*fcnt] = (filter_entry *) malloc(sizeof(filter_entry)); |
181 |
filters[fcnt]->explicit = expl; |
|
182 |
|
(*filters)[*fcnt]->custom = expl; |
183 |
s = min((match[1].rm_eo - match[1].rm_so), FIELD_NAME_MAX - 1); |
|
184 |
strncpy(filters[fcnt]->name, line + match[1].rm_so, s); |
s = min((match[2].rm_eo - match[2].rm_so), FIELD_NAME_MAX - 1); |
185 |
filters[fcnt]->name[s] = 0; |
strncpy((*filters)[*fcnt]->name, line + match[2].rm_so, s); |
186 |
|
(*filters)[*fcnt]->name[s] = 0; |
187 |
s = min((match[2].rm_eo - match[2].rm_so), FIELD_BODY_MAX - 1); |
|
188 |
strncpy(filters[fcnt]->body, line + match[2].rm_so, s); |
s = min((match[3].rm_eo - match[3].rm_so), FIELD_BODY_MAX - 1); |
189 |
filters[fcnt]->body[s] = 0; |
strncpy((*filters)[*fcnt]->body, line + match[3].rm_so, s); |
190 |
|
(*filters)[*fcnt]->body[s] = 0; |
191 |
|
|
192 |
#ifdef DEBUG |
#ifdef DEBUG |
193 |
printf("debug: filter entry '%s': '%s'\n", filters[fcnt]->name, |
printf(" '%s': '%s'\n", (*filters)[*fcnt]->name, |
194 |
filters[fcnt]->body); |
(*filters)[*fcnt]->body); |
195 |
#endif |
#endif |
196 |
|
|
197 |
fcnt++; |
(*fcnt)++; |
198 |
} |
} |