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