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