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