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