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