Add autoconnect option for Connect block.
[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, flags;
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 s_map *smap;
78   struct Privs privs;
79   struct Privs privs_dirty;
80
81 static void parse_error(char *pattern,...) {
82   static char error_buffer[1024];
83   va_list vl;
84   va_start(vl,pattern);
85   ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
86   va_end(vl);
87   yyerror(error_buffer);
88 }
89
90 %}
91
92 %token <text> QSTRING
93 %token <num> NUMBER
94
95 %token GENERAL
96 %token ADMIN
97 %token LOCATION
98 %token CONTACT
99 %token CONNECT
100 %token CLASS
101 %token CHANNEL
102 %token PINGFREQ
103 %token CONNECTFREQ
104 %token MAXLINKS
105 %token MAXHOPS
106 %token SENDQ
107 %token NAME
108 %token HOST
109 %token IP
110 %token USERNAME
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 %token FAST
158 %token AUTOCONNECT
159 /* and now a lot of privileges... */
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 TPRIV_APASS_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 arithmetic 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                         $$ = -$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($3);
263   MyFree($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     localConf.name = $3;
288   else {
289     if (strcmp(localConf.name, $3))
290       parse_error("Redefinition of server name %s (%s)", $3,
291                   localConf.name);
292     MyFree($3);
293   }
294 };
295
296 generaldesc: DESCRIPTION '=' QSTRING ';'
297 {
298   MyFree(localConf.description);
299   localConf.description = $3;
300   ircd_strncpy(cli_info(&me), $3, REALLEN);
301 };
302
303 generalvhost: VHOST '=' QSTRING ';'
304 {
305   struct irc_in_addr addr;
306   if (!ircd_aton(&addr, $3))
307       parse_error("Invalid virtual host '%s'.", $3);
308   else if (irc_in_addr_is_ipv4(&addr))
309     memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
310   else
311     memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
312   MyFree($3);
313 };
314
315 adminblock: ADMIN '{' adminitems '}'
316 {
317   if (localConf.location1 == NULL)
318     DupString(localConf.location1, "");
319   if (localConf.location2 == NULL)
320     DupString(localConf.location2, "");
321   if (localConf.contact == NULL)
322     DupString(localConf.contact, "");
323 } ';';
324 adminitems: adminitems adminitem | adminitem;
325 adminitem: adminlocation | admincontact | error;
326 adminlocation: LOCATION '=' QSTRING ';'
327 {
328   if (localConf.location1 == NULL)
329     localConf.location1 = $3;
330   else if (localConf.location2 == NULL)
331     localConf.location2 = $3;
332   else /* Otherwise just drop it. -A1kmm */
333     MyFree($3);
334 };
335 admincontact: CONTACT '=' QSTRING ';'
336 {
337  MyFree(localConf.contact);
338  localConf.contact = $3;
339 };
340
341 classblock: CLASS {
342   tping = 90;
343 } '{' classitems '}'
344 {
345   if (name != NULL)
346   {
347     struct ConnectionClass *c_class;
348     add_class(name, tping, tconn, maxlinks, sendq);
349     c_class = find_class(name);
350     MyFree(c_class->default_umode);
351     c_class->default_umode = pass;
352     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
353     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
354   }
355   else {
356    parse_error("Missing name in class block");
357   }
358   name = NULL;
359   pass = NULL;
360   tconn = 0;
361   maxlinks = 0;
362   sendq = 0;
363   memset(&privs, 0, sizeof(privs));
364   memset(&privs_dirty, 0, sizeof(privs_dirty));
365 } ';';
366 classitems: classitem classitems | classitem;
367 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
368            classsendq | classusermode | priv | error;
369 classname: NAME '=' QSTRING ';'
370 {
371   MyFree(name);
372   name = $3;
373 };
374 classpingfreq: PINGFREQ '=' timespec ';'
375 {
376   tping = $3;
377 };
378 classconnfreq: CONNECTFREQ '=' timespec ';'
379 {
380   tconn = $3;
381 };
382 classmaxlinks: MAXLINKS '=' expr ';'
383 {
384   maxlinks = $3;
385 };
386 classsendq: SENDQ '=' sizespec ';'
387 {
388   sendq = $3;
389 };
390 classusermode: USERMODE '=' QSTRING ';'
391 {
392   MyFree(pass);
393   pass = $3;
394 };
395
396 connectblock: CONNECT
397 {
398  maxlinks = 65535;
399  flags = CONF_AUTOCONNECT;
400 } '{' connectitems '}'
401 {
402  struct ConfItem *aconf = NULL;
403  if (name == NULL)
404   parse_error("Missing name in connect block");
405  else if (pass == NULL)
406   parse_error("Missing password in connect block");
407  else if (host == NULL)
408   parse_error("Missing host in connect block");
409  else if (strchr(host, '*') || strchr(host, '?'))
410   parse_error("Invalid host '%s' in connect block", host);
411  else if (c_class == NULL)
412   parse_error("Missing class in connect block");
413  else {
414    aconf = make_conf(CONF_SERVER);
415    aconf->name = name;
416    aconf->origin_name = origin;
417    aconf->passwd = pass;
418    aconf->conn_class = c_class;
419    aconf->address.port = port;
420    aconf->host = host;
421    aconf->maximum = maxlinks;
422    aconf->hub_limit = hub_limit;
423    aconf->flags = flags;
424    lookup_confhost(aconf);
425  }
426  if (!aconf) {
427    MyFree(name);
428    MyFree(pass);
429    MyFree(host);
430    MyFree(origin);
431    MyFree(hub_limit);
432  }
433  name = pass = host = origin = hub_limit = NULL;
434  c_class = NULL;
435  port = flags = 0;
436 }';';
437 connectitems: connectitem connectitems | connectitem;
438 connectitem: connectname | connectpass | connectclass | connecthost
439               | connectport | connectvhost | connectleaf | connecthub
440               | connecthublimit | connectmaxhops | connectauto | error;
441 connectname: NAME '=' QSTRING ';'
442 {
443  MyFree(name);
444  name = $3;
445 };
446 connectpass: PASS '=' QSTRING ';'
447 {
448  MyFree(pass);
449  pass = $3;
450 };
451 connectclass: CLASS '=' QSTRING ';'
452 {
453  c_class = find_class($3);
454  MyFree($3);
455 };
456 connecthost: HOST '=' QSTRING ';'
457 {
458  MyFree(host);
459  host = $3;
460 };
461 connectport: PORT '=' NUMBER ';'
462 {
463  port = $3;
464 };
465 connectvhost: VHOST '=' QSTRING ';'
466 {
467  MyFree(origin);
468  origin = $3;
469 };
470 connectleaf: LEAF ';'
471 {
472  maxlinks = 0;
473 };
474 connecthub: HUB ';'
475 {
476  MyFree(hub_limit);
477  DupString(hub_limit, "*");
478 };
479 connecthublimit: HUB '=' QSTRING ';'
480 {
481  MyFree(hub_limit);
482  hub_limit = $3;
483 };
484 connectmaxhops: MAXHOPS '=' expr ';'
485 {
486   maxlinks = $3;
487 };
488 connectauto: AUTOCONNECT '=' YES ';' { flags |= CONF_AUTOCONNECT; }
489  | AUTOCONNECT '=' NO ';' { flags &= ~CONF_AUTOCONNECT; };
490
491 uworldblock: UWORLD '{' uworlditems '}' ';';
492 uworlditems: uworlditem uworlditems | uworlditem;
493 uworlditem: uworldname | error;
494 uworldname: NAME '=' QSTRING ';'
495 {
496   make_conf(CONF_UWORLD)->host = $3;
497 };
498
499 operblock: OPER '{' operitems '}' ';'
500 {
501   struct ConfItem *aconf = NULL;
502   if (name == NULL)
503     parse_error("Missing name in operator block");
504   else if (pass == NULL)
505     parse_error("Missing password in operator block");
506   else if (host == NULL)
507     parse_error("Missing host in operator block");
508   else if (c_class == NULL)
509     parse_error("Missing class in operator block");
510   else {
511     aconf = make_conf(CONF_OPERATOR);
512     aconf->name = name;
513     aconf->passwd = pass;
514     conf_parse_userhost(aconf, host);
515     aconf->conn_class = c_class;
516     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
517     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
518     if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
519         && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
520       parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
521   }
522   if (!aconf) {
523     MyFree(name);
524     MyFree(pass);
525     MyFree(host);
526   }
527   name = pass = host = NULL;
528   c_class = NULL;
529   memset(&privs, 0, sizeof(privs));
530   memset(&privs_dirty, 0, sizeof(privs_dirty));
531 };
532 operitems: operitem | operitems operitem;
533 operitem: opername | operpass | operhost | operclass | priv | error;
534 opername: NAME '=' QSTRING ';'
535 {
536   MyFree(name);
537   name = $3;
538 };
539 operpass: PASS '=' QSTRING ';'
540 {
541   MyFree(pass);
542   pass = $3;
543 };
544 operhost: HOST '=' QSTRING ';'
545 {
546  MyFree(host);
547  if (!strchr($3, '@'))
548  {
549    int uh_len;
550    host = (char*) MyMalloc((uh_len = strlen($3)+3));
551    ircd_snprintf(0, host, uh_len, "*@%s", $3);
552    MyFree($3);
553  }
554  else
555    host = $3;
556 };
557 operclass: CLASS '=' QSTRING ';'
558 {
559  c_class = find_class($3);
560  MyFree($3);
561 };
562
563 priv: privtype '=' yesorno ';'
564 {
565   FlagSet(&privs_dirty, $1);
566   if (($3 == 1) ^ invert)
567     FlagSet(&privs, $1);
568   else
569     FlagClr(&privs, $1);
570   invert = 0;
571 };
572
573 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
574           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
575           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
576           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
577           KILL { $$ = PRIV_KILL; } |
578           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
579           TPRIV_REHASH { $$ = PRIV_REHASH; } |
580           TPRIV_RESTART { $$ = PRIV_RESTART; } |
581           TPRIV_DIE { $$ = PRIV_DIE; } |
582           TPRIV_GLINE { $$ = PRIV_GLINE; } |
583           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
584           JUPE { $$ = PRIV_JUPE; } |
585           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
586           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
587           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
588           TPRIV_SET { $$ = PRIV_SET; } |
589           TPRIV_WHOX { $$ = PRIV_WHOX; } |
590           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
591           TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
592           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
593           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
594           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
595           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
596           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
597           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
598           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
599           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
600           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
601           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
602           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
603           TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
604
605 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
606
607 /* The port block... */
608 portblock: PORT '{' portitems '}' ';'
609 {
610   if (port > 0 && port <= 0xFFFF)
611     add_listener(port, host, pass, tconn, tping);
612   else
613     parse_error("Port %d is out of range", port);
614   MyFree(host);
615   MyFree(pass);
616   host = pass = NULL;
617   port = tconn = tping = 0;
618 };
619 portitems: portitem portitems | portitem;
620 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
621 portnumber: PORT '=' NUMBER ';'
622 {
623   port = $3;
624 };
625
626 portvhost: VHOST '=' QSTRING ';'
627 {
628   MyFree(host);
629   host = $3;
630 };
631
632 portmask: MASK '=' QSTRING ';'
633 {
634   MyFree(pass);
635   pass = $3;
636 };
637
638 portserver: SERVER '=' YES ';'
639 {
640   tconn = -1;
641 } | SERVER '=' NO ';'
642 {
643   tconn = 0;
644 };
645
646 porthidden: HIDDEN '=' YES ';'
647 {
648   tping = -1;
649 } | HIDDEN '=' NO ';'
650 {
651   tping = 0;
652 };
653
654 clientblock: CLIENT
655 {
656   maxlinks = 65535;
657 }
658 '{' clientitems '}' ';'
659 {
660   struct irc_in_addr addr;
661   unsigned char addrbits = 0;
662
663   if (ip && !ipmask_parse(ip, &addr, &addrbits)) {
664     parse_error("Invalid IP address %s in block", ip);
665     MyFree(username);
666     MyFree(host);
667     MyFree(ip);
668     MyFree(pass);
669   } else {
670     struct ConfItem *aconf = make_conf(CONF_CLIENT);
671     aconf->username = username;
672     aconf->host = host;
673     if (ip)
674       memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
675     else
676       memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
677     aconf->addrbits = addrbits;
678     aconf->name = ip;
679     aconf->conn_class = c_class ? c_class : find_class("default");
680     aconf->maximum = maxlinks;
681     aconf->passwd = pass;
682   }
683   host = NULL;
684   username = NULL;
685   c_class = NULL;
686   ip = NULL;
687   pass = NULL;
688 };
689 clientitems: clientitem clientitems | clientitem;
690 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | error;
691 clienthost: HOST '=' QSTRING ';'
692 {
693   char *sep = strchr($3, '@');
694   MyFree(host);
695   if (sep) {
696     *sep++ = '\0';
697     MyFree(username);
698     DupString(host, sep);
699     username = $3;
700   } else {
701     host = $3;
702   }
703 };
704 clientip: IP '=' QSTRING ';'
705 {
706   char *sep;
707   sep = strchr($3, '@');
708   MyFree(ip);
709   if (sep) {
710     *sep++ = '\0';
711     MyFree(username);
712     DupString(ip, sep);
713     username = $3;
714   } else {
715     ip = $3;
716   }
717 };
718 clientusername: USERNAME '=' QSTRING ';'
719 {
720   MyFree(username);
721   username = $3;
722 };
723 clientclass: CLASS '=' QSTRING ';'
724 {
725   c_class = find_class($3);
726   MyFree($3);
727 };
728 clientpass: PASS '=' QSTRING ';'
729 {
730   MyFree(pass);
731   pass = $3;
732 };
733 clientmaxlinks: MAXLINKS '=' expr ';'
734 {
735   maxlinks = $3;
736 };
737
738 killblock: KILL
739 {
740   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
741 } '{' killitems '}'
742 {
743   if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
744     dconf->next = denyConfList;
745     denyConfList = dconf;
746   }
747   else
748   {
749     MyFree(dconf->usermask);
750     MyFree(dconf->hostmask);
751     MyFree(dconf->realmask);
752     MyFree(dconf->message);
753     MyFree(dconf);
754     parse_error("Kill block must match on at least one of username, host or realname");
755   }
756   dconf = NULL;
757 } ';';
758 killitems: killitem killitems | killitem;
759 killitem: killuhost | killreal | killusername | killreasonfile | killreason | error;
760 killuhost: HOST '=' QSTRING ';'
761 {
762   char *h;
763   MyFree(dconf->hostmask);
764   MyFree(dconf->usermask);
765   if ((h = strchr($3, '@')) == NULL)
766   {
767     DupString(dconf->usermask, "*");
768     dconf->hostmask = $3;
769   }
770   else
771   {
772     *h++ = '\0';
773     DupString(dconf->hostmask, h);
774     dconf->usermask = $3;
775   }
776   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
777 };
778
779 killusername: USERNAME '=' QSTRING ';'
780 {
781   MyFree(dconf->usermask);
782   dconf->usermask = $3;
783 };
784
785 killreal: REAL '=' QSTRING ';'
786 {
787  MyFree(dconf->realmask);
788  dconf->realmask = $3;
789 };
790
791 killreason: REASON '=' QSTRING ';'
792 {
793  dconf->flags &= ~DENY_FLAGS_FILE;
794  MyFree(dconf->message);
795  dconf->message = $3;
796 };
797
798 killreasonfile: TFILE '=' QSTRING ';'
799 {
800  dconf->flags |= DENY_FLAGS_FILE;
801  MyFree(dconf->message);
802  dconf->message = $3;
803 };
804
805 cruleblock: CRULE
806 {
807   tconn = CRULE_AUTO;
808 } '{' cruleitems '}' ';'
809 {
810   struct CRuleNode *node = NULL;
811   if (host == NULL)
812     parse_error("Missing host in crule block");
813   else if (pass == NULL)
814     parse_error("Missing rule in crule block");
815   else if ((node = crule_parse(pass)) == NULL)
816     parse_error("Invalid rule '%s' in crule block", pass);
817   else
818   {
819     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
820     p->hostmask = host;
821     p->rule = pass;
822     p->type = tconn;
823     p->node = node;
824     p->next = cruleConfList;
825     cruleConfList = p;
826   }
827   if (!node)
828   {
829     MyFree(host);
830     MyFree(pass);
831   }
832   host = pass = NULL;
833   tconn = 0;
834 };
835
836 cruleitems: cruleitem cruleitems | cruleitem;
837 cruleitem: cruleserver | crulerule | cruleall | error;
838
839 cruleserver: SERVER '=' QSTRING ';'
840 {
841   MyFree(host);
842   collapse($3);
843   host = $3;
844 };
845
846 crulerule: RULE '=' QSTRING ';'
847 {
848  MyFree(pass);
849  pass = $3;
850 };
851
852 cruleall: ALL '=' YES ';'
853 {
854  tconn = CRULE_ALL;
855 } | ALL '=' NO ';'
856 {
857  tconn = CRULE_AUTO;
858 };
859
860 motdblock: MOTD '{' motditems '}' ';'
861 {
862   if (host != NULL && pass != NULL)
863     motd_add(host, pass);
864   MyFree(host);
865   MyFree(pass);
866   host = pass = NULL;
867 };
868
869 motditems: motditem motditems | motditem;
870 motditem: motdhost | motdfile | error;
871 motdhost: HOST '=' QSTRING ';'
872 {
873   host = $3;
874 };
875
876 motdfile: TFILE '=' QSTRING ';'
877 {
878   pass = $3;
879 };
880
881 featuresblock: FEATURES '{' featureitems '}' ';';
882 featureitems: featureitems featureitem | featureitem;
883
884 featureitem: QSTRING
885 {
886   stringlist[0] = $1;
887   stringno = 1;
888 } '=' stringlist ';';
889
890 stringlist: QSTRING
891 {
892   stringlist[1] = $1;
893   stringno = 2;
894 } posextrastrings
895 {
896   unsigned int ii;
897   feature_set(NULL, (const char * const *)stringlist, stringno);
898   for (ii = 0; ii < stringno; ++ii)
899     MyFree(stringlist[ii]);
900 };
901 posextrastrings: /* empty */ | extrastrings;
902 extrastrings: extrastrings extrastring | extrastring;
903 extrastring: QSTRING
904 {
905   if (stringno < MAX_STRINGS)
906     stringlist[stringno++] = $1;
907   else
908     MyFree($1);
909 };
910
911 quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
912 quarantineitems: quarantineitems quarantineitem | quarantineitem;
913 quarantineitem: QSTRING '=' QSTRING ';'
914 {
915   struct qline *qconf = MyCalloc(1, sizeof(*qconf));
916   qconf->chname = $1;
917   qconf->reason = $3;
918   qconf->next = GlobalQuarantineList;
919   GlobalQuarantineList = qconf;
920 };
921
922 pseudoblock: PSEUDO QSTRING '{'
923 {
924   smap = MyCalloc(1, sizeof(struct s_map));
925   smap->command = $2;
926 }
927 pseudoitems '}' ';'
928 {
929   int valid = 0;
930
931   if (!smap->name)
932     parse_error("Missing name in pseudo %s block", smap->command);
933   else if (!smap->services)
934     parse_error("Missing nick in pseudo %s block", smap->command);
935   else
936     valid = 1;
937   if (valid && register_mapping(smap))
938   {
939     smap->next = GlobalServiceMapList;
940     GlobalServiceMapList = smap;
941   }
942   else
943   {
944     struct nick_host *nh, *next;
945     for (nh = smap->services; nh; nh = next)
946     {
947       next = nh->next;
948       MyFree(nh);
949     }
950     MyFree(smap->name);
951     MyFree(smap->command);
952     MyFree(smap->prepend);
953     MyFree(smap);
954   }
955   smap = NULL;
956 };
957
958 pseudoitems: pseudoitem pseudoitems | pseudoitem;
959 pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags | error;
960 pseudoname: NAME '=' QSTRING ';'
961 {
962   MyFree(smap->name);
963   smap->name = $3;
964 };
965 pseudoprepend: PREPEND '=' QSTRING ';'
966 {
967   MyFree(smap->prepend);
968   smap->prepend = $3;
969 };
970 pseudonick: NICK '=' QSTRING ';'
971 {
972   char *sep = strchr($3, '@');
973
974   if (sep != NULL) {
975     size_t slen = strlen($3);
976     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
977     memcpy(nh->nick, $3, slen + 1);
978     nh->nicklen = sep - $3;
979     nh->next = smap->services;
980     smap->services = nh;
981   }
982   MyFree($3);
983 };
984 pseudoflags: FAST ';'
985 {
986   smap->flags |= SMAP_FAST;
987 };
988
989 iauthblock: IAUTH '{'
990 {
991   tconn = 60;
992   tping = 60;
993 } iauthitems '}' ';'
994 {
995   if (!host)
996     parse_error("Missing host in iauth block");
997   else if (!port)
998     parse_error("Missing port in iauth block");
999   else
1000     iauth_connect(host, port, pass, tconn, tping);
1001   MyFree(pass);
1002   MyFree(host);
1003   pass = host = NULL;
1004   port = tconn = tping = 0;
1005 };
1006
1007 iauthitems: iauthitem iauthitems | iauthitem;
1008 iauthitem: iauthpass | iauthhost | iauthport | iauthconnfreq | iauthtimeout | error;
1009 iauthpass: PASS '=' QSTRING ';'
1010 {
1011   MyFree(pass);
1012   pass = $3;
1013 };
1014 iauthhost: HOST '=' QSTRING ';'
1015 {
1016   MyFree(host);
1017   host = $3;
1018 };
1019 iauthport: PORT '=' NUMBER ';'
1020 {
1021   port = $3;
1022 };
1023 iauthconnfreq: CONNECTFREQ '=' timespec ';'
1024 {
1025   tconn = $3;
1026 };
1027 iauthtimeout: TIMEOUT '=' timespec ';'
1028 {
1029   tping = $3;
1030 };