e1a0ace201f675f271bcda7cd754158d01731f92
[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 } '{' serveritems '}'
446 {
447  if (aconf->status == 0)
448  {
449    MyFree(aconf->host);
450    MyFree(aconf->name);
451    MyFree(aconf);
452    aconf = NULL;
453    parse_error("Bad server block");
454  }
455  else
456  {
457    aconf->next = GlobalConfList;
458    GlobalConfList = aconf;
459  }
460 } ';';
461 serveritems: serveritem serveritems | serveritem;
462 serveritem: servername | servermask | serverhub | serverleaf |
463              serveruworld | error;
464 servername: NAME '=' QSTRING
465 {
466  MyFree(aconf->name);
467  DupString(aconf->name, yylval.text);
468 } ';' ;
469 servermask: MASK '=' QSTRING
470 {
471  MyFree(aconf->host);
472  DupString(aconf->host, yylval.text);
473 } ';' ;
474 /* XXX - perhaps we should do this the hybrid way in connect blocks
475  * instead -A1kmm. */
476 serverhub: HUB '=' YES ';'
477 {
478  aconf->status |= CONF_HUB;
479  aconf->status &= ~CONF_LEAF;
480 }
481 | HUB '=' NO
482 {
483  aconf->status &= ~CONF_HUB;
484 } ';'; 
485 serverleaf: LEAF '=' YES ';'
486 {
487  if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
488   aconf->status |= CONF_LEAF;
489  else
490   parse_error("Server is both leaf and a hub");
491 }
492 | LEAF '=' NO ';'
493 {
494  aconf->status &= ~CONF_LEAF;
495 };
496 serveruworld: UWORLD '=' YES ';'
497 {
498  aconf->status |= CONF_UWORLD;
499  aconf->status &= ~CONF_LEAF;
500 }
501 | UWORLD '=' NO ';'
502 {
503   aconf->status &= ~CONF_UWORLD;
504 };
505
506 operblock: OPER
507 {
508   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
509   memset(aconf, 0, sizeof(*aconf));
510   memset(&privs, 0, sizeof(privs));
511   memset(&privs_dirty, 0, sizeof(privs_dirty));
512   aconf->status = CONF_OPERATOR;
513 } '{' operitems '}' ';'
514 {
515   if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL
516       && aconf->conn_class != NULL)
517   {
518     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
519     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
520     if (!PrivHas(&privs_dirty, PRIV_PROPAGATE)
521         && !PrivHas(&aconf->conn_class->privs_dirty, PRIV_PROPAGATE))
522       parse_error("Operator block for %s and class %s have no LOCAL setting", aconf->name, aconf->conn_class->cc_name);
523     aconf->next = GlobalConfList;
524     GlobalConfList = aconf;
525   }
526   else
527   {
528     log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
529     MyFree(aconf->name);
530     MyFree(aconf->passwd);
531     MyFree(aconf->host);
532     MyFree(aconf);
533     aconf = NULL;
534   }
535 };
536 operitems: operitem | operitems operitem;
537 operitem: opername | operpass | operhost | operclass | priv | error;
538
539 opername: NAME '=' QSTRING ';'
540 {
541   MyFree(aconf->name);
542   DupString(aconf->name, yylval.text);
543 };
544
545 operpass: PASS '=' QSTRING ';'
546 {
547   MyFree(aconf->passwd);
548   DupString(aconf->passwd, yylval.text);
549 };
550
551 operhost: HOST '=' QSTRING ';'
552 {
553  MyFree(aconf->host);
554  if (!strchr(yylval.text, '@'))
555  {
556    int uh_len;
557    char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3));
558    ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
559    aconf->host = b;
560  }
561  else
562    DupString(aconf->host, yylval.text);
563 };
564
565 operclass: CLASS '=' QSTRING ';'
566 {
567  aconf->conn_class = find_class(yylval.text);
568 };
569
570 priv: privtype '=' yesorno ';'
571 {
572   PrivSet(&privs_dirty, $1);
573   if (($3 == 1) ^ invert)
574     PrivSet(&privs, $1);
575   else
576     PrivClr(&privs, $1);
577   invert = 0;
578 };
579
580 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
581           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
582           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
583           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
584           KILL { $$ = PRIV_KILL; } |
585           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
586           TPRIV_REHASH { $$ = PRIV_REHASH; } |
587           TPRIV_RESTART { $$ = PRIV_RESTART; } |
588           TPRIV_DIE { $$ = PRIV_DIE; } |
589           TPRIV_GLINE { $$ = PRIV_GLINE; } |
590           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
591           JUPE { $$ = PRIV_JUPE; } |
592           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
593           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
594           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
595           TPRIV_SET { $$ = PRIV_SET; } |
596           TPRIV_WHOX { $$ = PRIV_WHOX; } |
597           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
598           TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
599           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
600           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
601           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
602           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
603           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
604           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
605           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
606           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
607           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
608           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
609           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; };
610
611 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
612
613 /* The port block... */
614 portblock: PORT {
615   port = 0;
616   host = NULL;
617   /* Hijack these for is_server, is_hidden to cut down on globals... */
618   tconn = 0;
619   tping = 0;
620   /* and this for mask... */
621   pass = NULL;
622 } '{' portitems '}' ';'
623 {
624   if (port > 0 && port <= 0xFFFF)
625   {
626     add_listener(port, host, pass, tconn, tping);
627   }
628   else
629   {
630     parse_error("Bad port block");
631   }
632   MyFree(host);
633   MyFree(pass);
634   host = pass = NULL;
635 };
636 portitems: portitem portitems | portitem;
637 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
638 portnumber: PORT '=' NUMBER ';'
639 {
640   port = yylval.num;
641 };
642
643 portvhost: VHOST '=' QSTRING ';'
644 {
645   MyFree(host);
646   DupString(host, yylval.text);
647 };
648
649 portmask: MASK '=' QSTRING ';'
650 {
651   MyFree(pass);
652   DupString(pass, yylval.text);
653 };
654
655 portserver: SERVER '=' YES ';'
656 {
657   tconn = -1;
658 } | SERVER '=' NO ';'
659 {
660   tconn = 0;
661 };
662
663 porthidden: HIDDEN '=' YES ';'
664 {
665   tping = -1;
666 } | HIDDEN '=' NO ';'
667 {
668   tping = 0;
669 };
670
671 clientblock: CLIENT
672 {
673   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
674   memset(aconf, 0, sizeof(*aconf));
675   aconf->status = CONF_CLIENT;
676 } '{' clientitems '}'
677 {
678   if ((aconf->host != NULL || aconf->name!=NULL))
679   {
680     if (aconf->host == NULL)
681       DupString(aconf->host, "");
682     if (aconf->name == NULL)
683       DupString(aconf->name, "");
684     if (aconf->conn_class == NULL)
685       aconf->conn_class = find_class("default");
686     aconf->next = GlobalConfList;
687     GlobalConfList = aconf;
688     aconf = NULL;
689   }
690   else
691   {
692    MyFree(aconf->host);
693    MyFree(aconf->passwd);
694    MyFree(aconf);
695    aconf = NULL;
696    parse_error("Bad client block");
697   }
698 } ';';
699 clientitems: clientitem clientitems | clientitem;
700 clientitem: clienthost | clientclass | clientpass | clientip | error;
701 clientip: IP '=' QSTRING ';'
702 {
703   MyFree(aconf->host);
704   DupString(aconf->host, yylval.text);
705 };
706
707 clienthost: HOST '=' QSTRING ';'
708 {
709   MyFree(aconf->name);
710   DupString(aconf->name, yylval.text);
711 };
712
713 clientclass: CLASS '=' QSTRING ';'
714 {
715   aconf->conn_class = find_class(yylval.text);
716 };
717
718 clientpass: PASS '=' QSTRING ';'
719 {
720   MyFree(aconf->passwd);
721   DupString(aconf->passwd, yylval.text);
722 };
723
724 killblock: KILL
725 {
726   dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
727   memset(dconf, 0, sizeof(*dconf));
728 } '{' killitems '}'
729 {
730   if (dconf->hostmask != NULL)
731   {
732     if (dconf->usermask == NULL)
733       DupString(dconf->usermask, "*");
734     dconf->next = denyConfList;
735     denyConfList = dconf;
736     dconf = NULL;
737   }
738   else
739   {
740     MyFree(dconf->hostmask);
741     MyFree(dconf->message);
742     MyFree(dconf);
743     dconf = NULL;
744     parse_error("Bad kill block");
745   }
746 } ';';
747 killitems: killitem killitems | killitem;
748 killitem: killuhost | killreal | killreasonfile | killreason | error;
749 killuhost: HOST '=' QSTRING ';'
750 {
751   char *u, *h;
752   dconf->flags &= ~DENY_FLAGS_REALNAME;
753   MyFree(dconf->hostmask);
754   MyFree(dconf->usermask);
755   if ((h = strchr(yylval.text, '@')) == NULL)
756   {
757     u = "*";
758     h = yylval.text;
759   }
760   else
761   {
762     u = yylval.text;
763     h++;
764   }
765   DupString(dconf->hostmask, h);
766   DupString(dconf->usermask, u);
767   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
768 };
769
770 killreal: REAL '=' QSTRING ';'
771 {
772  dconf->flags &= ~DENY_FLAGS_IP;
773  dconf->flags |= DENY_FLAGS_REALNAME;
774  MyFree(dconf->hostmask);
775  /* Leave usermask so you can specify user and real... */
776  DupString(dconf->hostmask, yylval.text);
777 };
778
779 killreason: REASON '=' QSTRING ';'
780 {
781  dconf->flags &= DENY_FLAGS_FILE;
782  MyFree(dconf->message);
783  DupString(dconf->message, yylval.text);
784 };
785
786 killreasonfile: TFILE '=' QSTRING ';'
787 {
788  dconf->flags |= DENY_FLAGS_FILE;
789  MyFree(dconf->message);
790  DupString(dconf->message, yylval.text);
791 };
792
793 cruleblock: CRULE
794 {
795   host = pass = NULL;
796   tconn = CRULE_AUTO;
797 } '{' cruleitems '}'
798 {
799   struct CRuleNode *node;
800   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
801   {
802     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
803     p->hostmask = host;
804     p->rule = pass;
805     p->type = tconn;
806     p->node = node;
807     p->next = cruleConfList;
808     cruleConfList = p;
809   }
810   else
811   {
812     MyFree(host);
813     MyFree(pass);
814     parse_error("Bad CRule block");
815   }
816 } ';';
817
818 cruleitems: cruleitem cruleitems | cruleitem;
819 cruleitem: cruleserver | crulerule | cruleall | error;
820
821 cruleserver: SERVER '=' QSTRING ';'
822 {
823   MyFree(host);
824   collapse(yylval.text);
825   DupString(host, yylval.text);
826 };
827
828 crulerule: RULE '=' QSTRING ';'
829 {
830  MyFree(pass);
831  DupString(pass, yylval.text);
832 };
833
834 cruleall: ALL '=' YES ';'
835 {
836  tconn = CRULE_ALL;
837 } | ALL '=' NO ';'
838 {
839  tconn = CRULE_AUTO;
840 };
841
842 motdblock: MOTD {
843  pass = host = NULL;
844 } '{' motditems '}'
845 {
846   if (host != NULL && pass != NULL)
847     motd_add(host, pass);
848   MyFree(host);
849   MyFree(pass);
850   host = pass = NULL;
851 } ';';
852
853 motditems: motditem motditems | motditem;
854 motditem: motdhost | motdfile | error;
855 motdhost: HOST '=' QSTRING ';'
856 {
857   DupString(host, yylval.text);
858 };
859
860 motdfile: TFILE '=' QSTRING ';'
861 {
862   DupString(pass, yylval.text);
863 };
864
865 featuresblock: FEATURES '{' featureitems '}' ';';
866 featureitems: featureitems featureitem | featureitem;
867
868 featureitem: QSTRING
869 {
870   stringlist[0] = $1;
871   stringno = 1;
872 } '=' stringlist ';';
873
874 stringlist: QSTRING
875 {
876   stringlist[1] = $1;
877   stringno = 2;
878 } posextrastrings
879 {
880   feature_set(NULL, (const char * const *)stringlist, stringno);
881 };
882 posextrastrings: /* empty */ | extrastrings;
883 extrastrings: extrastrings extrastring | extrastring;
884 extrastring: QSTRING
885 {
886   if (stringno < MAX_STRINGS)
887     stringlist[stringno++] = $1;
888 };
889
890 quarantineblock: QUARANTINE '{'
891 {
892   if (qconf != NULL)
893     qconf = (struct qline*) MyMalloc(sizeof(*qconf));
894   else
895   {
896     if (qconf->chname != NULL)
897       MyFree(qconf->chname);
898     if (qconf->reason != NULL)
899       MyFree(qconf->reason);
900   }
901   memset(qconf, 0, sizeof(*qconf));
902 } quarantineitems '}' ';'
903 {
904   if (qconf->chname == NULL || qconf->reason == NULL)
905   {
906     log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
907               "and a reason.");
908     return 0;
909   }
910   qconf->next = GlobalQuarantineList;
911   GlobalQuarantineList = qconf;
912   qconf = NULL;
913 };
914
915 quarantineitems: CHANNEL NAME '=' QSTRING ';'
916 {
917   DupString(qconf->chname, yylval.text);
918 } | REASON '=' QSTRING ';'
919 {
920   DupString(qconf->reason, yylval.text);
921 };
922
923 pseudoblock: PSEUDO QSTRING '{'
924 {
925   smap = MyCalloc(1, sizeof(struct s_map));
926   DupString(smap->command, $2);
927 }
928 pseudoitems '}' ';'
929 {
930   if (!smap->name || !smap->services)
931   {
932     log_write(LS_CONFIG, L_ERROR, 0, "pseudo commands need a service name and list of target nicks.");
933     return 0;
934   }
935   if (register_mapping(smap))
936   {
937     smap->next = GlobalServiceMapList;
938     GlobalServiceMapList = smap;
939   }
940   else
941   {
942     struct nick_host *nh, *next;
943     for (nh = smap->services; nh; nh = next)
944     {
945       next = nh->next;
946       MyFree(nh);
947     }
948     MyFree(smap->name);
949     MyFree(smap->command);
950     MyFree(smap->prepend);
951     MyFree(smap);
952   }
953   smap = NULL;
954 };
955
956 pseudoitems: pseudoitem pseudoitems | pseudoitem;
957 pseudoitem: pseudoname | pseudoprepend | pseudonick | error;
958 pseudoname: NAME '=' QSTRING ';'
959 {
960   DupString(smap->name, yylval.text);
961 };
962 pseudoprepend: PREPEND '=' QSTRING ';'
963 {
964   DupString(smap->prepend, yylval.text);
965 };
966 pseudonick: NICK '=' QSTRING ';'
967 {
968   char *sep = strchr(yylval.text, '@');
969
970   if (sep != NULL) {
971     size_t slen = strlen(yylval.text);
972     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
973     memcpy(nh->nick, yylval.text, slen + 1);
974     nh->nicklen = sep - yylval.text;
975     nh->next = smap->services;
976     smap->services = nh;
977   }
978 };
979
980 iauthblock: IAUTH '{'
981 {
982   pass = host = NULL;
983   port = 0;
984   tconn = 60;
985   tping = 60;
986 } iauthitems '}' ';'
987 {
988   if (!name || !host || !port) {
989     log_write(LS_CONFIG, L_ERROR, 0, "IAuth block needs a server name and port.");
990     return 0;
991   }
992   iauth_connect(host, port, pass, tconn, tping);
993   MyFree(pass);
994   MyFree(host);
995   pass = host = NULL;
996 };
997
998 iauthitems: iauthitem iauthitems | iauthitem;
999 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
1000 iauthpass: PASS '=' QSTRING ';'
1001 {
1002   MyFree(pass);
1003   DupString(pass, yylval.text);
1004 };
1005 iauthhost: HOST '=' QSTRING ';'
1006 {
1007   MyFree(host);
1008   DupString(host, yylval.text);
1009 };
1010 iauthport: PORT '=' NUMBER ';'
1011 {
1012   port = yylval.num;
1013 };
1014 iauthconnfreq: CONNECTFREQ '=' timespec ';'
1015 {
1016   tconn = yylval.num;
1017 };
1018 iauthtimeout: TIMEOUT '=' timespec ';'
1019 {
1020   tping = yylval.num;
1021 };