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