Get rid of CONF_LOCOP; use PRIV_PROPAGATE instead.
[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, invert;
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 | 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 operhost: HOST '=' QSTRING ';'
539 {
540  MyFree(aconf->host);
541  if (!strchr(yylval.text, '@'))
542  {
543    int uh_len;
544    char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3));
545    ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
546    aconf->host = b;
547  }
548  else
549    DupString(aconf->host, yylval.text);
550 };
551
552 operclass: CLASS '=' QSTRING ';'
553 {
554  aconf->conn_class = find_class(yylval.text);
555 };
556
557 operpriv: privtype '=' yesorno ';'
558 {
559   PrivSet(&aconf->privs_dirty, $1);
560   if (($3 == 1) ^ invert)
561     PrivSet(&aconf->privs, $1);
562   else
563     PrivClr(&aconf->privs, $1);
564   invert = 0;
565 };
566
567 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
568           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
569           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
570           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
571           TPRIV_KILL { $$ = PRIV_KILL; } |
572           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
573           TPRIV_REHASH { $$ = PRIV_REHASH; } |
574           TPRIV_RESTART { $$ = PRIV_RESTART; } |
575           TPRIV_DIE { $$ = PRIV_DIE; } |
576           TPRIV_GLINE { $$ = PRIV_GLINE; } |
577           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
578           TPRIV_JUPE { $$ = PRIV_JUPE; } |
579           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
580           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
581           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
582           TPRIV_SET { $$ = PRIV_SET; } |
583           TPRIV_WHOX { $$ = PRIV_WHOX; } |
584           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
585           TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
586           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
587           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
588           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
589           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
590           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
591           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
592           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
593           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
594           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; };
595
596 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
597
598 /* The port block... */
599 portblock: PORT {
600   port = 0;
601   host = NULL;
602   /* Hijack these for is_server, is_hidden to cut down on globals... */
603   tconn = 0;
604   tping = 0;
605   /* and this for mask... */
606   pass = NULL;
607 } '{' portitems '}' ';'
608 {
609   if (port > 0 && port <= 0xFFFF)
610   {
611     add_listener(port, host, pass, tconn, tping);
612     host = pass = NULL;
613   }
614   else
615   {
616     MyFree(host);
617     MyFree(pass);
618     parse_error("Bad port block");
619   }
620 };
621 portitems: portitem portitems | portitem;
622 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
623 portnumber: PORT '=' NUMBER ';'
624 {
625   port = yylval.num;
626 };
627
628 portvhost: VHOST '=' QSTRING ';'
629 {
630   MyFree(host);
631   DupString(host, yylval.text);
632 };
633
634 portmask: MASK '=' QSTRING ';'
635 {
636   MyFree(pass);
637   DupString(pass, yylval.text);
638 };
639
640 portserver: SERVER '=' YES ';'
641 {
642   tconn = -1;
643 } | SERVER '=' NO ';'
644 {
645   tconn = 0;
646 };
647
648 porthidden: HIDDEN '=' YES ';'
649 {
650   tping = -1;
651 } | HIDDEN '=' NO ';'
652 {
653   tping = 0;
654 };
655
656 clientblock: CLIENT
657 {
658   aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
659   memset(aconf, 0, sizeof(*aconf));
660   aconf->status = CONF_CLIENT;
661 } '{' clientitems '}'
662 {
663   if ((aconf->host != NULL || aconf->name!=NULL))
664   {
665     if (aconf->host == NULL)
666       DupString(aconf->host, "");
667     if (aconf->name == NULL)
668       DupString(aconf->name, "");
669     if (aconf->conn_class == NULL)
670       aconf->conn_class = find_class("default");
671     aconf->next = GlobalConfList;
672     GlobalConfList = aconf;
673     aconf = NULL;
674   }
675   else
676   {
677    MyFree(aconf->host);
678    MyFree(aconf->passwd);
679    MyFree(aconf);
680    aconf = NULL;
681    parse_error("Bad client block");
682   }
683 } ';';
684 clientitems: clientitem clientitems | clientitem;
685 clientitem: clienthost | clientclass | clientpass | clientip | error;
686 clientip: IP '=' QSTRING ';'
687 {
688   MyFree(aconf->host);
689   DupString(aconf->host, yylval.text);
690 };
691
692 clienthost: HOST '=' QSTRING ';'
693 {
694   MyFree(aconf->name);
695   DupString(aconf->name, yylval.text);
696 };
697
698 clientclass: CLASS '=' QSTRING ';'
699 {
700   aconf->conn_class = find_class(yylval.text);
701 };
702
703 clientpass: PASS '=' QSTRING ';'
704 {
705   MyFree(aconf->passwd);
706   DupString(aconf->passwd, yylval.text);
707 };
708
709 killblock: KILL
710 {
711   dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
712   memset(dconf, 0, sizeof(*dconf));
713 } '{' killitems '}'
714 {
715   if (dconf->hostmask != NULL)
716   {
717     if (dconf->usermask == NULL)
718       DupString(dconf->usermask, "*");
719     dconf->next = denyConfList;
720     denyConfList = dconf;
721     dconf = NULL;
722   }
723   else
724   {
725     MyFree(dconf->hostmask);
726     MyFree(dconf->message);
727     MyFree(dconf);
728     dconf = NULL;
729     parse_error("Bad kill block");
730   }
731 } ';';
732 killitems: killitem killitems | killitem;
733 killitem: killuhost | killreal | killreasonfile | killreason | error;
734 killuhost: HOST '=' QSTRING ';'
735 {
736   char *u, *h;
737   dconf->flags &= ~DENY_FLAGS_REALNAME;
738   MyFree(dconf->hostmask);
739   MyFree(dconf->usermask);
740   if ((h = strchr(yylval.text, '@')) == NULL)
741   {
742     u = "*";
743     h = yylval.text;
744   }
745   else
746   {
747     u = yylval.text;
748     h++;
749   }
750   DupString(dconf->hostmask, h);
751   DupString(dconf->usermask, u);
752   if (strchr(yylval.text, '.'))
753   {
754     int  c_class;
755     char ipname[16];
756     int  ad[4] = { 0 };
757     int  bits2 = 0;
758     dconf->flags |= DENY_FLAGS_IP;
759     c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
760                      &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
761     if (c_class != 5) {
762       dconf->bits = c_class * 8;
763     }
764     else {
765       dconf->bits = bits2;
766     }
767     ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
768                   ad[2], ad[3]);
769     dconf->address = inet_addr(ipname);
770   }
771 };
772
773 killreal: REAL '=' QSTRING ';'
774 {
775  dconf->flags &= ~DENY_FLAGS_IP;
776  dconf->flags |= DENY_FLAGS_REALNAME;
777  MyFree(dconf->hostmask);
778  /* Leave usermask so you can specify user and real... */
779  DupString(dconf->hostmask, yylval.text);
780 };
781
782 killreason: REASON '=' QSTRING ';'
783 {
784  dconf->flags &= DENY_FLAGS_FILE;
785  MyFree(dconf->message);
786  DupString(dconf->message, yylval.text);
787 };
788
789 killreasonfile: TFILE '=' QSTRING ';'
790 {
791  dconf->flags |= DENY_FLAGS_FILE;
792  MyFree(dconf->message);
793  DupString(dconf->message, yylval.text);
794 };
795
796 cruleblock: CRULE
797 {
798   host = pass = NULL;
799   tconn = CRULE_AUTO;
800 } '{' cruleitems '}'
801 {
802   struct CRuleNode *node;
803   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
804   {
805     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
806     p->hostmask = host;
807     p->rule = pass;
808     p->type = tconn;
809     p->node = node;
810     p->next = cruleConfList;
811     cruleConfList = p;
812   }
813   else
814   {
815     MyFree(host);
816     MyFree(pass);
817     parse_error("Bad CRule block");
818   }
819 } ';';
820
821 cruleitems: cruleitem cruleitems | cruleitem;
822 cruleitem: cruleserver | crulerule | cruleall | error;
823
824 cruleserver: SERVER '=' QSTRING ';'
825 {
826   MyFree(host);
827   collapse(yylval.text);
828   DupString(host, yylval.text);
829 };
830
831 crulerule: RULE '=' QSTRING ';'
832 {
833  MyFree(pass);
834  DupString(pass, yylval.text);
835 };
836
837 cruleall: ALL '=' YES ';'
838 {
839  tconn = CRULE_ALL;
840 } | ALL '=' NO ';'
841 {
842  tconn = CRULE_AUTO;
843 };
844
845 motdblock: MOTD {
846  pass = host = NULL;
847 } '{' motditems '}'
848 {
849   if (host != NULL && pass != NULL)
850     motd_add(host, pass);
851   MyFree(host);
852   MyFree(pass);
853   host = pass = NULL;
854 } ';';
855
856 motditems: motditem motditems | motditem;
857 motditem: motdhost | motdfile | error;
858 motdhost: HOST '=' QSTRING ';'
859 {
860   DupString(host, yylval.text);
861 };
862
863 motdfile: TFILE '=' QSTRING ';'
864 {
865   DupString(pass, yylval.text);
866 };
867
868 featuresblock: FEATURES '{' featureitems '}' ';';
869 featureitems: featureitems featureitem | featureitem;
870
871 featureitem: QSTRING
872 {
873   stringlist[0] = $1;
874   stringno = 1;
875 } '=' stringlist ';';
876
877 stringlist: QSTRING
878 {
879   stringlist[1] = $1;
880   stringno = 2;
881 } posextrastrings
882 {
883   feature_set(NULL, (const char * const *)stringlist, stringno);
884 };
885 posextrastrings: /* empty */ | extrastrings;
886 extrastrings: extrastrings extrastring | extrastring;
887 extrastring: QSTRING
888 {
889   if (stringno < MAX_STRINGS)
890     stringlist[stringno++] = $1;
891 };
892
893 quarantineblock: QUARANTINE '{'
894 {
895   if (qconf != NULL)
896     qconf = (struct qline*) MyMalloc(sizeof(*qconf));
897   else
898   {
899     if (qconf->chname != NULL)
900       MyFree(qconf->chname);
901     if (qconf->reason != NULL)
902       MyFree(qconf->reason);
903   }
904   memset(qconf, 0, sizeof(*qconf));
905 } quarantineitems '}' ';'
906 {
907   if (qconf->chname == NULL || qconf->reason == NULL)
908   {
909     log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
910               "and a reason.");
911     return 0;
912   }
913   qconf->next = GlobalQuarantineList;
914   GlobalQuarantineList = qconf;
915   qconf = NULL;
916 };
917
918 quarantineitems: CHANNEL NAME '=' QSTRING ';'
919 {
920   DupString(qconf->chname, yylval.text);
921 } | REASON '=' QSTRING ';'
922 {
923   DupString(qconf->reason, yylval.text);
924 };
925
926 pseudoblock: PSEUDO QSTRING '{'
927 {
928   smap = MyCalloc(1, sizeof(struct s_map));
929   DupString(smap->command, $2);
930 }
931 pseudoitems '}' ';'
932 {
933   if (!smap->name || !smap->services)
934   {
935     log_write(LS_CONFIG, L_ERROR, 0, "pseudo commands need a service name and list of target nicks.");
936     return 0;
937   }
938   if (register_mapping(smap))
939   {
940     smap->next = GlobalServiceMapList;
941     GlobalServiceMapList = smap;
942   }
943   else
944   {
945     struct nick_host *nh, *next;
946     for (nh = smap->services; nh; nh = next)
947     {
948       next = nh->next;
949       MyFree(nh);
950     }
951     MyFree(smap->name);
952     MyFree(smap->command);
953     MyFree(smap->prepend);
954     MyFree(smap);
955   }
956   smap = NULL;
957 };
958
959 pseudoitems: pseudoitem pseudoitems | pseudoitem;
960 pseudoitem: pseudoname | pseudoprepend | pseudonick | error;
961 pseudoname: NAME '=' QSTRING ';'
962 {
963   DupString(smap->name, yylval.text);
964 };
965 pseudoprepend: PREPEND '=' QSTRING ';'
966 {
967   DupString(smap->prepend, yylval.text);
968 };
969 pseudonick: NICK '=' QSTRING ';'
970 {
971   char *sep = strchr(yylval.text, '@');
972
973   if (sep != NULL) {
974     size_t slen = strlen(yylval.text);
975     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
976     memcpy(nh->nick, yylval.text, slen + 1);
977     nh->nicklen = sep - yylval.text;
978     nh->next = smap->services;
979     smap->services = nh;
980   }
981 };