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