d2f37632723716f8852c22271b81fd4a974a85b2
[ircu2.10.12-pk.git] / ircd / ircd_parser.y
1 /*
2  * ircd_parser.y: A yacc/bison parser for ircd config files.
3  * This is part of ircu, an Internet Relay Chat server.
4  * The contents of this file are Copyright 2001 Diane Bruce,
5  * Andrew Miller, the ircd-hybrid team and the ircu team.
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19  *  USA.
20  * $Id$
21  */
22 %{
23
24 #include "config.h"
25 #include "s_conf.h"
26 #include "class.h"
27 #include "client.h"
28 #include "crule.h"
29 #include "ircd_features.h"
30 #include "fileio.h"
31 #include "gline.h"
32 #include "hash.h"
33 #include "ircd.h"
34 #include "ircd_alloc.h"
35 #include "ircd_auth.h"
36 #include "ircd_chattr.h"
37 #include "ircd_log.h"
38 #include "ircd_reply.h"
39 #include "ircd_snprintf.h"
40 #include "ircd_string.h"
41 #include "list.h"
42 #include "listener.h"
43 #include "match.h"
44 #include "motd.h"
45 #include "numeric.h"
46 #include "numnicks.h"
47 #include "opercmds.h"
48 #include "parse.h"
49 #include "res.h"
50 #include "s_bsd.h"
51 #include "s_conf.h"
52 #include "s_debug.h"
53 #include "s_misc.h"
54 #include "send.h"
55 #include "struct.h"
56 #include "sys.h"
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include <arpa/inet.h>
61 #define MAX_STRINGS 80 /* Maximum number of feature params. */
62   extern struct LocalConf   localConf;
63   extern struct DenyConf*   denyConfList;
64   extern struct CRuleConf*  cruleConfList;
65   extern struct ServerConf* serverConfList;
66   extern struct s_map*      GlobalServiceMapList;
67   extern struct qline*      GlobalQuarantineList;
68
69   int yylex(void);
70   /* Now all the globals we need :/... */
71   int tping, tconn, maxlinks, sendq, port, invert, stringno;
72   char *name, *pass, *host, *ip, *username, *origin, *hub_limit;
73   char *stringlist[MAX_STRINGS];
74   struct ConnectionClass *c_class;
75   struct DenyConf *dconf;
76   struct ServerConf *sconf;
77   struct s_map *smap;
78   struct Privs privs;
79   struct Privs privs_dirty;
80
81 static void parse_error(char *pattern,...) {
82   static char error_buffer[1024];
83   va_list vl;
84   va_start(vl,pattern);
85   ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
86   va_end(vl);
87   yyerror(error_buffer);
88 }
89
90 %}
91
92 %token <text> QSTRING
93 %token <num> NUMBER
94 %token <text> FNAME
95
96 %token GENERAL
97 %token ADMIN
98 %token LOCATION
99 %token CONTACT
100 %token CONNECT
101 %token CLASS
102 %token CHANNEL
103 %token PINGFREQ
104 %token CONNECTFREQ
105 %token MAXLINKS
106 %token MAXHOPS
107 %token SENDQ
108 %token NAME
109 %token HOST
110 %token IP
111 %token USERNAME
112 %token PASS
113 %token LOCAL
114 %token SECONDS
115 %token MINUTES
116 %token HOURS
117 %token DAYS
118 %token WEEKS
119 %token MONTHS
120 %token YEARS
121 %token DECADES
122 %token BYTES
123 %token KBYTES
124 %token MBYTES
125 %token GBYTES
126 %token TBYTES
127 %token SERVER
128 %token PORT
129 %token MASK
130 %token HUB
131 %token LEAF
132 %token UWORLD
133 %token YES
134 %token NO
135 %token OPER
136 %token VHOST
137 %token HIDDEN
138 %token MOTD
139 %token JUPE
140 %token NICK
141 %token NUMERIC
142 %token DESCRIPTION
143 %token CLIENT
144 %token KILL
145 %token CRULE
146 %token REAL
147 %token REASON
148 %token TFILE
149 %token RULE
150 %token ALL
151 %token FEATURES
152 %token QUARANTINE
153 %token PSEUDO
154 %token PREPEND
155 %token USERMODE
156 %token IAUTH
157 %token TIMEOUT
158 %token FAST
159 /* and now a lot of privileges... */
160 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
161 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
162 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_LOCAL_JUPE TPRIV_LOCAL_BADCHAN
163 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
164 %token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
165 %token TPRIV_UNLIMIT_QUERY TPRIV_DISPLAY TPRIV_SEE_OPERS TPRIV_WIDE_GLINE
166 %token TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE TPRIV_APASS_OPMODE
167 /* and some types... */
168 %type <num> sizespec
169 %type <num> timespec timefactor factoredtimes factoredtime
170 %type <num> expr yesorno privtype
171 %left '+' '-'
172 %left '*' '/'
173
174 %union{
175  char *text;
176  int num;
177 }
178
179 %%
180 /* Blocks in the config file... */
181 blocks: blocks block | block;
182 block: adminblock | generalblock | classblock | connectblock |
183        uworldblock | operblock | portblock | jupeblock | clientblock |
184        killblock | cruleblock | motdblock | featuresblock | quarantineblock |
185        pseudoblock | iauthblock | error;
186
187 /* The timespec, sizespec and expr was ripped straight from
188  * ircd-hybrid-7. */
189 timespec: expr | factoredtimes;
190
191 factoredtimes: factoredtimes factoredtime
192 {
193   $$ = $1 + $2;
194 } | factoredtime;
195
196 factoredtime: expr timefactor
197 {
198   $$ = $1 * $2;
199 };
200
201 timefactor: SECONDS { $$ = 1; }
202 | MINUTES { $$ = 60; }
203 | HOURS { $$ = 60 * 60; }
204 | DAYS { $$ = 60 * 60 * 24; }
205 | WEEKS { $$ = 60 * 60 * 24 * 7; }
206 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
207 | YEARS { $$ = 60 * 60 * 24 * 365; }
208 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
209
210
211 sizespec:       expr    {
212                         $$ = $1;
213                 }
214                 | expr BYTES  { 
215                         $$ = $1;
216                 }
217                 | expr KBYTES {
218                         $$ = $1 * 1024;
219                 }
220                 | expr MBYTES {
221                         $$ = $1 * 1024 * 1024;
222                 }
223                 | expr GBYTES {
224                         $$ = $1 * 1024 * 1024 * 1024;
225                 }
226                 | expr TBYTES {
227                         $$ = $1 * 1024 * 1024 * 1024;
228                 }
229                 ;
230
231 /* this is an arithmetic expression */
232 expr: NUMBER
233                 { 
234                         $$ = $1;
235                 }
236                 | expr '+' expr { 
237                         $$ = $1 + $3;
238                 }
239                 | expr '-' expr { 
240                         $$ = $1 - $3;
241                 }
242                 | expr '*' expr { 
243                         $$ = $1 * $3;
244                 }
245                 | expr '/' expr { 
246                         $$ = $1 / $3;
247                 }
248 /* leave this out until we find why it makes BSD yacc dump core -larne
249                 | '-' expr  %prec NEG {
250                         $$ = -$2;
251                 } */
252                 | '(' expr ')' {
253                         $$ = $2;
254                 }
255                 ;
256
257 jupeblock: JUPE '{' jupeitems '}' ';' ;
258 jupeitems: jupeitem jupeitems | jupeitem;
259 jupeitem: jupenick | error;
260 jupenick: NICK '=' QSTRING
261 {
262   addNickJupes($3);
263 } ';';
264
265 generalblock: GENERAL '{' generalitems '}'
266 {
267   if (localConf.name == NULL)
268     parse_error("Your General block must contain a name.");
269   if (localConf.numeric == 0)
270     parse_error("Your General block must contain a numeric (between 1 and 4095).");
271 } ';' ;
272 generalitems: generalitem generalitems | generalitem;
273 generalitem: generalnumeric | generalname | generalvhost | generaldesc | error;
274 generalnumeric: NUMERIC '=' NUMBER ';'
275 {
276   if (localConf.numeric == 0)
277     localConf.numeric = $3;
278   else if (localConf.numeric != $3)
279     parse_error("Redefinition of server numeric %i (%i)", $3,
280                 localConf.numeric);
281 };
282
283 generalname: NAME '=' QSTRING ';'
284 {
285   if (localConf.name == NULL)
286     DupString(localConf.name, $3);
287   else if (strcmp(localConf.name, $3))
288     parse_error("Redefinition of server name %s (%s)", $3,
289                 localConf.name);
290 };
291
292 generaldesc: DESCRIPTION '=' QSTRING ';'
293 {
294   MyFree(localConf.description);
295   DupString(localConf.description, $3);
296   ircd_strncpy(cli_info(&me), $3, REALLEN);
297 };
298
299 generalvhost: VHOST '=' QSTRING ';'
300 {
301   struct irc_in_addr addr;
302   if (!ircd_aton(&addr, $3))
303       parse_error("Invalid virtual host '%s'.", $3);
304   else if (irc_in_addr_is_ipv4(&addr))
305     memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
306   else
307     memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
308 };
309
310 adminblock: ADMIN '{' adminitems '}'
311 {
312   if (localConf.location1 == NULL)
313     DupString(localConf.location1, "");
314   if (localConf.location2 == NULL)
315     DupString(localConf.location2, "");
316   if (localConf.contact == NULL)
317     DupString(localConf.contact, "");
318 } ';';
319 adminitems: adminitems adminitem | adminitem;
320 adminitem: adminlocation | admincontact | error;
321 adminlocation: LOCATION '=' QSTRING ';'
322 {
323  if (localConf.location1 == NULL)
324   DupString(localConf.location1, $3);
325  else if (localConf.location2 == NULL)
326   DupString(localConf.location2, $3);
327  /* Otherwise just drop it. -A1kmm */
328 };
329 admincontact: CONTACT '=' QSTRING ';'
330 {
331  if (localConf.contact != NULL)
332    MyFree(localConf.contact);
333  DupString(localConf.contact, $3);
334 };
335
336 classblock: CLASS {
337   tping = 90;
338 } '{' classitems '}'
339 {
340   if (name != NULL)
341   {
342     struct ConnectionClass *c_class;
343     add_class(name, tping, tconn, maxlinks, sendq);
344     c_class = find_class(name);
345     MyFree(c_class->default_umode);
346     c_class->default_umode = pass;
347     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
348     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
349   }
350   else {
351    parse_error("Missing name in class block");
352   }
353   name = NULL;
354   pass = NULL;
355   tconn = 0;
356   maxlinks = 0;
357   sendq = 0;
358   memset(&privs, 0, sizeof(privs));
359   memset(&privs_dirty, 0, sizeof(privs_dirty));
360 } ';';
361 classitems: classitem classitems | classitem;
362 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
363            classsendq | classusermode | priv | error;
364 classname: NAME '=' QSTRING ';'
365 {
366   MyFree(name);
367   DupString(name, $3);
368 };
369 classpingfreq: PINGFREQ '=' timespec ';'
370 {
371   tping = $3;
372 };
373 classconnfreq: CONNECTFREQ '=' timespec ';'
374 {
375   tconn = $3;
376 };
377 classmaxlinks: MAXLINKS '=' expr ';'
378 {
379   maxlinks = $3;
380 };
381 classsendq: SENDQ '=' sizespec ';'
382 {
383   sendq = $3;
384 };
385 classusermode: USERMODE '=' QSTRING ';'
386 {
387   MyFree(pass);
388   DupString(pass, $3);
389 };
390
391 connectblock: CONNECT
392 {
393  maxlinks = 65535;
394 } '{' connectitems '}'
395 {
396  if (name != NULL && pass != NULL && host != NULL && c_class != NULL
397      && !strchr(host, '*') && !strchr(host, '?'))
398  {
399    struct ConfItem *aconf = make_conf(CONF_SERVER);
400    aconf->name = name;
401    aconf->origin_name = origin;
402    aconf->passwd = pass;
403    aconf->conn_class = c_class;
404    aconf->address.port = port;
405    aconf->host = host;
406    aconf->maximum = maxlinks;
407    aconf->hub_limit = hub_limit;
408    lookup_confhost(aconf);
409  }
410  else
411  {
412    MyFree(name);
413    MyFree(pass);
414    MyFree(host);
415    MyFree(origin);
416    MyFree(hub_limit);
417    parse_error("Bad connect block");
418  }
419  name = pass = host = origin = hub_limit = NULL;
420  c_class = NULL;
421  port = 0;
422 }';';
423 connectitems: connectitem connectitems | connectitem;
424 connectitem: connectname | connectpass | connectclass | connecthost
425               | connectport | connectvhost | connectleaf | connecthub
426               | connecthublimit | connectmaxhops | error;
427 connectname: NAME '=' QSTRING ';'
428 {
429  MyFree(name);
430  DupString(name, $3);
431 };
432 connectpass: PASS '=' QSTRING ';'
433 {
434  MyFree(pass);
435  DupString(pass, $3);
436 };
437 connectclass: CLASS '=' QSTRING ';'
438 {
439  c_class = find_class($3);
440 };
441 connecthost: HOST '=' QSTRING ';'
442 {
443  MyFree(host);
444  DupString(host, $3);
445 };
446 connectport: PORT '=' NUMBER ';'
447 {
448  port = $3;
449 };
450 connectvhost: VHOST '=' QSTRING ';'
451 {
452  MyFree(origin);
453  DupString(origin, $3);
454 };
455 connectleaf: LEAF ';'
456 {
457  maxlinks = 0;
458 };
459 connecthub: HUB ';'
460 {
461  MyFree(hub_limit);
462  DupString(hub_limit, "*");
463 };
464 connecthublimit: HUB '=' QSTRING ';'
465 {
466  MyFree(hub_limit);
467  DupString(hub_limit, $3);
468 };
469 connectmaxhops: MAXHOPS '=' expr ';'
470 {
471   maxlinks = $3;
472 };
473
474 uworldblock: UWORLD '{' uworlditems '}' ';';
475 uworlditems: uworlditem uworlditems | uworlditem;
476 uworlditem: uworldname | error;
477 uworldname: NAME '=' QSTRING ';'
478 {
479  struct ConfItem *aconf;
480  aconf = make_conf(CONF_UWORLD);
481  DupString(aconf->host, $3);
482 };
483
484 operblock: OPER '{' operitems '}' ';'
485 {
486   if (name && pass && host && c_class)
487   {
488     struct ConfItem *aconf = make_conf(CONF_OPERATOR);
489     aconf->name = name;
490     aconf->passwd = pass;
491     conf_parse_userhost(aconf, host);
492     aconf->conn_class = c_class;
493     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
494     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
495     if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
496         && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
497       parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
498   }
499   else
500   {
501     parse_error("operator blocks need a name, password, class and host.");
502     MyFree(name);
503     MyFree(pass);
504     MyFree(host);
505   }
506   name = pass = host = NULL;
507   c_class = NULL;
508   memset(&privs, 0, sizeof(privs));
509   memset(&privs_dirty, 0, sizeof(privs_dirty));
510 };
511 operitems: operitem | operitems operitem;
512 operitem: opername | operpass | operhost | operclass | priv | error;
513 opername: NAME '=' QSTRING ';'
514 {
515   MyFree(name);
516   DupString(name, $3);
517 };
518 operpass: PASS '=' QSTRING ';'
519 {
520   MyFree(pass);
521   DupString(pass, $3);
522 };
523 operhost: HOST '=' QSTRING ';'
524 {
525  MyFree(host);
526  if (!strchr($3, '@'))
527  {
528    int uh_len;
529    char *b = (char*) MyMalloc((uh_len = strlen($3)+3));
530    ircd_snprintf(0, b, uh_len, "*@%s", $3);
531    host = b;
532  }
533  else
534    DupString(host, $3);
535 };
536 operclass: CLASS '=' QSTRING ';'
537 {
538  c_class = find_class($3);
539 };
540
541 priv: privtype '=' yesorno ';'
542 {
543   FlagSet(&privs_dirty, $1);
544   if (($3 == 1) ^ invert)
545     FlagSet(&privs, $1);
546   else
547     FlagClr(&privs, $1);
548   invert = 0;
549 };
550
551 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
552           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
553           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
554           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
555           KILL { $$ = PRIV_KILL; } |
556           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
557           TPRIV_REHASH { $$ = PRIV_REHASH; } |
558           TPRIV_RESTART { $$ = PRIV_RESTART; } |
559           TPRIV_DIE { $$ = PRIV_DIE; } |
560           TPRIV_GLINE { $$ = PRIV_GLINE; } |
561           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
562           JUPE { $$ = PRIV_JUPE; } |
563           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
564           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
565           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
566           TPRIV_SET { $$ = PRIV_SET; } |
567           TPRIV_WHOX { $$ = PRIV_WHOX; } |
568           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
569           TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
570           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
571           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
572           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
573           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
574           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
575           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
576           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
577           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
578           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
579           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
580           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
581           TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
582
583 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
584
585 /* The port block... */
586 portblock: PORT '{' portitems '}' ';'
587 {
588   if (port > 0 && port <= 0xFFFF)
589   {
590     add_listener(port, host, pass, tconn, tping);
591   }
592   else
593   {
594     parse_error("Bad port block");
595   }
596   MyFree(host);
597   MyFree(pass);
598   host = pass = NULL;
599   port = tconn = tping = 0;
600 };
601 portitems: portitem portitems | portitem;
602 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
603 portnumber: PORT '=' NUMBER ';'
604 {
605   port = $3;
606 };
607
608 portvhost: VHOST '=' QSTRING ';'
609 {
610   MyFree(host);
611   DupString(host, $3);
612 };
613
614 portmask: MASK '=' QSTRING ';'
615 {
616   MyFree(pass);
617   DupString(pass, $3);
618 };
619
620 portserver: SERVER '=' YES ';'
621 {
622   tconn = -1;
623 } | SERVER '=' NO ';'
624 {
625   tconn = 0;
626 };
627
628 porthidden: HIDDEN '=' YES ';'
629 {
630   tping = -1;
631 } | HIDDEN '=' NO ';'
632 {
633   tping = 0;
634 };
635
636 clientblock: CLIENT
637 {
638   maxlinks = 65535;
639 }
640 '{' clientitems '}' ';'
641 {
642   struct irc_in_addr addr;
643   unsigned char addrbits = 0;
644
645   if (ip && !ipmask_parse(ip, &addr, &addrbits)) {
646     parse_error("Invalid IP address in block");
647     MyFree(username);
648     MyFree(host);
649     MyFree(ip);
650     MyFree(pass);
651   } else {
652     struct ConfItem *aconf = make_conf(CONF_CLIENT);
653     aconf->username = username;
654     aconf->host = host;
655     if (ip)
656       memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
657     else
658       memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
659     aconf->addrbits = addrbits;
660     aconf->name = ip;
661     aconf->conn_class = c_class ? c_class : find_class("default");
662     aconf->maximum = maxlinks;
663     aconf->passwd = pass;
664   }
665   host = NULL;
666   username = NULL;
667   c_class = NULL;
668   ip = NULL;
669   pass = NULL;
670 };
671 clientitems: clientitem clientitems | clientitem;
672 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | error;
673 clienthost: HOST '=' QSTRING ';'
674 {
675   char *sep = strchr($3, '@');
676   MyFree(host);
677   if (sep) {
678     *sep++ = '\0';
679     MyFree(username);
680     DupString(username, $3);
681     DupString(host, sep);
682   } else {
683     DupString(host, $3);
684   }
685 };
686 clientip: IP '=' QSTRING ';'
687 {
688   char *sep = strchr($3, '@');
689   MyFree(ip);
690   if (sep) {
691     *sep++ = '\0';
692     MyFree(username);
693     DupString(username, $3);
694     DupString(ip, sep);
695   } else {
696     DupString(ip, $3);
697   }
698 };
699 clientusername: USERNAME '=' QSTRING ';'
700 {
701   MyFree(username);
702   DupString(username, $3);
703 };
704 clientclass: CLASS '=' QSTRING ';'
705 {
706   c_class = find_class($3);
707 };
708 clientpass: PASS '=' QSTRING ';'
709 {
710   MyFree(pass);
711   DupString(pass, $3);
712 };
713 clientmaxlinks: MAXLINKS '=' expr ';'
714 {
715   maxlinks = $3;
716 };
717
718 killblock: KILL
719 {
720   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
721 } '{' killitems '}'
722 {
723   if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
724     dconf->next = denyConfList;
725     denyConfList = dconf;
726   }
727   else
728   {
729     MyFree(dconf->usermask);
730     MyFree(dconf->hostmask);
731     MyFree(dconf->realmask);
732     MyFree(dconf->message);
733     MyFree(dconf);
734     parse_error("Bad kill block");
735   }
736   dconf = NULL;
737 } ';';
738 killitems: killitem killitems | killitem;
739 killitem: killuhost | killreal | killusername | killreasonfile | killreason | error;
740 killuhost: HOST '=' QSTRING ';'
741 {
742   char *u, *h;
743   MyFree(dconf->hostmask);
744   MyFree(dconf->usermask);
745   if ((h = strchr($3, '@')) == NULL)
746   {
747     u = "*";
748     h = $3;
749   }
750   else
751   {
752     u = $3;
753     *h++ = '\0';
754   }
755   DupString(dconf->hostmask, h);
756   DupString(dconf->usermask, u);
757   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
758 };
759
760 killusername: USERNAME '=' QSTRING ';'
761 {
762   MyFree(dconf->usermask);
763   DupString(dconf->usermask, $3);
764 };
765
766 killreal: REAL '=' QSTRING ';'
767 {
768  MyFree(dconf->realmask);
769  DupString(dconf->realmask, $3);
770 };
771
772 killreason: REASON '=' QSTRING ';'
773 {
774  dconf->flags &= ~DENY_FLAGS_FILE;
775  MyFree(dconf->message);
776  DupString(dconf->message, $3);
777 };
778
779 killreasonfile: TFILE '=' QSTRING ';'
780 {
781  dconf->flags |= DENY_FLAGS_FILE;
782  MyFree(dconf->message);
783  DupString(dconf->message, $3);
784 };
785
786 cruleblock: CRULE
787 {
788   tconn = CRULE_AUTO;
789 } '{' cruleitems '}' ';'
790 {
791   struct CRuleNode *node;
792   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
793   {
794     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
795     p->hostmask = host;
796     p->rule = pass;
797     p->type = tconn;
798     p->node = node;
799     p->next = cruleConfList;
800     cruleConfList = p;
801   }
802   else
803   {
804     MyFree(host);
805     MyFree(pass);
806     parse_error("Bad CRule block");
807   }
808   host = pass = NULL;
809   tconn = 0;
810 };
811
812 cruleitems: cruleitem cruleitems | cruleitem;
813 cruleitem: cruleserver | crulerule | cruleall | error;
814
815 cruleserver: SERVER '=' QSTRING ';'
816 {
817   MyFree(host);
818   collapse($3);
819   DupString(host, $3);
820 };
821
822 crulerule: RULE '=' QSTRING ';'
823 {
824  MyFree(pass);
825  DupString(pass, $3);
826 };
827
828 cruleall: ALL '=' YES ';'
829 {
830  tconn = CRULE_ALL;
831 } | ALL '=' NO ';'
832 {
833  tconn = CRULE_AUTO;
834 };
835
836 motdblock: MOTD '{' motditems '}' ';'
837 {
838   if (host != NULL && pass != NULL)
839     motd_add(host, pass);
840   MyFree(host);
841   MyFree(pass);
842   host = pass = NULL;
843 };
844
845 motditems: motditem motditems | motditem;
846 motditem: motdhost | motdfile | error;
847 motdhost: HOST '=' QSTRING ';'
848 {
849   DupString(host, $3);
850 };
851
852 motdfile: TFILE '=' QSTRING ';'
853 {
854   DupString(pass, $3);
855 };
856
857 featuresblock: FEATURES '{' featureitems '}' ';';
858 featureitems: featureitems featureitem | featureitem;
859
860 featureitem: QSTRING
861 {
862   stringlist[0] = $1;
863   stringno = 1;
864 } '=' stringlist ';';
865
866 stringlist: QSTRING
867 {
868   stringlist[1] = $1;
869   stringno = 2;
870 } posextrastrings
871 {
872   feature_set(NULL, (const char * const *)stringlist, stringno);
873 };
874 posextrastrings: /* empty */ | extrastrings;
875 extrastrings: extrastrings extrastring | extrastring;
876 extrastring: QSTRING
877 {
878   if (stringno < MAX_STRINGS)
879     stringlist[stringno++] = $1;
880 };
881
882 quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
883 quarantineitems: quarantineitems quarantineitem | quarantineitem;
884 quarantineitem: QSTRING '=' QSTRING ';'
885 {
886   struct qline *qconf = MyCalloc(1, sizeof(*qconf));
887   DupString(qconf->chname, $1);
888   DupString(qconf->reason, $3);
889   qconf->next = GlobalQuarantineList;
890   GlobalQuarantineList = qconf;
891 };
892
893 pseudoblock: PSEUDO QSTRING '{'
894 {
895   smap = MyCalloc(1, sizeof(struct s_map));
896   DupString(smap->command, $2);
897 }
898 pseudoitems '}' ';'
899 {
900   if (!smap->name || !smap->services)
901   {
902     parse_error("pseudo commands need a service name and list of target nicks.");
903     return 0;
904   }
905   if (register_mapping(smap))
906   {
907     smap->next = GlobalServiceMapList;
908     GlobalServiceMapList = smap;
909   }
910   else
911   {
912     struct nick_host *nh, *next;
913     for (nh = smap->services; nh; nh = next)
914     {
915       next = nh->next;
916       MyFree(nh);
917     }
918     MyFree(smap->name);
919     MyFree(smap->command);
920     MyFree(smap->prepend);
921     MyFree(smap);
922   }
923   smap = NULL;
924 };
925
926 pseudoitems: pseudoitem pseudoitems | pseudoitem;
927 pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags | error;
928 pseudoname: NAME '=' QSTRING ';'
929 {
930   DupString(smap->name, $3);
931 };
932 pseudoprepend: PREPEND '=' QSTRING ';'
933 {
934   DupString(smap->prepend, $3);
935 };
936 pseudonick: NICK '=' QSTRING ';'
937 {
938   char *sep = strchr($3, '@');
939
940   if (sep != NULL) {
941     size_t slen = strlen($3);
942     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
943     memcpy(nh->nick, $3, slen + 1);
944     nh->nicklen = sep - $3;
945     nh->next = smap->services;
946     smap->services = nh;
947   }
948 };
949 pseudoflags: FAST ';'
950 {
951   smap->flags |= SMAP_FAST;
952 };
953
954 iauthblock: IAUTH '{'
955 {
956   tconn = 60;
957   tping = 60;
958 } iauthitems '}' ';'
959 {
960   if (!host || !port) {
961     parse_error("IAuth block needs a server name and port.");
962     return 0;
963   }
964   iauth_connect(host, port, pass, tconn, tping);
965   MyFree(pass);
966   MyFree(host);
967   pass = host = NULL;
968   port = tconn = tping = 0;
969 };
970
971 iauthitems: iauthitem iauthitems | iauthitem;
972 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
973 iauthpass: PASS '=' QSTRING ';'
974 {
975   MyFree(pass);
976   DupString(pass, $3);
977 };
978 iauthhost: HOST '=' QSTRING ';'
979 {
980   MyFree(host);
981   DupString(host, $3);
982 };
983 iauthport: PORT '=' NUMBER ';'
984 {
985   port = $3;
986 };
987 iauthconnfreq: CONNECTFREQ '=' timespec ';'
988 {
989   tconn = $3;
990 };
991 iauthtimeout: TIMEOUT '=' timespec ';'
992 {
993   tping = $3;
994 };