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