ca58bf3fc93c807a6f35bde0da0c5fd903c7b8cc
[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 "support.h"
57 #include "sys.h"
58 #include <stdlib.h>
59 #include <stdio.h>
60 #include <string.h>
61 #include <arpa/inet.h>
62 #define MAX_STRINGS 80 /* Maximum number of feature params. */
63   extern struct LocalConf   localConf;
64   extern struct DenyConf*   denyConfList;
65   extern struct CRuleConf*  cruleConfList;
66   extern struct ServerConf* serverConfList;
67   extern struct s_map*      GlobalServiceMapList;
68   extern struct qline*      GlobalQuarantineList;
69  
70
71   int yylex(void);
72   /* Now all the globals we need :/... */
73   int tping, tconn, maxlinks, sendq, port, invert;
74   int stringno;
75   char *name, *pass, *host;
76   char *stringlist[MAX_STRINGS];
77   struct ConnectionClass *c_class;
78   struct ConfItem *aconf;
79   struct DenyConf *dconf;
80   struct ServerConf *sconf;
81   struct qline *qconf = NULL;
82   struct s_map *smap;
83   struct Privs privs;
84   struct Privs privs_dirty;
85
86 static void parse_error(char *pattern,...) {
87   static char error_buffer[1024];
88   va_list vl;
89   va_start(vl,pattern);
90   ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
91   va_end(vl);
92   yyerror(error_buffer);
93 }
94
95 %}
96
97 %token <text> QSTRING
98 %token <num> NUMBER
99 %token <text> FNAME
100
101 %token GENERAL
102 %token ADMIN
103 %token LOCATION
104 %token CONTACT
105 %token CONNECT
106 %token CLASS
107 %token CHANNEL
108 %token PINGFREQ
109 %token CONNECTFREQ
110 %token MAXLINKS
111 %token SENDQ
112 %token NAME
113 %token HOST
114 %token PASS
115 %token LOCAL
116 %token SECONDS
117 %token MINUTES
118 %token HOURS
119 %token DAYS
120 %token WEEKS
121 %token MONTHS
122 %token YEARS
123 %token DECADES
124 %token BYTES
125 %token KBYTES
126 %token MBYTES
127 %token GBYTES
128 %token TBYTES
129 %token SERVER
130 %token PORT
131 %token MASK
132 %token HUB
133 %token LEAF
134 %token UWORLD
135 %token YES
136 %token NO
137 %token OPER
138 %token PORT
139 %token VHOST
140 %token MASK
141 %token HIDDEN
142 %token MOTD
143 %token JUPE
144 %token NICK
145 %token NUMERIC
146 %token DESCRIPTION
147 %token CLIENT
148 %token KILL
149 %token CRULE
150 %token REAL
151 %token REASON
152 %token TFILE
153 %token RULE
154 %token ALL
155 %token IP
156 %token FEATURES
157 %token QUARANTINE
158 %token PSEUDO
159 %token PREPEND
160 %token USERMODE
161 %token IAUTH
162 %token TIMEOUT
163 /* and now a lot of priviledges... */
164 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
165 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
166 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_LOCAL_JUPE TPRIV_LOCAL_BADCHAN
167 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
168 %token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
169 %token TPRIV_UNLIMIT_QUERY TPRIV_DISPLAY TPRIV_SEE_OPERS TPRIV_WIDE_GLINE
170 %token TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE
171 /* and some types... */
172 %type <num> sizespec
173 %type <num> timespec timefactor factoredtimes factoredtime
174 %type <num> expr yesorno privtype
175 %left '+' '-'
176 %left '*' '/'
177
178 %union{
179  char *text;
180  int num;
181 }
182
183 %%
184 /* Blocks in the config file... */
185 blocks: blocks block | block;
186 block: adminblock | generalblock | classblock | connectblock |
187        serverblock | operblock | portblock | jupeblock | clientblock |
188        killblock | cruleblock | motdblock | featuresblock | quarantineblock |
189        pseudoblock | iauthblock | error;
190
191 /* The timespec, sizespec and expr was ripped straight from
192  * ircd-hybrid-7. */
193 timespec: expr | factoredtimes;
194
195 factoredtimes: factoredtimes factoredtime
196 {
197   $$ = $1 + $2;
198 } | factoredtime;
199
200 factoredtime: expr timefactor
201 {
202   $$ = $1 * $2;
203 };
204
205 timefactor: SECONDS { $$ = 1; }
206 | MINUTES { $$ = 60; }
207 | HOURS { $$ = 60 * 60; }
208 | DAYS { $$ = 60 * 60 * 24; }
209 | WEEKS { $$ = 60 * 60 * 24 * 7; }
210 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
211 | YEARS { $$ = 60 * 60 * 24 * 365; }
212 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
213
214
215 sizespec:       expr    {
216                         $$ = $1;
217                 }
218                 | expr BYTES  { 
219                         $$ = $1;
220                 }
221                 | expr KBYTES {
222                         $$ = $1 * 1024;
223                 }
224                 | expr MBYTES {
225                         $$ = $1 * 1024 * 1024;
226                 }
227                 | expr GBYTES {
228                         $$ = $1 * 1024 * 1024 * 1024;
229                 }
230                 | expr TBYTES {
231                         $$ = $1 * 1024 * 1024 * 1024;
232                 }
233                 ;
234
235 /* this is an arithmatic expression */
236 expr: NUMBER
237                 { 
238                         $$ = $1;
239                 }
240                 | expr '+' expr { 
241                         $$ = $1 + $3;
242                 }
243                 | expr '-' expr { 
244                         $$ = $1 - $3;
245                 }
246                 | expr '*' expr { 
247                         $$ = $1 * $3;
248                 }
249                 | expr '/' expr { 
250                         $$ = $1 / $3;
251                 }
252 /* leave this out until we find why it makes BSD yacc dump core -larne
253                 | '-' expr  %prec NEG
254                 = {
255                         $$ = -$2;
256                 } */
257                 | '(' expr ')' {
258                         $$ = $2;
259                 }
260                 ;
261
262 jupeblock: JUPE '{' jupeitems '}' ';' ;
263 jupeitems: jupeitem jupeitems | jupeitem;
264 jupeitem: jupenick | error;
265 jupenick: NICK '=' QSTRING
266 {
267   addNickJupes(yylval.text);
268 } ';';
269
270 generalblock: GENERAL '{' generalitems '}' ';' ;
271 generalitems: generalitem generalitems | generalitem;
272 generalitem: generalnumeric | generalname | generalvhost | generaldesc | error;
273 generalnumeric: NUMERIC '=' NUMBER ';'
274 {
275   if (localConf.numeric == 0)
276     localConf.numeric = yylval.num;
277   else if (localConf.numeric != yylval.num)
278     parse_error("Redefinition of server numeric %i (%i)",yylval.num,
279                 localConf.numeric);
280 };
281
282 generalname: NAME '=' QSTRING ';'
283 {
284   if (localConf.name == NULL)
285     DupString(localConf.name, yylval.text);
286   else if (strcmp(localConf.name, yylval.text))
287     parse_error("Redefinition of server name %s (%s)",yylval.text,
288                 localConf.name);
289 };
290
291 generaldesc: DESCRIPTION '=' QSTRING ';'
292 {
293   MyFree(localConf.description);
294   DupString(localConf.description, yylval.text);
295   ircd_strncpy(cli_info(&me), yylval.text, REALLEN);
296 };
297
298 generalvhost: VHOST '=' QSTRING ';'
299 {
300   if (INADDR_NONE ==
301       (localConf.vhost_address.s_addr = inet_addr(yylval.text)))
302     localConf.vhost_address.s_addr = INADDR_ANY;
303 };
304
305 adminblock: ADMIN '{' adminitems '}'
306 {
307   if (localConf.location1 == NULL)
308     DupString(localConf.location1, "");
309   if (localConf.location2 == NULL)
310     DupString(localConf.location2, "");
311   if (localConf.contact == NULL)
312     DupString(localConf.contact, "");
313 } ';';
314 adminitems: adminitems adminitem | adminitem;
315 adminitem: adminlocation | admincontact | error;
316 adminlocation: LOCATION '=' QSTRING ';'
317 {
318  if (localConf.location1 == NULL)
319   DupString(localConf.location1, yylval.text);
320  else if (localConf.location2 == NULL)
321   DupString(localConf.location2, yylval.text);
322  /* Otherwise just drop it. -A1kmm */
323 };
324 admincontact: CONTACT '=' QSTRING ';'
325 {
326  if (localConf.contact != NULL)
327    MyFree(localConf.contact);
328  DupString(localConf.contact, yylval.text);
329 };
330
331 classblock: CLASS {
332   name = NULL;
333   tping = 90;
334   tconn = 0;
335   maxlinks = 0;
336   sendq = 0;
337   pass = NULL;
338   memset(&privs, 0, sizeof(privs));
339   memset(&privs_dirty, 0, sizeof(privs_dirty));
340 } '{' classitems '}'
341 {
342   if (name != NULL)
343   {
344     struct ConnectionClass *c_class;
345     add_class(name, tping, tconn, maxlinks, sendq);
346     c_class = find_class(name);
347     c_class->default_umode = pass;
348     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
349     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
350   }
351   else {
352    parse_error("Missing name in class block");
353   }
354   pass = NULL;
355 } ';';
356 classitems: classitem classitems | classitem;
357 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
358            classsendq | classusermode | priv | error;
359 classname: NAME '=' QSTRING ';'
360 {
361   MyFree(name);
362   DupString(name, yylval.text);
363 };
364 classpingfreq: PINGFREQ '=' timespec ';'
365 {
366   tping = yylval.num;
367 };
368 classconnfreq: CONNECTFREQ '=' timespec ';'
369 {
370   tconn = yylval.num;
371 };
372 classmaxlinks: MAXLINKS '=' expr ';'
373 {
374   maxlinks = yylval.num;
375 };
376 classsendq: SENDQ '=' sizespec ';'
377 {
378   sendq = yylval.num;
379 };
380 classusermode: USERMODE '=' QSTRING ';'
381 {
382   if (pass)
383     MyFree(pass);
384   DupString(pass, yylval.text);
385 };
386
387 connectblock: CONNECT
388 {
389  name = pass = host = NULL;
390  c_class = NULL;
391  port = 0;
392 } '{' connectitems '}'
393 {
394  if (name != NULL && pass != NULL && host != NULL && c_class != NULL && 
395      /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
396      !strchr(host, '?'))
397  {
398    aconf = make_conf();
399    aconf->status = CONF_SERVER;
400    aconf->name = name;
401    aconf->passwd = pass;
402    aconf->conn_class = c_class;
403    aconf->port = port;
404    aconf->status = CONF_SERVER;
405    aconf->host = host;
406    aconf->next = GlobalConfList;
407    aconf->ipnum.s_addr = INADDR_NONE;
408    lookup_confhost(aconf);
409    GlobalConfList = aconf;
410  }
411  else
412  {
413    MyFree(name);
414    MyFree(pass);
415    MyFree(host);
416    name = pass = host = NULL;
417    parse_error("Bad connect block");
418  }
419 }';';
420 connectitems: connectitem connectitems | connectitem;
421 connectitem: connectname | connectpass | connectclass | connecthost
422               | connectport | error;
423 connectname: NAME '=' QSTRING ';'
424 {
425  MyFree(name);
426  DupString(name, yylval.text);
427 };
428 connectpass: PASS '=' QSTRING ';'
429 {
430  MyFree(pass);
431  DupString(pass, yylval.text);
432 };
433 connectclass: CLASS '=' QSTRING ';'
434 {
435  c_class = find_class(yylval.text);
436 };
437 connecthost: HOST '=' QSTRING ';'
438 {
439  MyFree(host);
440  DupString(host, yylval.text);
441 };
442 connectport: PORT '=' NUMBER ';'
443 {
444  port = yylval.num;
445 };
446
447 serverblock: SERVER
448 {
449  aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
450  memset(aconf, 0, sizeof(*aconf));
451 } '{' serveritems '}'
452 {
453  if (aconf->status == 0)
454  {
455    MyFree(aconf->host);
456    MyFree(aconf->name);
457    MyFree(aconf);
458    aconf = NULL;
459    parse_error("Bad server block");
460  }
461  else
462  {
463    aconf->next = GlobalConfList;
464    GlobalConfList = aconf;
465  }
466 } ';';
467 serveritems: serveritem serveritems | serveritem;
468 serveritem: servername | servermask | serverhub | serverleaf |
469              serveruworld | error;
470 servername: NAME '=' QSTRING
471 {
472  MyFree(aconf->name);
473  DupString(aconf->name, yylval.text);
474 } ';' ;
475 servermask: MASK '=' QSTRING
476 {
477  MyFree(aconf->host);
478  DupString(aconf->host, yylval.text);
479 } ';' ;
480 /* XXX - perhaps we should do this the hybrid way in connect blocks
481  * instead -A1kmm. */
482 serverhub: HUB '=' YES ';'
483 {
484  aconf->status |= CONF_HUB;
485  aconf->status &= ~CONF_LEAF;
486 }
487 | HUB '=' NO
488 {
489  aconf->status &= ~CONF_HUB;
490 } ';'; 
491 serverleaf: LEAF '=' YES ';'
492 {
493  if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
494   aconf->status |= CONF_LEAF;
495  else
496   parse_error("Server is both leaf and a hub");
497 }
498 | LEAF '=' NO ';'
499 {
500  aconf->status &= ~CONF_LEAF;
501 };
502 serveruworld: UWORLD '=' YES ';'
503 {
504  aconf->status |= CONF_UWORLD;
505  aconf->status &= ~CONF_LEAF;
506 }
507 | UWORLD '=' NO ';'
508 {
509   aconf->status &= ~CONF_UWORLD;
510 };
511
512 operblock: OPER
513 {
514   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
515   memset(aconf, 0, sizeof(*aconf));
516   memset(&privs, 0, sizeof(privs));
517   memset(&privs_dirty, 0, sizeof(privs_dirty));
518   aconf->status = CONF_OPERATOR;
519 } '{' operitems '}' ';'
520 {
521   if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL
522       && aconf->conn_class != NULL)
523   {
524     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
525     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
526     if (!PrivHas(&privs_dirty, PRIV_PROPAGATE)
527         && !PrivHas(&aconf->conn_class->privs_dirty, PRIV_PROPAGATE))
528       parse_error("Operator block for %s and class %s have no LOCAL setting", aconf->name, aconf->conn_class->cc_name);
529     aconf->next = GlobalConfList;
530     GlobalConfList = aconf;
531   }
532   else
533   {
534     log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
535     MyFree(aconf->name);
536     MyFree(aconf->passwd);
537     MyFree(aconf->host);
538     MyFree(aconf);
539     aconf = NULL;
540   }
541 };
542 operitems: operitem | operitems operitem;
543 operitem: opername | operpass | operhost | operclass | priv | error;
544
545 opername: NAME '=' QSTRING ';'
546 {
547   MyFree(aconf->name);
548   DupString(aconf->name, yylval.text);
549 };
550
551 operpass: PASS '=' QSTRING ';'
552 {
553   MyFree(aconf->passwd);
554   DupString(aconf->passwd, yylval.text);
555 };
556
557 operhost: HOST '=' QSTRING ';'
558 {
559  MyFree(aconf->host);
560  if (!strchr(yylval.text, '@'))
561  {
562    int uh_len;
563    char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3));
564    ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
565    aconf->host = b;
566  }
567  else
568    DupString(aconf->host, yylval.text);
569 };
570
571 operclass: CLASS '=' QSTRING ';'
572 {
573  aconf->conn_class = find_class(yylval.text);
574 };
575
576 priv: privtype '=' yesorno ';'
577 {
578   PrivSet(&privs_dirty, $1);
579   if (($3 == 1) ^ invert)
580     PrivSet(&privs, $1);
581   else
582     PrivClr(&privs, $1);
583   invert = 0;
584 };
585
586 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
587           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
588           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
589           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
590           KILL { $$ = PRIV_KILL; } |
591           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
592           TPRIV_REHASH { $$ = PRIV_REHASH; } |
593           TPRIV_RESTART { $$ = PRIV_RESTART; } |
594           TPRIV_DIE { $$ = PRIV_DIE; } |
595           TPRIV_GLINE { $$ = PRIV_GLINE; } |
596           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
597           JUPE { $$ = PRIV_JUPE; } |
598           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
599           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
600           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
601           TPRIV_SET { $$ = PRIV_SET; } |
602           TPRIV_WHOX { $$ = PRIV_WHOX; } |
603           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
604           TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
605           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
606           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
607           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
608           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
609           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
610           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
611           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
612           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
613           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
614           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
615           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; };
616
617 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
618
619 /* The port block... */
620 portblock: PORT {
621   port = 0;
622   host = NULL;
623   /* Hijack these for is_server, is_hidden to cut down on globals... */
624   tconn = 0;
625   tping = 0;
626   /* and this for mask... */
627   pass = NULL;
628 } '{' portitems '}' ';'
629 {
630   if (port > 0 && port <= 0xFFFF)
631   {
632     add_listener(port, host, pass, tconn, tping);
633   }
634   else
635   {
636     parse_error("Bad port block");
637   }
638   MyFree(host);
639   MyFree(pass);
640   host = pass = NULL;
641 };
642 portitems: portitem portitems | portitem;
643 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
644 portnumber: PORT '=' NUMBER ';'
645 {
646   port = yylval.num;
647 };
648
649 portvhost: VHOST '=' QSTRING ';'
650 {
651   MyFree(host);
652   DupString(host, yylval.text);
653 };
654
655 portmask: MASK '=' QSTRING ';'
656 {
657   MyFree(pass);
658   DupString(pass, yylval.text);
659 };
660
661 portserver: SERVER '=' YES ';'
662 {
663   tconn = -1;
664 } | SERVER '=' NO ';'
665 {
666   tconn = 0;
667 };
668
669 porthidden: HIDDEN '=' YES ';'
670 {
671   tping = -1;
672 } | HIDDEN '=' NO ';'
673 {
674   tping = 0;
675 };
676
677 clientblock: CLIENT
678 {
679   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
680   memset(aconf, 0, sizeof(*aconf));
681   aconf->status = CONF_CLIENT;
682 } '{' clientitems '}'
683 {
684   if ((aconf->host != NULL || aconf->name!=NULL))
685   {
686     if (aconf->host == NULL)
687       DupString(aconf->host, "");
688     if (aconf->name == NULL)
689       DupString(aconf->name, "");
690     if (aconf->conn_class == NULL)
691       aconf->conn_class = find_class("default");
692     aconf->next = GlobalConfList;
693     GlobalConfList = aconf;
694     aconf = NULL;
695   }
696   else
697   {
698    MyFree(aconf->host);
699    MyFree(aconf->passwd);
700    MyFree(aconf);
701    aconf = NULL;
702    parse_error("Bad client block");
703   }
704 } ';';
705 clientitems: clientitem clientitems | clientitem;
706 clientitem: clienthost | clientclass | clientpass | clientip | error;
707 clientip: IP '=' QSTRING ';'
708 {
709   MyFree(aconf->host);
710   DupString(aconf->host, yylval.text);
711 };
712
713 clienthost: HOST '=' QSTRING ';'
714 {
715   MyFree(aconf->name);
716   DupString(aconf->name, yylval.text);
717 };
718
719 clientclass: CLASS '=' QSTRING ';'
720 {
721   aconf->conn_class = find_class(yylval.text);
722 };
723
724 clientpass: PASS '=' QSTRING ';'
725 {
726   MyFree(aconf->passwd);
727   DupString(aconf->passwd, yylval.text);
728 };
729
730 killblock: KILL
731 {
732   dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
733   memset(dconf, 0, sizeof(*dconf));
734 } '{' killitems '}'
735 {
736   if (dconf->hostmask != NULL)
737   {
738     if (dconf->usermask == NULL)
739       DupString(dconf->usermask, "*");
740     dconf->next = denyConfList;
741     denyConfList = dconf;
742     dconf = NULL;
743   }
744   else
745   {
746     MyFree(dconf->hostmask);
747     MyFree(dconf->message);
748     MyFree(dconf);
749     dconf = NULL;
750     parse_error("Bad kill block");
751   }
752 } ';';
753 killitems: killitem killitems | killitem;
754 killitem: killuhost | killreal | killreasonfile | killreason | error;
755 killuhost: HOST '=' QSTRING ';'
756 {
757   char *u, *h;
758   dconf->flags &= ~DENY_FLAGS_REALNAME;
759   MyFree(dconf->hostmask);
760   MyFree(dconf->usermask);
761   if ((h = strchr(yylval.text, '@')) == NULL)
762   {
763     u = "*";
764     h = yylval.text;
765   }
766   else
767   {
768     u = yylval.text;
769     h++;
770   }
771   DupString(dconf->hostmask, h);
772   DupString(dconf->usermask, u);
773   if (strchr(yylval.text, '.'))
774   {
775     int  c_class;
776     char ipname[16];
777     int  ad[4] = { 0 };
778     int  bits2 = 0;
779     dconf->flags |= DENY_FLAGS_IP;
780     c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
781                      &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
782     if (c_class != 5) {
783       dconf->bits = c_class * 8;
784     }
785     else {
786       dconf->bits = bits2;
787     }
788     ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
789                   ad[2], ad[3]);
790     dconf->address = inet_addr(ipname);
791   }
792 };
793
794 killreal: REAL '=' QSTRING ';'
795 {
796  dconf->flags &= ~DENY_FLAGS_IP;
797  dconf->flags |= DENY_FLAGS_REALNAME;
798  MyFree(dconf->hostmask);
799  /* Leave usermask so you can specify user and real... */
800  DupString(dconf->hostmask, yylval.text);
801 };
802
803 killreason: REASON '=' QSTRING ';'
804 {
805  dconf->flags &= DENY_FLAGS_FILE;
806  MyFree(dconf->message);
807  DupString(dconf->message, yylval.text);
808 };
809
810 killreasonfile: TFILE '=' QSTRING ';'
811 {
812  dconf->flags |= DENY_FLAGS_FILE;
813  MyFree(dconf->message);
814  DupString(dconf->message, yylval.text);
815 };
816
817 cruleblock: CRULE
818 {
819   host = pass = NULL;
820   tconn = CRULE_AUTO;
821 } '{' cruleitems '}'
822 {
823   struct CRuleNode *node;
824   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
825   {
826     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
827     p->hostmask = host;
828     p->rule = pass;
829     p->type = tconn;
830     p->node = node;
831     p->next = cruleConfList;
832     cruleConfList = p;
833   }
834   else
835   {
836     MyFree(host);
837     MyFree(pass);
838     parse_error("Bad CRule block");
839   }
840 } ';';
841
842 cruleitems: cruleitem cruleitems | cruleitem;
843 cruleitem: cruleserver | crulerule | cruleall | error;
844
845 cruleserver: SERVER '=' QSTRING ';'
846 {
847   MyFree(host);
848   collapse(yylval.text);
849   DupString(host, yylval.text);
850 };
851
852 crulerule: RULE '=' QSTRING ';'
853 {
854  MyFree(pass);
855  DupString(pass, yylval.text);
856 };
857
858 cruleall: ALL '=' YES ';'
859 {
860  tconn = CRULE_ALL;
861 } | ALL '=' NO ';'
862 {
863  tconn = CRULE_AUTO;
864 };
865
866 motdblock: MOTD {
867  pass = host = NULL;
868 } '{' motditems '}'
869 {
870   if (host != NULL && pass != NULL)
871     motd_add(host, pass);
872   MyFree(host);
873   MyFree(pass);
874   host = pass = NULL;
875 } ';';
876
877 motditems: motditem motditems | motditem;
878 motditem: motdhost | motdfile | error;
879 motdhost: HOST '=' QSTRING ';'
880 {
881   DupString(host, yylval.text);
882 };
883
884 motdfile: TFILE '=' QSTRING ';'
885 {
886   DupString(pass, yylval.text);
887 };
888
889 featuresblock: FEATURES '{' featureitems '}' ';';
890 featureitems: featureitems featureitem | featureitem;
891
892 featureitem: QSTRING
893 {
894   stringlist[0] = $1;
895   stringno = 1;
896 } '=' stringlist ';';
897
898 stringlist: QSTRING
899 {
900   stringlist[1] = $1;
901   stringno = 2;
902 } posextrastrings
903 {
904   feature_set(NULL, (const char * const *)stringlist, stringno);
905 };
906 posextrastrings: /* empty */ | extrastrings;
907 extrastrings: extrastrings extrastring | extrastring;
908 extrastring: QSTRING
909 {
910   if (stringno < MAX_STRINGS)
911     stringlist[stringno++] = $1;
912 };
913
914 quarantineblock: QUARANTINE '{'
915 {
916   if (qconf != NULL)
917     qconf = (struct qline*) MyMalloc(sizeof(*qconf));
918   else
919   {
920     if (qconf->chname != NULL)
921       MyFree(qconf->chname);
922     if (qconf->reason != NULL)
923       MyFree(qconf->reason);
924   }
925   memset(qconf, 0, sizeof(*qconf));
926 } quarantineitems '}' ';'
927 {
928   if (qconf->chname == NULL || qconf->reason == NULL)
929   {
930     log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
931               "and a reason.");
932     return 0;
933   }
934   qconf->next = GlobalQuarantineList;
935   GlobalQuarantineList = qconf;
936   qconf = NULL;
937 };
938
939 quarantineitems: CHANNEL NAME '=' QSTRING ';'
940 {
941   DupString(qconf->chname, yylval.text);
942 } | REASON '=' QSTRING ';'
943 {
944   DupString(qconf->reason, yylval.text);
945 };
946
947 pseudoblock: PSEUDO QSTRING '{'
948 {
949   smap = MyCalloc(1, sizeof(struct s_map));
950   DupString(smap->command, $2);
951 }
952 pseudoitems '}' ';'
953 {
954   if (!smap->name || !smap->services)
955   {
956     log_write(LS_CONFIG, L_ERROR, 0, "pseudo commands need a service name and list of target nicks.");
957     return 0;
958   }
959   if (register_mapping(smap))
960   {
961     smap->next = GlobalServiceMapList;
962     GlobalServiceMapList = smap;
963   }
964   else
965   {
966     struct nick_host *nh, *next;
967     for (nh = smap->services; nh; nh = next)
968     {
969       next = nh->next;
970       MyFree(nh);
971     }
972     MyFree(smap->name);
973     MyFree(smap->command);
974     MyFree(smap->prepend);
975     MyFree(smap);
976   }
977   smap = NULL;
978 };
979
980 pseudoitems: pseudoitem pseudoitems | pseudoitem;
981 pseudoitem: pseudoname | pseudoprepend | pseudonick | error;
982 pseudoname: NAME '=' QSTRING ';'
983 {
984   DupString(smap->name, yylval.text);
985 };
986 pseudoprepend: PREPEND '=' QSTRING ';'
987 {
988   DupString(smap->prepend, yylval.text);
989 };
990 pseudonick: NICK '=' QSTRING ';'
991 {
992   char *sep = strchr(yylval.text, '@');
993
994   if (sep != NULL) {
995     size_t slen = strlen(yylval.text);
996     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
997     memcpy(nh->nick, yylval.text, slen + 1);
998     nh->nicklen = sep - yylval.text;
999     nh->next = smap->services;
1000     smap->services = nh;
1001   }
1002 };
1003
1004 iauthblock: IAUTH '{'
1005 {
1006   pass = host = NULL;
1007   port = 0;
1008   tconn = 60;
1009   tping = 60;
1010 } iauthitems '}' ';'
1011 {
1012   if (!name || !host || !port) {
1013     log_write(LS_CONFIG, L_ERROR, 0, "IAuth block needs a server name and port.");
1014     return 0;
1015   }
1016   iauth_connect(host, port, pass, tconn, tping);
1017   MyFree(pass);
1018   MyFree(host);
1019   pass = host = NULL;
1020 };
1021
1022 iauthitems: iauthitem iauthitems | iauthitem;
1023 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
1024 iauthpass: PASS '=' QSTRING ';'
1025 {
1026   MyFree(pass);
1027   DupString(pass, yylval.text);
1028 };
1029 iauthhost: HOST '=' QSTRING ';'
1030 {
1031   MyFree(host);
1032   DupString(host, yylval.text);
1033 };
1034 iauthport: PORT '=' NUMBER ';'
1035 {
1036   port = yylval.num;
1037 };
1038 iauthconnfreq: CONNECTFREQ '=' timespec ';'
1039 {
1040   tconn = yylval.num;
1041 };
1042 iauthtimeout: TIMEOUT '=' timespec ';'
1043 {
1044   tping = yylval.num;
1045 };