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