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