ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/branches/1.1.x/src/config-parser.y
Revision: 8749
Committed: Tue Jan 1 11:06:27 2019 UTC (7 years, 6 months ago) by michael
File size: 14723 byte(s)
Log Message:
- Update copyright years

File Contents

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

Properties

Name Value
svn:eol-style native
svn:keywords Id