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