]> jfr.im git - irc/quakenet/snircd.git/blob - ircd/ircd_parser.y
Import of u2_10_12_08
[irc/quakenet/snircd.git] / ircd / ircd_parser.y
1 /*
2 * ircd_parser.y: A yacc/bison parser for ircd config files.
3 * This is part of ircu, an Internet Relay Chat server.
4 * The contents of this file are Copyright 2001 Diane Bruce,
5 * Andrew Miller, the ircd-hybrid team and the ircu team.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
20 * $Id: ircd_parser.y,v 1.56.2.6 2006/06/30 19:54:35 entrope Exp $
21 */
22 %{
23
24 #include "config.h"
25 #include "s_conf.h"
26 #include "class.h"
27 #include "client.h"
28 #include "crule.h"
29 #include "ircd_features.h"
30 #include "fileio.h"
31 #include "gline.h"
32 #include "hash.h"
33 #include "ircd.h"
34 #include "ircd_alloc.h"
35 #include "ircd_chattr.h"
36 #include "ircd_log.h"
37 #include "ircd_reply.h"
38 #include "ircd_snprintf.h"
39 #include "ircd_string.h"
40 #include "list.h"
41 #include "listener.h"
42 #include "match.h"
43 #include "motd.h"
44 #include "numeric.h"
45 #include "numnicks.h"
46 #include "opercmds.h"
47 #include "parse.h"
48 #include "res.h"
49 #include "s_auth.h"
50 #include "s_bsd.h"
51 #include "s_conf.h"
52 #include "s_debug.h"
53 #include "s_misc.h"
54 #include "send.h"
55 #include "struct.h"
56 #include "sys.h"
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include <arpa/inet.h>
61 #define MAX_STRINGS 80 /* Maximum number of feature params. */
62 extern struct LocalConf localConf;
63 extern struct DenyConf* denyConfList;
64 extern struct CRuleConf* cruleConfList;
65 extern struct ServerConf* serverConfList;
66 extern struct s_map* GlobalServiceMapList;
67 extern struct qline* GlobalQuarantineList;
68
69 int yylex(void);
70 /* Now all the globals we need :/... */
71 int tping, tconn, maxlinks, sendq, port, invert, stringno, flags;
72 char *name, *pass, *host, *ip, *username, *origin, *hub_limit;
73 char *stringlist[MAX_STRINGS];
74 struct ConnectionClass *c_class;
75 struct DenyConf *dconf;
76 struct ServerConf *sconf;
77 struct s_map *smap;
78 struct Privs privs;
79 struct Privs privs_dirty;
80
81 static void parse_error(char *pattern,...) {
82 static char error_buffer[1024];
83 va_list vl;
84 va_start(vl,pattern);
85 ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
86 va_end(vl);
87 yyerror(error_buffer);
88 }
89
90 %}
91
92 %token <text> QSTRING
93 %token <num> NUMBER
94
95 %token GENERAL
96 %token ADMIN
97 %token LOCATION
98 %token CONTACT
99 %token CONNECT
100 %token CLASS
101 %token CHANNEL
102 %token PINGFREQ
103 %token CONNECTFREQ
104 %token MAXLINKS
105 %token MAXHOPS
106 %token SENDQ
107 %token NAME
108 %token HOST
109 %token IP
110 %token USERNAME
111 %token PASS
112 %token LOCAL
113 %token SECONDS
114 %token MINUTES
115 %token HOURS
116 %token DAYS
117 %token WEEKS
118 %token MONTHS
119 %token YEARS
120 %token DECADES
121 %token BYTES
122 %token KBYTES
123 %token MBYTES
124 %token GBYTES
125 %token TBYTES
126 %token SERVER
127 %token PORT
128 %token MASK
129 %token HUB
130 %token LEAF
131 %token UWORLD
132 %token YES
133 %token NO
134 %token OPER
135 %token VHOST
136 %token HIDDEN
137 %token MOTD
138 %token JUPE
139 %token NICK
140 %token NUMERIC
141 %token DESCRIPTION
142 %token CLIENT
143 %token KILL
144 %token CRULE
145 %token REAL
146 %token REASON
147 %token TFILE
148 %token RULE
149 %token ALL
150 %token FEATURES
151 %token QUARANTINE
152 %token PSEUDO
153 %token PREPEND
154 %token USERMODE
155 %token IAUTH
156 %token TIMEOUT
157 %token FAST
158 %token AUTOCONNECT
159 %token PROGRAM
160 /* and now a lot of privileges... */
161 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
162 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
163 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_LOCAL_JUPE TPRIV_LOCAL_BADCHAN
164 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
165 %token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
166 %token TPRIV_UNLIMIT_QUERY TPRIV_DISPLAY TPRIV_SEE_OPERS TPRIV_WIDE_GLINE
167 %token TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE TPRIV_APASS_OPMODE
168 %token TPRIV_LIST_CHAN
169 /* and some types... */
170 %type <num> sizespec
171 %type <num> timespec timefactor factoredtimes factoredtime
172 %type <num> expr yesorno privtype
173 %left '+' '-'
174 %left '*' '/'
175
176 %union{
177 char *text;
178 int num;
179 }
180
181 %%
182 /* Blocks in the config file... */
183 blocks: blocks block | block;
184 block: adminblock | generalblock | classblock | connectblock |
185 uworldblock | operblock | portblock | jupeblock | clientblock |
186 killblock | cruleblock | motdblock | featuresblock | quarantineblock |
187 pseudoblock | iauthblock | error ';';
188
189 /* The timespec, sizespec and expr was ripped straight from
190 * ircd-hybrid-7. */
191 timespec: expr | factoredtimes;
192
193 factoredtimes: factoredtimes factoredtime
194 {
195 $$ = $1 + $2;
196 } | factoredtime;
197
198 factoredtime: expr timefactor
199 {
200 $$ = $1 * $2;
201 };
202
203 timefactor: SECONDS { $$ = 1; }
204 | MINUTES { $$ = 60; }
205 | HOURS { $$ = 60 * 60; }
206 | DAYS { $$ = 60 * 60 * 24; }
207 | WEEKS { $$ = 60 * 60 * 24 * 7; }
208 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
209 | YEARS { $$ = 60 * 60 * 24 * 365; }
210 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
211
212
213 sizespec: expr {
214 $$ = $1;
215 }
216 | expr BYTES {
217 $$ = $1;
218 }
219 | expr KBYTES {
220 $$ = $1 * 1024;
221 }
222 | expr MBYTES {
223 $$ = $1 * 1024 * 1024;
224 }
225 | expr GBYTES {
226 $$ = $1 * 1024 * 1024 * 1024;
227 }
228 | expr TBYTES {
229 $$ = $1 * 1024 * 1024 * 1024;
230 }
231 ;
232
233 /* this is an arithmetic expression */
234 expr: NUMBER
235 {
236 $$ = $1;
237 }
238 | expr '+' expr {
239 $$ = $1 + $3;
240 }
241 | expr '-' expr {
242 $$ = $1 - $3;
243 }
244 | expr '*' expr {
245 $$ = $1 * $3;
246 }
247 | expr '/' expr {
248 $$ = $1 / $3;
249 }
250 /* leave this out until we find why it makes BSD yacc dump core -larne
251 | '-' expr %prec NEG {
252 $$ = -$2;
253 } */
254 | '(' expr ')' {
255 $$ = $2;
256 }
257 ;
258
259 jupeblock: JUPE '{' jupeitems '}' ';' ;
260 jupeitems: jupeitem jupeitems | jupeitem;
261 jupeitem: jupenick;
262 jupenick: NICK '=' QSTRING ';'
263 {
264 addNickJupes($3);
265 MyFree($3);
266 };
267
268 generalblock: GENERAL
269 {
270 /* Zero out the vhost addresses, in case they were removed. */
271 memset(&VirtualHost_v4.addr, 0, sizeof(VirtualHost_v4.addr));
272 memset(&VirtualHost_v6.addr, 0, sizeof(VirtualHost_v6.addr));
273 } '{' generalitems '}' ';' {
274 if (localConf.name == NULL)
275 parse_error("Your General block must contain a name.");
276 if (localConf.numeric == 0)
277 parse_error("Your General block must contain a numeric (between 1 and 4095).");
278 };
279 generalitems: generalitem generalitems | generalitem;
280 generalitem: generalnumeric | generalname | generalvhost | generaldesc;
281 generalnumeric: NUMERIC '=' NUMBER ';'
282 {
283 if (localConf.numeric == 0)
284 localConf.numeric = $3;
285 else if (localConf.numeric != $3)
286 parse_error("Redefinition of server numeric %i (%i)", $3,
287 localConf.numeric);
288 };
289
290 generalname: NAME '=' QSTRING ';'
291 {
292 if (localConf.name == NULL)
293 localConf.name = $3;
294 else {
295 if (strcmp(localConf.name, $3))
296 parse_error("Redefinition of server name %s (%s)", $3,
297 localConf.name);
298 MyFree($3);
299 }
300 };
301
302 generaldesc: DESCRIPTION '=' QSTRING ';'
303 {
304 MyFree(localConf.description);
305 localConf.description = $3;
306 ircd_strncpy(cli_info(&me), $3, REALLEN);
307 };
308
309 generalvhost: VHOST '=' QSTRING ';'
310 {
311 struct irc_in_addr addr;
312 if (!strcmp($3, "*")) {
313 /* This traditionally meant bind to all interfaces and connect
314 * from the default. */
315 } else if (!ircd_aton(&addr, $3))
316 parse_error("Invalid virtual host '%s'.", $3);
317 else if (irc_in_addr_is_ipv4(&addr))
318 memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
319 else
320 memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
321 MyFree($3);
322 };
323
324 adminblock: ADMIN
325 {
326 MyFree(localConf.location1);
327 MyFree(localConf.location2);
328 MyFree(localConf.contact);
329 localConf.location1 = localConf.location2 = localConf.contact = NULL;
330 }
331 '{' adminitems '}' ';'
332 {
333 if (localConf.location1 == NULL)
334 DupString(localConf.location1, "");
335 if (localConf.location2 == NULL)
336 DupString(localConf.location2, "");
337 if (localConf.contact == NULL)
338 DupString(localConf.contact, "");
339 };
340 adminitems: adminitems adminitem | adminitem;
341 adminitem: adminlocation | admincontact;
342 adminlocation: LOCATION '=' QSTRING ';'
343 {
344 if (localConf.location1 == NULL)
345 localConf.location1 = $3;
346 else if (localConf.location2 == NULL)
347 localConf.location2 = $3;
348 else /* Otherwise just drop it. -A1kmm */
349 MyFree($3);
350 };
351 admincontact: CONTACT '=' QSTRING ';'
352 {
353 MyFree(localConf.contact);
354 localConf.contact = $3;
355 };
356
357 classblock: CLASS {
358 tping = 90;
359 } '{' classitems '}' ';'
360 {
361 if (name != NULL)
362 {
363 struct ConnectionClass *c_class;
364 add_class(name, tping, tconn, maxlinks, sendq);
365 c_class = find_class(name);
366 MyFree(c_class->default_umode);
367 c_class->default_umode = pass;
368 memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
369 memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
370 }
371 else {
372 parse_error("Missing name in class block");
373 }
374 name = NULL;
375 pass = NULL;
376 tconn = 0;
377 maxlinks = 0;
378 sendq = 0;
379 memset(&privs, 0, sizeof(privs));
380 memset(&privs_dirty, 0, sizeof(privs_dirty));
381 };
382 classitems: classitem classitems | classitem;
383 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
384 classsendq | classusermode | priv;
385 classname: NAME '=' QSTRING ';'
386 {
387 MyFree(name);
388 name = $3;
389 };
390 classpingfreq: PINGFREQ '=' timespec ';'
391 {
392 tping = $3;
393 };
394 classconnfreq: CONNECTFREQ '=' timespec ';'
395 {
396 tconn = $3;
397 };
398 classmaxlinks: MAXLINKS '=' expr ';'
399 {
400 maxlinks = $3;
401 };
402 classsendq: SENDQ '=' sizespec ';'
403 {
404 sendq = $3;
405 };
406 classusermode: USERMODE '=' QSTRING ';'
407 {
408 MyFree(pass);
409 pass = $3;
410 };
411
412 connectblock: CONNECT
413 {
414 maxlinks = 65535;
415 flags = CONF_AUTOCONNECT;
416 } '{' connectitems '}' ';'
417 {
418 struct ConfItem *aconf = NULL;
419 if (name == NULL)
420 parse_error("Missing name in connect block");
421 else if (pass == NULL)
422 parse_error("Missing password in connect block");
423 else if (host == NULL)
424 parse_error("Missing host in connect block");
425 else if (strchr(host, '*') || strchr(host, '?'))
426 parse_error("Invalid host '%s' in connect block", host);
427 else if (c_class == NULL)
428 parse_error("Missing or non-existent class in connect block");
429 else {
430 aconf = make_conf(CONF_SERVER);
431 aconf->name = name;
432 aconf->origin_name = origin;
433 aconf->passwd = pass;
434 aconf->conn_class = c_class;
435 aconf->address.port = port;
436 aconf->host = host;
437 aconf->maximum = maxlinks;
438 aconf->hub_limit = hub_limit;
439 aconf->flags = flags;
440 lookup_confhost(aconf);
441 }
442 if (!aconf) {
443 MyFree(name);
444 MyFree(pass);
445 MyFree(host);
446 MyFree(origin);
447 MyFree(hub_limit);
448 }
449 name = pass = host = origin = hub_limit = NULL;
450 c_class = NULL;
451 port = flags = 0;
452 };
453 connectitems: connectitem connectitems | connectitem;
454 connectitem: connectname | connectpass | connectclass | connecthost
455 | connectport | connectvhost | connectleaf | connecthub
456 | connecthublimit | connectmaxhops | connectauto;
457 connectname: NAME '=' QSTRING ';'
458 {
459 MyFree(name);
460 name = $3;
461 };
462 connectpass: PASS '=' QSTRING ';'
463 {
464 MyFree(pass);
465 pass = $3;
466 };
467 connectclass: CLASS '=' QSTRING ';'
468 {
469 c_class = find_class($3);
470 if (!c_class)
471 parse_error("No such connection class '%s' for Connect block", $3);
472 MyFree($3);
473 };
474 connecthost: HOST '=' QSTRING ';'
475 {
476 MyFree(host);
477 host = $3;
478 };
479 connectport: PORT '=' NUMBER ';'
480 {
481 port = $3;
482 };
483 connectvhost: VHOST '=' QSTRING ';'
484 {
485 MyFree(origin);
486 origin = $3;
487 };
488 connectleaf: LEAF ';'
489 {
490 maxlinks = 0;
491 };
492 connecthub: HUB ';'
493 {
494 MyFree(hub_limit);
495 DupString(hub_limit, "*");
496 };
497 connecthublimit: HUB '=' QSTRING ';'
498 {
499 MyFree(hub_limit);
500 hub_limit = $3;
501 };
502 connectmaxhops: MAXHOPS '=' expr ';'
503 {
504 maxlinks = $3;
505 };
506 connectauto: AUTOCONNECT '=' YES ';' { flags |= CONF_AUTOCONNECT; }
507 | AUTOCONNECT '=' NO ';' { flags &= ~CONF_AUTOCONNECT; };
508
509 uworldblock: UWORLD '{' uworlditems '}' ';';
510 uworlditems: uworlditem uworlditems | uworlditem;
511 uworlditem: uworldname;
512 uworldname: NAME '=' QSTRING ';'
513 {
514 make_conf(CONF_UWORLD)->host = $3;
515 };
516
517 operblock: OPER '{' operitems '}' ';'
518 {
519 struct ConfItem *aconf = NULL;
520 if (name == NULL)
521 parse_error("Missing name in operator block");
522 else if (pass == NULL)
523 parse_error("Missing password in operator block");
524 else if (host == NULL)
525 parse_error("Missing host in operator block");
526 else if (c_class == NULL)
527 parse_error("Invalid or missing class in operator block");
528 else {
529 aconf = make_conf(CONF_OPERATOR);
530 aconf->name = name;
531 aconf->passwd = pass;
532 conf_parse_userhost(aconf, host);
533 aconf->conn_class = c_class;
534 memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
535 memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
536 if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
537 && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
538 parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
539 }
540 if (!aconf) {
541 MyFree(name);
542 MyFree(pass);
543 MyFree(host);
544 }
545 name = pass = host = NULL;
546 c_class = NULL;
547 memset(&privs, 0, sizeof(privs));
548 memset(&privs_dirty, 0, sizeof(privs_dirty));
549 };
550 operitems: operitem | operitems operitem;
551 operitem: opername | operpass | operhost | operclass | priv;
552 opername: NAME '=' QSTRING ';'
553 {
554 MyFree(name);
555 name = $3;
556 };
557 operpass: PASS '=' QSTRING ';'
558 {
559 MyFree(pass);
560 pass = $3;
561 };
562 operhost: HOST '=' QSTRING ';'
563 {
564 MyFree(host);
565 if (!strchr($3, '@'))
566 {
567 int uh_len;
568 host = (char*) MyMalloc((uh_len = strlen($3)+3));
569 ircd_snprintf(0, host, uh_len, "*@%s", $3);
570 MyFree($3);
571 }
572 else
573 host = $3;
574 };
575 operclass: CLASS '=' QSTRING ';'
576 {
577 c_class = find_class($3);
578 if (!c_class)
579 parse_error("No such connection class '%s' for Operator block", $3);
580 MyFree($3);
581 };
582
583 priv: privtype '=' yesorno ';'
584 {
585 FlagSet(&privs_dirty, $1);
586 if (($3 == 1) ^ invert)
587 FlagSet(&privs, $1);
588 else
589 FlagClr(&privs, $1);
590 invert = 0;
591 };
592
593 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
594 TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
595 TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
596 TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
597 KILL { $$ = PRIV_KILL; } |
598 TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
599 TPRIV_REHASH { $$ = PRIV_REHASH; } |
600 TPRIV_RESTART { $$ = PRIV_RESTART; } |
601 TPRIV_DIE { $$ = PRIV_DIE; } |
602 TPRIV_GLINE { $$ = PRIV_GLINE; } |
603 TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
604 JUPE { $$ = PRIV_JUPE; } |
605 TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
606 TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
607 TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
608 TPRIV_SET { $$ = PRIV_SET; } |
609 TPRIV_WHOX { $$ = PRIV_WHOX; } |
610 TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
611 TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
612 TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
613 TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
614 TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
615 TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
616 TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
617 TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
618 TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
619 TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
620 TPRIV_LIST_CHAN { $$ = PRIV_LIST_CHAN; } |
621 LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
622 TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
623 TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
624 TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
625
626 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
627
628 /* The port block... */
629 portblock: PORT '{' portitems '}' ';'
630 {
631 if (port > 0 && port <= 0xFFFF)
632 add_listener(port, host, pass, tconn, tping);
633 else
634 parse_error("Port %d is out of range", port);
635 MyFree(host);
636 MyFree(pass);
637 host = pass = NULL;
638 port = tconn = tping = 0;
639 };
640 portitems: portitem portitems | portitem;
641 portitem: portnumber | portvhost | portmask | portserver | porthidden;
642 portnumber: PORT '=' NUMBER ';'
643 {
644 port = $3;
645 };
646
647 portvhost: VHOST '=' QSTRING ';'
648 {
649 MyFree(host);
650 host = $3;
651 };
652
653 portmask: MASK '=' QSTRING ';'
654 {
655 MyFree(pass);
656 pass = $3;
657 };
658
659 portserver: SERVER '=' YES ';'
660 {
661 tconn = -1;
662 } | SERVER '=' NO ';'
663 {
664 tconn = 0;
665 };
666
667 porthidden: HIDDEN '=' YES ';'
668 {
669 tping = -1;
670 } | HIDDEN '=' NO ';'
671 {
672 tping = 0;
673 };
674
675 clientblock: CLIENT
676 {
677 maxlinks = 65535;
678 port = 0;
679 }
680 '{' clientitems '}' ';'
681 {
682 struct ConfItem *aconf = 0;
683 struct irc_in_addr addr;
684 unsigned char addrbits = 0;
685
686 if (!c_class)
687 parse_error("Invalid or missing class in Client block");
688 else if (ip && !ipmask_parse(ip, &addr, &addrbits))
689 parse_error("Invalid IP address %s in Client block", ip);
690 else {
691 aconf = make_conf(CONF_CLIENT);
692 aconf->username = username;
693 aconf->host = host;
694 if (ip)
695 memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
696 else
697 memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
698 aconf->address.port = port;
699 aconf->addrbits = addrbits;
700 aconf->name = ip;
701 aconf->conn_class = c_class;
702 aconf->maximum = maxlinks;
703 aconf->passwd = pass;
704 }
705 if (!aconf) {
706 MyFree(username);
707 MyFree(host);
708 MyFree(ip);
709 MyFree(pass);
710 }
711 host = NULL;
712 username = NULL;
713 c_class = NULL;
714 ip = NULL;
715 pass = NULL;
716 port = 0;
717 };
718 clientitems: clientitem clientitems | clientitem;
719 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | clientport;
720 clienthost: HOST '=' QSTRING ';'
721 {
722 char *sep = strchr($3, '@');
723 MyFree(host);
724 if (sep) {
725 *sep++ = '\0';
726 MyFree(username);
727 DupString(host, sep);
728 username = $3;
729 } else {
730 host = $3;
731 }
732 };
733 clientip: IP '=' QSTRING ';'
734 {
735 char *sep;
736 sep = strchr($3, '@');
737 MyFree(ip);
738 if (sep) {
739 *sep++ = '\0';
740 MyFree(username);
741 DupString(ip, sep);
742 username = $3;
743 } else {
744 ip = $3;
745 }
746 };
747 clientusername: USERNAME '=' QSTRING ';'
748 {
749 MyFree(username);
750 username = $3;
751 };
752 clientclass: CLASS '=' QSTRING ';'
753 {
754 c_class = find_class($3);
755 if (!c_class)
756 parse_error("No such connection class '%s' for Client block", $3);
757 MyFree($3);
758 };
759 clientpass: PASS '=' QSTRING ';'
760 {
761 MyFree(pass);
762 pass = $3;
763 };
764 clientmaxlinks: MAXLINKS '=' expr ';'
765 {
766 maxlinks = $3;
767 };
768 clientport: PORT '=' expr ';'
769 {
770 port = $3;
771 };
772
773 killblock: KILL
774 {
775 dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
776 } '{' killitems '}' ';'
777 {
778 if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
779 dconf->next = denyConfList;
780 denyConfList = dconf;
781 }
782 else
783 {
784 MyFree(dconf->usermask);
785 MyFree(dconf->hostmask);
786 MyFree(dconf->realmask);
787 MyFree(dconf->message);
788 MyFree(dconf);
789 parse_error("Kill block must match on at least one of username, host or realname");
790 }
791 dconf = NULL;
792 };
793 killitems: killitem killitems | killitem;
794 killitem: killuhost | killreal | killusername | killreasonfile | killreason;
795 killuhost: HOST '=' QSTRING ';'
796 {
797 char *h;
798 MyFree(dconf->hostmask);
799 MyFree(dconf->usermask);
800 if ((h = strchr($3, '@')) == NULL)
801 {
802 DupString(dconf->usermask, "*");
803 dconf->hostmask = $3;
804 }
805 else
806 {
807 *h++ = '\0';
808 DupString(dconf->hostmask, h);
809 dconf->usermask = $3;
810 }
811 ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
812 };
813
814 killusername: USERNAME '=' QSTRING ';'
815 {
816 MyFree(dconf->usermask);
817 dconf->usermask = $3;
818 };
819
820 killreal: REAL '=' QSTRING ';'
821 {
822 MyFree(dconf->realmask);
823 dconf->realmask = $3;
824 };
825
826 killreason: REASON '=' QSTRING ';'
827 {
828 dconf->flags &= ~DENY_FLAGS_FILE;
829 MyFree(dconf->message);
830 dconf->message = $3;
831 };
832
833 killreasonfile: TFILE '=' QSTRING ';'
834 {
835 dconf->flags |= DENY_FLAGS_FILE;
836 MyFree(dconf->message);
837 dconf->message = $3;
838 };
839
840 cruleblock: CRULE
841 {
842 tconn = CRULE_AUTO;
843 } '{' cruleitems '}' ';'
844 {
845 struct CRuleNode *node = NULL;
846 if (host == NULL)
847 parse_error("Missing host in crule block");
848 else if (pass == NULL)
849 parse_error("Missing rule in crule block");
850 else if ((node = crule_parse(pass)) == NULL)
851 parse_error("Invalid rule '%s' in crule block", pass);
852 else
853 {
854 struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
855 p->hostmask = host;
856 p->rule = pass;
857 p->type = tconn;
858 p->node = node;
859 p->next = cruleConfList;
860 cruleConfList = p;
861 }
862 if (!node)
863 {
864 MyFree(host);
865 MyFree(pass);
866 }
867 host = pass = NULL;
868 tconn = 0;
869 };
870
871 cruleitems: cruleitem cruleitems | cruleitem;
872 cruleitem: cruleserver | crulerule | cruleall;
873
874 cruleserver: SERVER '=' QSTRING ';'
875 {
876 MyFree(host);
877 collapse($3);
878 host = $3;
879 };
880
881 crulerule: RULE '=' QSTRING ';'
882 {
883 MyFree(pass);
884 pass = $3;
885 };
886
887 cruleall: ALL '=' YES ';'
888 {
889 tconn = CRULE_ALL;
890 } | ALL '=' NO ';'
891 {
892 tconn = CRULE_AUTO;
893 };
894
895 motdblock: MOTD '{' motditems '}' ';'
896 {
897 if (host != NULL && pass != NULL)
898 motd_add(host, pass);
899 MyFree(host);
900 MyFree(pass);
901 host = pass = NULL;
902 };
903
904 motditems: motditem motditems | motditem;
905 motditem: motdhost | motdfile;
906 motdhost: HOST '=' QSTRING ';'
907 {
908 host = $3;
909 };
910
911 motdfile: TFILE '=' QSTRING ';'
912 {
913 pass = $3;
914 };
915
916 featuresblock: FEATURES '{' featureitems '}' ';';
917 featureitems: featureitems featureitem | featureitem;
918
919 featureitem: QSTRING
920 {
921 stringlist[0] = $1;
922 stringno = 1;
923 } '=' stringlist ';' {
924 unsigned int ii;
925 feature_set(NULL, (const char * const *)stringlist, stringno);
926 for (ii = 0; ii < stringno; ++ii)
927 MyFree(stringlist[ii]);
928 };
929
930 stringlist: stringlist extrastring | extrastring;
931 extrastring: QSTRING
932 {
933 if (stringno < MAX_STRINGS)
934 stringlist[stringno++] = $1;
935 else
936 MyFree($1);
937 };
938
939 quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
940 quarantineitems: quarantineitems quarantineitem | quarantineitem;
941 quarantineitem: QSTRING '=' QSTRING ';'
942 {
943 struct qline *qconf = MyCalloc(1, sizeof(*qconf));
944 qconf->chname = $1;
945 qconf->reason = $3;
946 qconf->next = GlobalQuarantineList;
947 GlobalQuarantineList = qconf;
948 };
949
950 pseudoblock: PSEUDO QSTRING '{'
951 {
952 smap = MyCalloc(1, sizeof(struct s_map));
953 smap->command = $2;
954 }
955 pseudoitems '}' ';'
956 {
957 int valid = 0;
958
959 if (!smap->name)
960 parse_error("Missing name in pseudo %s block", smap->command);
961 else if (!smap->services)
962 parse_error("Missing nick in pseudo %s block", smap->command);
963 else
964 valid = 1;
965 if (valid && register_mapping(smap))
966 {
967 smap->next = GlobalServiceMapList;
968 GlobalServiceMapList = smap;
969 }
970 else
971 {
972 free_mapping(smap);
973 }
974 smap = NULL;
975 };
976
977 pseudoitems: pseudoitem pseudoitems | pseudoitem;
978 pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags;
979 pseudoname: NAME '=' QSTRING ';'
980 {
981 MyFree(smap->name);
982 smap->name = $3;
983 };
984 pseudoprepend: PREPEND '=' QSTRING ';'
985 {
986 MyFree(smap->prepend);
987 smap->prepend = $3;
988 };
989 pseudonick: NICK '=' QSTRING ';'
990 {
991 char *sep = strchr($3, '@');
992
993 if (sep != NULL) {
994 size_t slen = strlen($3);
995 struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
996 memcpy(nh->nick, $3, slen + 1);
997 nh->nicklen = sep - $3;
998 nh->next = smap->services;
999 smap->services = nh;
1000 }
1001 MyFree($3);
1002 };
1003 pseudoflags: FAST ';'
1004 {
1005 smap->flags |= SMAP_FAST;
1006 };
1007
1008 iauthblock: IAUTH '{' iauthitems '}' ';'
1009 {
1010 auth_spawn(stringno, stringlist);
1011 while (stringno > 0)
1012 MyFree(stringlist[--stringno]);
1013 };
1014
1015 iauthitems: iauthitem iauthitems | iauthitem;
1016 iauthitem: iauthprogram;
1017 iauthprogram: PROGRAM '='
1018 {
1019 while (stringno > 0)
1020 MyFree(stringlist[--stringno]);
1021 } stringlist ';';