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(C) 2001 by Andrew Miller, the
5 * 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.
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.
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,
29 #include "ircd_features.h"
34 #include "ircd_alloc.h"
35 #include "ircd_chattr.h"
37 #include "ircd_reply.h"
38 #include "ircd_snprintf.h"
39 #include "ircd_string.h"
58 #include <arpa/inet.h>
59 #define MAX_STRINGS 80 /* Maximum number of feature params. */
60 extern struct LocalConf localConf;
61 extern struct DenyConf* denyConfList;
62 extern struct CRuleConf* cruleConfList;
63 extern struct ServerConf* serverConfList;
66 /* Now all the globals we need :/... */
67 int tping, tconn, maxlinks, sendq, port;
69 char *name, *pass, *host;
70 char *stringlist[MAX_STRINGS];
71 struct ConnectionClass *class;
72 struct ConfItem *aconf;
73 struct DenyConf *dconf;
74 struct ServerConf *sconf;
136 /* and now a lot of priviledges... */
137 %token TPRIV_CHAN_LIMIT, TPRIV_MODE_LCHAN, TPRIV_DEOP_LCHAN, TPRIV_WALK_LCHAN
138 %token TPRIV_KILL, TPRIV_LOCAL_KILL, TPRIV_REHASH, TPRIV_RESTART, TPRIV_DIE
139 %token TPRIV_GLINE, TPRIV_LOCAL_GLINE, TPRIV_JUPE, TPRIV_LOCAL_JUPE
140 %token TPRIV_LOCAL_OPMODE, TPRIV_OPMODE, TPRIV_SET, TPRIV_WHOX, TPRIV_BADCHAN
141 %token TPRIV_LOCAL_BADCHAN
142 %token TPRIV_SEE_CHAN, TPRIV_SHOW_INVIS, TPRIV_SHOW_ALL_INVIS, TPRIV_PROPAGATE
143 %token TPRIV_UNLIMIT_QUERY, TPRIV_DISPLAY, TPRIV_SEE_OPERS, TPRIV_WIDE_GLINE
144 /* and some types... */
146 %type <num> timespec, timefactor, factoredtimes, factoredtime
147 %type <num> expr, yesorno, privtype
157 /* Blocks in the config file... */
158 blocks: blocks block | block;
159 block: adminblock | generalblock | classblock | connectblock |
160 serverblock | operblock | portblock | jupeblock | clientblock |
161 killblock | cruleblock | motdblock | featuresblock;
163 /* The timespec, sizespec and expr was ripped straight from
165 timespec: expr | factoredtimes;
167 factoredtimes: factoredtimes factoredtime
172 factoredtime: expr timefactor
177 timefactor: SECONDS { $$ = 1; }
178 | MINUTES { $$ = 60; }
179 | HOURS { $$ = 60 * 60; }
180 | DAYS { $$ = 60 * 60 * 24; }
181 | WEEKS { $$ = 60 * 60 * 24 * 7; }
182 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
183 | YEARS { $$ = 60 * 60 * 24 * 365; }
184 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
201 $$ = $1 * 1024 * 1024;
205 $$ = $1 * 1024 * 1024 * 1024;
209 $$ = $1 * 1024 * 1024 * 1024;
213 /* this is an arithmatic expression */
234 /* leave this out until we find why it makes BSD yacc dump core -larne
245 jupeblock: JUPE '{' jupeitems '}' ';' ;
246 jupeitems: jupeitem jupeitems | jupeitem;
248 jupenick: NICK '=' QSTRING
250 addNickJupes(yylval.text);
253 generalblock: GENERAL '{' generalitems '}' ';' ;
254 generalitems: generalitem generalitems | generalitem;
255 generalitem: generalnumeric | generalname | generalvhost | generaldesc;
256 generalnumeric: NUMERIC '=' NUMBER ';'
258 if (localConf.numeric == 0)
259 localConf.numeric = yylval.num;
262 generalname: NAME '=' QSTRING ';'
264 if (localConf.name == NULL)
265 DupString(localConf.name, yylval.text);
268 generaldesc: DESCRIPTION '=' QSTRING ';'
270 MyFree(localConf.description);
271 DupString(localConf.description, yylval.text);
272 ircd_strncpy(cli_info(&me), yylval.text, REALLEN);
275 generalvhost: VHOST '=' QSTRING ';'
278 (localConf.vhost_address.s_addr = inet_addr(yylval.text)))
279 localConf.vhost_address.s_addr = INADDR_ANY;
282 adminblock: ADMIN '{' adminitems '}'
284 if (localConf.location1 == NULL)
285 DupString(localConf.location1, "");
286 if (localConf.location2 == NULL)
287 DupString(localConf.location2, "");
288 if (localConf.contact == NULL)
289 DupString(localConf.contact, "");
291 adminitems: adminitems adminitem | adminitem;
292 adminitem: adminlocation | admincontact;
293 adminlocation: LOCATION '=' QSTRING ';'
295 if (localConf.location1 == NULL)
296 DupString(localConf.location1, yylval.text);
297 else if (localConf.location2 == NULL)
298 DupString(localConf.location2, yylval.text);
299 /* Otherwise just drop it. -A1kmm */
301 admincontact: CONTACT '=' QSTRING ';'
303 if (localConf.contact != NULL)
304 free(localConf.contact);
305 DupString(localConf.contact, yylval.text);
318 add_class(name, tping, tconn, maxlinks, sendq);
321 classitems: classitem classitems | classitem;
322 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
324 classname: NAME '=' QSTRING ';'
327 DupString(name, yylval.text);
329 classpingfreq: PINGFREQ '=' timespec ';'
333 classconnfreq: CONNECTFREQ '=' timespec ';'
337 classmaxlinks: MAXLINKS '=' expr ';'
339 maxlinks = yylval.num;
341 classsendq: SENDQ '=' sizespec ';'
346 connectblock: CONNECT
348 name = pass = host = NULL;
351 } '{' connectitems '}'
353 if (name != NULL && pass != NULL && host != NULL && class != NULL &&
354 /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
357 aconf = MyMalloc(sizeof(*aconf));
358 aconf->status = CONF_SERVER;
360 aconf->passwd = pass;
361 aconf->conn_class = class;
363 aconf->status = CONF_SERVER;
365 aconf->next = GlobalConfList;
366 GlobalConfList = aconf;
367 printf("Server added: %s\n", name);
368 /* ccount++; -- XXX fixme --- A1kmm */
375 name = pass = host = NULL;
378 connectitems: connectitem connectitems | connectitem;
379 connectitem: connectname | connectpass | connectclass | connecthost
381 connectname: NAME '=' QSTRING ';'
384 DupString(name, yylval.text);
386 connectpass: PASS '=' QSTRING ';'
389 DupString(pass, yylval.text);
391 connectclass: CLASS '=' QSTRING ';'
393 class = find_class(yylval.text);
395 connecthost: HOST '=' QSTRING ';'
398 DupString(host, yylval.text);
400 connectport: PORT '=' NUMBER ';'
407 aconf = MyMalloc(sizeof(*aconf));
408 memset(aconf, 0, sizeof(*aconf));
409 } '{' serveritems '}'
411 if (aconf->status == 0)
420 aconf->next = GlobalConfList;
421 GlobalConfList = aconf;
424 serveritems: serveritem serveritems | serveritem;
425 serveritem: servername | servermask | serverhub | serverleaf |
427 servername: NAME '=' QSTRING
430 DupString(aconf->name, yylval.text);
432 servermask: MASK '=' QSTRING
435 DupString(aconf->host, yylval.text);
437 /* XXX - perhaps we should do this the hybrid way in connect blocks
439 serverhub: HUB '=' YES ';'
441 aconf->status |= CONF_HUB;
442 aconf->status &= ~CONF_LEAF;
446 aconf->status &= ~CONF_HUB;
448 serverleaf: LEAF '=' YES ';'
450 if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
451 aconf->status |= CONF_LEAF;
455 aconf->status &= ~CONF_LEAF;
457 serveruworld: UWORLD '=' YES ';'
459 aconf->status |= CONF_UWORLD;
460 aconf->status &= ~CONF_LEAF;
464 aconf->status &= ~CONF_UWORLD;
469 aconf = MyMalloc(sizeof(*aconf));
470 memset(aconf, 0, sizeof(*aconf));
471 aconf->status = CONF_OPERATOR;
472 set_initial_oper_privs(aconf, (FLAGS_OPER | FLAGS_LOCOP));
473 } '{' operitems '}' ';'
475 if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL)
477 log_write(LS_CONFIG, L_ERROR, 0, "added an oper block for host %s", aconf->host);
478 aconf->next = GlobalConfList;
479 GlobalConfList = aconf;
483 log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
485 MyFree(aconf->passwd);
491 operitems: operitem | operitems operitem;
492 operitem: opername | operpass | operlocal | operhost | operclass | operpriv;
494 opername: NAME '=' QSTRING ';'
497 DupString(aconf->name, yylval.text);
500 operpass: PASS '=' QSTRING ';'
502 MyFree(aconf->passwd);
503 DupString(aconf->passwd, yylval.text);
506 operlocal: LOCAL '=' YES ';'
508 /* XXX it would be good to get rid of local operators and add same
509 * permission values here. But for now, I am just going with local
511 aconf->status = CONF_LOCOP;
512 /* XXX blow away existing priviledges. */
513 set_initial_oper_privs(aconf, FLAGS_LOCOP);
516 /* XXX blow away existing priviledges. */
517 set_initial_oper_privs(aconf, (FLAGS_OPER|FLAGS_LOCOP));
518 aconf->status = CONF_OPERATOR;
521 operhost: HOST '=' QSTRING ';'
524 if (!strchr(yylval.text, '@'))
527 char *b = MyMalloc((uh_len = strlen(yylval.text)+3));
528 ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
532 DupString(aconf->host, yylval.text);
535 operclass: CLASS '=' QSTRING ';'
537 aconf->conn_class = find_class(yylval.text);
540 operpriv: privtype '=' yesorno ';'
543 PrivSet(&aconf->privs, $1);
545 PrivClr(&aconf->privs, $1);
548 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
549 TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
550 TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
551 TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
552 TPRIV_KILL { $$ = PRIV_KILL; } |
553 TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
554 TPRIV_REHASH { $$ = PRIV_REHASH; } |
555 TPRIV_RESTART { $$ = PRIV_RESTART; } |
556 TPRIV_DIE { $$ = PRIV_DIE; } |
557 TPRIV_GLINE { $$ = PRIV_GLINE; } |
558 TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
559 TPRIV_JUPE { $$ = PRIV_JUPE; } |
560 TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
561 TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
562 TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
563 TPRIV_SET { $$ = PRIV_SET; } |
564 TPRIV_WHOX { $$ = PRIV_WHOX; } |
565 TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
566 TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
567 TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
568 TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
569 TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
570 TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
571 TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
572 TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
573 TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
574 TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; };
576 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
578 /* The port block... */
582 /* Hijack these for is_server, is_hidden to cut down on globals... */
585 /* and this for mask... */
587 } '{' portitems '}' ';'
589 if (port > 0 && port <= 0xFFFF)
591 add_listener(port, host, pass, tconn, tping);
600 portitems: portitem portitems | portitem;
601 portitem: portnumber | portvhost | portmask | portserver | porthidden;
602 portnumber: PORT '=' NUMBER ';'
607 portvhost: VHOST '=' QSTRING ';'
610 DupString(host, yylval.text);
613 portmask: MASK '=' QSTRING ';'
616 DupString(pass, yylval.text);
619 portserver: SERVER '=' YES ';'
622 } | SERVER '=' NO ';'
627 porthidden: HIDDEN '=' YES ';'
630 } | HIDDEN '=' NO ';'
637 aconf = MyMalloc(sizeof(*aconf));
638 memset(aconf, 0, sizeof(*aconf));
639 aconf->status = CONF_CLIENT;
640 } '{' clientitems '}'
642 if ((aconf->host != NULL || aconf->name!=NULL))
644 if (aconf->host == NULL)
645 DupString(aconf->host, "");
646 if (aconf->name == NULL)
647 DupString(aconf->name, "");
648 if (aconf->conn_class == NULL)
649 aconf->conn_class = find_class("default");
650 aconf->next = GlobalConfList;
651 GlobalConfList = aconf;
657 MyFree(aconf->passwd);
662 clientitems: clientitem clientitems | clientitem;
663 clientitem: clienthost | clientclass | clientpass | clientip;
664 clientip: IP '=' QSTRING ';'
667 DupString(aconf->host, yylval.text);
670 clienthost: HOST '=' QSTRING ';'
673 DupString(aconf->name, yylval.text);
676 clientclass: CLASS '=' QSTRING ';'
678 aconf->conn_class = find_class(yylval.text);
681 clientpass: PASS '=' QSTRING ';'
683 MyFree(aconf->passwd);
684 DupString(aconf->passwd, yylval.text);
689 dconf = MyMalloc(sizeof(*dconf));
690 memset(dconf, 0, sizeof(*dconf));
693 if (dconf->hostmask != NULL)
695 if (dconf->usermask == NULL)
696 DupString(dconf->usermask, "*");
697 dconf->next = denyConfList;
698 denyConfList = dconf;
703 MyFree(dconf->hostmask);
704 MyFree(dconf->message);
709 killitems: killitem killitems | killitem;
710 killitem: killuhost | killreal | killreasonfile | killreason;
711 killuhost: HOST '=' QSTRING ';'
714 dconf->flags &= ~DENY_FLAGS_REALNAME;
715 MyFree(dconf->hostmask);
716 MyFree(dconf->usermask);
717 if ((h = strchr(yylval.text, '@')) == NULL)
727 DupString(dconf->hostmask, h);
728 DupString(dconf->usermask, u);
729 if (strchr(yylval.text, '.'))
735 dconf->flags |= DENY_FLAGS_IP;
736 c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
737 &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
739 dconf->bits = c_class * 8;
744 ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
746 dconf->address = inet_addr(ipname);
750 killreal: REAL '=' QSTRING ';'
752 dconf->flags &= ~DENY_FLAGS_IP;
753 dconf->flags |= DENY_FLAGS_REALNAME;
754 MyFree(dconf->hostmask);
755 /* Leave usermask so you can specify user and real... */
756 DupString(dconf->hostmask, yylval.text);
759 killreason: REASON '=' QSTRING ';'
761 dconf->flags &= DENY_FLAGS_FILE;
762 MyFree(dconf->message);
763 DupString(dconf->message, yylval.text);
766 killreasonfile: TFILE '=' QSTRING ';'
768 dconf->flags |= DENY_FLAGS_FILE;
769 MyFree(dconf->message);
770 DupString(dconf->message, yylval.text);
779 struct CRuleNode *node;
780 if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
782 struct CRuleConf *p = MyMalloc(sizeof(*p));
787 p->next = cruleConfList;
797 cruleitems: cruleitem cruleitems | cruleitem;
798 cruleitem: cruleserver | crulerule | cruleall;
800 cruleserver: SERVER '=' QSTRING ';'
803 collapse(yylval.text);
804 DupString(host, yylval.text);
807 crulerule: RULE '=' QSTRING ';'
810 DupString(pass, yylval.text);
813 cruleall: ALL '=' YES ';'
825 if (host != NULL && pass != NULL)
826 motd_add(host, pass);
832 motditems: motditem motditems | motditem;
833 motditem: motdhost | motdfile;
834 motdhost: HOST '=' QSTRING ';'
836 DupString(host, yylval.text);
839 motdfile: TFILE '=' QSTRING ';'
841 DupString(pass, yylval.text);
844 featuresblock: FEATURES '{' featureitems '}' ';';
845 featureitems: featureitems featureitem | featureitem;
851 } '=' stringlist ';';
859 feature_set(NULL, (const char * const *)stringlist, stringno);
861 posextrastrings: /* empty */ | extrastrings;
862 extrastrings: extrastrings extrastring | extrastring;
865 if (stringno < MAX_STRINGS)
866 stringlist[stringno++] = $1;