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