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