1 |
/* |
2 |
* Copyright (C) 2002-2003 Erik Fears |
3 |
* |
4 |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License |
6 |
* as published by the Free Software Foundation; either version 2 |
7 |
* of the License, or (at your option) any later version. |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
* GNU General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to |
16 |
* |
17 |
* The Free Software Foundation, Inc. |
18 |
* 59 Temple Place - Suite 330 |
19 |
* Boston, MA 02111-1307, USA. |
20 |
* |
21 |
* |
22 |
*/ |
23 |
|
24 |
|
25 |
%{ |
26 |
#include <stdio.h> |
27 |
#include <string.h> |
28 |
#include "malloc.h" |
29 |
#include "config.h" |
30 |
|
31 |
int yylex(void); |
32 |
|
33 |
int yydebug=0; |
34 |
void *tmp; /* Variable to temporarily hold nodes before insertion to list */ |
35 |
|
36 |
%} |
37 |
|
38 |
%token AWAY |
39 |
%token BAN_UNKNOWN |
40 |
%token BLACKLIST |
41 |
%token BYTES KBYTES MBYTES |
42 |
%token CHANNEL |
43 |
%token CONNREGEX |
44 |
%token DNS_FDLIMIT |
45 |
%token DNSBL_FROM |
46 |
%token DNSBL_TO |
47 |
%token EXEMPT |
48 |
%token FD |
49 |
%token INVITE |
50 |
%token IRC |
51 |
%token KLINE |
52 |
%token KEY |
53 |
%token MASK |
54 |
%token MAX_READ |
55 |
%token MODE |
56 |
%token NAME |
57 |
%token NEGCACHE |
58 |
%token NICK |
59 |
%token NICKSERV |
60 |
%token OPER |
61 |
%token OPM |
62 |
%token OPTIONS |
63 |
%token PASSWORD |
64 |
%token PERFORM |
65 |
%token PIDFILE |
66 |
%token PORT |
67 |
%token PROTOCOL |
68 |
%token READTIMEOUT |
69 |
%token REALNAME |
70 |
%token REPLY |
71 |
%token SCANLOG |
72 |
%token SCANNER |
73 |
%token SECONDS MINUTES HOURS DAYS WEEKS MONTHS YEARS |
74 |
%token SENDMAIL |
75 |
%token SERVER |
76 |
%token TARGET_IP |
77 |
%token TARGET_PORT |
78 |
%token TARGET_STRING |
79 |
%token TIMEOUT |
80 |
%token TYPE |
81 |
%token USERNAME |
82 |
%token USER |
83 |
%token VHOST |
84 |
|
85 |
%union |
86 |
{ |
87 |
int number; |
88 |
char *string; |
89 |
} |
90 |
|
91 |
%token <number> NUMBER |
92 |
%token <string> STRING |
93 |
%token <number> PROTOCOLTYPE |
94 |
%type <number> timespec |
95 |
%type <number> timespec_ |
96 |
%type <number> sizespec |
97 |
%type <number> sizespec_ |
98 |
|
99 |
%% |
100 |
|
101 |
config: |
102 |
| config config_items |
103 |
; |
104 |
|
105 |
config_items: irc_entry | |
106 |
options_entry | |
107 |
opm_entry | |
108 |
user_entry | |
109 |
scanner_entry | |
110 |
exempt_entry; |
111 |
|
112 |
timespec_: { $$ = 0; } | timespec; |
113 |
timespec: NUMBER timespec_ { $$ = $1 + $2; } | |
114 |
NUMBER SECONDS timespec_ { $$ = $1 + $3; } | |
115 |
NUMBER MINUTES timespec_ { $$ = $1 * 60 + $3; } | |
116 |
NUMBER HOURS timespec_ { $$ = $1 * 60 * 60 + $3; } | |
117 |
NUMBER DAYS timespec_ { $$ = $1 * 60 * 60 * 24 + $3; } | |
118 |
NUMBER WEEKS timespec_ { $$ = $1 * 60 * 60 * 24 * 7 + $3; } | |
119 |
NUMBER MONTHS timespec_ { $$ = $1 * 60 * 60 * 24 * 7 * 4 + $3; } | |
120 |
NUMBER YEARS timespec_ { $$ = $1 * 60 * 60 * 24 * 365 + $3; } |
121 |
; |
122 |
|
123 |
sizespec_: { $$ = 0; } | sizespec; |
124 |
sizespec: NUMBER sizespec_ { $$ = $1 + $2; } | |
125 |
NUMBER BYTES sizespec_ { $$ = $1 + $3; } | |
126 |
NUMBER KBYTES sizespec_ { $$ = $1 * 1024 + $3; } | |
127 |
NUMBER MBYTES sizespec_ { $$ = $1 * 1024 * 1024 + $3; } |
128 |
; |
129 |
|
130 |
/*************************** OPTIONS BLOCK ***********************/ |
131 |
|
132 |
options_entry: OPTIONS '{' options_items '}' ';'; |
133 |
|
134 |
options_items: options_items options_item | |
135 |
options_item; |
136 |
|
137 |
options_item: options_negcache | |
138 |
options_pidfile | |
139 |
options_dns_fdlimit | |
140 |
options_scanlog | |
141 |
error; |
142 |
|
143 |
options_negcache: NEGCACHE '=' timespec ';' |
144 |
{ |
145 |
OptionsItem->negcache = $3; |
146 |
}; |
147 |
|
148 |
options_pidfile: PIDFILE '=' STRING ';' |
149 |
{ |
150 |
MyFree(OptionsItem->pidfile); |
151 |
OptionsItem->pidfile = xstrdup($3); |
152 |
}; |
153 |
|
154 |
options_dns_fdlimit: DNS_FDLIMIT '=' NUMBER ';' |
155 |
{ |
156 |
OptionsItem->dns_fdlimit = $3; |
157 |
}; |
158 |
|
159 |
options_scanlog: SCANLOG '=' STRING ';' |
160 |
{ |
161 |
MyFree(OptionsItem->scanlog); |
162 |
OptionsItem->scanlog = xstrdup($3); |
163 |
}; |
164 |
|
165 |
/*************************** IRC BLOCK ***************************/ |
166 |
|
167 |
irc_entry: IRC '{' irc_items '}' ';'; |
168 |
|
169 |
irc_items: irc_items irc_item | |
170 |
irc_item; |
171 |
|
172 |
irc_item: irc_away | |
173 |
irc_connregex | |
174 |
irc_kline | |
175 |
irc_nick | |
176 |
irc_nickserv | |
177 |
irc_mode | |
178 |
irc_oper | |
179 |
irc_password | |
180 |
irc_port | |
181 |
irc_readtimeout | |
182 |
irc_realname | |
183 |
irc_server | |
184 |
irc_username | |
185 |
irc_vhost | |
186 |
irc_perform | |
187 |
channel_entry | |
188 |
error; |
189 |
|
190 |
irc_away: AWAY '=' STRING ';' |
191 |
{ |
192 |
MyFree(IRCItem->away); |
193 |
IRCItem->away = xstrdup($3); |
194 |
}; |
195 |
|
196 |
irc_kline: KLINE '=' STRING ';' |
197 |
{ |
198 |
MyFree(IRCItem->kline); |
199 |
IRCItem->kline = xstrdup($3); |
200 |
}; |
201 |
|
202 |
irc_mode: MODE '=' STRING ';' |
203 |
{ |
204 |
MyFree(IRCItem->mode); |
205 |
IRCItem->mode = xstrdup($3); |
206 |
}; |
207 |
|
208 |
irc_nick: NICK '=' STRING ';' |
209 |
{ |
210 |
MyFree(IRCItem->nick); |
211 |
IRCItem->nick = xstrdup($3); |
212 |
}; |
213 |
|
214 |
irc_nickserv: NICKSERV '=' STRING ';' |
215 |
{ |
216 |
MyFree(IRCItem->nickserv); |
217 |
IRCItem->nickserv = xstrdup($3); |
218 |
}; |
219 |
|
220 |
irc_oper: OPER '=' STRING ';' |
221 |
{ |
222 |
MyFree(IRCItem->oper); |
223 |
IRCItem->oper = xstrdup($3); |
224 |
}; |
225 |
|
226 |
irc_password: PASSWORD '=' STRING ';' |
227 |
{ |
228 |
MyFree(IRCItem->password); |
229 |
IRCItem->password = xstrdup($3); |
230 |
}; |
231 |
|
232 |
irc_perform: PERFORM '=' STRING ';' |
233 |
{ |
234 |
node_t *node; |
235 |
node = node_create(xstrdup($3)); |
236 |
|
237 |
list_add(IRCItem->performs, node); |
238 |
}; |
239 |
|
240 |
irc_port: PORT '=' NUMBER ';' |
241 |
{ |
242 |
IRCItem->port = $3; |
243 |
}; |
244 |
|
245 |
irc_readtimeout: READTIMEOUT '=' timespec ';' |
246 |
{ |
247 |
IRCItem->readtimeout = $3; |
248 |
}; |
249 |
|
250 |
irc_realname: REALNAME '=' STRING ';' |
251 |
{ |
252 |
MyFree(IRCItem->realname); |
253 |
IRCItem->realname = xstrdup($3); |
254 |
}; |
255 |
|
256 |
irc_server: SERVER '=' STRING ';' |
257 |
{ |
258 |
MyFree(IRCItem->server); |
259 |
IRCItem->server = xstrdup($3); |
260 |
}; |
261 |
|
262 |
irc_username: USERNAME '=' STRING ';' |
263 |
{ |
264 |
MyFree(IRCItem->username); |
265 |
IRCItem->username = xstrdup($3); |
266 |
}; |
267 |
|
268 |
irc_vhost: VHOST '=' STRING ';' |
269 |
{ |
270 |
MyFree(IRCItem->vhost); |
271 |
IRCItem->vhost = xstrdup($3); |
272 |
}; |
273 |
|
274 |
irc_connregex: CONNREGEX '=' STRING ';' |
275 |
{ |
276 |
MyFree(IRCItem->connregex); |
277 |
IRCItem->connregex = xstrdup($3); |
278 |
}; |
279 |
|
280 |
|
281 |
/************************** CHANNEL BLOCK *************************/ |
282 |
|
283 |
channel_entry: |
284 |
{ |
285 |
node_t *node; |
286 |
struct ChannelConf *item; |
287 |
|
288 |
item = MyMalloc(sizeof *item); |
289 |
|
290 |
item->name = xstrdup(""); |
291 |
item->key = xstrdup(""); |
292 |
item->invite = xstrdup(""); |
293 |
|
294 |
node = node_create(item); |
295 |
list_add(IRCItem->channels, node); |
296 |
|
297 |
tmp = (void *) item; |
298 |
} |
299 |
CHANNEL '{' channel_items '}' ';'; |
300 |
|
301 |
channel_items: channel_items channel_item | |
302 |
channel_item; |
303 |
|
304 |
channel_item: channel_name | |
305 |
channel_key | |
306 |
channel_invite; |
307 |
|
308 |
channel_name: NAME '=' STRING ';' |
309 |
{ |
310 |
struct ChannelConf *item = tmp; |
311 |
|
312 |
MyFree(item->name); |
313 |
item->name = xstrdup($3); |
314 |
}; |
315 |
|
316 |
channel_key: KEY '=' STRING ';' |
317 |
{ |
318 |
struct ChannelConf *item = tmp; |
319 |
|
320 |
MyFree(item->key); |
321 |
item->key = xstrdup($3); |
322 |
}; |
323 |
|
324 |
channel_invite: INVITE '=' STRING ';' |
325 |
{ |
326 |
struct ChannelConf *item = tmp; |
327 |
|
328 |
MyFree(item->invite); |
329 |
item->invite = xstrdup($3); |
330 |
}; |
331 |
|
332 |
/*************************** USER BLOCK ***************************/ |
333 |
|
334 |
user_entry: |
335 |
{ |
336 |
node_t *node; |
337 |
struct UserConf *item; |
338 |
|
339 |
item = MyMalloc(sizeof *item); |
340 |
|
341 |
item->masks = list_create(); |
342 |
item->scanners = list_create(); |
343 |
|
344 |
node = node_create(item); |
345 |
list_add(UserItemList, node); |
346 |
|
347 |
tmp = (void *) item; |
348 |
} |
349 |
USER '{' user_items '}' ';' ; |
350 |
|
351 |
user_items: user_items user_item | |
352 |
user_item; |
353 |
|
354 |
user_item: user_mask | |
355 |
user_scanner | |
356 |
error; |
357 |
|
358 |
user_mask: MASK '=' STRING ';' |
359 |
{ |
360 |
struct UserConf *item = (struct UserConf *) tmp; |
361 |
|
362 |
node_t *node; |
363 |
node = node_create((void *) xstrdup($3)); |
364 |
|
365 |
list_add(item->masks, node); |
366 |
}; |
367 |
|
368 |
user_scanner: SCANNER '=' STRING ';' |
369 |
{ |
370 |
struct UserConf *item = (struct UserConf *) tmp; |
371 |
|
372 |
node_t *node; |
373 |
node = node_create((void *) xstrdup($3)); |
374 |
|
375 |
list_add(item->scanners, node); |
376 |
}; |
377 |
|
378 |
/*************************** SCANNER BLOCK ***************************/ |
379 |
|
380 |
scanner_entry: |
381 |
{ |
382 |
node_t *node; |
383 |
struct ScannerConf *item, *olditem; |
384 |
|
385 |
item = MyMalloc(sizeof *item); |
386 |
|
387 |
/* Setup ScannerConf defaults */ |
388 |
item->name = xstrdup("undefined"); |
389 |
|
390 |
if(LIST_SIZE(ScannerItemList) > 0) |
391 |
{ |
392 |
olditem = ScannerItemList->tail->data; |
393 |
|
394 |
item->vhost = xstrdup(olditem->vhost); |
395 |
item->fd = olditem->fd; |
396 |
item->target_ip = xstrdup(olditem->target_ip); |
397 |
item->target_port = olditem->target_port; |
398 |
item->timeout = olditem->timeout; |
399 |
item->max_read = olditem->max_read; |
400 |
|
401 |
item->target_string = olditem->target_string; |
402 |
item->target_string_created = 0; |
403 |
} |
404 |
else |
405 |
{ |
406 |
item->vhost = xstrdup("0.0.0.0"); |
407 |
item->fd = 512; |
408 |
item->target_ip = xstrdup("127.0.0.1"); |
409 |
item->target_port = 6667; |
410 |
item->timeout = 30; |
411 |
item->max_read = 4096; |
412 |
|
413 |
item->target_string = list_create(); |
414 |
item->target_string_created = 1; |
415 |
} |
416 |
|
417 |
item->protocols = list_create(); |
418 |
|
419 |
node = node_create(item); |
420 |
|
421 |
list_add(ScannerItemList, node); |
422 |
tmp = (void *) item; |
423 |
} |
424 |
SCANNER '{' scanner_items '}' ';' ; |
425 |
|
426 |
scanner_items: scanner_items scanner_item | |
427 |
scanner_item; |
428 |
|
429 |
scanner_item: scanner_name | |
430 |
scanner_vhost | |
431 |
scanner_fd | |
432 |
scanner_target_ip | |
433 |
scanner_target_port | |
434 |
scanner_target_string | |
435 |
scanner_protocol | |
436 |
scanner_timeout | |
437 |
scanner_max_read | |
438 |
error; |
439 |
|
440 |
scanner_name: NAME '=' STRING ';' |
441 |
{ |
442 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
443 |
MyFree(item->name); |
444 |
item->name = xstrdup($3); |
445 |
}; |
446 |
|
447 |
scanner_vhost: VHOST '=' STRING ';' |
448 |
{ |
449 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
450 |
MyFree(item->vhost); |
451 |
item->vhost = xstrdup($3); |
452 |
}; |
453 |
|
454 |
scanner_target_ip: TARGET_IP '=' STRING ';' |
455 |
{ |
456 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
457 |
MyFree(item->target_ip); |
458 |
item->target_ip = xstrdup($3); |
459 |
}; |
460 |
|
461 |
scanner_target_string: TARGET_STRING '=' STRING ';' |
462 |
{ |
463 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
464 |
|
465 |
node_t *node; |
466 |
node = node_create($3); |
467 |
|
468 |
if(item->target_string_created == 0) |
469 |
{ |
470 |
item->target_string = list_create(); |
471 |
item->target_string_created = 1; |
472 |
} |
473 |
|
474 |
list_add(item->target_string, node); |
475 |
}; |
476 |
|
477 |
scanner_fd: FD '=' NUMBER ';' |
478 |
{ |
479 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
480 |
item->fd = $3; |
481 |
}; |
482 |
|
483 |
scanner_target_port: TARGET_PORT '=' NUMBER ';' |
484 |
{ |
485 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
486 |
item->target_port = $3; |
487 |
}; |
488 |
|
489 |
scanner_timeout: TIMEOUT '=' timespec ';' |
490 |
{ |
491 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
492 |
item->timeout = $3; |
493 |
}; |
494 |
|
495 |
scanner_max_read: MAX_READ '=' sizespec ';' |
496 |
{ |
497 |
struct ScannerConf *item = (struct ScannerConf *) tmp; |
498 |
item->max_read = $3; |
499 |
}; |
500 |
|
501 |
scanner_protocol: PROTOCOL '=' PROTOCOLTYPE ':' NUMBER ';' |
502 |
{ |
503 |
struct ProtocolConf *item; |
504 |
struct ScannerConf *item2; |
505 |
|
506 |
node_t *node; |
507 |
|
508 |
item = MyMalloc(sizeof *item); |
509 |
item->type = $3; |
510 |
item->port = $5; |
511 |
|
512 |
item2 = (struct ScannerConf *) tmp; |
513 |
|
514 |
node = node_create(item); |
515 |
list_add(item2->protocols, node); |
516 |
}; |
517 |
|
518 |
/*************************** OPM BLOCK ***************************/ |
519 |
|
520 |
opm_entry: OPM '{' opm_items '}' ';' ; |
521 |
|
522 |
opm_items: opm_items opm_item | |
523 |
opm_item; |
524 |
|
525 |
opm_item: opm_dnsbl_from | |
526 |
opm_dnsbl_to | |
527 |
opm_sendmail | |
528 |
opm_blacklist_entry | |
529 |
error; |
530 |
|
531 |
opm_dnsbl_from: DNSBL_FROM '=' STRING ';' |
532 |
{ |
533 |
MyFree(OpmItem->dnsbl_from); |
534 |
OpmItem->dnsbl_from = xstrdup($3); |
535 |
}; |
536 |
|
537 |
opm_dnsbl_to: DNSBL_TO '=' STRING ';' |
538 |
{ |
539 |
MyFree(OpmItem->dnsbl_to); |
540 |
OpmItem->dnsbl_to = xstrdup($3); |
541 |
}; |
542 |
|
543 |
opm_sendmail: SENDMAIL '=' STRING ';' |
544 |
{ |
545 |
MyFree(OpmItem->sendmail); |
546 |
OpmItem->sendmail = xstrdup($3); |
547 |
}; |
548 |
|
549 |
/************************** BLACKLIST BLOCK *************************/ |
550 |
|
551 |
opm_blacklist_entry: |
552 |
{ |
553 |
node_t *node; |
554 |
struct BlacklistConf *item; |
555 |
|
556 |
item = MyMalloc(sizeof *item); |
557 |
|
558 |
item->name = xstrdup(""); |
559 |
item->kline = xstrdup(""); |
560 |
item->ban_unknown = 0; |
561 |
item->type = A_BITMASK; |
562 |
item->reply = list_create(); |
563 |
|
564 |
node = node_create(item); |
565 |
list_add(OpmItem->blacklists, node); |
566 |
|
567 |
tmp = (void *) item; |
568 |
} |
569 |
BLACKLIST '{' blacklist_items '}' ';'; |
570 |
|
571 |
blacklist_items: blacklist_items blacklist_item | |
572 |
blacklist_item; |
573 |
|
574 |
blacklist_item: blacklist_name | |
575 |
blacklist_type | |
576 |
blacklist_kline | |
577 |
blacklist_ban_unknown | |
578 |
blacklist_reply | |
579 |
error; |
580 |
|
581 |
blacklist_name: NAME '=' STRING ';' { |
582 |
struct BlacklistConf *item = tmp; |
583 |
|
584 |
MyFree(item->name); |
585 |
item->name = xstrdup($3); |
586 |
}; |
587 |
|
588 |
blacklist_kline: KLINE '=' STRING ';' { |
589 |
struct BlacklistConf *item = tmp; |
590 |
|
591 |
MyFree(item->kline); |
592 |
item->kline = xstrdup($3); |
593 |
}; |
594 |
|
595 |
blacklist_type: TYPE '=' STRING ';' { |
596 |
struct BlacklistConf *item = tmp; |
597 |
|
598 |
if(strcmp("A record bitmask", $3) == 0) |
599 |
item->type = A_BITMASK; |
600 |
else if(strcmp("A record reply", $3) == 0) |
601 |
item->type = A_REPLY; |
602 |
else |
603 |
yyerror("Unknown blacklist type defined"); |
604 |
}; |
605 |
|
606 |
blacklist_ban_unknown: BAN_UNKNOWN '=' NUMBER ';' { |
607 |
struct BlacklistConf *item = tmp; |
608 |
|
609 |
item->ban_unknown = $3; |
610 |
}; |
611 |
|
612 |
blacklist_reply: REPLY '{' blacklist_reply_items '}' ';'; |
613 |
|
614 |
blacklist_reply_items: blacklist_reply_items blacklist_reply_item | |
615 |
blacklist_reply_item; |
616 |
|
617 |
blacklist_reply_item: NUMBER '=' STRING ';' |
618 |
{ |
619 |
struct BlacklistReplyConf *item; |
620 |
struct BlacklistConf *blacklist = tmp; |
621 |
node_t *node; |
622 |
|
623 |
item = MyMalloc(sizeof *item); |
624 |
|
625 |
item->number = $1; |
626 |
item->type = xstrdup($3); |
627 |
|
628 |
node = node_create(item); |
629 |
list_add(blacklist->reply, node); |
630 |
}; |
631 |
|
632 |
/*************************** EXEMPT BLOCK ***************************/ |
633 |
|
634 |
|
635 |
exempt_entry: EXEMPT '{' exempt_items '}' ';' ; |
636 |
|
637 |
exempt_items: exempt_items exempt_item | |
638 |
exempt_item; |
639 |
|
640 |
exempt_item: exempt_mask | |
641 |
error; |
642 |
|
643 |
exempt_mask: MASK '=' STRING ';' |
644 |
{ |
645 |
node_t *node; |
646 |
node = node_create(xstrdup($3)); |
647 |
|
648 |
list_add(ExemptItem->masks, node); |
649 |
}; |
650 |
|
651 |
%% |