Fix sporadic spurious (and mysterious) config file parsing failures.
[ircu2.10.12-pk.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$
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_auth.h"
36 #include "ircd_chattr.h"
37 #include "ircd_log.h"
38 #include "ircd_reply.h"
39 #include "ircd_snprintf.h"
40 #include "ircd_string.h"
41 #include "list.h"
42 #include "listener.h"
43 #include "match.h"
44 #include "motd.h"
45 #include "numeric.h"
46 #include "numnicks.h"
47 #include "opercmds.h"
48 #include "parse.h"
49 #include "res.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;
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 /* and now a lot of privileges... */
159 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
160 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
161 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_LOCAL_JUPE TPRIV_LOCAL_BADCHAN
162 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
163 %token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
164 %token TPRIV_UNLIMIT_QUERY TPRIV_DISPLAY TPRIV_SEE_OPERS TPRIV_WIDE_GLINE
165 %token TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE TPRIV_APASS_OPMODE
166 /* and some types... */
167 %type <num> sizespec
168 %type <num> timespec timefactor factoredtimes factoredtime
169 %type <num> expr yesorno privtype
170 %left '+' '-'
171 %left '*' '/'
172
173 %union{
174  char *text;
175  int num;
176 }
177
178 %%
179 /* Blocks in the config file... */
180 blocks: blocks block | block;
181 block: adminblock | generalblock | classblock | connectblock |
182        uworldblock | operblock | portblock | jupeblock | clientblock |
183        killblock | cruleblock | motdblock | featuresblock | quarantineblock |
184        pseudoblock | iauthblock | error;
185
186 /* The timespec, sizespec and expr was ripped straight from
187  * ircd-hybrid-7. */
188 timespec: expr | factoredtimes;
189
190 factoredtimes: factoredtimes factoredtime
191 {
192   $$ = $1 + $2;
193 } | factoredtime;
194
195 factoredtime: expr timefactor
196 {
197   $$ = $1 * $2;
198 };
199
200 timefactor: SECONDS { $$ = 1; }
201 | MINUTES { $$ = 60; }
202 | HOURS { $$ = 60 * 60; }
203 | DAYS { $$ = 60 * 60 * 24; }
204 | WEEKS { $$ = 60 * 60 * 24 * 7; }
205 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
206 | YEARS { $$ = 60 * 60 * 24 * 365; }
207 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
208
209
210 sizespec:       expr    {
211                         $$ = $1;
212                 }
213                 | expr BYTES  { 
214                         $$ = $1;
215                 }
216                 | expr KBYTES {
217                         $$ = $1 * 1024;
218                 }
219                 | expr MBYTES {
220                         $$ = $1 * 1024 * 1024;
221                 }
222                 | expr GBYTES {
223                         $$ = $1 * 1024 * 1024 * 1024;
224                 }
225                 | expr TBYTES {
226                         $$ = $1 * 1024 * 1024 * 1024;
227                 }
228                 ;
229
230 /* this is an arithmetic expression */
231 expr: NUMBER
232                 { 
233                         $$ = $1;
234                 }
235                 | expr '+' expr { 
236                         $$ = $1 + $3;
237                 }
238                 | expr '-' expr { 
239                         $$ = $1 - $3;
240                 }
241                 | expr '*' expr { 
242                         $$ = $1 * $3;
243                 }
244                 | expr '/' expr { 
245                         $$ = $1 / $3;
246                 }
247 /* leave this out until we find why it makes BSD yacc dump core -larne
248                 | '-' expr  %prec NEG {
249                         $$ = -$2;
250                 } */
251                 | '(' expr ')' {
252                         $$ = $2;
253                 }
254                 ;
255
256 jupeblock: JUPE '{' jupeitems '}' ';' ;
257 jupeitems: jupeitem jupeitems | jupeitem;
258 jupeitem: jupenick | error;
259 jupenick: NICK '=' QSTRING
260 {
261   addNickJupes($3);
262   MyFree($3);
263 } ';';
264
265 generalblock: GENERAL '{' generalitems '}'
266 {
267   if (localConf.name == NULL)
268     parse_error("Your General block must contain a name.");
269   if (localConf.numeric == 0)
270     parse_error("Your General block must contain a numeric (between 1 and 4095).");
271 } ';' ;
272 generalitems: generalitem generalitems | generalitem;
273 generalitem: generalnumeric | generalname | generalvhost | generaldesc | error;
274 generalnumeric: NUMERIC '=' NUMBER ';'
275 {
276   if (localConf.numeric == 0)
277     localConf.numeric = $3;
278   else if (localConf.numeric != $3)
279     parse_error("Redefinition of server numeric %i (%i)", $3,
280                 localConf.numeric);
281 };
282
283 generalname: NAME '=' QSTRING ';'
284 {
285   if (localConf.name == NULL)
286     localConf.name = $3;
287   else {
288     if (strcmp(localConf.name, $3))
289       parse_error("Redefinition of server name %s (%s)", $3,
290                   localConf.name);
291     MyFree($3);
292   }
293 };
294
295 generaldesc: DESCRIPTION '=' QSTRING ';'
296 {
297   MyFree(localConf.description);
298   localConf.description = $3;
299   ircd_strncpy(cli_info(&me), $3, REALLEN);
300 };
301
302 generalvhost: VHOST '=' QSTRING ';'
303 {
304   struct irc_in_addr addr;
305   if (!ircd_aton(&addr, $3))
306       parse_error("Invalid virtual host '%s'.", $3);
307   else if (irc_in_addr_is_ipv4(&addr))
308     memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
309   else
310     memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
311   MyFree($3);
312 };
313
314 adminblock: ADMIN '{' adminitems '}'
315 {
316   if (localConf.location1 == NULL)
317     DupString(localConf.location1, "");
318   if (localConf.location2 == NULL)
319     DupString(localConf.location2, "");
320   if (localConf.contact == NULL)
321     DupString(localConf.contact, "");
322 } ';';
323 adminitems: adminitems adminitem | adminitem;
324 adminitem: adminlocation | admincontact | error;
325 adminlocation: LOCATION '=' QSTRING ';'
326 {
327   if (localConf.location1 == NULL)
328     localConf.location1 = $3;
329   else if (localConf.location2 == NULL)
330     localConf.location2 = $3;
331   else /* Otherwise just drop it. -A1kmm */
332     MyFree($3);
333 };
334 admincontact: CONTACT '=' QSTRING ';'
335 {
336  MyFree(localConf.contact);
337  localConf.contact = $3;
338 };
339
340 classblock: CLASS {
341   tping = 90;
342 } '{' classitems '}'
343 {
344   if (name != NULL)
345   {
346     struct ConnectionClass *c_class;
347     add_class(name, tping, tconn, maxlinks, sendq);
348     c_class = find_class(name);
349     MyFree(c_class->default_umode);
350     c_class->default_umode = pass;
351     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
352     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
353   }
354   else {
355    parse_error("Missing name in class block");
356   }
357   name = NULL;
358   pass = NULL;
359   tconn = 0;
360   maxlinks = 0;
361   sendq = 0;
362   memset(&privs, 0, sizeof(privs));
363   memset(&privs_dirty, 0, sizeof(privs_dirty));
364 } ';';
365 classitems: classitem classitems | classitem;
366 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
367            classsendq | classusermode | priv | error;
368 classname: NAME '=' QSTRING ';'
369 {
370   MyFree(name);
371   name = $3;
372 };
373 classpingfreq: PINGFREQ '=' timespec ';'
374 {
375   tping = $3;
376 };
377 classconnfreq: CONNECTFREQ '=' timespec ';'
378 {
379   tconn = $3;
380 };
381 classmaxlinks: MAXLINKS '=' expr ';'
382 {
383   maxlinks = $3;
384 };
385 classsendq: SENDQ '=' sizespec ';'
386 {
387   sendq = $3;
388 };
389 classusermode: USERMODE '=' QSTRING ';'
390 {
391   MyFree(pass);
392   pass = $3;
393 };
394
395 connectblock: CONNECT
396 {
397  maxlinks = 65535;
398 } '{' connectitems '}'
399 {
400  if (name != NULL && pass != NULL && host != NULL && c_class != NULL
401      && !strchr(host, '*') && !strchr(host, '?'))
402  {
403    struct ConfItem *aconf = make_conf(CONF_SERVER);
404    aconf->name = name;
405    aconf->origin_name = origin;
406    aconf->passwd = pass;
407    aconf->conn_class = c_class;
408    aconf->address.port = port;
409    aconf->host = host;
410    aconf->maximum = maxlinks;
411    aconf->hub_limit = hub_limit;
412    lookup_confhost(aconf);
413  }
414  else
415  {
416    MyFree(name);
417    MyFree(pass);
418    MyFree(host);
419    MyFree(origin);
420    MyFree(hub_limit);
421    parse_error("Bad connect block");
422  }
423  name = pass = host = origin = hub_limit = NULL;
424  c_class = NULL;
425  port = 0;
426 }';';
427 connectitems: connectitem connectitems | connectitem;
428 connectitem: connectname | connectpass | connectclass | connecthost
429               | connectport | connectvhost | connectleaf | connecthub
430               | connecthublimit | connectmaxhops | error;
431 connectname: NAME '=' QSTRING ';'
432 {
433  MyFree(name);
434  name = $3;
435 };
436 connectpass: PASS '=' QSTRING ';'
437 {
438  MyFree(pass);
439  pass = $3;
440 };
441 connectclass: CLASS '=' QSTRING ';'
442 {
443  c_class = find_class($3);
444 };
445 connecthost: HOST '=' QSTRING ';'
446 {
447  MyFree(host);
448  host = $3;
449 };
450 connectport: PORT '=' NUMBER ';'
451 {
452  port = $3;
453 };
454 connectvhost: VHOST '=' QSTRING ';'
455 {
456  MyFree(origin);
457  origin = $3;
458 };
459 connectleaf: LEAF ';'
460 {
461  maxlinks = 0;
462 };
463 connecthub: HUB ';'
464 {
465  MyFree(hub_limit);
466  DupString(hub_limit, "*");
467 };
468 connecthublimit: HUB '=' QSTRING ';'
469 {
470  MyFree(hub_limit);
471  hub_limit = $3;
472 };
473 connectmaxhops: MAXHOPS '=' expr ';'
474 {
475   maxlinks = $3;
476 };
477
478 uworldblock: UWORLD '{' uworlditems '}' ';';
479 uworlditems: uworlditem uworlditems | uworlditem;
480 uworlditem: uworldname | error;
481 uworldname: NAME '=' QSTRING ';'
482 {
483   make_conf(CONF_UWORLD)->host = $3;
484 };
485
486 operblock: OPER '{' operitems '}' ';'
487 {
488   if (name && pass && host && c_class)
489   {
490     struct ConfItem *aconf = make_conf(CONF_OPERATOR);
491     aconf->name = name;
492     aconf->passwd = pass;
493     conf_parse_userhost(aconf, host);
494     aconf->conn_class = c_class;
495     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
496     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
497     if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
498         && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
499       parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
500   }
501   else
502   {
503     parse_error("operator blocks need a name, password, class and host.");
504     MyFree(name);
505     MyFree(pass);
506     MyFree(host);
507   }
508   name = pass = host = NULL;
509   c_class = NULL;
510   memset(&privs, 0, sizeof(privs));
511   memset(&privs_dirty, 0, sizeof(privs_dirty));
512 };
513 operitems: operitem | operitems operitem;
514 operitem: opername | operpass | operhost | operclass | priv | error;
515 opername: NAME '=' QSTRING ';'
516 {
517   MyFree(name);
518   name = $3;
519 };
520 operpass: PASS '=' QSTRING ';'
521 {
522   MyFree(pass);
523   pass = $3;
524 };
525 operhost: HOST '=' QSTRING ';'
526 {
527  MyFree(host);
528  if (!strchr($3, '@'))
529  {
530    int uh_len;
531    host = (char*) MyMalloc((uh_len = strlen($3)+3));
532    ircd_snprintf(0, host, uh_len, "*@%s", $3);
533    MyFree($3);
534  }
535  else
536    host = $3;
537 };
538 operclass: CLASS '=' QSTRING ';'
539 {
540  c_class = find_class($3);
541  MyFree($3);
542 };
543
544 priv: privtype '=' yesorno ';'
545 {
546   FlagSet(&privs_dirty, $1);
547   if (($3 == 1) ^ invert)
548     FlagSet(&privs, $1);
549   else
550     FlagClr(&privs, $1);
551   invert = 0;
552 };
553
554 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
555           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
556           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
557           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
558           KILL { $$ = PRIV_KILL; } |
559           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
560           TPRIV_REHASH { $$ = PRIV_REHASH; } |
561           TPRIV_RESTART { $$ = PRIV_RESTART; } |
562           TPRIV_DIE { $$ = PRIV_DIE; } |
563           TPRIV_GLINE { $$ = PRIV_GLINE; } |
564           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
565           JUPE { $$ = PRIV_JUPE; } |
566           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
567           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
568           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
569           TPRIV_SET { $$ = PRIV_SET; } |
570           TPRIV_WHOX { $$ = PRIV_WHOX; } |
571           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
572           TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
573           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
574           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
575           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
576           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
577           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
578           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
579           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
580           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
581           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
582           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
583           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
584           TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
585
586 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
587
588 /* The port block... */
589 portblock: PORT '{' portitems '}' ';'
590 {
591   if (port > 0 && port <= 0xFFFF)
592   {
593     add_listener(port, host, pass, tconn, tping);
594   }
595   else
596   {
597     parse_error("Bad port block");
598   }
599   MyFree(host);
600   MyFree(pass);
601   host = pass = NULL;
602   port = tconn = tping = 0;
603 };
604 portitems: portitem portitems | portitem;
605 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
606 portnumber: PORT '=' NUMBER ';'
607 {
608   port = $3;
609 };
610
611 portvhost: VHOST '=' QSTRING ';'
612 {
613   MyFree(host);
614   host = $3;
615 };
616
617 portmask: MASK '=' QSTRING ';'
618 {
619   MyFree(pass);
620   pass = $3;
621 };
622
623 portserver: SERVER '=' YES ';'
624 {
625   tconn = -1;
626 } | SERVER '=' NO ';'
627 {
628   tconn = 0;
629 };
630
631 porthidden: HIDDEN '=' YES ';'
632 {
633   tping = -1;
634 } | HIDDEN '=' NO ';'
635 {
636   tping = 0;
637 };
638
639 clientblock: CLIENT
640 {
641   maxlinks = 65535;
642 }
643 '{' clientitems '}' ';'
644 {
645   struct irc_in_addr addr;
646   unsigned char addrbits = 0;
647
648   if (ip && !ipmask_parse(ip, &addr, &addrbits)) {
649     parse_error("Invalid IP address in block");
650     MyFree(username);
651     MyFree(host);
652     MyFree(ip);
653     MyFree(pass);
654   } else {
655     struct ConfItem *aconf = make_conf(CONF_CLIENT);
656     aconf->username = username;
657     aconf->host = host;
658     if (ip)
659       memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
660     else
661       memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
662     aconf->addrbits = addrbits;
663     aconf->name = ip;
664     aconf->conn_class = c_class ? c_class : find_class("default");
665     aconf->maximum = maxlinks;
666     aconf->passwd = pass;
667   }
668   host = NULL;
669   username = NULL;
670   c_class = NULL;
671   ip = NULL;
672   pass = NULL;
673 };
674 clientitems: clientitem clientitems | clientitem;
675 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | error;
676 clienthost: HOST '=' QSTRING ';'
677 {
678   char *sep = strchr($3, '@');
679   MyFree(host);
680   if (sep) {
681     *sep++ = '\0';
682     MyFree(username);
683     DupString(host, sep);
684     username = $3;
685   } else {
686     host = $3;
687   }
688 };
689 clientip: IP '=' QSTRING ';'
690 {
691   char *sep;
692   sep = strchr($3, '@');
693   MyFree(ip);
694   if (sep) {
695     *sep++ = '\0';
696     MyFree(username);
697     DupString(ip, sep);
698     username = $3;
699   } else {
700     ip = $3;
701   }
702 };
703 clientusername: USERNAME '=' QSTRING ';'
704 {
705   MyFree(username);
706   username = $3;
707 };
708 clientclass: CLASS '=' QSTRING ';'
709 {
710   c_class = find_class($3);
711   MyFree($3);
712 };
713 clientpass: PASS '=' QSTRING ';'
714 {
715   MyFree(pass);
716   pass = $3;
717 };
718 clientmaxlinks: MAXLINKS '=' expr ';'
719 {
720   maxlinks = $3;
721 };
722
723 killblock: KILL
724 {
725   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
726 } '{' killitems '}'
727 {
728   if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
729     dconf->next = denyConfList;
730     denyConfList = dconf;
731   }
732   else
733   {
734     MyFree(dconf->usermask);
735     MyFree(dconf->hostmask);
736     MyFree(dconf->realmask);
737     MyFree(dconf->message);
738     MyFree(dconf);
739     parse_error("Bad kill block");
740   }
741   dconf = NULL;
742 } ';';
743 killitems: killitem killitems | killitem;
744 killitem: killuhost | killreal | killusername | killreasonfile | killreason | error;
745 killuhost: HOST '=' QSTRING ';'
746 {
747   char *h;
748   MyFree(dconf->hostmask);
749   MyFree(dconf->usermask);
750   if ((h = strchr($3, '@')) == NULL)
751   {
752     DupString(dconf->usermask, "*");
753     dconf->hostmask = $3;
754   }
755   else
756   {
757     *h++ = '\0';
758     DupString(dconf->hostmask, h);
759     dconf->usermask = $3;
760   }
761   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
762 };
763
764 killusername: USERNAME '=' QSTRING ';'
765 {
766   MyFree(dconf->usermask);
767   dconf->usermask = $3;
768 };
769
770 killreal: REAL '=' QSTRING ';'
771 {
772  MyFree(dconf->realmask);
773  dconf->realmask = $3;
774 };
775
776 killreason: REASON '=' QSTRING ';'
777 {
778  dconf->flags &= ~DENY_FLAGS_FILE;
779  MyFree(dconf->message);
780  dconf->message = $3;
781 };
782
783 killreasonfile: TFILE '=' QSTRING ';'
784 {
785  dconf->flags |= DENY_FLAGS_FILE;
786  MyFree(dconf->message);
787  dconf->message = $3;
788 };
789
790 cruleblock: CRULE
791 {
792   tconn = CRULE_AUTO;
793 } '{' cruleitems '}' ';'
794 {
795   struct CRuleNode *node;
796   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
797   {
798     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
799     p->hostmask = host;
800     p->rule = pass;
801     p->type = tconn;
802     p->node = node;
803     p->next = cruleConfList;
804     cruleConfList = p;
805   }
806   else
807   {
808     MyFree(host);
809     MyFree(pass);
810     parse_error("Bad CRule block");
811   }
812   host = pass = NULL;
813   tconn = 0;
814 };
815
816 cruleitems: cruleitem cruleitems | cruleitem;
817 cruleitem: cruleserver | crulerule | cruleall | error;
818
819 cruleserver: SERVER '=' QSTRING ';'
820 {
821   MyFree(host);
822   collapse($3);
823   host = $3;
824 };
825
826 crulerule: RULE '=' QSTRING ';'
827 {
828  MyFree(pass);
829  pass = $3;
830 };
831
832 cruleall: ALL '=' YES ';'
833 {
834  tconn = CRULE_ALL;
835 } | ALL '=' NO ';'
836 {
837  tconn = CRULE_AUTO;
838 };
839
840 motdblock: MOTD '{' motditems '}' ';'
841 {
842   if (host != NULL && pass != NULL)
843     motd_add(host, pass);
844   MyFree(host);
845   MyFree(pass);
846   host = pass = NULL;
847 };
848
849 motditems: motditem motditems | motditem;
850 motditem: motdhost | motdfile | error;
851 motdhost: HOST '=' QSTRING ';'
852 {
853   host = $3;
854 };
855
856 motdfile: TFILE '=' QSTRING ';'
857 {
858   pass = $3;
859 };
860
861 featuresblock: FEATURES '{' featureitems '}' ';';
862 featureitems: featureitems featureitem | featureitem;
863
864 featureitem: QSTRING
865 {
866   stringlist[0] = $1;
867   stringno = 1;
868 } '=' stringlist ';';
869
870 stringlist: QSTRING
871 {
872   stringlist[1] = $1;
873   stringno = 2;
874 } posextrastrings
875 {
876   unsigned int ii;
877   feature_set(NULL, (const char * const *)stringlist, stringno);
878   for (ii = 0; ii < stringno; ++ii)
879     MyFree(stringlist[ii]);
880 };
881 posextrastrings: /* empty */ | extrastrings;
882 extrastrings: extrastrings extrastring | extrastring;
883 extrastring: QSTRING
884 {
885   if (stringno < MAX_STRINGS)
886     stringlist[stringno++] = $1;
887   else
888     MyFree($1);
889 };
890
891 quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
892 quarantineitems: quarantineitems quarantineitem | quarantineitem;
893 quarantineitem: QSTRING '=' QSTRING ';'
894 {
895   struct qline *qconf = MyCalloc(1, sizeof(*qconf));
896   qconf->chname = $1;
897   qconf->reason = $3;
898   qconf->next = GlobalQuarantineList;
899   GlobalQuarantineList = qconf;
900 };
901
902 pseudoblock: PSEUDO QSTRING '{'
903 {
904   smap = MyCalloc(1, sizeof(struct s_map));
905   smap->command = $2;
906 }
907 pseudoitems '}' ';'
908 {
909   if (!smap->name || !smap->services)
910   {
911     parse_error("pseudo commands need a service name and list of target nicks.");
912     return 0;
913   }
914   if (register_mapping(smap))
915   {
916     smap->next = GlobalServiceMapList;
917     GlobalServiceMapList = smap;
918   }
919   else
920   {
921     struct nick_host *nh, *next;
922     for (nh = smap->services; nh; nh = next)
923     {
924       next = nh->next;
925       MyFree(nh);
926     }
927     MyFree(smap->name);
928     MyFree(smap->command);
929     MyFree(smap->prepend);
930     MyFree(smap);
931   }
932   smap = NULL;
933 };
934
935 pseudoitems: pseudoitem pseudoitems | pseudoitem;
936 pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags | error;
937 pseudoname: NAME '=' QSTRING ';'
938 {
939   smap->name = $3;
940 };
941 pseudoprepend: PREPEND '=' QSTRING ';'
942 {
943   smap->prepend = $3;
944 };
945 pseudonick: NICK '=' QSTRING ';'
946 {
947   char *sep = strchr($3, '@');
948
949   if (sep != NULL) {
950     size_t slen = strlen($3);
951     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
952     memcpy(nh->nick, $3, slen + 1);
953     nh->nicklen = sep - $3;
954     nh->next = smap->services;
955     smap->services = nh;
956   }
957   MyFree($3);
958 };
959 pseudoflags: FAST ';'
960 {
961   smap->flags |= SMAP_FAST;
962 };
963
964 iauthblock: IAUTH '{'
965 {
966   tconn = 60;
967   tping = 60;
968 } iauthitems '}' ';'
969 {
970   if (!host || !port) {
971     parse_error("IAuth block needs a server name and port.");
972     return 0;
973   }
974   iauth_connect(host, port, pass, tconn, tping);
975   MyFree(pass);
976   MyFree(host);
977   pass = host = NULL;
978   port = tconn = tping = 0;
979 };
980
981 iauthitems: iauthitem iauthitems | iauthitem;
982 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
983 iauthpass: PASS '=' QSTRING ';'
984 {
985   MyFree(pass);
986   pass = $3;
987 };
988 iauthhost: HOST '=' QSTRING ';'
989 {
990   MyFree(host);
991   host = $3;
992 };
993 iauthport: PORT '=' NUMBER ';'
994 {
995   port = $3;
996 };
997 iauthconnfreq: CONNECTFREQ '=' timespec ';'
998 {
999   tconn = $3;
1000 };
1001 iauthtimeout: TIMEOUT '=' timespec ';'
1002 {
1003   tping = $3;
1004 };