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