Add '6' to server options when compiled with IPv6 support (and related
[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 qline *qconf = NULL;
78   struct s_map *smap;
79   struct Privs privs;
80   struct Privs privs_dirty;
81
82 static void parse_error(char *pattern,...) {
83   static char error_buffer[1024];
84   va_list vl;
85   va_start(vl,pattern);
86   ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
87   va_end(vl);
88   yyerror(error_buffer);
89 }
90
91 %}
92
93 %token <text> QSTRING
94 %token <num> NUMBER
95 %token <text> FNAME
96
97 %token GENERAL
98 %token ADMIN
99 %token LOCATION
100 %token CONTACT
101 %token CONNECT
102 %token CLASS
103 %token CHANNEL
104 %token PINGFREQ
105 %token CONNECTFREQ
106 %token MAXLINKS
107 %token MAXHOPS
108 %token SENDQ
109 %token NAME
110 %token HOST
111 %token IP
112 %token USERNAME
113 %token PASS
114 %token LOCAL
115 %token SECONDS
116 %token MINUTES
117 %token HOURS
118 %token DAYS
119 %token WEEKS
120 %token MONTHS
121 %token YEARS
122 %token DECADES
123 %token BYTES
124 %token KBYTES
125 %token MBYTES
126 %token GBYTES
127 %token TBYTES
128 %token SERVER
129 %token PORT
130 %token MASK
131 %token HUB
132 %token LEAF
133 %token UWORLD
134 %token YES
135 %token NO
136 %token OPER
137 %token VHOST
138 %token HIDDEN
139 %token MOTD
140 %token JUPE
141 %token NICK
142 %token NUMERIC
143 %token DESCRIPTION
144 %token CLIENT
145 %token KILL
146 %token CRULE
147 %token REAL
148 %token REASON
149 %token TFILE
150 %token RULE
151 %token ALL
152 %token FEATURES
153 %token QUARANTINE
154 %token PSEUDO
155 %token PREPEND
156 %token USERMODE
157 %token IAUTH
158 %token TIMEOUT
159 /* and now a lot of priviledges... */
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 arithmatic 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                 = {
251                         $$ = -$2;
252                 } */
253                 | '(' expr ')' {
254                         $$ = $2;
255                 }
256                 ;
257
258 jupeblock: JUPE '{' jupeitems '}' ';' ;
259 jupeitems: jupeitem jupeitems | jupeitem;
260 jupeitem: jupenick | error;
261 jupenick: NICK '=' QSTRING
262 {
263   addNickJupes($3);
264 } ';';
265
266 generalblock: GENERAL '{' generalitems '}'
267 {
268   if (localConf.name == NULL)
269     parse_error("Your General block must contain a name.");
270   if (localConf.numeric == 0)
271     parse_error("Your General block must contain a numeric (between 1 and 4095).");
272 } ';' ;
273 generalitems: generalitem generalitems | generalitem;
274 generalitem: generalnumeric | generalname | generalvhost | generaldesc | error;
275 generalnumeric: NUMERIC '=' NUMBER ';'
276 {
277   if (localConf.numeric == 0)
278     localConf.numeric = $3;
279   else if (localConf.numeric != $3)
280     parse_error("Redefinition of server numeric %i (%i)", $3,
281                 localConf.numeric);
282 };
283
284 generalname: NAME '=' QSTRING ';'
285 {
286   if (localConf.name == NULL)
287     DupString(localConf.name, $3);
288   else if (strcmp(localConf.name, $3))
289     parse_error("Redefinition of server name %s (%s)", $3,
290                 localConf.name);
291 };
292
293 generaldesc: DESCRIPTION '=' QSTRING ';'
294 {
295   MyFree(localConf.description);
296   DupString(localConf.description, $3);
297   ircd_strncpy(cli_info(&me), $3, REALLEN);
298 };
299
300 generalvhost: VHOST '=' QSTRING ';'
301 {
302   struct irc_in_addr addr;
303   if (!ircd_aton(&addr, $3))
304       parse_error("Invalid virtual host '%s'.", $3);
305   else if (irc_in_addr_is_ipv4(&addr))
306     memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
307   else
308     memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
309 };
310
311 adminblock: ADMIN '{' adminitems '}'
312 {
313   if (localConf.location1 == NULL)
314     DupString(localConf.location1, "");
315   if (localConf.location2 == NULL)
316     DupString(localConf.location2, "");
317   if (localConf.contact == NULL)
318     DupString(localConf.contact, "");
319 } ';';
320 adminitems: adminitems adminitem | adminitem;
321 adminitem: adminlocation | admincontact | error;
322 adminlocation: LOCATION '=' QSTRING ';'
323 {
324  if (localConf.location1 == NULL)
325   DupString(localConf.location1, $3);
326  else if (localConf.location2 == NULL)
327   DupString(localConf.location2, $3);
328  /* Otherwise just drop it. -A1kmm */
329 };
330 admincontact: CONTACT '=' QSTRING ';'
331 {
332  if (localConf.contact != NULL)
333    MyFree(localConf.contact);
334  DupString(localConf.contact, $3);
335 };
336
337 classblock: CLASS {
338   tping = 90;
339 } '{' classitems '}'
340 {
341   if (name != NULL)
342   {
343     struct ConnectionClass *c_class;
344     add_class(name, tping, tconn, maxlinks, sendq);
345     c_class = find_class(name);
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 {
476  if (name)
477  {
478   struct ConfItem *aconf = make_conf(CONF_UWORLD);
479   aconf->host = name;
480  }
481  else
482  {
483   MyFree(name);
484   parse_error("Bad UWorld block");
485  }
486  name = NULL;
487 };
488 uworlditems: uworlditem uworlditems | uworlditem;
489 uworlditem: uworldname | error;
490 uworldname: NAME '=' QSTRING ';'
491 {
492  MyFree(name);
493  DupString(name, $3);
494 };
495
496 operblock: OPER '{' operitems '}' ';'
497 {
498   if (name && pass && host && c_class)
499   {
500     struct ConfItem *aconf = make_conf(CONF_OPERATOR);
501     aconf->name = name;
502     aconf->passwd = pass;
503     conf_parse_userhost(aconf, host);
504     aconf->conn_class = c_class;
505     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
506     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
507     if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
508         && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
509       parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
510   }
511   else
512   {
513     parse_error("operator blocks need a name, password, class and host.");
514     MyFree(name);
515     MyFree(pass);
516     MyFree(host);
517   }
518   name = pass = host = NULL;
519   c_class = NULL;
520   memset(&privs, 0, sizeof(privs));
521   memset(&privs_dirty, 0, sizeof(privs_dirty));
522 };
523 operitems: operitem | operitems operitem;
524 operitem: opername | operpass | operhost | operclass | priv | error;
525 opername: NAME '=' QSTRING ';'
526 {
527   MyFree(name);
528   DupString(name, $3);
529 };
530 operpass: PASS '=' QSTRING ';'
531 {
532   MyFree(pass);
533   DupString(pass, $3);
534 };
535 operhost: HOST '=' QSTRING ';'
536 {
537  MyFree(host);
538  if (!strchr($3, '@'))
539  {
540    int uh_len;
541    char *b = (char*) MyMalloc((uh_len = strlen($3)+3));
542    ircd_snprintf(0, b, uh_len, "*@%s", $3);
543    host = b;
544  }
545  else
546    DupString(host, $3);
547 };
548 operclass: CLASS '=' QSTRING ';'
549 {
550  c_class = find_class($3);
551 };
552
553 priv: privtype '=' yesorno ';'
554 {
555   FlagSet(&privs_dirty, $1);
556   if (($3 == 1) ^ invert)
557     FlagSet(&privs, $1);
558   else
559     FlagClr(&privs, $1);
560   invert = 0;
561 };
562
563 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
564           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
565           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
566           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
567           KILL { $$ = PRIV_KILL; } |
568           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
569           TPRIV_REHASH { $$ = PRIV_REHASH; } |
570           TPRIV_RESTART { $$ = PRIV_RESTART; } |
571           TPRIV_DIE { $$ = PRIV_DIE; } |
572           TPRIV_GLINE { $$ = PRIV_GLINE; } |
573           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
574           JUPE { $$ = PRIV_JUPE; } |
575           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
576           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
577           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
578           TPRIV_SET { $$ = PRIV_SET; } |
579           TPRIV_WHOX { $$ = PRIV_WHOX; } |
580           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
581           TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
582           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
583           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
584           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
585           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
586           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
587           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
588           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
589           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
590           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
591           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
592           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
593           TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
594
595 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
596
597 /* The port block... */
598 portblock: PORT '{' portitems '}' ';'
599 {
600   if (port > 0 && port <= 0xFFFF)
601   {
602     add_listener(port, host, pass, tconn, tping);
603   }
604   else
605   {
606     parse_error("Bad port block");
607   }
608   MyFree(host);
609   MyFree(pass);
610   host = pass = NULL;
611   port = tconn = tping = 0;
612 };
613 portitems: portitem portitems | portitem;
614 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
615 portnumber: PORT '=' NUMBER ';'
616 {
617   port = $3;
618 };
619
620 portvhost: VHOST '=' QSTRING ';'
621 {
622   MyFree(host);
623   DupString(host, $3);
624 };
625
626 portmask: MASK '=' QSTRING ';'
627 {
628   MyFree(pass);
629   DupString(pass, $3);
630 };
631
632 portserver: SERVER '=' YES ';'
633 {
634   tconn = -1;
635 } | SERVER '=' NO ';'
636 {
637   tconn = 0;
638 };
639
640 porthidden: HIDDEN '=' YES ';'
641 {
642   tping = -1;
643 } | HIDDEN '=' NO ';'
644 {
645   tping = 0;
646 };
647
648 clientblock: CLIENT
649 {
650   maxlinks = 65535;
651 }
652 '{' clientitems '}' ';'
653 {
654   struct irc_in_addr addr;
655   unsigned char addrbits = 0;
656
657   if (ip && !ipmask_parse(ip, &addr, &addrbits)) {
658     parse_error("Invalid IP address in block");
659     MyFree(username);
660     MyFree(host);
661     MyFree(ip);
662   } else {
663     struct ConfItem *aconf = make_conf(CONF_CLIENT);
664     aconf->username = username;
665     aconf->host = host;
666     if (ip)
667       memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
668     else
669       memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
670     aconf->addrbits = addrbits;
671     aconf->name = ip;
672     aconf->conn_class = c_class ? c_class : find_class("default");
673     aconf->maximum = maxlinks;
674   }
675   host = NULL;
676   username = NULL;
677   c_class = NULL;
678   ip = NULL;
679 };
680 clientitems: clientitem clientitems | clientitem;
681 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | error;
682 clienthost: HOST '=' QSTRING ';'
683 {
684   char *sep = strchr($3, '@');
685   MyFree(host);
686   if (sep) {
687     *sep++ = '\0';
688     MyFree(username);
689     DupString(username, $3);
690     DupString(host, sep);
691   } else {
692     DupString(host, $3);
693   }
694 };
695 clientip: IP '=' QSTRING ';'
696 {
697   char *sep = strchr($3, '@');
698   MyFree(ip);
699   if (sep) {
700     *sep++ = '\0';
701     MyFree(username);
702     DupString(username, $3);
703     DupString(ip, sep);
704   } else {
705     DupString(ip, $3);
706   }
707 };
708 clientusername: USERNAME '=' QSTRING ';'
709 {
710   MyFree(username);
711   DupString(username, $3);
712 };
713 clientclass: CLASS '=' QSTRING ';'
714 {
715   c_class = find_class($3);
716 };
717 clientpass: PASS '=' QSTRING ';'
718 {
719   MyFree(pass);
720   DupString(pass, $3);
721 };
722 clientmaxlinks: MAXLINKS '=' expr ';'
723 {
724   maxlinks = $3;
725 };
726
727 killblock: KILL
728 {
729   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
730 } '{' killitems '}'
731 {
732   if (dconf->hostmask != NULL)
733   {
734     if (dconf->usermask == NULL)
735       DupString(dconf->usermask, "*");
736     dconf->next = denyConfList;
737     denyConfList = dconf;
738   }
739   else
740   {
741     MyFree(dconf->hostmask);
742     MyFree(dconf->message);
743     MyFree(dconf);
744     parse_error("Bad kill block");
745   }
746   dconf = NULL;
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($3, '@')) == NULL)
757   {
758     u = "*";
759     h = $3;
760   }
761   else
762   {
763     u = $3;
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, $3);
778 };
779
780 killreason: REASON '=' QSTRING ';'
781 {
782  dconf->flags &= ~DENY_FLAGS_FILE;
783  MyFree(dconf->message);
784  DupString(dconf->message, $3);
785 };
786
787 killreasonfile: TFILE '=' QSTRING ';'
788 {
789  dconf->flags |= DENY_FLAGS_FILE;
790  MyFree(dconf->message);
791  DupString(dconf->message, $3);
792 };
793
794 cruleblock: CRULE
795 {
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   host = pass = NULL;
817   tconn = 0;
818 };
819
820 cruleitems: cruleitem cruleitems | cruleitem;
821 cruleitem: cruleserver | crulerule | cruleall | error;
822
823 cruleserver: SERVER '=' QSTRING ';'
824 {
825   MyFree(host);
826   collapse($3);
827   DupString(host, $3);
828 };
829
830 crulerule: RULE '=' QSTRING ';'
831 {
832  MyFree(pass);
833  DupString(pass, $3);
834 };
835
836 cruleall: ALL '=' YES ';'
837 {
838  tconn = CRULE_ALL;
839 } | ALL '=' NO ';'
840 {
841  tconn = CRULE_AUTO;
842 };
843
844 motdblock: MOTD '{' 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, $3);
858 };
859
860 motdfile: TFILE '=' QSTRING ';'
861 {
862   DupString(pass, $3);
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   qconf = (struct qline*) MyCalloc(1, sizeof(*qconf));
893 } quarantineitems '}' ';'
894 {
895   if (qconf->chname == NULL || qconf->reason == NULL)
896   {
897     parse_error("quarantine blocks need a channel name and a reason.");
898     return 0;
899   }
900   qconf->next = GlobalQuarantineList;
901   GlobalQuarantineList = qconf;
902   qconf = NULL;
903 };
904
905 quarantineitems: CHANNEL NAME '=' QSTRING ';'
906 {
907   DupString(qconf->chname, $4);
908 } | REASON '=' QSTRING ';'
909 {
910   DupString(qconf->reason, $3);
911 };
912
913 pseudoblock: PSEUDO QSTRING '{'
914 {
915   smap = MyCalloc(1, sizeof(struct s_map));
916   DupString(smap->command, $2);
917 }
918 pseudoitems '}' ';'
919 {
920   if (!smap->name || !smap->services)
921   {
922     parse_error("pseudo commands need a service name and list of target nicks.");
923     return 0;
924   }
925   if (register_mapping(smap))
926   {
927     smap->next = GlobalServiceMapList;
928     GlobalServiceMapList = smap;
929   }
930   else
931   {
932     struct nick_host *nh, *next;
933     for (nh = smap->services; nh; nh = next)
934     {
935       next = nh->next;
936       MyFree(nh);
937     }
938     MyFree(smap->name);
939     MyFree(smap->command);
940     MyFree(smap->prepend);
941     MyFree(smap);
942   }
943   smap = NULL;
944 };
945
946 pseudoitems: pseudoitem pseudoitems | pseudoitem;
947 pseudoitem: pseudoname | pseudoprepend | pseudonick | error;
948 pseudoname: NAME '=' QSTRING ';'
949 {
950   DupString(smap->name, $3);
951 };
952 pseudoprepend: PREPEND '=' QSTRING ';'
953 {
954   DupString(smap->prepend, $3);
955 };
956 pseudonick: NICK '=' QSTRING ';'
957 {
958   char *sep = strchr($3, '@');
959
960   if (sep != NULL) {
961     size_t slen = strlen($3);
962     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
963     memcpy(nh->nick, $3, slen + 1);
964     nh->nicklen = sep - $3;
965     nh->next = smap->services;
966     smap->services = nh;
967   }
968 };
969
970 iauthblock: IAUTH '{'
971 {
972   tconn = 60;
973   tping = 60;
974 } iauthitems '}' ';'
975 {
976   if (!host || !port) {
977     parse_error("IAuth block needs a server name and port.");
978     return 0;
979   }
980   iauth_connect(host, port, pass, tconn, tping);
981   MyFree(pass);
982   MyFree(host);
983   pass = host = NULL;
984   port = tconn = tping = 0;
985 };
986
987 iauthitems: iauthitem iauthitems | iauthitem;
988 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
989 iauthpass: PASS '=' QSTRING ';'
990 {
991   MyFree(pass);
992   DupString(pass, $3);
993 };
994 iauthhost: HOST '=' QSTRING ';'
995 {
996   MyFree(host);
997   DupString(host, $3);
998 };
999 iauthport: PORT '=' NUMBER ';'
1000 {
1001   port = $3;
1002 };
1003 iauthconnfreq: CONNECTFREQ '=' timespec ';'
1004 {
1005   tconn = $3;
1006 };
1007 iauthtimeout: TIMEOUT '=' timespec ';'
1008 {
1009   tping = $3;
1010 };