Clear information leaks from one conf block to another.
[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, *origin, *hub_limit;
73   char *stringlist[MAX_STRINGS];
74   struct ConnectionClass *c_class;
75   struct DenyConf *dconf;
76   struct ServerConf *sconf;
77   struct qline *qconf = NULL;
78   struct s_map *smap;
79   struct Privs privs;
80   struct Privs privs_dirty;
81
82 static void parse_error(char *pattern,...) {
83   static char error_buffer[1024];
84   va_list vl;
85   va_start(vl,pattern);
86   ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
87   va_end(vl);
88   yyerror(error_buffer);
89 }
90
91 %}
92
93 %token <text> QSTRING
94 %token <num> NUMBER
95 %token <text> FNAME
96
97 %token GENERAL
98 %token ADMIN
99 %token LOCATION
100 %token CONTACT
101 %token CONNECT
102 %token CLASS
103 %token CHANNEL
104 %token PINGFREQ
105 %token CONNECTFREQ
106 %token MAXLINKS
107 %token MAXHOPS
108 %token SENDQ
109 %token NAME
110 %token HOST
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 IP
151 %token FEATURES
152 %token QUARANTINE
153 %token PSEUDO
154 %token PREPEND
155 %token USERMODE
156 %token IAUTH
157 %token TIMEOUT
158 /* and now a lot of priviledges... */
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
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 arithmatic 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                 = {
250                         $$ = -$2;
251                 } */
252                 | '(' expr ')' {
253                         $$ = $2;
254                 }
255                 ;
256
257 jupeblock: JUPE '{' jupeitems '}' ';' ;
258 jupeitems: jupeitem jupeitems | jupeitem;
259 jupeitem: jupenick | error;
260 jupenick: NICK '=' QSTRING
261 {
262   addNickJupes($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     DupString(localConf.name, $3);
287   else if (strcmp(localConf.name, $3))
288     parse_error("Redefinition of server name %s (%s)", $3,
289                 localConf.name);
290 };
291
292 generaldesc: DESCRIPTION '=' QSTRING ';'
293 {
294   MyFree(localConf.description);
295   DupString(localConf.description, $3);
296   ircd_strncpy(cli_info(&me), $3, REALLEN);
297 };
298
299 generalvhost: VHOST '=' QSTRING ';'
300 {
301   ircd_aton(&VirtualHost.addr, $3);
302 };
303
304 adminblock: ADMIN '{' adminitems '}'
305 {
306   if (localConf.location1 == NULL)
307     DupString(localConf.location1, "");
308   if (localConf.location2 == NULL)
309     DupString(localConf.location2, "");
310   if (localConf.contact == NULL)
311     DupString(localConf.contact, "");
312 } ';';
313 adminitems: adminitems adminitem | adminitem;
314 adminitem: adminlocation | admincontact | error;
315 adminlocation: LOCATION '=' QSTRING ';'
316 {
317  if (localConf.location1 == NULL)
318   DupString(localConf.location1, $3);
319  else if (localConf.location2 == NULL)
320   DupString(localConf.location2, $3);
321  /* Otherwise just drop it. -A1kmm */
322 };
323 admincontact: CONTACT '=' QSTRING ';'
324 {
325  if (localConf.contact != NULL)
326    MyFree(localConf.contact);
327  DupString(localConf.contact, $3);
328 };
329
330 classblock: CLASS {
331   tping = 90;
332 } '{' classitems '}'
333 {
334   if (name != NULL)
335   {
336     struct ConnectionClass *c_class;
337     add_class(name, tping, tconn, maxlinks, sendq);
338     c_class = find_class(name);
339     c_class->default_umode = pass;
340     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
341     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
342   }
343   else {
344    parse_error("Missing name in class block");
345   }
346   name = NULL;
347   pass = NULL;
348   tconn = 0;
349   maxlinks = 0;
350   sendq = 0;
351   memset(&privs, 0, sizeof(privs));
352   memset(&privs_dirty, 0, sizeof(privs_dirty));
353 } ';';
354 classitems: classitem classitems | classitem;
355 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
356            classsendq | classusermode | priv | error;
357 classname: NAME '=' QSTRING ';'
358 {
359   MyFree(name);
360   DupString(name, $3);
361 };
362 classpingfreq: PINGFREQ '=' timespec ';'
363 {
364   tping = $3;
365 };
366 classconnfreq: CONNECTFREQ '=' timespec ';'
367 {
368   tconn = $3;
369 };
370 classmaxlinks: MAXLINKS '=' expr ';'
371 {
372   maxlinks = $3;
373 };
374 classsendq: SENDQ '=' sizespec ';'
375 {
376   sendq = $3;
377 };
378 classusermode: USERMODE '=' QSTRING ';'
379 {
380   MyFree(pass);
381   DupString(pass, $3);
382 };
383
384 connectblock: CONNECT
385 {
386  maxlinks = 65535;
387 } '{' connectitems '}'
388 {
389  if (name != NULL && pass != NULL && host != NULL && c_class != NULL
390      && !strchr(host, '*') && !strchr(host, '?'))
391  {
392    struct ConfItem *aconf = make_conf(CONF_SERVER);
393    aconf->name = name;
394    aconf->origin_name = origin;
395    aconf->passwd = pass;
396    aconf->conn_class = c_class;
397    aconf->address.port = port;
398    aconf->host = host;
399    aconf->maximum = maxlinks;
400    aconf->hub_limit = hub_limit;
401    lookup_confhost(aconf);
402  }
403  else
404  {
405    MyFree(name);
406    MyFree(pass);
407    MyFree(host);
408    MyFree(origin);
409    MyFree(hub_limit);
410    parse_error("Bad connect block");
411  }
412  name = pass = host = origin = hub_limit = NULL;
413  c_class = NULL;
414  port = 0;
415 }';';
416 connectitems: connectitem connectitems | connectitem;
417 connectitem: connectname | connectpass | connectclass | connecthost
418               | connectport | connectvhost | connectleaf | connecthub
419               | connecthublimit | connectmaxhops | error;
420 connectname: NAME '=' QSTRING ';'
421 {
422  MyFree(name);
423  DupString(name, $3);
424 };
425 connectpass: PASS '=' QSTRING ';'
426 {
427  MyFree(pass);
428  DupString(pass, $3);
429 };
430 connectclass: CLASS '=' QSTRING ';'
431 {
432  c_class = find_class($3);
433 };
434 connecthost: HOST '=' QSTRING ';'
435 {
436  MyFree(host);
437  DupString(host, $3);
438 };
439 connectport: PORT '=' NUMBER ';'
440 {
441  port = $3;
442 };
443 connectvhost: VHOST '=' QSTRING ';'
444 {
445  MyFree(origin);
446  DupString(origin, $3);
447 };
448 connectleaf: LEAF ';'
449 {
450  maxlinks = 0;
451 };
452 connecthub: HUB ';'
453 {
454  MyFree(hub_limit);
455  DupString(hub_limit, "*");
456 };
457 connecthublimit: HUB '=' QSTRING ';'
458 {
459  MyFree(hub_limit);
460  DupString(hub_limit, $3);
461 };
462 connectmaxhops: MAXHOPS '=' expr ';'
463 {
464   maxlinks = $3;
465 }
466
467 uworldblock: UWORLD '{' uworlditems '}' ';'
468 {
469  if (name)
470  {
471   struct ConfItem *aconf = make_conf(CONF_UWORLD);
472   aconf->name = name;
473  }
474  else
475  {
476   MyFree(name);
477   parse_error("Bad UWorld block");
478  }
479  name = NULL;
480 };
481 uworlditems: uworlditem uworlditems | uworlditem;
482 uworlditem: uworldname | error;
483 uworldname: NAME '=' QSTRING ';'
484 {
485  MyFree(name);
486  DupString(name, $3);
487 };
488
489 operblock: OPER '{' operitems '}' ';'
490 {
491   if (name && pass && host && c_class)
492   {
493     struct ConfItem *aconf = make_conf(CONF_OPERATOR);
494     aconf->name = name;
495     aconf->passwd = pass;
496     aconf->host = host;
497     aconf->conn_class = c_class;
498     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
499     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
500     if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
501         && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
502       parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
503   }
504   else
505   {
506     log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
507     MyFree(name);
508     MyFree(pass);
509     MyFree(host);
510   }
511   name = pass = host = NULL;
512   c_class = NULL;
513   memset(&privs, 0, sizeof(privs));
514   memset(&privs_dirty, 0, sizeof(privs_dirty));
515 };
516 operitems: operitem | operitems operitem;
517 operitem: opername | operpass | operhost | operclass | priv | error;
518 opername: NAME '=' QSTRING ';'
519 {
520   MyFree(name);
521   DupString(name, $3);
522 };
523 operpass: PASS '=' QSTRING ';'
524 {
525   MyFree(pass);
526   DupString(pass, $3);
527 };
528 operhost: HOST '=' QSTRING ';'
529 {
530  MyFree(host);
531  if (!strchr($3, '@'))
532  {
533    int uh_len;
534    char *b = (char*) MyMalloc((uh_len = strlen($3)+3));
535    ircd_snprintf(0, b, uh_len, "*@%s", $3);
536    host = b;
537  }
538  else
539    DupString(host, $3);
540 };
541 operclass: CLASS '=' QSTRING ';'
542 {
543  c_class = find_class($3);
544 };
545
546 priv: privtype '=' yesorno ';'
547 {
548   FlagSet(&privs_dirty, $1);
549   if (($3 == 1) ^ invert)
550     FlagSet(&privs, $1);
551   else
552     FlagClr(&privs, $1);
553   invert = 0;
554 };
555
556 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
557           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
558           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
559           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
560           KILL { $$ = PRIV_KILL; } |
561           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
562           TPRIV_REHASH { $$ = PRIV_REHASH; } |
563           TPRIV_RESTART { $$ = PRIV_RESTART; } |
564           TPRIV_DIE { $$ = PRIV_DIE; } |
565           TPRIV_GLINE { $$ = PRIV_GLINE; } |
566           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
567           JUPE { $$ = PRIV_JUPE; } |
568           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
569           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
570           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
571           TPRIV_SET { $$ = PRIV_SET; } |
572           TPRIV_WHOX { $$ = PRIV_WHOX; } |
573           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
574           TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
575           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
576           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
577           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
578           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
579           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
580           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
581           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
582           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
583           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
584           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
585           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; };
586
587 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
588
589 /* The port block... */
590 portblock: PORT '{' portitems '}' ';'
591 {
592   if (port > 0 && port <= 0xFFFF)
593   {
594     add_listener(port, host, pass, tconn, tping);
595   }
596   else
597   {
598     parse_error("Bad port block");
599   }
600   MyFree(host);
601   MyFree(pass);
602   host = pass = NULL;
603   port = tconn = tping = 0;
604 };
605 portitems: portitem portitems | portitem;
606 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
607 portnumber: PORT '=' NUMBER ';'
608 {
609   port = $3;
610 };
611
612 portvhost: VHOST '=' QSTRING ';'
613 {
614   MyFree(host);
615   DupString(host, $3);
616 };
617
618 portmask: MASK '=' QSTRING ';'
619 {
620   MyFree(pass);
621   DupString(pass, $3);
622 };
623
624 portserver: SERVER '=' YES ';'
625 {
626   tconn = -1;
627 } | SERVER '=' NO ';'
628 {
629   tconn = 0;
630 };
631
632 porthidden: HIDDEN '=' YES ';'
633 {
634   tping = -1;
635 } | HIDDEN '=' NO ';'
636 {
637   tping = 0;
638 };
639
640 clientblock: CLIENT
641 {
642   maxlinks = 65535;
643 }
644 '{' clientitems '}' ';'
645 {
646   if (host && name)
647   {
648     struct ConfItem *aconf = make_conf(CONF_CLIENT);
649     aconf->host = host;
650     aconf->name = name;
651     aconf->conn_class = c_class ? c_class : find_class("default");
652     aconf->maximum = maxlinks;
653   }
654   else
655   {
656     MyFree(host);
657     MyFree(name);
658     parse_error("Bad client block");
659   }
660   host = name = NULL;
661   c_class = NULL;
662 };
663 clientitems: clientitem clientitems | clientitem;
664 clientitem: clienthost | clientclass | clientpass | clientip
665   | clientmaxlinks | error;
666 clientip: IP '=' QSTRING ';'
667 {
668   MyFree(host);
669   DupString(host, $3);
670 };
671 clienthost: HOST '=' QSTRING ';'
672 {
673   MyFree(name);
674   DupString(name, $3);
675 };
676 clientclass: CLASS '=' QSTRING ';'
677 {
678   c_class = find_class($3);
679 };
680 clientpass: PASS '=' QSTRING ';'
681 {
682   MyFree(pass);
683   DupString(pass, $3);
684 };
685 clientmaxlinks: MAXLINKS '=' expr ';'
686 {
687   maxlinks = $3;
688 };
689
690 killblock: KILL
691 {
692   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
693 } '{' killitems '}'
694 {
695   if (dconf->hostmask != NULL)
696   {
697     if (dconf->usermask == NULL)
698       DupString(dconf->usermask, "*");
699     dconf->next = denyConfList;
700     denyConfList = dconf;
701   }
702   else
703   {
704     MyFree(dconf->hostmask);
705     MyFree(dconf->message);
706     MyFree(dconf);
707     parse_error("Bad kill block");
708   }
709   dconf = NULL;
710 } ';';
711 killitems: killitem killitems | killitem;
712 killitem: killuhost | killreal | killreasonfile | killreason | error;
713 killuhost: HOST '=' QSTRING ';'
714 {
715   char *u, *h;
716   dconf->flags &= ~DENY_FLAGS_REALNAME;
717   MyFree(dconf->hostmask);
718   MyFree(dconf->usermask);
719   if ((h = strchr($3, '@')) == NULL)
720   {
721     u = "*";
722     h = $3;
723   }
724   else
725   {
726     u = $3;
727     h++;
728   }
729   DupString(dconf->hostmask, h);
730   DupString(dconf->usermask, u);
731   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
732 };
733
734 killreal: REAL '=' QSTRING ';'
735 {
736  dconf->flags &= ~DENY_FLAGS_IP;
737  dconf->flags |= DENY_FLAGS_REALNAME;
738  MyFree(dconf->hostmask);
739  /* Leave usermask so you can specify user and real... */
740  DupString(dconf->hostmask, $3);
741 };
742
743 killreason: REASON '=' QSTRING ';'
744 {
745  dconf->flags &= DENY_FLAGS_FILE;
746  MyFree(dconf->message);
747  DupString(dconf->message, $3);
748 };
749
750 killreasonfile: TFILE '=' QSTRING ';'
751 {
752  dconf->flags |= DENY_FLAGS_FILE;
753  MyFree(dconf->message);
754  DupString(dconf->message, $3);
755 };
756
757 cruleblock: CRULE
758 {
759   tconn = CRULE_AUTO;
760 } '{' cruleitems '}' ';'
761 {
762   struct CRuleNode *node;
763   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
764   {
765     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
766     p->hostmask = host;
767     p->rule = pass;
768     p->type = tconn;
769     p->node = node;
770     p->next = cruleConfList;
771     cruleConfList = p;
772   }
773   else
774   {
775     MyFree(host);
776     MyFree(pass);
777     parse_error("Bad CRule block");
778   }
779   host = pass = NULL;
780 };
781
782 cruleitems: cruleitem cruleitems | cruleitem;
783 cruleitem: cruleserver | crulerule | cruleall | error;
784
785 cruleserver: SERVER '=' QSTRING ';'
786 {
787   MyFree(host);
788   collapse($3);
789   DupString(host, $3);
790 };
791
792 crulerule: RULE '=' QSTRING ';'
793 {
794  MyFree(pass);
795  DupString(pass, $3);
796 };
797
798 cruleall: ALL '=' YES ';'
799 {
800  tconn = CRULE_ALL;
801 } | ALL '=' NO ';'
802 {
803  tconn = CRULE_AUTO;
804 };
805
806 motdblock: MOTD '{' motditems '}' ';'
807 {
808   if (host != NULL && pass != NULL)
809     motd_add(host, pass);
810   MyFree(host);
811   MyFree(pass);
812   host = pass = NULL;
813 };
814
815 motditems: motditem motditems | motditem;
816 motditem: motdhost | motdfile | error;
817 motdhost: HOST '=' QSTRING ';'
818 {
819   DupString(host, $3);
820 };
821
822 motdfile: TFILE '=' QSTRING ';'
823 {
824   DupString(pass, $3);
825 };
826
827 featuresblock: FEATURES '{' featureitems '}' ';';
828 featureitems: featureitems featureitem | featureitem;
829
830 featureitem: QSTRING
831 {
832   stringlist[0] = $1;
833   stringno = 1;
834 } '=' stringlist ';';
835
836 stringlist: QSTRING
837 {
838   stringlist[1] = $1;
839   stringno = 2;
840 } posextrastrings
841 {
842   feature_set(NULL, (const char * const *)stringlist, stringno);
843 };
844 posextrastrings: /* empty */ | extrastrings;
845 extrastrings: extrastrings extrastring | extrastring;
846 extrastring: QSTRING
847 {
848   if (stringno < MAX_STRINGS)
849     stringlist[stringno++] = $1;
850 };
851
852 quarantineblock: QUARANTINE '{'
853 {
854   qconf = (struct qline*) MyCalloc(1, sizeof(*qconf));
855 } quarantineitems '}' ';'
856 {
857   if (qconf->chname == NULL || qconf->reason == NULL)
858   {
859     log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
860               "and a reason.");
861     return 0;
862   }
863   qconf->next = GlobalQuarantineList;
864   GlobalQuarantineList = qconf;
865   qconf = NULL;
866 };
867
868 quarantineitems: CHANNEL NAME '=' QSTRING ';'
869 {
870   DupString(qconf->chname, $4);
871 } | REASON '=' QSTRING ';'
872 {
873   DupString(qconf->reason, $3);
874 };
875
876 pseudoblock: PSEUDO QSTRING '{'
877 {
878   smap = MyCalloc(1, sizeof(struct s_map));
879   DupString(smap->command, $2);
880 }
881 pseudoitems '}' ';'
882 {
883   if (!smap->name || !smap->services)
884   {
885     log_write(LS_CONFIG, L_ERROR, 0, "pseudo commands need a service name and list of target nicks.");
886     return 0;
887   }
888   if (register_mapping(smap))
889   {
890     smap->next = GlobalServiceMapList;
891     GlobalServiceMapList = smap;
892   }
893   else
894   {
895     struct nick_host *nh, *next;
896     for (nh = smap->services; nh; nh = next)
897     {
898       next = nh->next;
899       MyFree(nh);
900     }
901     MyFree(smap->name);
902     MyFree(smap->command);
903     MyFree(smap->prepend);
904     MyFree(smap);
905   }
906   smap = NULL;
907 };
908
909 pseudoitems: pseudoitem pseudoitems | pseudoitem;
910 pseudoitem: pseudoname | pseudoprepend | pseudonick | error;
911 pseudoname: NAME '=' QSTRING ';'
912 {
913   DupString(smap->name, $3);
914 };
915 pseudoprepend: PREPEND '=' QSTRING ';'
916 {
917   DupString(smap->prepend, $3);
918 };
919 pseudonick: NICK '=' QSTRING ';'
920 {
921   char *sep = strchr($3, '@');
922
923   if (sep != NULL) {
924     size_t slen = strlen($3);
925     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
926     memcpy(nh->nick, $3, slen + 1);
927     nh->nicklen = sep - $3;
928     nh->next = smap->services;
929     smap->services = nh;
930   }
931 };
932
933 iauthblock: IAUTH '{'
934 {
935   tconn = 60;
936   tping = 60;
937 } iauthitems '}' ';'
938 {
939   if (!host || !port) {
940     log_write(LS_CONFIG, L_ERROR, 0, "IAuth block needs a server name and port.");
941     return 0;
942   }
943   iauth_connect(host, port, pass, tconn, tping);
944   MyFree(pass);
945   MyFree(host);
946   pass = host = NULL;
947   port = 0;
948 };
949
950 iauthitems: iauthitem iauthitems | iauthitem;
951 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
952 iauthpass: PASS '=' QSTRING ';'
953 {
954   MyFree(pass);
955   DupString(pass, $3);
956 };
957 iauthhost: HOST '=' QSTRING ';'
958 {
959   MyFree(host);
960   DupString(host, $3);
961 };
962 iauthport: PORT '=' NUMBER ';'
963 {
964   port = $3;
965 };
966 iauthconnfreq: CONNECTFREQ '=' timespec ';'
967 {
968   tconn = $3;
969 };
970 iauthtimeout: TIMEOUT '=' timespec ';'
971 {
972   tping = $3;
973 };