add unlimited flood priv
[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_chattr.h"
36 #include "ircd_log.h"
37 #include "ircd_reply.h"
38 #include "ircd_snprintf.h"
39 #include "ircd_string.h"
40 #include "list.h"
41 #include "listener.h"
42 #include "match.h"
43 #include "motd.h"
44 #include "numeric.h"
45 #include "numnicks.h"
46 #include "opercmds.h"
47 #include "parse.h"
48 #include "res.h"
49 #include "s_auth.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
62 #define MAX_STRINGS 80 /* Maximum number of feature params. */
63 #define USE_IPV4 (1 << 16)
64 #define USE_IPV6 (1 << 17)
65
66   extern struct LocalConf   localConf;
67   extern struct DenyConf*   denyConfList;
68   extern struct CRuleConf*  cruleConfList;
69   extern struct ServerConf* serverConfList;
70   extern struct s_map*      GlobalServiceMapList;
71   extern struct qline*      GlobalQuarantineList;
72
73   int yylex(void);
74   /* Now all the globals we need :/... */
75   int tping, tconn, maxlinks, sendq, port, invert, stringno, flags;
76   char *name, *pass, *host, *ip, *username, *origin, *hub_limit;
77   struct SLink *hosts;
78   char *stringlist[MAX_STRINGS];
79   struct ListenerFlags listen_flags;
80   struct ConnectionClass *c_class;
81   struct DenyConf *dconf;
82   struct ServerConf *sconf;
83   struct s_map *smap;
84   struct Privs privs;
85   struct Privs privs_dirty;
86
87 static void parse_error(char *pattern,...) {
88   static char error_buffer[1024];
89   va_list vl;
90   va_start(vl,pattern);
91   ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), pattern, vl);
92   va_end(vl);
93   yyerror(error_buffer);
94 }
95
96 static void free_slist(struct SLink **link) {
97   struct SLink *next;
98   while (*link != NULL) {
99     next = (*link)->next;
100     MyFree((*link)->value.cp);
101     free_link(*link);
102     *link = next;
103   }
104 }
105
106 %}
107
108 %token <text> QSTRING
109 %token <num> NUMBER
110
111 %token GENERAL
112 %token ADMIN
113 %token LOCATION
114 %token CONTACT
115 %token CONNECT
116 %token CLASS
117 %token CHANNEL
118 %token PINGFREQ
119 %token CONNECTFREQ
120 %token MAXLINKS
121 %token MAXHOPS
122 %token SENDQ
123 %token NAME
124 %token HOST
125 %token IP
126 %token USERNAME
127 %token PASS
128 %token LOCAL
129 %token SECONDS
130 %token MINUTES
131 %token HOURS
132 %token DAYS
133 %token WEEKS
134 %token MONTHS
135 %token YEARS
136 %token DECADES
137 %token BYTES
138 %token KBYTES
139 %token MBYTES
140 %token GBYTES
141 %token TBYTES
142 %token SERVER
143 %token PORT
144 %token MASK
145 %token HUB
146 %token LEAF
147 %token UWORLD
148 %token YES
149 %token NO
150 %token OPER
151 %token VHOST
152 %token HIDDEN
153 %token MOTD
154 %token JUPE
155 %token NICK
156 %token NUMERIC
157 %token DESCRIPTION
158 %token CLIENT
159 %token KILL
160 %token CRULE
161 %token REAL
162 %token REASON
163 %token TFILE
164 %token RULE
165 %token ALL
166 %token FEATURES
167 %token QUARANTINE
168 %token PSEUDO
169 %token PREPEND
170 %token USERMODE
171 %token IAUTH
172 %token TIMEOUT
173 %token FAST
174 %token AUTOCONNECT
175 %token PROGRAM
176 %token TOK_IPV4 TOK_IPV6
177 %token DNS
178 /* and now a lot of privileges... */
179 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
180 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
181 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_LOCAL_JUPE TPRIV_LOCAL_BADCHAN
182 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
183 %token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
184 %token TPRIV_UNLIMIT_QUERY TPRIV_UNLIMIT_FLOOD TPRIV_DISPLAY TPRIV_SEE_OPERS
185 %token TPRIV_WIDE_GLINE TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE
186 %token TPRIV_APASS_OPMODE TPRIV_LIST_CHAN
187 /* and some types... */
188 %type <num> sizespec
189 %type <num> timespec timefactor factoredtimes factoredtime
190 %type <num> expr yesorno privtype address_family
191 %left '+' '-'
192 %left '*' '/'
193
194 %union{
195  char *text;
196  int num;
197 }
198
199 %%
200 /* Blocks in the config file... */
201 blocks: blocks block | block;
202 block: adminblock | generalblock | classblock | connectblock |
203        uworldblock | operblock | portblock | jupeblock | clientblock |
204        killblock | cruleblock | motdblock | featuresblock | quarantineblock |
205        pseudoblock | iauthblock | error ';';
206
207 /* The timespec, sizespec and expr was ripped straight from
208  * ircd-hybrid-7. */
209 timespec: expr | factoredtimes;
210
211 factoredtimes: factoredtimes factoredtime
212 {
213   $$ = $1 + $2;
214 } | factoredtime;
215
216 factoredtime: expr timefactor
217 {
218   $$ = $1 * $2;
219 };
220
221 timefactor: SECONDS { $$ = 1; }
222 | MINUTES { $$ = 60; }
223 | HOURS { $$ = 60 * 60; }
224 | DAYS { $$ = 60 * 60 * 24; }
225 | WEEKS { $$ = 60 * 60 * 24 * 7; }
226 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
227 | YEARS { $$ = 60 * 60 * 24 * 365; }
228 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
229
230
231 sizespec:       expr    {
232                         $$ = $1;
233                 }
234                 | expr BYTES  { 
235                         $$ = $1;
236                 }
237                 | expr KBYTES {
238                         $$ = $1 * 1024;
239                 }
240                 | expr MBYTES {
241                         $$ = $1 * 1024 * 1024;
242                 }
243                 | expr GBYTES {
244                         $$ = $1 * 1024 * 1024 * 1024;
245                 }
246                 | expr TBYTES {
247                         $$ = $1 * 1024 * 1024 * 1024;
248                 }
249                 ;
250
251 /* this is an arithmetic expression */
252 expr: NUMBER
253                 { 
254                         $$ = $1;
255                 }
256                 | expr '+' expr { 
257                         $$ = $1 + $3;
258                 }
259                 | expr '-' expr { 
260                         $$ = $1 - $3;
261                 }
262                 | expr '*' expr { 
263                         $$ = $1 * $3;
264                 }
265                 | expr '/' expr { 
266                         $$ = $1 / $3;
267                 }
268 /* leave this out until we find why it makes BSD yacc dump core -larne
269                 | '-' expr  %prec NEG {
270                         $$ = -$2;
271                 } */
272                 | '(' expr ')' {
273                         $$ = $2;
274                 }
275                 ;
276
277 jupeblock: JUPE '{' jupeitems '}' ';' ;
278 jupeitems: jupeitem jupeitems | jupeitem;
279 jupeitem: jupenick;
280 jupenick: NICK '=' QSTRING ';'
281 {
282   addNickJupes($3);
283   MyFree($3);
284 };
285
286 generalblock: GENERAL
287 {
288     /* Zero out the vhost addresses, in case they were removed. */
289     memset(&VirtualHost_v4.addr, 0, sizeof(VirtualHost_v4.addr));
290     memset(&VirtualHost_v6.addr, 0, sizeof(VirtualHost_v6.addr));
291 } '{' generalitems '}' ';' {
292   if (localConf.name == NULL)
293     parse_error("Your General block must contain a name.");
294   if (localConf.numeric == 0)
295     parse_error("Your General block must contain a numeric (between 1 and 4095).");
296 };
297 generalitems: generalitem generalitems | generalitem;
298 generalitem: generalnumeric | generalname | generalvhost | generaldesc
299   | generaldnsvhost | generaldnsserver;
300
301 generalnumeric: NUMERIC '=' NUMBER ';'
302 {
303   if (localConf.numeric == 0)
304     localConf.numeric = $3;
305   else if (localConf.numeric != $3)
306     parse_error("Redefinition of server numeric %i (%i)", $3,
307                 localConf.numeric);
308 };
309
310 generalname: NAME '=' QSTRING ';'
311 {
312   if (localConf.name == NULL)
313     localConf.name = $3;
314   else {
315     if (strcmp(localConf.name, $3))
316       parse_error("Redefinition of server name %s (%s)", $3,
317                   localConf.name);
318     MyFree($3);
319   }
320 };
321
322 generaldesc: DESCRIPTION '=' QSTRING ';'
323 {
324   MyFree(localConf.description);
325   localConf.description = $3;
326   ircd_strncpy(cli_info(&me), $3, REALLEN);
327 };
328
329 generalvhost: VHOST '=' QSTRING ';'
330 {
331   struct irc_in_addr addr;
332   char *vhost = $3;
333
334   if (!strcmp(vhost, "*")) {
335     /* This traditionally meant bind to all interfaces and connect
336      * from the default. */
337   } else if (!ircd_aton(&addr, vhost))
338     parse_error("Invalid virtual host '%s'.", vhost);
339   else if (irc_in_addr_is_ipv4(&addr))
340     memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
341   else
342     memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
343   MyFree(vhost);
344 };
345
346 generaldnsvhost: DNS VHOST '=' address_family QSTRING ';'
347 {
348   struct irc_in_addr addr;
349   int families = $4;
350   char *vhost = $5;
351
352   if (!strcmp(vhost, "*")) {
353     /* Let the operating system assign the default. */
354   } else if (!ircd_aton(&addr, vhost))
355     parse_error("Invalid DNS virtual host '%s'.", vhost);
356   else
357   {
358     if ((families & USE_IPV4)
359         || (!families && irc_in_addr_is_ipv4(&addr)))
360       memcpy(&VirtualHost_dns_v4.addr, &addr, sizeof(addr));
361     if ((families & USE_IPV6)
362         || (!families && !irc_in_addr_is_ipv4(&addr)))
363       memcpy(&VirtualHost_dns_v6.addr, &addr, sizeof(addr));
364   }
365   MyFree(vhost);
366 };
367
368 generaldnsserver: DNS SERVER '=' QSTRING ';'
369 {
370   char *server = $4;
371
372   add_nameserver(server);
373   MyFree(server);
374 };
375
376 adminblock: ADMIN
377 {
378   MyFree(localConf.location1);
379   MyFree(localConf.location2);
380   MyFree(localConf.contact);
381   localConf.location1 = localConf.location2 = localConf.contact = NULL;
382 }
383 '{' adminitems '}' ';'
384 {
385   if (localConf.location1 == NULL)
386     DupString(localConf.location1, "");
387   if (localConf.location2 == NULL)
388     DupString(localConf.location2, "");
389   if (localConf.contact == NULL)
390     DupString(localConf.contact, "");
391 };
392 adminitems: adminitems adminitem | adminitem;
393 adminitem: adminlocation | admincontact;
394 adminlocation: LOCATION '=' QSTRING ';'
395 {
396   if (localConf.location1 == NULL)
397     localConf.location1 = $3;
398   else if (localConf.location2 == NULL)
399     localConf.location2 = $3;
400   else /* Otherwise just drop it. -A1kmm */
401     MyFree($3);
402 };
403 admincontact: CONTACT '=' QSTRING ';'
404 {
405  MyFree(localConf.contact);
406  localConf.contact = $3;
407 };
408
409 classblock: CLASS {
410   tping = 90;
411 } '{' classitems '}' ';'
412 {
413   if (name != NULL)
414   {
415     struct ConnectionClass *c_class;
416     add_class(name, tping, tconn, maxlinks, sendq);
417     c_class = find_class(name);
418     MyFree(c_class->default_umode);
419     c_class->default_umode = pass;
420     memcpy(&c_class->privs, &privs, sizeof(c_class->privs));
421     memcpy(&c_class->privs_dirty, &privs_dirty, sizeof(c_class->privs_dirty));
422   }
423   else {
424    parse_error("Missing name in class block");
425   }
426   name = NULL;
427   pass = NULL;
428   tconn = 0;
429   maxlinks = 0;
430   sendq = 0;
431   memset(&privs, 0, sizeof(privs));
432   memset(&privs_dirty, 0, sizeof(privs_dirty));
433 };
434 classitems: classitem classitems | classitem;
435 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
436            classsendq | classusermode | priv;
437 classname: NAME '=' QSTRING ';'
438 {
439   MyFree(name);
440   name = $3;
441 };
442 classpingfreq: PINGFREQ '=' timespec ';'
443 {
444   tping = $3;
445 };
446 classconnfreq: CONNECTFREQ '=' timespec ';'
447 {
448   tconn = $3;
449 };
450 classmaxlinks: MAXLINKS '=' expr ';'
451 {
452   maxlinks = $3;
453 };
454 classsendq: SENDQ '=' sizespec ';'
455 {
456   sendq = $3;
457 };
458 classusermode: USERMODE '=' QSTRING ';'
459 {
460   MyFree(pass);
461   pass = $3;
462 };
463
464 connectblock: CONNECT
465 {
466  flags = CONF_AUTOCONNECT;
467 } '{' connectitems '}' ';'
468 {
469  struct ConfItem *aconf = NULL;
470  if (name == NULL)
471   parse_error("Missing name in connect block");
472  else if (pass == NULL)
473   parse_error("Missing password in connect block");
474  else if (strlen(pass) > PASSWDLEN)
475   parse_error("Password too long in connect block");
476  else if (host == NULL)
477   parse_error("Missing host in connect block");
478  else if (strchr(host, '*') || strchr(host, '?'))
479   parse_error("Invalid host '%s' in connect block", host);
480  else if (c_class == NULL)
481   parse_error("Missing or non-existent class in connect block");
482  else {
483    aconf = make_conf(CONF_SERVER);
484    aconf->name = name;
485    aconf->origin_name = origin;
486    aconf->passwd = pass;
487    aconf->conn_class = c_class;
488    aconf->address.port = port;
489    aconf->host = host;
490    /* If the user specified a hub allowance, but not maximum links,
491     * allow an effectively unlimited number of hops.
492     */
493    aconf->maximum = (hub_limit != NULL && maxlinks == 0) ? 65535 : maxlinks;
494    aconf->hub_limit = hub_limit;
495    aconf->flags = flags;
496    lookup_confhost(aconf);
497  }
498  if (!aconf) {
499    MyFree(name);
500    MyFree(pass);
501    MyFree(host);
502    MyFree(origin);
503    MyFree(hub_limit);
504  }
505  name = pass = host = origin = hub_limit = NULL;
506  c_class = NULL;
507  port = flags = maxlinks = 0;
508 };
509 connectitems: connectitem connectitems | connectitem;
510 connectitem: connectname | connectpass | connectclass | connecthost
511               | connectport | connectvhost | connectleaf | connecthub
512               | connecthublimit | connectmaxhops | connectauto;
513 connectname: NAME '=' QSTRING ';'
514 {
515  MyFree(name);
516  name = $3;
517 };
518 connectpass: PASS '=' QSTRING ';'
519 {
520  MyFree(pass);
521  pass = $3;
522 };
523 connectclass: CLASS '=' QSTRING ';'
524 {
525  c_class = find_class($3);
526  if (!c_class)
527   parse_error("No such connection class '%s' for Connect block", $3);
528  MyFree($3);
529 };
530 connecthost: HOST '=' QSTRING ';'
531 {
532  MyFree(host);
533  host = $3;
534 };
535 connectport: PORT '=' NUMBER ';'
536 {
537  port = $3;
538 };
539 connectvhost: VHOST '=' QSTRING ';'
540 {
541  MyFree(origin);
542  origin = $3;
543 };
544 connectleaf: LEAF ';'
545 {
546  maxlinks = 0;
547 };
548 connecthub: HUB ';'
549 {
550  MyFree(hub_limit);
551  DupString(hub_limit, "*");
552 };
553 connecthublimit: HUB '=' QSTRING ';'
554 {
555  MyFree(hub_limit);
556  hub_limit = $3;
557 };
558 connectmaxhops: MAXHOPS '=' expr ';'
559 {
560   maxlinks = $3;
561 };
562 connectauto: AUTOCONNECT '=' YES ';' { flags |= CONF_AUTOCONNECT; }
563  | AUTOCONNECT '=' NO ';' { flags &= ~CONF_AUTOCONNECT; };
564
565 uworldblock: UWORLD '{' uworlditems '}' ';';
566 uworlditems: uworlditem uworlditems | uworlditem;
567 uworlditem: uworldname;
568 uworldname: NAME '=' QSTRING ';'
569 {
570   make_conf(CONF_UWORLD)->host = $3;
571 };
572
573 operblock: OPER '{' operitems '}' ';'
574 {
575   struct ConfItem *aconf = NULL;
576   struct SLink *link;
577
578   if (name == NULL)
579     parse_error("Missing name in operator block");
580   else if (pass == NULL)
581     parse_error("Missing password in operator block");
582   /* Do not check password length because it may be crypted. */
583   else if (hosts == NULL)
584     parse_error("Missing host(s) in operator block");
585   else if (c_class == NULL)
586     parse_error("Invalid or missing class in operator block");
587   else if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
588            && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
589     parse_error("Operator block for %s and class %s have no LOCAL setting", name, c_class->cc_name);
590   else for (link = hosts; link != NULL; link = link->next) {
591     aconf = make_conf(CONF_OPERATOR);
592     DupString(aconf->name, name);
593     DupString(aconf->passwd, pass);
594     conf_parse_userhost(aconf, link->value.cp);
595     aconf->conn_class = c_class;
596     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
597     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
598   }
599   MyFree(name);
600   MyFree(pass);
601   free_slist(&hosts);
602   name = pass = NULL;
603   c_class = NULL;
604   memset(&privs, 0, sizeof(privs));
605   memset(&privs_dirty, 0, sizeof(privs_dirty));
606 };
607 operitems: operitem | operitems operitem;
608 operitem: opername | operpass | operhost | operclass | priv;
609 opername: NAME '=' QSTRING ';'
610 {
611   MyFree(name);
612   name = $3;
613 };
614 operpass: PASS '=' QSTRING ';'
615 {
616   MyFree(pass);
617   pass = $3;
618 };
619 operhost: HOST '=' QSTRING ';'
620 {
621  struct SLink *link;
622  link = make_link();
623  if (!strchr($3, '@'))
624  {
625    int uh_len;
626    link->value.cp = (char*) MyMalloc((uh_len = strlen($3)+3));
627    ircd_snprintf(0, link->value.cp, uh_len, "*@%s", $3);
628  }
629  else
630    DupString(link->value.cp, $3);
631  MyFree($3);
632  link->next = hosts;
633  hosts = link;
634 };
635 operclass: CLASS '=' QSTRING ';'
636 {
637  c_class = find_class($3);
638  if (!c_class)
639   parse_error("No such connection class '%s' for Operator block", $3);
640  MyFree($3);
641 };
642
643 priv: privtype '=' yesorno ';'
644 {
645   FlagSet(&privs_dirty, $1);
646   if (($3 == 1) ^ invert)
647     FlagSet(&privs, $1);
648   else
649     FlagClr(&privs, $1);
650   invert = 0;
651 };
652
653 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
654           TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
655           TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
656           TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
657           KILL { $$ = PRIV_KILL; } |
658           TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
659           TPRIV_REHASH { $$ = PRIV_REHASH; } |
660           TPRIV_RESTART { $$ = PRIV_RESTART; } |
661           TPRIV_DIE { $$ = PRIV_DIE; } |
662           TPRIV_GLINE { $$ = PRIV_GLINE; } |
663           TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
664           JUPE { $$ = PRIV_JUPE; } |
665           TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
666           TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
667           TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
668           TPRIV_SET { $$ = PRIV_SET; } |
669           TPRIV_WHOX { $$ = PRIV_WHOX; } |
670           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
671           TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
672           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
673           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
674           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
675           TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
676           TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
677           TPRIV_UNLIMIT_FLOOD { $$ = PRIV_UNLIMIT_FLOOD; } |
678           TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
679           TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
680           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
681           TPRIV_LIST_CHAN { $$ = PRIV_LIST_CHAN; } |
682           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
683           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
684           TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
685           TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
686
687 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
688
689 /* not a recursive definition because some pedant will just come along
690  * and whine that the parser accepts "ipv4 ipv4 ipv4 ipv4"
691  */
692 address_family:
693                { $$ = 0; }
694     | TOK_IPV4 { $$ = USE_IPV4; }
695     | TOK_IPV6 { $$ = USE_IPV6; }
696     | TOK_IPV4 TOK_IPV6 { $$ = USE_IPV4 | USE_IPV6; }
697     | TOK_IPV6 TOK_IPV4 { $$ = USE_IPV6 | USE_IPV4; }
698     ;
699
700 /* The port block... */
701 portblock: PORT '{' portitems '}' ';' {
702   struct ListenerFlags flags_here;
703   struct SLink *link;
704   if (hosts == NULL) {
705     struct SLink *link;
706     link = make_link();
707     DupString(link->value.cp, "*");
708     link->flags = 0;
709     link->next = hosts;
710     hosts = link;
711   }
712   for (link = hosts; link != NULL; link = link->next) {
713     memcpy(&flags_here, &listen_flags, sizeof(flags_here));
714     switch (link->flags & (USE_IPV4 | USE_IPV6)) {
715     case USE_IPV4:
716       FlagSet(&flags_here, LISTEN_IPV4);
717       break;
718     case USE_IPV6:
719       FlagSet(&flags_here, LISTEN_IPV6);
720       break;
721     default: /* 0 or USE_IPV4|USE_IPV6 */
722       FlagSet(&flags_here, LISTEN_IPV4);
723       FlagSet(&flags_here, LISTEN_IPV6);
724       break;
725     }
726     if (link->flags & 65535)
727       port = link->flags & 65535;
728     add_listener(port, link->value.cp, pass, &flags_here);
729   }
730   free_slist(&hosts);
731   MyFree(pass);
732   memset(&listen_flags, 0, sizeof(listen_flags));
733   pass = NULL;
734   port = 0;
735 };
736 portitems: portitem portitems | portitem;
737 portitem: portnumber | portvhost | portvhostnumber | portmask | portserver | porthidden;
738 portnumber: PORT '=' address_family NUMBER ';'
739 {
740   if ($4 < 1 || $4 > 65535) {
741     parse_error("Port %d is out of range", port);
742   } else {
743     port = $3 | $4;
744     if (hosts && (0 == (hosts->flags & 65535)))
745       hosts->flags = (hosts->flags & ~65535) | port;
746   }
747 };
748
749 portvhost: VHOST '=' address_family QSTRING ';'
750 {
751   struct SLink *link;
752   link = make_link();
753   link->value.cp = $4;
754   link->flags = $3 | port;
755   link->next = hosts;
756   hosts = link;
757 };
758
759 portvhostnumber: VHOST '=' address_family QSTRING NUMBER ';'
760 {
761   if ($5 < 1 || $5 > 65535) {
762     parse_error("Port %d is out of range", port);
763   } else {
764     struct SLink *link;
765     link = make_link();
766     link->value.cp = $4;
767     link->flags = $3 | $5;
768     link->next = hosts;
769     hosts = link;
770   }
771 };
772
773 portmask: MASK '=' QSTRING ';'
774 {
775   MyFree(pass);
776   pass = $3;
777 };
778
779 portserver: SERVER '=' YES ';'
780 {
781   FlagSet(&listen_flags, LISTEN_SERVER);
782 } | SERVER '=' NO ';'
783 {
784   FlagClr(&listen_flags, LISTEN_SERVER);
785 };
786
787 porthidden: HIDDEN '=' YES ';'
788 {
789   FlagSet(&listen_flags, LISTEN_HIDDEN);
790 } | HIDDEN '=' NO ';'
791 {
792   FlagClr(&listen_flags, LISTEN_HIDDEN);
793 };
794
795 clientblock: CLIENT
796 {
797   maxlinks = 65535;
798   port = 0;
799 }
800 '{' clientitems '}' ';'
801 {
802   struct ConfItem *aconf = 0;
803   struct irc_in_addr addr;
804   unsigned char addrbits = 0;
805
806   if (!c_class)
807     parse_error("Invalid or missing class in Client block");
808   else if (pass && strlen(pass) > PASSWDLEN)
809     parse_error("Password too long in connect block");
810   else if (ip && !ipmask_parse(ip, &addr, &addrbits))
811     parse_error("Invalid IP address %s in Client block", ip);
812   else {
813     aconf = make_conf(CONF_CLIENT);
814     aconf->username = username;
815     aconf->host = host;
816     if (ip)
817       memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
818     else
819       memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
820     aconf->address.port = port;
821     aconf->addrbits = addrbits;
822     aconf->name = ip;
823     aconf->conn_class = c_class;
824     aconf->maximum = maxlinks;
825     aconf->passwd = pass;
826   }
827   if (!aconf) {
828     MyFree(username);
829     MyFree(host);
830     MyFree(ip);
831     MyFree(pass);
832   }
833   host = NULL;
834   username = NULL;
835   c_class = NULL;
836   maxlinks = 0;
837   ip = NULL;
838   pass = NULL;
839   port = 0;
840 };
841 clientitems: clientitem clientitems | clientitem;
842 clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | clientport;
843 clienthost: HOST '=' QSTRING ';'
844 {
845   char *sep = strchr($3, '@');
846   MyFree(host);
847   if (sep) {
848     *sep++ = '\0';
849     MyFree(username);
850     DupString(host, sep);
851     username = $3;
852   } else {
853     host = $3;
854   }
855 };
856 clientip: IP '=' QSTRING ';'
857 {
858   char *sep;
859   sep = strchr($3, '@');
860   MyFree(ip);
861   if (sep) {
862     *sep++ = '\0';
863     MyFree(username);
864     DupString(ip, sep);
865     username = $3;
866   } else {
867     ip = $3;
868   }
869 };
870 clientusername: USERNAME '=' QSTRING ';'
871 {
872   MyFree(username);
873   username = $3;
874 };
875 clientclass: CLASS '=' QSTRING ';'
876 {
877   c_class = find_class($3);
878   if (!c_class)
879     parse_error("No such connection class '%s' for Client block", $3);
880   MyFree($3);
881 };
882 clientpass: PASS '=' QSTRING ';'
883 {
884   MyFree(pass);
885   pass = $3;
886 };
887 clientmaxlinks: MAXLINKS '=' expr ';'
888 {
889   maxlinks = $3;
890 };
891 clientport: PORT '=' expr ';'
892 {
893   port = $3;
894 };
895
896 killblock: KILL
897 {
898   dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
899 } '{' killitems '}' ';'
900 {
901   if (dconf->usermask || dconf->hostmask ||dconf->realmask) {
902     dconf->next = denyConfList;
903     denyConfList = dconf;
904   }
905   else
906   {
907     MyFree(dconf->usermask);
908     MyFree(dconf->hostmask);
909     MyFree(dconf->realmask);
910     MyFree(dconf->message);
911     MyFree(dconf);
912     parse_error("Kill block must match on at least one of username, host or realname");
913   }
914   dconf = NULL;
915 };
916 killitems: killitem killitems | killitem;
917 killitem: killuhost | killreal | killusername | killreasonfile | killreason;
918 killuhost: HOST '=' QSTRING ';'
919 {
920   char *h;
921   MyFree(dconf->hostmask);
922   MyFree(dconf->usermask);
923   if ((h = strchr($3, '@')) == NULL)
924   {
925     DupString(dconf->usermask, "*");
926     dconf->hostmask = $3;
927   }
928   else
929   {
930     *h++ = '\0';
931     DupString(dconf->hostmask, h);
932     dconf->usermask = $3;
933   }
934   ipmask_parse(dconf->hostmask, &dconf->address, &dconf->bits);
935 };
936
937 killusername: USERNAME '=' QSTRING ';'
938 {
939   MyFree(dconf->usermask);
940   dconf->usermask = $3;
941 };
942
943 killreal: REAL '=' QSTRING ';'
944 {
945  MyFree(dconf->realmask);
946  dconf->realmask = $3;
947 };
948
949 killreason: REASON '=' QSTRING ';'
950 {
951  dconf->flags &= ~DENY_FLAGS_FILE;
952  MyFree(dconf->message);
953  dconf->message = $3;
954 };
955
956 killreasonfile: TFILE '=' QSTRING ';'
957 {
958  dconf->flags |= DENY_FLAGS_FILE;
959  MyFree(dconf->message);
960  dconf->message = $3;
961 };
962
963 cruleblock: CRULE
964 {
965   tconn = CRULE_AUTO;
966 } '{' cruleitems '}' ';'
967 {
968   struct CRuleNode *node = NULL;
969   struct SLink *link;
970
971   if (hosts == NULL)
972     parse_error("Missing server(s) in crule block");
973   else if (pass == NULL)
974     parse_error("Missing rule in crule block");
975   else if ((node = crule_parse(pass)) == NULL)
976     parse_error("Invalid rule '%s' in crule block", pass);
977   else for (link = hosts; link != NULL; link = link->next)
978   {
979     struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
980     if (node == NULL)
981       node = crule_parse(pass);
982     DupString(p->hostmask, link->value.cp);
983     DupString(p->rule, pass);
984     p->type = tconn;
985     p->node = node;
986     node = NULL;
987     p->next = cruleConfList;
988     cruleConfList = p;
989   }
990   free_slist(&hosts);
991   MyFree(pass);
992   pass = NULL;
993   tconn = 0;
994 };
995
996 cruleitems: cruleitem cruleitems | cruleitem;
997 cruleitem: cruleserver | crulerule | cruleall;
998
999 cruleserver: SERVER '=' QSTRING ';'
1000 {
1001   struct SLink *link;
1002   link = make_link();
1003   link->value.cp = $3;
1004   link->next = hosts;
1005   hosts = link;
1006 };
1007
1008 crulerule: RULE '=' QSTRING ';'
1009 {
1010  MyFree(pass);
1011  pass = $3;
1012 };
1013
1014 cruleall: ALL '=' YES ';'
1015 {
1016  tconn = CRULE_ALL;
1017 } | ALL '=' NO ';'
1018 {
1019  tconn = CRULE_AUTO;
1020 };
1021
1022 motdblock: MOTD '{' motditems '}' ';'
1023 {
1024   struct SLink *link;
1025   if (pass != NULL)
1026     for (link = hosts; link != NULL; link = link->next)
1027       motd_add(link->value.cp, pass);
1028   free_slist(&hosts);
1029   MyFree(pass);
1030   pass = NULL;
1031 };
1032
1033 motditems: motditem motditems | motditem;
1034 motditem: motdhost | motdfile;
1035 motdhost: HOST '=' QSTRING ';'
1036 {
1037   struct SLink *link;
1038   link = make_link();
1039   link->value.cp = $3;
1040   link->next = hosts;
1041   hosts = link;
1042 };
1043
1044 motdfile: TFILE '=' QSTRING ';'
1045 {
1046   MyFree(pass);
1047   pass = $3;
1048 };
1049
1050 featuresblock: FEATURES '{' featureitems '}' ';';
1051 featureitems: featureitems featureitem | featureitem;
1052
1053 featureitem: QSTRING
1054 {
1055   stringlist[0] = $1;
1056   stringno = 1;
1057 } '=' stringlist ';' {
1058   unsigned int ii;
1059   feature_set(NULL, (const char * const *)stringlist, stringno);
1060   for (ii = 0; ii < stringno; ++ii)
1061     MyFree(stringlist[ii]);
1062 };
1063
1064 stringlist: stringlist extrastring | extrastring;
1065 extrastring: QSTRING
1066 {
1067   if (stringno < MAX_STRINGS)
1068     stringlist[stringno++] = $1;
1069   else
1070     MyFree($1);
1071 };
1072
1073 quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
1074 quarantineitems: quarantineitems quarantineitem | quarantineitem;
1075 quarantineitem: QSTRING '=' QSTRING ';'
1076 {
1077   struct qline *qconf = MyCalloc(1, sizeof(*qconf));
1078   qconf->chname = $1;
1079   qconf->reason = $3;
1080   qconf->next = GlobalQuarantineList;
1081   GlobalQuarantineList = qconf;
1082 };
1083
1084 pseudoblock: PSEUDO QSTRING '{'
1085 {
1086   smap = MyCalloc(1, sizeof(struct s_map));
1087   smap->command = $2;
1088 }
1089 pseudoitems '}' ';'
1090 {
1091   int valid = 0;
1092
1093   if (!smap->name)
1094     parse_error("Missing name in pseudo %s block", smap->command);
1095   else if (!smap->services)
1096     parse_error("Missing nick in pseudo %s block", smap->command);
1097   else if (!strIsAlpha(smap->command))
1098     parse_error("Pseudo command %s invalid: must all be letters", smap->command);
1099   else
1100     valid = 1;
1101   if (valid && register_mapping(smap))
1102   {
1103     smap->next = GlobalServiceMapList;
1104     GlobalServiceMapList = smap;
1105   }
1106   else
1107   {
1108     free_mapping(smap);
1109   }
1110   smap = NULL;
1111 };
1112
1113 pseudoitems: pseudoitem pseudoitems | pseudoitem;
1114 pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags;
1115 pseudoname: NAME '=' QSTRING ';'
1116 {
1117   MyFree(smap->name);
1118   smap->name = $3;
1119 };
1120 pseudoprepend: PREPEND '=' QSTRING ';'
1121 {
1122   MyFree(smap->prepend);
1123   smap->prepend = $3;
1124 };
1125 pseudonick: NICK '=' QSTRING ';'
1126 {
1127   char *sep = strchr($3, '@');
1128
1129   if (sep != NULL) {
1130     size_t slen = strlen($3);
1131     struct nick_host *nh = MyMalloc(sizeof(*nh) + slen);
1132     memcpy(nh->nick, $3, slen + 1);
1133     nh->nicklen = sep - $3;
1134     nh->next = smap->services;
1135     smap->services = nh;
1136   }
1137   MyFree($3);
1138 };
1139 pseudoflags: FAST ';'
1140 {
1141   smap->flags |= SMAP_FAST;
1142 };
1143
1144 iauthblock: IAUTH '{' iauthitems '}' ';'
1145 {
1146   auth_spawn(stringno, stringlist);
1147   while (stringno > 0)
1148   {
1149     --stringno;
1150     MyFree(stringlist[stringno]);
1151   }
1152 };
1153
1154 iauthitems: iauthitem iauthitems | iauthitem;
1155 iauthitem: iauthprogram;
1156 iauthprogram: PROGRAM '='
1157 {
1158   while (stringno > 0)
1159   {
1160     --stringno;
1161     MyFree(stringlist[stringno]);
1162   }
1163 } stringlist ';';