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"
59 #include <arpa/inet.h>
60 #define MAX_STRINGS 80 /* Maximum number of feature params. */
61 extern struct LocalConf localConf;
62 extern struct DenyConf* denyConfList;
63 extern struct CRuleConf* cruleConfList;
64 extern struct ServerConf* serverConfList;
65 extern struct qline *GlobalQuarantineList;
69 /* Now all the globals we need :/... */
70 int tping, tconn, maxlinks, sendq, port;
72 char *name, *pass, *host;
73 char *stringlist[MAX_STRINGS];
74 struct ConnectionClass *class;
75 struct ConfItem *aconf;
76 struct DenyConf *dconf;
77 struct ServerConf *sconf;
78 struct qline *qconf = NULL;
142 /* and now a lot of priviledges... */
143 %token TPRIV_CHAN_LIMIT, TPRIV_MODE_LCHAN, TPRIV_DEOP_LCHAN, TPRIV_WALK_LCHAN
144 %token TPRIV_KILL, TPRIV_LOCAL_KILL, TPRIV_REHASH, TPRIV_RESTART, TPRIV_DIE
145 %token TPRIV_GLINE, TPRIV_LOCAL_GLINE, TPRIV_JUPE, TPRIV_LOCAL_JUPE
146 %token TPRIV_LOCAL_OPMODE, TPRIV_OPMODE, TPRIV_SET, TPRIV_WHOX, TPRIV_BADCHAN
147 %token TPRIV_LOCAL_BADCHAN
148 %token TPRIV_SEE_CHAN, TPRIV_SHOW_INVIS, TPRIV_SHOW_ALL_INVIS, TPRIV_PROPAGATE
149 %token TPRIV_UNLIMIT_QUERY, TPRIV_DISPLAY, TPRIV_SEE_OPERS, TPRIV_WIDE_GLINE
150 /* and some types... */
152 %type <num> timespec, timefactor, factoredtimes, factoredtime
153 %type <num> expr, yesorno, privtype
163 /* Blocks in the config file... */
164 blocks: blocks block | block;
165 block: adminblock | generalblock | classblock | connectblock |
166 serverblock | operblock | portblock | jupeblock | clientblock |
167 killblock | cruleblock | motdblock | featuresblock | quarantineblock;
169 /* The timespec, sizespec and expr was ripped straight from
171 timespec: expr | factoredtimes;
173 factoredtimes: factoredtimes factoredtime
178 factoredtime: expr timefactor
183 timefactor: SECONDS { $$ = 1; }
184 | MINUTES { $$ = 60; }
185 | HOURS { $$ = 60 * 60; }
186 | DAYS { $$ = 60 * 60 * 24; }
187 | WEEKS { $$ = 60 * 60 * 24 * 7; }
188 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
189 | YEARS { $$ = 60 * 60 * 24 * 365; }
190 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
207 $$ = $1 * 1024 * 1024;
211 $$ = $1 * 1024 * 1024 * 1024;
215 $$ = $1 * 1024 * 1024 * 1024;
219 /* this is an arithmatic expression */
240 /* leave this out until we find why it makes BSD yacc dump core -larne
251 jupeblock: JUPE '{' jupeitems '}' ';' ;
252 jupeitems: jupeitem jupeitems | jupeitem;
254 jupenick: NICK '=' QSTRING
256 addNickJupes(yylval.text);
259 generalblock: GENERAL '{' generalitems '}' ';' ;
260 generalitems: generalitem generalitems | generalitem;
261 generalitem: generalnumeric | generalname | generalvhost | generaldesc;
262 generalnumeric: NUMERIC '=' NUMBER ';'
264 if (localConf.numeric == 0)
265 localConf.numeric = yylval.num;
268 generalname: NAME '=' QSTRING ';'
270 if (localConf.name == NULL)
271 DupString(localConf.name, yylval.text);
274 generaldesc: DESCRIPTION '=' QSTRING ';'
276 MyFree(localConf.description);
277 DupString(localConf.description, yylval.text);
278 ircd_strncpy(cli_info(&me), yylval.text, REALLEN);
281 generalvhost: VHOST '=' QSTRING ';'
284 (localConf.vhost_address.s_addr = inet_addr(yylval.text)))
285 localConf.vhost_address.s_addr = INADDR_ANY;
288 adminblock: ADMIN '{' adminitems '}'
290 if (localConf.location1 == NULL)
291 DupString(localConf.location1, "");
292 if (localConf.location2 == NULL)
293 DupString(localConf.location2, "");
294 if (localConf.contact == NULL)
295 DupString(localConf.contact, "");
297 adminitems: adminitems adminitem | adminitem;
298 adminitem: adminlocation | admincontact;
299 adminlocation: LOCATION '=' QSTRING ';'
301 if (localConf.location1 == NULL)
302 DupString(localConf.location1, yylval.text);
303 else if (localConf.location2 == NULL)
304 DupString(localConf.location2, yylval.text);
305 /* Otherwise just drop it. -A1kmm */
307 admincontact: CONTACT '=' QSTRING ';'
309 if (localConf.contact != NULL)
310 MyFree(localConf.contact);
311 DupString(localConf.contact, yylval.text);
324 add_class(name, tping, tconn, maxlinks, sendq);
327 classitems: classitem classitems | classitem;
328 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
330 classname: NAME '=' QSTRING ';'
333 DupString(name, yylval.text);
335 classpingfreq: PINGFREQ '=' timespec ';'
339 classconnfreq: CONNECTFREQ '=' timespec ';'
343 classmaxlinks: MAXLINKS '=' expr ';'
345 maxlinks = yylval.num;
347 classsendq: SENDQ '=' sizespec ';'
352 connectblock: CONNECT
354 name = pass = host = NULL;
357 } '{' connectitems '}'
359 if (name != NULL && pass != NULL && host != NULL && class != NULL &&
360 /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
364 aconf->status = CONF_SERVER;
366 aconf->passwd = pass;
367 aconf->conn_class = class;
369 aconf->status = CONF_SERVER;
371 aconf->next = GlobalConfList;
372 aconf->ipnum.s_addr = INADDR_NONE;
373 lookup_confhost(aconf);
374 GlobalConfList = aconf;
381 name = pass = host = NULL;
384 connectitems: connectitem connectitems | connectitem;
385 connectitem: connectname | connectpass | connectclass | connecthost
387 connectname: NAME '=' QSTRING ';'
390 DupString(name, yylval.text);
392 connectpass: PASS '=' QSTRING ';'
395 DupString(pass, yylval.text);
397 connectclass: CLASS '=' QSTRING ';'
399 class = find_class(yylval.text);
401 connecthost: HOST '=' QSTRING ';'
404 DupString(host, yylval.text);
406 connectport: PORT '=' NUMBER ';'
413 aconf = MyMalloc(sizeof(*aconf));
414 memset(aconf, 0, sizeof(*aconf));
415 } '{' serveritems '}'
417 if (aconf->status == 0)
426 aconf->next = GlobalConfList;
427 GlobalConfList = aconf;
430 serveritems: serveritem serveritems | serveritem;
431 serveritem: servername | servermask | serverhub | serverleaf |
433 servername: NAME '=' QSTRING
436 DupString(aconf->name, yylval.text);
438 servermask: MASK '=' QSTRING
441 DupString(aconf->host, yylval.text);
443 /* XXX - perhaps we should do this the hybrid way in connect blocks
445 serverhub: HUB '=' YES ';'
447 aconf->status |= CONF_HUB;
448 aconf->status &= ~CONF_LEAF;
452 aconf->status &= ~CONF_HUB;
454 serverleaf: LEAF '=' YES ';'
456 if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
457 aconf->status |= CONF_LEAF;
461 aconf->status &= ~CONF_LEAF;
463 serveruworld: UWORLD '=' YES ';'
465 aconf->status |= CONF_UWORLD;
466 aconf->status &= ~CONF_LEAF;
470 aconf->status &= ~CONF_UWORLD;
475 aconf = MyMalloc(sizeof(*aconf));
476 memset(aconf, 0, sizeof(*aconf));
477 aconf->status = CONF_OPERATOR;
478 } '{' operitems '}' ';'
480 if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL)
482 aconf->next = GlobalConfList;
483 GlobalConfList = aconf;
487 log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
489 MyFree(aconf->passwd);
495 operitems: operitem | operitems operitem;
496 operitem: opername | operpass | operlocal | operhost | operclass | operpriv;
498 opername: NAME '=' QSTRING ';'
501 DupString(aconf->name, yylval.text);
504 operpass: PASS '=' QSTRING ';'
506 MyFree(aconf->passwd);
507 DupString(aconf->passwd, yylval.text);
510 operlocal: LOCAL '=' YES ';'
512 /* XXX it would be good to get rid of local operators and add same
513 * permission values here. But for now, I am just going with local
515 aconf->status = CONF_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 ';'
544 PrivSet(&aconf->privs_dirty, $1);
545 PrivSet(&aconf->privs, $1);
549 PrivSet(&aconf->privs_dirty, $1);
550 PrivClr(&aconf->privs, $1);
554 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
555 TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
556 TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
557 TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
558 TPRIV_KILL { $$ = PRIV_KILL; } |
559 TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
560 TPRIV_REHASH { $$ = PRIV_REHASH; } |
561 TPRIV_RESTART { $$ = PRIV_RESTART; } |
562 TPRIV_DIE { $$ = PRIV_DIE; } |
563 TPRIV_GLINE { $$ = PRIV_GLINE; } |
564 TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
565 TPRIV_JUPE { $$ = PRIV_JUPE; } |
566 TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
567 TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
568 TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
569 TPRIV_SET { $$ = PRIV_SET; } |
570 TPRIV_WHOX { $$ = PRIV_WHOX; } |
571 TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
572 TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
573 TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
574 TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
575 TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
576 TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
577 TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
578 TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
579 TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
580 TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; };
582 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
584 /* The port block... */
588 /* Hijack these for is_server, is_hidden to cut down on globals... */
591 /* and this for mask... */
593 } '{' portitems '}' ';'
595 if (port > 0 && port <= 0xFFFF)
597 add_listener(port, host, pass, tconn, tping);
606 portitems: portitem portitems | portitem;
607 portitem: portnumber | portvhost | portmask | portserver | porthidden;
608 portnumber: PORT '=' NUMBER ';'
613 portvhost: VHOST '=' QSTRING ';'
616 DupString(host, yylval.text);
619 portmask: MASK '=' QSTRING ';'
622 DupString(pass, yylval.text);
625 portserver: SERVER '=' YES ';'
628 } | SERVER '=' NO ';'
633 porthidden: HIDDEN '=' YES ';'
636 } | HIDDEN '=' NO ';'
643 aconf = MyMalloc(sizeof(*aconf));
644 memset(aconf, 0, sizeof(*aconf));
645 aconf->status = CONF_CLIENT;
646 } '{' clientitems '}'
648 if ((aconf->host != NULL || aconf->name!=NULL))
650 if (aconf->host == NULL)
651 DupString(aconf->host, "");
652 if (aconf->name == NULL)
653 DupString(aconf->name, "");
654 if (aconf->conn_class == NULL)
655 aconf->conn_class = find_class("default");
656 aconf->next = GlobalConfList;
657 GlobalConfList = aconf;
663 MyFree(aconf->passwd);
668 clientitems: clientitem clientitems | clientitem;
669 clientitem: clienthost | clientclass | clientpass | clientip;
670 clientip: IP '=' QSTRING ';'
673 DupString(aconf->host, yylval.text);
676 clienthost: HOST '=' QSTRING ';'
679 DupString(aconf->name, yylval.text);
682 clientclass: CLASS '=' QSTRING ';'
684 aconf->conn_class = find_class(yylval.text);
687 clientpass: PASS '=' QSTRING ';'
689 MyFree(aconf->passwd);
690 DupString(aconf->passwd, yylval.text);
695 dconf = MyMalloc(sizeof(*dconf));
696 memset(dconf, 0, sizeof(*dconf));
699 if (dconf->hostmask != NULL)
701 if (dconf->usermask == NULL)
702 DupString(dconf->usermask, "*");
703 dconf->next = denyConfList;
704 denyConfList = dconf;
709 MyFree(dconf->hostmask);
710 MyFree(dconf->message);
715 killitems: killitem killitems | killitem;
716 killitem: killuhost | killreal | killreasonfile | killreason;
717 killuhost: HOST '=' QSTRING ';'
720 dconf->flags &= ~DENY_FLAGS_REALNAME;
721 MyFree(dconf->hostmask);
722 MyFree(dconf->usermask);
723 if ((h = strchr(yylval.text, '@')) == NULL)
733 DupString(dconf->hostmask, h);
734 DupString(dconf->usermask, u);
735 if (strchr(yylval.text, '.'))
741 dconf->flags |= DENY_FLAGS_IP;
742 c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
743 &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
745 dconf->bits = c_class * 8;
750 ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
752 dconf->address = inet_addr(ipname);
756 killreal: REAL '=' QSTRING ';'
758 dconf->flags &= ~DENY_FLAGS_IP;
759 dconf->flags |= DENY_FLAGS_REALNAME;
760 MyFree(dconf->hostmask);
761 /* Leave usermask so you can specify user and real... */
762 DupString(dconf->hostmask, yylval.text);
765 killreason: REASON '=' QSTRING ';'
767 dconf->flags &= DENY_FLAGS_FILE;
768 MyFree(dconf->message);
769 DupString(dconf->message, yylval.text);
772 killreasonfile: TFILE '=' QSTRING ';'
774 dconf->flags |= DENY_FLAGS_FILE;
775 MyFree(dconf->message);
776 DupString(dconf->message, yylval.text);
785 struct CRuleNode *node;
786 if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
788 struct CRuleConf *p = MyMalloc(sizeof(*p));
793 p->next = cruleConfList;
803 cruleitems: cruleitem cruleitems | cruleitem;
804 cruleitem: cruleserver | crulerule | cruleall;
806 cruleserver: SERVER '=' QSTRING ';'
809 collapse(yylval.text);
810 DupString(host, yylval.text);
813 crulerule: RULE '=' QSTRING ';'
816 DupString(pass, yylval.text);
819 cruleall: ALL '=' YES ';'
831 if (host != NULL && pass != NULL)
832 motd_add(host, pass);
838 motditems: motditem motditems | motditem;
839 motditem: motdhost | motdfile;
840 motdhost: HOST '=' QSTRING ';'
842 DupString(host, yylval.text);
845 motdfile: TFILE '=' QSTRING ';'
847 DupString(pass, yylval.text);
850 featuresblock: FEATURES '{' featureitems '}' ';';
851 featureitems: featureitems featureitem | featureitem;
857 } '=' stringlist ';';
865 feature_set(NULL, (const char * const *)stringlist, stringno);
867 posextrastrings: /* empty */ | extrastrings;
868 extrastrings: extrastrings extrastring | extrastring;
871 if (stringno < MAX_STRINGS)
872 stringlist[stringno++] = $1;
875 quarantineblock: QUARANTINE '{'
878 qconf = MyMalloc(sizeof(*qconf));
881 if (qconf->chname != NULL)
882 MyFree(qconf->chname);
883 if (qconf->reason != NULL)
884 MyFree(qconf->reason);
886 memset(qconf, 0, sizeof(*qconf));
887 } quarantineitems '}' ';'
889 if (qconf->chname == NULL || qconf->reason == NULL)
891 log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
895 qconf->next = GlobalQuarantineList;
896 GlobalQuarantineList = qconf;
900 quarantineitems: CHANNEL NAME '=' QSTRING ';'
902 DupString(qconf->chname, yylval.text);
903 } | REASON '=' QSTRING ';'
905 DupString(qconf->reason, yylval.text);