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