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