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