2ce1b6c79cf129c07cfdc7551b6965bdbaafbba6
[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, flags;
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
95 %token GENERAL
96 %token ADMIN
97 %token LOCATION
98 %token CONTACT
99 %token CONNECT
100 %token CLASS
101 %token CHANNEL
102 %token PINGFREQ
103 %token CONNECTFREQ
104 %token MAXLINKS
105 %token MAXHOPS
106 %token SENDQ
107 %token NAME
108 %token HOST
109 %token IP
110 %token USERNAME
111 %token PASS
112 %token LOCAL
113 %token SECONDS
114 %token MINUTES
115 %token HOURS
116 %token DAYS
117 %token WEEKS
118 %token MONTHS
119 %token YEARS
120 %token DECADES
121 %token BYTES
122 %token KBYTES
123 %token MBYTES
124 %token GBYTES
125 %token TBYTES
126 %token SERVER
127 %token PORT
128 %token MASK
129 %token HUB
130 %token LEAF
131 %token UWORLD
132 %token YES
133 %token NO
134 %token OPER
135 %token VHOST
136 %token HIDDEN
137 %token MOTD
138 %token JUPE
139 %token NICK
140 %token NUMERIC
141 %token DESCRIPTION
142 %token CLIENT
143 %token KILL
144 %token CRULE
145 %token REAL
146 %token REASON
147 %token TFILE
148 %token RULE
149 %token ALL
150 %token FEATURES
151 %token QUARANTINE
152 %token PSEUDO
153 %token PREPEND
154 %token USERMODE
155 %token IAUTH
156 %token TIMEOUT
157 %token FAST
158 %token AUTOCONNECT
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;
260 jupenick: NICK '=' QSTRING ';'
261 {
262   addNickJupes($3);
263   MyFree($3);
264 };
265
266 generalblock: GENERAL
267 {
268     /* Zero out the vhost addresses, in case they were removed. */
269     memset(&VirtualHost_v4.addr, 0, sizeof(VirtualHost_v4.addr));
270     memset(&VirtualHost_v6.addr, 0, sizeof(VirtualHost_v6.addr));
271 } '{' generalitems '}' ';' {
272   if (localConf.name == NULL)
273     parse_error("Your General block must contain a name.");
274   if (localConf.numeric == 0)
275     parse_error("Your General block must contain a numeric (between 1 and 4095).");
276 };
277 generalitems: generalitem generalitems | generalitem;
278 generalitem: generalnumeric | generalname | generalvhost | generaldesc;
279 generalnumeric: NUMERIC '=' NUMBER ';'
280 {
281   if (localConf.numeric == 0)
282     localConf.numeric = $3;
283   else if (localConf.numeric != $3)
284     parse_error("Redefinition of server numeric %i (%i)", $3,
285                 localConf.numeric);
286 };
287
288 generalname: NAME '=' QSTRING ';'
289 {
290   if (localConf.name == NULL)
291     localConf.name = $3;
292   else {
293     if (strcmp(localConf.name, $3))
294       parse_error("Redefinition of server name %s (%s)", $3,
295                   localConf.name);
296     MyFree($3);
297   }
298 };
299
300 generaldesc: DESCRIPTION '=' QSTRING ';'
301 {
302   MyFree(localConf.description);
303   localConf.description = $3;
304   ircd_strncpy(cli_info(&me), $3, REALLEN);
305 };
306
307 generalvhost: VHOST '=' QSTRING ';'
308 {
309   struct irc_in_addr addr;
310   if (!strcmp($3, "*")) {
311     /* This traditionally meant bind to all interfaces and connect
312      * from the default. */
313   } else if (!ircd_aton(&addr, $3))
314     parse_error("Invalid virtual host '%s'.", $3);
315   else if (irc_in_addr_is_ipv4(&addr))
316     memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
317   else
318     memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
319   MyFree($3);
320 };
321
322 adminblock: ADMIN '{' adminitems '}' ';'
323 {
324   if (localConf.location1 == NULL)
325     DupString(localConf.location1, "");
326   if (localConf.location2 == NULL)
327     DupString(localConf.location2, "");
328   if (localConf.contact == NULL)
329     DupString(localConf.contact, "");
330 };
331 adminitems: adminitems adminitem | adminitem;
332 adminitem: adminlocation | admincontact;
333 adminlocation: LOCATION '=' QSTRING ';'
334 {
335   if (localConf.location1 == NULL)
336     localConf.location1 = $3;
337   else if (localConf.location2 == NULL)
338     localConf.location2 = $3;
339   else /* Otherwise just drop it. -A1kmm */
340     MyFree($3);
341 };
342 admincontact: CONTACT '=' QSTRING ';'
343 {
344  MyFree(localConf.contact);
345  localConf.contact = $3;
346 };
347
348 classblock: CLASS {
349   tping = 90;
350 } '{' classitems '}' ';'
351 {
352   if (name != NULL)
353   {
354     struct ConnectionClass *c_class;
355     add_class(name, tping, tconn, maxlinks, sendq);
356     c_class = find_class(name);
357     MyFree(c_class->default_umode);
358     c_class->default_umode = pass;
359     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
360     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
361   }
362   else {
363    parse_error("Missing name in class block");
364   }
365   name = NULL;
366   pass = NULL;
367   tconn = 0;
368   maxlinks = 0;
369   sendq = 0;
370   memset(&privs, 0, sizeof(privs));
371   memset(&privs_dirty, 0, sizeof(privs_dirty));
372 };
373 classitems: classitem classitems | classitem;
374 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
375            classsendq | classusermode | priv;
376 classname: NAME '=' QSTRING ';'
377 {
378   MyFree(name);
379   name = $3;
380 };
381 classpingfreq: PINGFREQ '=' timespec ';'
382 {
383   tping = $3;
384 };
385 classconnfreq: CONNECTFREQ '=' timespec ';'
386 {
387   tconn = $3;
388 };
389 classmaxlinks: MAXLINKS '=' expr ';'
390 {
391   maxlinks = $3;
392 };
393 classsendq: SENDQ '=' sizespec ';'
394 {
395   sendq = $3;
396 };
397 classusermode: USERMODE '=' QSTRING ';'
398 {
399   MyFree(pass);
400   pass = $3;
401 };
402
403 connectblock: CONNECT
404 {
405  maxlinks = 65535;
406  flags = CONF_AUTOCONNECT;
407 } '{' connectitems '}' ';'
408 {
409  struct ConfItem *aconf = NULL;
410  if (name == NULL)
411   parse_error("Missing name in connect block");
412  else if (pass == NULL)
413   parse_error("Missing password in connect block");
414  else if (host == NULL)
415   parse_error("Missing host in connect block");
416  else if (strchr(host, '*') || strchr(host, '?'))
417   parse_error("Invalid host '%s' in connect block", host);
418  else if (c_class == NULL)
419   parse_error("Missing or non-existent class in connect block");
420  else {
421    aconf = make_conf(CONF_SERVER);
422    aconf->name = name;
423    aconf->origin_name = origin;
424    aconf->passwd = pass;
425    aconf->conn_class = c_class;
426    aconf->address.port = port;
427    aconf->host = host;
428    aconf->maximum = maxlinks;
429    aconf->hub_limit = hub_limit;
430    aconf->flags = flags;
431    lookup_confhost(aconf);
432  }
433  if (!aconf) {
434    MyFree(name);
435    MyFree(pass);
436    MyFree(host);
437    MyFree(origin);
438    MyFree(hub_limit);
439  }
440  name = pass = host = origin = hub_limit = NULL;
441  c_class = NULL;
442  port = flags = 0;
443 };
444 connectitems: connectitem connectitems | connectitem;
445 connectitem: connectname | connectpass | connectclass | connecthost
446               | connectport | connectvhost | connectleaf | connecthub
447               | connecthublimit | connectmaxhops | connectauto;
448 connectname: NAME '=' QSTRING ';'
449 {
450  MyFree(name);
451  name = $3;
452 };
453 connectpass: PASS '=' QSTRING ';'
454 {
455  MyFree(pass);
456  pass = $3;
457 };
458 connectclass: CLASS '=' QSTRING ';'
459 {
460  c_class = find_class($3);
461  if (!c_class)
462   parse_error("No such connection class '%s' for Connect block", $3);
463  MyFree($3);
464 };
465 connecthost: HOST '=' QSTRING ';'
466 {
467  MyFree(host);
468  host = $3;
469 };
470 connectport: PORT '=' NUMBER ';'
471 {
472  port = $3;
473 };
474 connectvhost: VHOST '=' QSTRING ';'
475 {
476  MyFree(origin);
477  origin = $3;
478 };
479 connectleaf: LEAF ';'
480 {
481  maxlinks = 0;
482 };
483 connecthub: HUB ';'
484 {
485  MyFree(hub_limit);
486  DupString(hub_limit, "*");
487 };
488 connecthublimit: HUB '=' QSTRING ';'
489 {
490  MyFree(hub_limit);
491  hub_limit = $3;
492 };
493 connectmaxhops: MAXHOPS '=' expr ';'
494 {
495   maxlinks = $3;
496 };
497 connectauto: AUTOCONNECT '=' YES ';' { flags |= CONF_AUTOCONNECT; }
498  | AUTOCONNECT '=' NO ';' { flags &= ~CONF_AUTOCONNECT; };
499
500 uworldblock: UWORLD '{' uworlditems '}' ';';
501 uworlditems: uworlditem uworlditems | uworlditem;
502 uworlditem: uworldname;
503 uworldname: NAME '=' QSTRING ';'
504 {
505   make_conf(CONF_UWORLD)->host = $3;
506 };
507
508 operblock: OPER '{' operitems '}' ';'
509 {
510   struct ConfItem *aconf = NULL;
511   if (name == NULL)
512     parse_error("Missing name in operator block");
513   else if (pass == NULL)
514     parse_error("Missing password in operator block");
515   else if (host == NULL)
516     parse_error("Missing host in operator block");
517   else if (c_class == NULL)
518     parse_error("Invalid or missing class in operator block");
519   else {
520     aconf = make_conf(CONF_OPERATOR);
521     aconf->name = name;
522     aconf->passwd = pass;
523     conf_parse_userhost(aconf, host);
524     aconf->conn_class = c_class;
525     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
526     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
527     if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
528         && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
529       parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
530   }
531   if (!aconf) {
532     MyFree(name);
533     MyFree(pass);
534     MyFree(host);
535   }
536   name = pass = host = NULL;
537   c_class = NULL;
538   memset(&privs, 0, sizeof(privs));
539   memset(&privs_dirty, 0, sizeof(privs_dirty));
540 };
541 operitems: operitem | operitems operitem;
542 operitem: opername | operpass | operhost | operclass | priv;
543 opername: NAME '=' QSTRING ';'
544 {
545   MyFree(name);
546   name = $3;
547 };
548 operpass: PASS '=' QSTRING ';'
549 {
550   MyFree(pass);
551   pass = $3;
552 };
553 operhost: HOST '=' QSTRING ';'
554 {
555  MyFree(host);
556  if (!strchr($3, '@'))
557  {
558    int uh_len;
559    host = (char*) MyMalloc((uh_len = strlen($3)+3));
560    ircd_snprintf(0, host, uh_len, "*@%s", $3);
561    MyFree($3);
562  }
563  else
564    host = $3;
565 };
566 operclass: CLASS '=' QSTRING ';'
567 {
568  c_class = find_class($3);
569  if (!c_class)
570   parse_error("No such connection class '%s' for Operator block", $3);
571  MyFree($3);
572 };
573
574 priv: privtype '=' yesorno ';'
575 {
576   FlagSet(&privs_dirty, $1);
577   if (($3 == 1) ^ invert)
578     FlagSet(&privs, $1);
579   else
580     FlagClr(&privs, $1);
581   invert = 0;
582 };
583
584 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
585           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
586           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
587           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
588           KILL { $$ = PRIV_KILL; } |
589           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
590           TPRIV_REHASH { $$ = PRIV_REHASH; } |
591           TPRIV_RESTART { $$ = PRIV_RESTART; } |
592           TPRIV_DIE { $$ = PRIV_DIE; } |
593           TPRIV_GLINE { $$ = PRIV_GLINE; } |
594           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
595           JUPE { $$ = PRIV_JUPE; } |
596           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
597           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
598           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
599           TPRIV_SET { $$ = PRIV_SET; } |
600           TPRIV_WHOX { $$ = PRIV_WHOX; } |
601           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
602           TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
603           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
604           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
605           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
606           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
607           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
608           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
609           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
610           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
611           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
612           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
613           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
614           TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
615
616 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
617
618 /* The port block... */
619 portblock: PORT '{' portitems '}' ';'
620 {
621   if (port > 0 && port <= 0xFFFF)
622     add_listener(port, host, pass, tconn, tping);
623   else
624     parse_error("Port %d is out of range", port);
625   MyFree(host);
626   MyFree(pass);
627   host = pass = NULL;
628   port = tconn = tping = 0;
629 };
630 portitems: portitem portitems | portitem;
631 portitem: portnumber | portvhost | portmask | portserver | porthidden;
632 portnumber: PORT '=' NUMBER ';'
633 {
634   port = $3;
635 };
636
637 portvhost: VHOST '=' QSTRING ';'
638 {
639   MyFree(host);
640   host = $3;
641 };
642
643 portmask: MASK '=' QSTRING ';'
644 {
645   MyFree(pass);
646   pass = $3;
647 };
648
649 portserver: SERVER '=' YES ';'
650 {
651   tconn = -1;
652 } | SERVER '=' NO ';'
653 {
654   tconn = 0;
655 };
656
657 porthidden: HIDDEN '=' YES ';'
658 {
659   tping = -1;
660 } | HIDDEN '=' NO ';'
661 {
662   tping = 0;
663 };
664
665 clientblock: CLIENT
666 {
667   maxlinks = 65535;
668 }
669 '{' clientitems '}' ';'
670 {
671   struct ConfItem *aconf = 0;
672   struct irc_in_addr addr;
673   unsigned char addrbits = 0;
674
675   if (!c_class)
676     parse_error("Invalid or missing class in Client block");
677   else if (ip && !ipmask_parse(ip, &addr, &addrbits))
678     parse_error("Invalid IP address %s in Client block", ip);
679   else {
680     aconf = make_conf(CONF_CLIENT);
681     aconf->username = username;
682     aconf->host = host;
683     if (ip)
684       memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
685     else
686       memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
687     aconf->addrbits = addrbits;
688     aconf->name = ip;
689     aconf->conn_class = c_class;
690     aconf->maximum = maxlinks;
691     aconf->passwd = pass;
692   }
693   if (!aconf) {
694     MyFree(username);
695     MyFree(host);
696     MyFree(ip);
697     MyFree(pass);
698   }
699   host = NULL;
700   username = NULL;
701   c_class = NULL;
702   ip = NULL;
703   pass = NULL;
704 };
705 clientitems: clientitem clientitems | clientitem;
706 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks;
707 clienthost: HOST '=' QSTRING ';'
708 {
709   char *sep = strchr($3, '@');
710   MyFree(host);
711   if (sep) {
712     *sep++ = '\0';
713     MyFree(username);
714     DupString(host, sep);
715     username = $3;
716   } else {
717     host = $3;
718   }
719 };
720 clientip: IP '=' QSTRING ';'
721 {
722   char *sep;
723   sep = strchr($3, '@');
724   MyFree(ip);
725   if (sep) {
726     *sep++ = '\0';
727     MyFree(username);
728     DupString(ip, sep);
729     username = $3;
730   } else {
731     ip = $3;
732   }
733 };
734 clientusername: USERNAME '=' QSTRING ';'
735 {
736   MyFree(username);
737   username = $3;
738 };
739 clientclass: CLASS '=' QSTRING ';'
740 {
741   c_class = find_class($3);
742   if (!c_class)
743     parse_error("No such connection class '%s' for Class block", $3);
744   MyFree($3);
745 };
746 clientpass: PASS '=' QSTRING ';'
747 {
748   MyFree(pass);
749   pass = $3;
750 };
751 clientmaxlinks: MAXLINKS '=' expr ';'
752 {
753   maxlinks = $3;
754 };
755
756 killblock: KILL
757 {
758   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
759 } '{' killitems '}' ';'
760 {
761   if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
762     dconf->next = denyConfList;
763     denyConfList = dconf;
764   }
765   else
766   {
767     MyFree(dconf->usermask);
768     MyFree(dconf->hostmask);
769     MyFree(dconf->realmask);
770     MyFree(dconf->message);
771     MyFree(dconf);
772     parse_error("Kill block must match on at least one of username, host or realname");
773   }
774   dconf = NULL;
775 };
776 killitems: killitem killitems | killitem;
777 killitem: killuhost | killreal | killusername | killreasonfile | killreason;
778 killuhost: HOST '=' QSTRING ';'
779 {
780   char *h;
781   MyFree(dconf->hostmask);
782   MyFree(dconf->usermask);
783   if ((h = strchr($3, '@')) == NULL)
784   {
785     DupString(dconf->usermask, "*");
786     dconf->hostmask = $3;
787   }
788   else
789   {
790     *h++ = '\0';
791     DupString(dconf->hostmask, h);
792     dconf->usermask = $3;
793   }
794   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
795 };
796
797 killusername: USERNAME '=' QSTRING ';'
798 {
799   MyFree(dconf->usermask);
800   dconf->usermask = $3;
801 };
802
803 killreal: REAL '=' QSTRING ';'
804 {
805  MyFree(dconf->realmask);
806  dconf->realmask = $3;
807 };
808
809 killreason: REASON '=' QSTRING ';'
810 {
811  dconf->flags &= ~DENY_FLAGS_FILE;
812  MyFree(dconf->message);
813  dconf->message = $3;
814 };
815
816 killreasonfile: TFILE '=' QSTRING ';'
817 {
818  dconf->flags |= DENY_FLAGS_FILE;
819  MyFree(dconf->message);
820  dconf->message = $3;
821 };
822
823 cruleblock: CRULE
824 {
825   tconn = CRULE_AUTO;
826 } '{' cruleitems '}' ';'
827 {
828   struct CRuleNode *node = NULL;
829   if (host == NULL)
830     parse_error("Missing host in crule block");
831   else if (pass == NULL)
832     parse_error("Missing rule in crule block");
833   else if ((node = crule_parse(pass)) == NULL)
834     parse_error("Invalid rule '%s' in crule block", pass);
835   else
836   {
837     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
838     p->hostmask = host;
839     p->rule = pass;
840     p->type = tconn;
841     p->node = node;
842     p->next = cruleConfList;
843     cruleConfList = p;
844   }
845   if (!node)
846   {
847     MyFree(host);
848     MyFree(pass);
849   }
850   host = pass = NULL;
851   tconn = 0;
852 };
853
854 cruleitems: cruleitem cruleitems | cruleitem;
855 cruleitem: cruleserver | crulerule | cruleall;
856
857 cruleserver: SERVER '=' QSTRING ';'
858 {
859   MyFree(host);
860   collapse($3);
861   host = $3;
862 };
863
864 crulerule: RULE '=' QSTRING ';'
865 {
866  MyFree(pass);
867  pass = $3;
868 };
869
870 cruleall: ALL '=' YES ';'
871 {
872  tconn = CRULE_ALL;
873 } | ALL '=' NO ';'
874 {
875  tconn = CRULE_AUTO;
876 };
877
878 motdblock: MOTD '{' motditems '}' ';'
879 {
880   if (host != NULL && pass != NULL)
881     motd_add(host, pass);
882   MyFree(host);
883   MyFree(pass);
884   host = pass = NULL;
885 };
886
887 motditems: motditem motditems | motditem;
888 motditem: motdhost | motdfile;
889 motdhost: HOST '=' QSTRING ';'
890 {
891   host = $3;
892 };
893
894 motdfile: TFILE '=' QSTRING ';'
895 {
896   pass = $3;
897 };
898
899 featuresblock: FEATURES '{' featureitems '}' ';';
900 featureitems: featureitems featureitem | featureitem;
901
902 featureitem: QSTRING
903 {
904   stringlist[0] = $1;
905   stringno = 1;
906 } '=' stringlist ';';
907
908 stringlist: QSTRING
909 {
910   stringlist[1] = $1;
911   stringno = 2;
912 } posextrastrings
913 {
914   unsigned int ii;
915   feature_set(NULL, (const char * const *)stringlist, stringno);
916   for (ii = 0; ii < stringno; ++ii)
917     MyFree(stringlist[ii]);
918 };
919 posextrastrings: /* empty */ | extrastrings;
920 extrastrings: extrastrings extrastring | extrastring;
921 extrastring: QSTRING
922 {
923   if (stringno < MAX_STRINGS)
924     stringlist[stringno++] = $1;
925   else
926     MyFree($1);
927 };
928
929 quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
930 quarantineitems: quarantineitems quarantineitem | quarantineitem;
931 quarantineitem: QSTRING '=' QSTRING ';'
932 {
933   struct qline *qconf = MyCalloc(1, sizeof(*qconf));
934   qconf->chname = $1;
935   qconf->reason = $3;
936   qconf->next = GlobalQuarantineList;
937   GlobalQuarantineList = qconf;
938 };
939
940 pseudoblock: PSEUDO QSTRING '{'
941 {
942   smap = MyCalloc(1, sizeof(struct s_map));
943   smap->command = $2;
944 }
945 pseudoitems '}' ';'
946 {
947   int valid = 0;
948
949   if (!smap->name)
950     parse_error("Missing name in pseudo %s block", smap->command);
951   else if (!smap->services)
952     parse_error("Missing nick in pseudo %s block", smap->command);
953   else
954     valid = 1;
955   if (valid && register_mapping(smap))
956   {
957     smap->next = GlobalServiceMapList;
958     GlobalServiceMapList = smap;
959   }
960   else
961   {
962     struct nick_host *nh, *next;
963     for (nh = smap->services; nh; nh = next)
964     {
965       next = nh->next;
966       MyFree(nh);
967     }
968     MyFree(smap->name);
969     MyFree(smap->command);
970     MyFree(smap->prepend);
971     MyFree(smap);
972   }
973   smap = NULL;
974 };
975
976 pseudoitems: pseudoitem pseudoitems | pseudoitem;
977 pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags;
978 pseudoname: NAME '=' QSTRING ';'
979 {
980   MyFree(smap->name);
981   smap->name = $3;
982 };
983 pseudoprepend: PREPEND '=' QSTRING ';'
984 {
985   MyFree(smap->prepend);
986   smap->prepend = $3;
987 };
988 pseudonick: NICK '=' QSTRING ';'
989 {
990   char *sep = strchr($3, '@');
991
992   if (sep != NULL) {
993     size_t slen = strlen($3);
994     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
995     memcpy(nh->nick, $3, slen + 1);
996     nh->nicklen = sep - $3;
997     nh->next = smap->services;
998     smap->services = nh;
999   }
1000   MyFree($3);
1001 };
1002 pseudoflags: FAST ';'
1003 {
1004   smap->flags |= SMAP_FAST;
1005 };
1006
1007 iauthblock: IAUTH '{'
1008 {
1009   tconn = 60;
1010   tping = 60;
1011 } iauthitems '}' ';'
1012 {
1013   if (!host)
1014     parse_error("Missing host in iauth block");
1015   else if (!port)
1016     parse_error("Missing port in iauth block");
1017   else
1018     iauth_connect(host, port, pass, tconn, tping);
1019   MyFree(pass);
1020   MyFree(host);
1021   pass = host = NULL;
1022   port = tconn = tping = 0;
1023 };
1024
1025 iauthitems: iauthitem iauthitems | iauthitem;
1026 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout;
1027 iauthpass: PASS '=' QSTRING ';'
1028 {
1029   MyFree(pass);
1030   pass = $3;
1031 };
1032 iauthhost: HOST '=' QSTRING ';'
1033 {
1034   MyFree(host);
1035   host = $3;
1036 };
1037 iauthport: PORT '=' NUMBER ';'
1038 {
1039   port = $3;
1040 };
1041 iauthconnfreq: CONNECTFREQ '=' timespec ';'
1042 {
1043   tconn = $3;
1044 };
1045 iauthtimeout: TIMEOUT '=' timespec ';'
1046 {
1047   tping = $3;
1048 };