2004-05-09 Michael Poole <mdpoole@troilus.org>
[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(C) 2001 by Andrew Miller, the
5  * 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_bsd.h"
50 #include "s_conf.h"
51 #include "s_debug.h"
52 #include "s_misc.h"
53 #include "send.h"
54 #include "struct.h"
55 #include "support.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 qline     *GlobalQuarantineList;
67  
68
69   int yylex(void);
70   /* Now all the globals we need :/... */
71   int tping, tconn, maxlinks, sendq, port;
72   int stringno;
73   char *name, *pass, *host;
74   char *stringlist[MAX_STRINGS];
75   struct ConnectionClass *c_class;
76   struct ConfItem *aconf;
77   struct DenyConf *dconf;
78   struct ServerConf *sconf;
79   struct qline *qconf = NULL;
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 %token <text> FNAME
95
96 %token GENERAL
97 %token ADMIN
98 %token LOCATION
99 %token CONTACT
100 %token CONNECT
101 %token CLASS
102 %token CHANNEL
103 %token PINGFREQ
104 %token CONNECTFREQ
105 %token MAXLINKS
106 %token SENDQ
107 %token NAME
108 %token HOST
109 %token PASS
110 %token LOCAL
111 %token SECONDS
112 %token MINUTES
113 %token HOURS
114 %token DAYS
115 %token WEEKS
116 %token MONTHS
117 %token YEARS
118 %token DECADES
119 %token BYTES
120 %token KBYTES
121 %token MBYTES
122 %token GBYTES
123 %token TBYTES
124 %token SERVER
125 %token PORT
126 %token MASK
127 %token HUB
128 %token LEAF
129 %token UWORLD
130 %token YES
131 %token NO
132 %token OPER
133 %token PORT
134 %token VHOST
135 %token MASK
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 IP
151 %token FEATURES
152 %token QUARANTINE
153 /* and now a lot of priviledges... */
154 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
155 %token TPRIV_KILL TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
156 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_JUPE TPRIV_LOCAL_JUPE
157 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
158 %token TPRIV_LOCAL_BADCHAN
159 %token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
160 %token TPRIV_UNLIMIT_QUERY TPRIV_DISPLAY TPRIV_SEE_OPERS TPRIV_WIDE_GLINE
161 /* and some types... */
162 %type <num> sizespec
163 %type <num> timespec timefactor factoredtimes factoredtime
164 %type <num> expr yesorno privtype
165 %left '+' '-'
166 %left '*' '/'
167
168 %union{
169  char *text;
170  int num;
171 }
172
173 %%
174 /* Blocks in the config file... */
175 blocks: blocks block | block;
176 block: adminblock | generalblock | classblock | connectblock |
177        serverblock | operblock | portblock | jupeblock | clientblock |
178        killblock | cruleblock | motdblock | featuresblock | quarantineblock |
179        error;
180
181 /* The timespec, sizespec and expr was ripped straight from
182  * ircd-hybrid-7. */
183 timespec: expr | factoredtimes;
184
185 factoredtimes: factoredtimes factoredtime
186 {
187   $$ = $1 + $2;
188 } | factoredtime;
189
190 factoredtime: expr timefactor
191 {
192   $$ = $1 * $2;
193 };
194
195 timefactor: SECONDS { $$ = 1; }
196 | MINUTES { $$ = 60; }
197 | HOURS { $$ = 60 * 60; }
198 | DAYS { $$ = 60 * 60 * 24; }
199 | WEEKS { $$ = 60 * 60 * 24 * 7; }
200 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
201 | YEARS { $$ = 60 * 60 * 24 * 365; }
202 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
203
204
205 sizespec:       expr    {
206                         $$ = $1;
207                 }
208                 | expr BYTES  { 
209                         $$ = $1;
210                 }
211                 | expr KBYTES {
212                         $$ = $1 * 1024;
213                 }
214                 | expr MBYTES {
215                         $$ = $1 * 1024 * 1024;
216                 }
217                 | expr GBYTES {
218                         $$ = $1 * 1024 * 1024 * 1024;
219                 }
220                 | expr TBYTES {
221                         $$ = $1 * 1024 * 1024 * 1024;
222                 }
223                 ;
224
225 /* this is an arithmatic expression */
226 expr: NUMBER
227                 { 
228                         $$ = $1;
229                 }
230                 | expr '+' expr { 
231                         $$ = $1 + $3;
232                 }
233                 | expr '-' expr { 
234                         $$ = $1 - $3;
235                 }
236                 | expr '*' expr { 
237                         $$ = $1 * $3;
238                 }
239                 | expr '/' expr { 
240                         $$ = $1 / $3;
241                 }
242 /* leave this out until we find why it makes BSD yacc dump core -larne
243                 | '-' expr  %prec NEG
244                 = {
245                         $$ = -$2;
246                 } */
247                 | '(' expr ')' {
248                         $$ = $2;
249                 }
250                 ;
251
252 jupeblock: JUPE '{' jupeitems '}' ';' ;
253 jupeitems: jupeitem jupeitems | jupeitem;
254 jupeitem: jupenick | error;
255 jupenick: NICK '=' QSTRING
256 {
257   addNickJupes(yylval.text);
258 } ';';
259
260 generalblock: GENERAL '{' generalitems '}' ';' ;
261 generalitems: generalitem generalitems | generalitem;
262 generalitem: generalnumeric | generalname | generalvhost | generaldesc | error;
263 generalnumeric: NUMERIC '=' NUMBER ';'
264 {
265   if (localConf.numeric == 0)
266     localConf.numeric = yylval.num;
267   else
268     parse_error("Redefinition of server numeric %i (%i)",yylval.num,
269                 localConf.numeric);
270 };
271
272 generalname: NAME '=' QSTRING ';'
273 {
274   if (localConf.name == NULL)
275     DupString(localConf.name, yylval.text);
276   else
277     parse_error("Redefinition of server name %s (%s)",yylval.text,
278                 localConf.name);
279 };
280
281 generaldesc: DESCRIPTION '=' QSTRING ';'
282 {
283   MyFree(localConf.description);
284   DupString(localConf.description, yylval.text);
285   ircd_strncpy(cli_info(&me), yylval.text, REALLEN);
286 };
287
288 generalvhost: VHOST '=' QSTRING ';'
289 {
290   if (INADDR_NONE ==
291       (localConf.vhost_address.s_addr = inet_addr(yylval.text)))
292     localConf.vhost_address.s_addr = INADDR_ANY;
293 };
294
295 adminblock: ADMIN '{' adminitems '}'
296 {
297   if (localConf.location1 == NULL)
298     DupString(localConf.location1, "");
299   if (localConf.location2 == NULL)
300     DupString(localConf.location2, "");
301   if (localConf.contact == NULL)
302     DupString(localConf.contact, "");
303 } ';';
304 adminitems: adminitems adminitem | adminitem;
305 adminitem: adminlocation | admincontact | error;
306 adminlocation: LOCATION '=' QSTRING ';'
307 {
308  if (localConf.location1 == NULL)
309   DupString(localConf.location1, yylval.text);
310  else if (localConf.location2 == NULL)
311   DupString(localConf.location2, yylval.text);
312  /* Otherwise just drop it. -A1kmm */
313 };
314 admincontact: CONTACT '=' QSTRING ';'
315 {
316  if (localConf.contact != NULL)
317    MyFree(localConf.contact);
318  DupString(localConf.contact, yylval.text);
319 };
320
321 classblock: CLASS {
322   name = NULL;
323   tping = 90;
324   tconn = 0;
325   maxlinks = 0;
326   sendq = 0;
327 } '{' classitems '}'
328 {
329   if (name != NULL)
330   {
331    add_class(name, tping, tconn, maxlinks, sendq);
332   }
333   else {
334    parse_error("Missing name in class block");
335   }
336 } ';';
337 classitems: classitem classitems | classitem;
338 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
339            classsendq | error;
340 classname: NAME '=' QSTRING ';'
341 {
342   MyFree(name);
343   DupString(name, yylval.text);
344 };
345 classpingfreq: PINGFREQ '=' timespec ';'
346 {
347   tping = yylval.num;
348 };
349 classconnfreq: CONNECTFREQ '=' timespec ';'
350 {
351   tconn = yylval.num;
352 };
353 classmaxlinks: MAXLINKS '=' expr ';'
354 {
355   maxlinks = yylval.num;
356 };
357 classsendq: SENDQ '=' sizespec ';'
358 {
359   sendq = yylval.num;
360 };
361
362 connectblock: CONNECT
363 {
364  name = pass = host = NULL;
365  c_class = NULL;
366  port = 0;
367 } '{' connectitems '}'
368 {
369  if (name != NULL && pass != NULL && host != NULL && c_class != NULL && 
370      /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
371      !strchr(host, '?'))
372  {
373    aconf = make_conf();
374    aconf->status = CONF_SERVER;
375    aconf->name = name;
376    aconf->passwd = pass;
377    aconf->conn_class = c_class;
378    aconf->port = port;
379    aconf->status = CONF_SERVER;
380    aconf->host = host;
381    aconf->next = GlobalConfList;
382    aconf->ipnum.s_addr = INADDR_NONE;
383    lookup_confhost(aconf);
384    GlobalConfList = aconf;
385  }
386  else
387  {
388    MyFree(name);
389    MyFree(pass);
390    MyFree(host);
391    name = pass = host = NULL;
392    parse_error("Bad connect block");
393  }
394 }';';
395 connectitems: connectitem connectitems | connectitem;
396 connectitem: connectname | connectpass | connectclass | connecthost
397               | connectport | error;
398 connectname: NAME '=' QSTRING ';'
399 {
400  MyFree(name);
401  DupString(name, yylval.text);
402 };
403 connectpass: PASS '=' QSTRING ';'
404 {
405  MyFree(pass);
406  DupString(pass, yylval.text);
407 };
408 connectclass: CLASS '=' QSTRING ';'
409 {
410  c_class = find_class(yylval.text);
411 };
412 connecthost: HOST '=' QSTRING ';'
413 {
414  MyFree(host);
415  DupString(host, yylval.text);
416 };
417 connectport: PORT '=' NUMBER ';'
418 {
419  port = yylval.num;
420 };
421
422 serverblock: SERVER
423 {
424  aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
425  memset(aconf, 0, sizeof(*aconf));
426 } '{' serveritems '}'
427 {
428  if (aconf->status == 0)
429  {
430    MyFree(aconf->host);
431    MyFree(aconf->name);
432    MyFree(aconf);
433    aconf = NULL;
434    parse_error("Bad server block");
435  }
436  else
437  {
438    aconf->next = GlobalConfList;
439    GlobalConfList = aconf;
440  }
441 } ';';
442 serveritems: serveritem serveritems | serveritem;
443 serveritem: servername | servermask | serverhub | serverleaf |
444              serveruworld | error;
445 servername: NAME '=' QSTRING
446 {
447  MyFree(aconf->name);
448  DupString(aconf->name, yylval.text);
449 } ';' ;
450 servermask: MASK '=' QSTRING
451 {
452  MyFree(aconf->host);
453  DupString(aconf->host, yylval.text);
454 } ';' ;
455 /* XXX - perhaps we should do this the hybrid way in connect blocks
456  * instead -A1kmm. */
457 serverhub: HUB '=' YES ';'
458 {
459  aconf->status |= CONF_HUB;
460  aconf->status &= ~CONF_LEAF;
461 }
462 | HUB '=' NO
463 {
464  aconf->status &= ~CONF_HUB;
465 } ';'; 
466 serverleaf: LEAF '=' YES ';'
467 {
468  if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
469   aconf->status |= CONF_LEAF;
470  else
471   parse_error("Server is both leaf and a hub");
472 }
473 | LEAF '=' NO ';'
474 {
475  aconf->status &= ~CONF_LEAF;
476 };
477 serveruworld: UWORLD '=' YES ';'
478 {
479  aconf->status |= CONF_UWORLD;
480  aconf->status &= ~CONF_LEAF;
481 }
482 | UWORLD '=' NO ';'
483 {
484   aconf->status &= ~CONF_UWORLD;
485 };
486
487 operblock: OPER
488 {
489   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
490   memset(aconf, 0, sizeof(*aconf));
491   aconf->status = CONF_OPERATOR;
492 } '{' operitems '}' ';'
493 {
494   if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL)
495   {
496     aconf->next = GlobalConfList;
497     GlobalConfList = aconf;
498   }
499   else
500   {
501     log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
502     MyFree(aconf->name);
503     MyFree(aconf->passwd);
504     MyFree(aconf->host);
505     MyFree(aconf);
506     aconf = NULL;
507   }
508 };
509 operitems: operitem | operitems operitem;
510 operitem: opername | operpass | operlocal | operhost | operclass | operpriv | error;
511
512 opername: NAME '=' QSTRING ';'
513 {
514   MyFree(aconf->name);
515   DupString(aconf->name, yylval.text);
516 };
517
518 operpass: PASS '=' QSTRING ';'
519 {
520   MyFree(aconf->passwd);
521   DupString(aconf->passwd, yylval.text);
522 };
523
524 operlocal: LOCAL '=' YES ';'
525 {
526   /* XXX it would be good to get rid of local operators and add same
527    * permission values here. But for now, I am just going with local 
528    * opers... */
529   aconf->status = CONF_LOCOP;
530 } | LOCAL '=' NO ';'
531 {
532   aconf->status = CONF_OPERATOR;
533 };
534
535 operhost: HOST '=' QSTRING ';'
536 {
537  MyFree(aconf->host);
538  if (!strchr(yylval.text, '@'))
539  {
540    int uh_len;
541    char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3));
542    ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
543    aconf->host = b;
544  }
545  else
546    DupString(aconf->host, yylval.text);
547 };
548
549 operclass: CLASS '=' QSTRING ';'
550 {
551  aconf->conn_class = find_class(yylval.text);
552 };
553
554 operpriv: privtype '=' yesorno ';'
555 {
556   if ($3 == 1)
557   {
558     PrivSet(&aconf->privs_dirty, $1);
559     PrivSet(&aconf->privs, $1);
560   }
561   else
562   {
563     PrivSet(&aconf->privs_dirty, $1);
564     PrivClr(&aconf->privs, $1);
565   }
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           TPRIV_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           TPRIV_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 { $$ = TPRIV_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
596 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
597
598 /* The port block... */
599 portblock: PORT {
600   port = 0;
601   host = NULL;
602   /* Hijack these for is_server, is_hidden to cut down on globals... */
603   tconn = 0;
604   tping = 0;
605   /* and this for mask... */
606   pass = NULL;
607 } '{' portitems '}' ';'
608 {
609   if (port > 0 && port <= 0xFFFF)
610   {
611     add_listener(port, host, pass, tconn, tping);
612     host = pass = NULL;
613   }
614   else
615   {
616     MyFree(host);
617     MyFree(pass);
618     parse_error("Bad port block");
619   }
620 };
621 portitems: portitem portitems | portitem;
622 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
623 portnumber: PORT '=' NUMBER ';'
624 {
625   port = yylval.num;
626 };
627
628 portvhost: VHOST '=' QSTRING ';'
629 {
630   MyFree(host);
631   DupString(host, yylval.text);
632 };
633
634 portmask: MASK '=' QSTRING ';'
635 {
636   MyFree(pass);
637   DupString(pass, yylval.text);
638 };
639
640 portserver: SERVER '=' YES ';'
641 {
642   tconn = -1;
643 } | SERVER '=' NO ';'
644 {
645   tconn = 0;
646 };
647
648 porthidden: HIDDEN '=' YES ';'
649 {
650   tping = -1;
651 } | HIDDEN '=' NO ';'
652 {
653   tping = 0;
654 };
655
656 clientblock: CLIENT
657 {
658   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
659   memset(aconf, 0, sizeof(*aconf));
660   aconf->status = CONF_CLIENT;
661 } '{' clientitems '}'
662 {
663   if ((aconf->host != NULL || aconf->name!=NULL))
664   {
665     if (aconf->host == NULL)
666       DupString(aconf->host, "");
667     if (aconf->name == NULL)
668       DupString(aconf->name, "");
669     if (aconf->conn_class == NULL)
670       aconf->conn_class = find_class("default");
671     aconf->next = GlobalConfList;
672     GlobalConfList = aconf;
673     aconf = NULL;
674   }
675   else
676   {
677    MyFree(aconf->host);
678    MyFree(aconf->passwd);
679    MyFree(aconf);
680    aconf = NULL;
681    parse_error("Bad client block");
682   }
683 } ';';
684 clientitems: clientitem clientitems | clientitem;
685 clientitem: clienthost | clientclass | clientpass | clientip | error;
686 clientip: IP '=' QSTRING ';'
687 {
688   MyFree(aconf->host);
689   DupString(aconf->host, yylval.text);
690 };
691
692 clienthost: HOST '=' QSTRING ';'
693 {
694   MyFree(aconf->name);
695   DupString(aconf->name, yylval.text);
696 };
697
698 clientclass: CLASS '=' QSTRING ';'
699 {
700   aconf->conn_class = find_class(yylval.text);
701 };
702
703 clientpass: PASS '=' QSTRING ';'
704 {
705   MyFree(aconf->passwd);
706   DupString(aconf->passwd, yylval.text);
707 };
708
709 killblock: KILL
710 {
711   dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
712   memset(dconf, 0, sizeof(*dconf));
713 } '{' killitems '}'
714 {
715   if (dconf->hostmask != NULL)
716   {
717     if (dconf->usermask == NULL)
718       DupString(dconf->usermask, "*");
719     dconf->next = denyConfList;
720     denyConfList = dconf;
721     dconf = NULL;
722   }
723   else
724   {
725     MyFree(dconf->hostmask);
726     MyFree(dconf->message);
727     MyFree(dconf);
728     dconf = NULL;
729     parse_error("Bad kill block");
730   }
731 } ';';
732 killitems: killitem killitems | killitem;
733 killitem: killuhost | killreal | killreasonfile | killreason | error;
734 killuhost: HOST '=' QSTRING ';'
735 {
736   char *u, *h;
737   dconf->flags &= ~DENY_FLAGS_REALNAME;
738   MyFree(dconf->hostmask);
739   MyFree(dconf->usermask);
740   if ((h = strchr(yylval.text, '@')) == NULL)
741   {
742     u = "*";
743     h = yylval.text;
744   }
745   else
746   {
747     u = yylval.text;
748     h++;
749   }
750   DupString(dconf->hostmask, h);
751   DupString(dconf->usermask, u);
752   if (strchr(yylval.text, '.'))
753   {
754     int  c_class;
755     char ipname[16];
756     int  ad[4] = { 0 };
757     int  bits2 = 0;
758     dconf->flags |= DENY_FLAGS_IP;
759     c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
760                      &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
761     if (c_class != 5) {
762       dconf->bits = c_class * 8;
763     }
764     else {
765       dconf->bits = bits2;
766     }
767     ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
768                   ad[2], ad[3]);
769     dconf->address = inet_addr(ipname);
770   }
771 };
772
773 killreal: REAL '=' QSTRING ';'
774 {
775  dconf->flags &= ~DENY_FLAGS_IP;
776  dconf->flags |= DENY_FLAGS_REALNAME;
777  MyFree(dconf->hostmask);
778  /* Leave usermask so you can specify user and real... */
779  DupString(dconf->hostmask, yylval.text);
780 };
781
782 killreason: REASON '=' QSTRING ';'
783 {
784  dconf->flags &= DENY_FLAGS_FILE;
785  MyFree(dconf->message);
786  DupString(dconf->message, yylval.text);
787 };
788
789 killreasonfile: TFILE '=' QSTRING ';'
790 {
791  dconf->flags |= DENY_FLAGS_FILE;
792  MyFree(dconf->message);
793  DupString(dconf->message, yylval.text);
794 };
795
796 cruleblock: CRULE
797 {
798   host = pass = NULL;
799   tconn = CRULE_AUTO;
800 } '{' cruleitems '}'
801 {
802   struct CRuleNode *node;
803   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
804   {
805     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
806     p->hostmask = host;
807     p->rule = pass;
808     p->type = tconn;
809     p->node = node;
810     p->next = cruleConfList;
811     cruleConfList = p;
812   }
813   else
814   {
815     MyFree(host);
816     MyFree(pass);
817     parse_error("Bad CRule block");
818   }
819 } ';';
820
821 cruleitems: cruleitem cruleitems | cruleitem;
822 cruleitem: cruleserver | crulerule | cruleall | error;
823
824 cruleserver: SERVER '=' QSTRING ';'
825 {
826   MyFree(host);
827   collapse(yylval.text);
828   DupString(host, yylval.text);
829 };
830
831 crulerule: RULE '=' QSTRING ';'
832 {
833  MyFree(pass);
834  DupString(pass, yylval.text);
835 };
836
837 cruleall: ALL '=' YES ';'
838 {
839  tconn = CRULE_ALL;
840 } | ALL '=' NO ';'
841 {
842  tconn = CRULE_AUTO;
843 };
844
845 motdblock: MOTD {
846  pass = host = NULL;
847 } '{' motditems '}'
848 {
849   if (host != NULL && pass != NULL)
850     motd_add(host, pass);
851   MyFree(host);
852   MyFree(pass);
853   host = pass = NULL;
854 } ';';
855
856 motditems: motditem motditems | motditem;
857 motditem: motdhost | motdfile | error;
858 motdhost: HOST '=' QSTRING ';'
859 {
860   DupString(host, yylval.text);
861 };
862
863 motdfile: TFILE '=' QSTRING ';'
864 {
865   DupString(pass, yylval.text);
866 };
867
868 featuresblock: FEATURES '{' featureitems '}' ';';
869 featureitems: featureitems featureitem | featureitem;
870
871 featureitem: QSTRING
872 {
873   stringlist[0] = $1;
874   stringno = 1;
875 } '=' stringlist ';';
876
877 stringlist: QSTRING
878 {
879   stringlist[1] = $1;
880   stringno = 2;
881 } posextrastrings
882 {
883   feature_set(NULL, (const char * const *)stringlist, stringno);
884 };
885 posextrastrings: /* empty */ | extrastrings;
886 extrastrings: extrastrings extrastring | extrastring;
887 extrastring: QSTRING
888 {
889   if (stringno < MAX_STRINGS)
890     stringlist[stringno++] = $1;
891 };
892
893 quarantineblock: QUARANTINE '{'
894 {
895   if (qconf != NULL)
896     qconf = (struct qline*) MyMalloc(sizeof(*qconf));
897   else
898   {
899     if (qconf->chname != NULL)
900       MyFree(qconf->chname);
901     if (qconf->reason != NULL)
902       MyFree(qconf->reason);
903   }
904   memset(qconf, 0, sizeof(*qconf));
905 } quarantineitems '}' ';'
906 {
907   if (qconf->chname == NULL || qconf->reason == NULL)
908   {
909     log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
910               "and a reason.");
911     return 0;
912   }
913   qconf->next = GlobalQuarantineList;
914   GlobalQuarantineList = qconf;
915   qconf = NULL;
916 };
917
918 quarantineitems: CHANNEL NAME '=' QSTRING ';'
919 {
920   DupString(qconf->chname, yylval.text);
921 } | REASON '=' QSTRING ';'
922 {
923   DupString(qconf->reason, yylval.text);
924 };