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"
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 qline *GlobalQuarantineList;
70 /* Now all the globals we need :/... */
71 int tping, tconn, maxlinks, sendq, port;
73 char *name, *pass, *host;
74 char *stringlist[MAX_STRINGS];
75 struct ConnectionClass *c_class;
76 struct ConfItem *aconf;
77 struct DenyConf *dconf;
78 struct ServerConf *sconf;
79 struct qline *qconf = NULL;
143 /* and now a lot of priviledges... */
144 %token TPRIV_CHAN_LIMIT, TPRIV_MODE_LCHAN, TPRIV_DEOP_LCHAN, TPRIV_WALK_LCHAN
145 %token TPRIV_KILL, TPRIV_LOCAL_KILL, TPRIV_REHASH, TPRIV_RESTART, TPRIV_DIE
146 %token TPRIV_GLINE, TPRIV_LOCAL_GLINE, TPRIV_JUPE, TPRIV_LOCAL_JUPE
147 %token TPRIV_LOCAL_OPMODE, TPRIV_OPMODE, TPRIV_SET, TPRIV_WHOX, TPRIV_BADCHAN
148 %token TPRIV_LOCAL_BADCHAN
149 %token TPRIV_SEE_CHAN, TPRIV_SHOW_INVIS, TPRIV_SHOW_ALL_INVIS, TPRIV_PROPAGATE
150 %token TPRIV_UNLIMIT_QUERY, TPRIV_DISPLAY, TPRIV_SEE_OPERS, TPRIV_WIDE_GLINE
151 /* and some types... */
153 %type <num> timespec, timefactor, factoredtimes, factoredtime
154 %type <num> expr, yesorno, privtype
164 /* Blocks in the config file... */
165 blocks: blocks block | block;
166 block: adminblock | generalblock | classblock | connectblock |
167 serverblock | operblock | portblock | jupeblock | clientblock |
168 killblock | cruleblock | motdblock | featuresblock | quarantineblock;
170 /* The timespec, sizespec and expr was ripped straight from
172 timespec: expr | factoredtimes;
174 factoredtimes: factoredtimes factoredtime
179 factoredtime: expr timefactor
184 timefactor: SECONDS { $$ = 1; }
185 | MINUTES { $$ = 60; }
186 | HOURS { $$ = 60 * 60; }
187 | DAYS { $$ = 60 * 60 * 24; }
188 | WEEKS { $$ = 60 * 60 * 24 * 7; }
189 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
190 | YEARS { $$ = 60 * 60 * 24 * 365; }
191 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
208 $$ = $1 * 1024 * 1024;
212 $$ = $1 * 1024 * 1024 * 1024;
216 $$ = $1 * 1024 * 1024 * 1024;
220 /* this is an arithmatic expression */
241 /* leave this out until we find why it makes BSD yacc dump core -larne
252 jupeblock: JUPE '{' jupeitems '}' ';' ;
253 jupeitems: jupeitem jupeitems | jupeitem;
255 jupenick: NICK '=' QSTRING
257 addNickJupes(yylval.text);
260 generalblock: GENERAL '{' generalitems '}' ';' ;
261 generalitems: generalitem generalitems | generalitem;
262 generalitem: generalnumeric | generalname | generalvhost | generaldesc;
263 generalnumeric: NUMERIC '=' NUMBER ';'
265 if (localConf.numeric == 0)
266 localConf.numeric = yylval.num;
269 generalname: NAME '=' QSTRING ';'
271 if (localConf.name == NULL)
272 DupString(localConf.name, yylval.text);
275 generaldesc: DESCRIPTION '=' QSTRING ';'
277 MyFree(localConf.description);
278 DupString(localConf.description, yylval.text);
279 ircd_strncpy(cli_info(&me), yylval.text, REALLEN);
282 generalvhost: VHOST '=' QSTRING ';'
285 (localConf.vhost_address.s_addr = inet_addr(yylval.text)))
286 localConf.vhost_address.s_addr = INADDR_ANY;
289 adminblock: ADMIN '{' adminitems '}'
291 if (localConf.location1 == NULL)
292 DupString(localConf.location1, "");
293 if (localConf.location2 == NULL)
294 DupString(localConf.location2, "");
295 if (localConf.contact == NULL)
296 DupString(localConf.contact, "");
298 adminitems: adminitems adminitem | adminitem;
299 adminitem: adminlocation | admincontact;
300 adminlocation: LOCATION '=' QSTRING ';'
302 if (localConf.location1 == NULL)
303 DupString(localConf.location1, yylval.text);
304 else if (localConf.location2 == NULL)
305 DupString(localConf.location2, yylval.text);
306 /* Otherwise just drop it. -A1kmm */
308 admincontact: CONTACT '=' QSTRING ';'
310 if (localConf.contact != NULL)
311 MyFree(localConf.contact);
312 DupString(localConf.contact, yylval.text);
325 add_class(name, tping, tconn, maxlinks, sendq);
328 classitems: classitem classitems | classitem;
329 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
331 classname: NAME '=' QSTRING ';'
334 DupString(name, yylval.text);
336 classpingfreq: PINGFREQ '=' timespec ';'
340 classconnfreq: CONNECTFREQ '=' timespec ';'
344 classmaxlinks: MAXLINKS '=' expr ';'
346 maxlinks = yylval.num;
348 classsendq: SENDQ '=' sizespec ';'
353 connectblock: CONNECT
355 name = pass = host = NULL;
358 } '{' connectitems '}'
360 if (name != NULL && pass != NULL && host != NULL && c_class != NULL &&
361 /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
365 aconf->status = CONF_SERVER;
367 aconf->passwd = pass;
368 aconf->conn_class = c_class;
370 aconf->status = CONF_SERVER;
372 aconf->next = GlobalConfList;
373 aconf->ipnum.s_addr = INADDR_NONE;
374 lookup_confhost(aconf);
375 GlobalConfList = aconf;
382 name = pass = host = NULL;
385 connectitems: connectitem connectitems | connectitem;
386 connectitem: connectname | connectpass | connectclass | connecthost
388 connectname: NAME '=' QSTRING ';'
391 DupString(name, yylval.text);
393 connectpass: PASS '=' QSTRING ';'
396 DupString(pass, yylval.text);
398 connectclass: CLASS '=' QSTRING ';'
400 c_class = find_class(yylval.text);
402 connecthost: HOST '=' QSTRING ';'
405 DupString(host, yylval.text);
407 connectport: PORT '=' NUMBER ';'
414 aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
415 memset(aconf, 0, sizeof(*aconf));
416 } '{' serveritems '}'
418 if (aconf->status == 0)
427 aconf->next = GlobalConfList;
428 GlobalConfList = aconf;
431 serveritems: serveritem serveritems | serveritem;
432 serveritem: servername | servermask | serverhub | serverleaf |
434 servername: NAME '=' QSTRING
437 DupString(aconf->name, yylval.text);
439 servermask: MASK '=' QSTRING
442 DupString(aconf->host, yylval.text);
444 /* XXX - perhaps we should do this the hybrid way in connect blocks
446 serverhub: HUB '=' YES ';'
448 aconf->status |= CONF_HUB;
449 aconf->status &= ~CONF_LEAF;
453 aconf->status &= ~CONF_HUB;
455 serverleaf: LEAF '=' YES ';'
457 if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
458 aconf->status |= CONF_LEAF;
462 aconf->status &= ~CONF_LEAF;
464 serveruworld: UWORLD '=' YES ';'
466 aconf->status |= CONF_UWORLD;
467 aconf->status &= ~CONF_LEAF;
471 aconf->status &= ~CONF_UWORLD;
476 aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
477 memset(aconf, 0, sizeof(*aconf));
478 aconf->status = CONF_OPERATOR;
479 } '{' operitems '}' ';'
481 if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL)
483 aconf->next = GlobalConfList;
484 GlobalConfList = aconf;
488 log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
490 MyFree(aconf->passwd);
496 operitems: operitem | operitems operitem;
497 operitem: opername | operpass | operlocal | operhost | operclass | operpriv;
499 opername: NAME '=' QSTRING ';'
502 DupString(aconf->name, yylval.text);
505 operpass: PASS '=' QSTRING ';'
507 MyFree(aconf->passwd);
508 DupString(aconf->passwd, yylval.text);
511 operlocal: LOCAL '=' YES ';'
513 /* XXX it would be good to get rid of local operators and add same
514 * permission values here. But for now, I am just going with local
516 aconf->status = CONF_LOCOP;
519 aconf->status = CONF_OPERATOR;
522 operhost: HOST '=' QSTRING ';'
525 if (!strchr(yylval.text, '@'))
528 char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3));
529 ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
533 DupString(aconf->host, yylval.text);
536 operclass: CLASS '=' QSTRING ';'
538 aconf->conn_class = find_class(yylval.text);
541 operpriv: privtype '=' yesorno ';'
545 PrivSet(&aconf->privs_dirty, $1);
546 PrivSet(&aconf->privs, $1);
550 PrivSet(&aconf->privs_dirty, $1);
551 PrivClr(&aconf->privs, $1);
555 privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
556 TPRIV_MODE_LCHAN { $$ = PRIV_MODE_LCHAN; } |
557 TPRIV_DEOP_LCHAN { $$ = PRIV_DEOP_LCHAN; } |
558 TPRIV_WALK_LCHAN { $$ = PRIV_WALK_LCHAN; } |
559 TPRIV_KILL { $$ = PRIV_KILL; } |
560 TPRIV_LOCAL_KILL { $$ = PRIV_LOCAL_KILL; } |
561 TPRIV_REHASH { $$ = PRIV_REHASH; } |
562 TPRIV_RESTART { $$ = PRIV_RESTART; } |
563 TPRIV_DIE { $$ = PRIV_DIE; } |
564 TPRIV_GLINE { $$ = PRIV_GLINE; } |
565 TPRIV_LOCAL_GLINE { $$ = PRIV_LOCAL_GLINE; } |
566 TPRIV_JUPE { $$ = PRIV_JUPE; } |
567 TPRIV_LOCAL_JUPE { $$ = PRIV_LOCAL_JUPE; } |
568 TPRIV_LOCAL_OPMODE { $$ = PRIV_LOCAL_OPMODE; } |
569 TPRIV_OPMODE { $$ = PRIV_OPMODE; }|
570 TPRIV_SET { $$ = PRIV_SET; } |
571 TPRIV_WHOX { $$ = PRIV_WHOX; } |
572 TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
573 TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
574 TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
575 TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
576 TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
577 TPRIV_PROPAGATE { $$ = PRIV_PROPAGATE; } |
578 TPRIV_UNLIMIT_QUERY { $$ = PRIV_UNLIMIT_QUERY; } |
579 TPRIV_DISPLAY { $$ = PRIV_DISPLAY; } |
580 TPRIV_SEE_OPERS { $$ = PRIV_SEE_OPERS; } |
581 TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; };
583 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
585 /* The port block... */
589 /* Hijack these for is_server, is_hidden to cut down on globals... */
592 /* and this for mask... */
594 } '{' portitems '}' ';'
596 if (port > 0 && port <= 0xFFFF)
598 add_listener(port, host, pass, tconn, tping);
607 portitems: portitem portitems | portitem;
608 portitem: portnumber | portvhost | portmask | portserver | porthidden;
609 portnumber: PORT '=' NUMBER ';'
614 portvhost: VHOST '=' QSTRING ';'
617 DupString(host, yylval.text);
620 portmask: MASK '=' QSTRING ';'
623 DupString(pass, yylval.text);
626 portserver: SERVER '=' YES ';'
629 } | SERVER '=' NO ';'
634 porthidden: HIDDEN '=' YES ';'
637 } | HIDDEN '=' NO ';'
644 aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
645 memset(aconf, 0, sizeof(*aconf));
646 aconf->status = CONF_CLIENT;
647 } '{' clientitems '}'
649 if ((aconf->host != NULL || aconf->name!=NULL))
651 if (aconf->host == NULL)
652 DupString(aconf->host, "");
653 if (aconf->name == NULL)
654 DupString(aconf->name, "");
655 if (aconf->conn_class == NULL)
656 aconf->conn_class = find_class("default");
657 aconf->next = GlobalConfList;
658 GlobalConfList = aconf;
664 MyFree(aconf->passwd);
669 clientitems: clientitem clientitems | clientitem;
670 clientitem: clienthost | clientclass | clientpass | clientip;
671 clientip: IP '=' QSTRING ';'
674 DupString(aconf->host, yylval.text);
677 clienthost: HOST '=' QSTRING ';'
680 DupString(aconf->name, yylval.text);
683 clientclass: CLASS '=' QSTRING ';'
685 aconf->conn_class = find_class(yylval.text);
688 clientpass: PASS '=' QSTRING ';'
690 MyFree(aconf->passwd);
691 DupString(aconf->passwd, yylval.text);
696 dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
697 memset(dconf, 0, sizeof(*dconf));
700 if (dconf->hostmask != NULL)
702 if (dconf->usermask == NULL)
703 DupString(dconf->usermask, "*");
704 dconf->next = denyConfList;
705 denyConfList = dconf;
710 MyFree(dconf->hostmask);
711 MyFree(dconf->message);
716 killitems: killitem killitems | killitem;
717 killitem: killuhost | killreal | killreasonfile | killreason;
718 killuhost: HOST '=' QSTRING ';'
721 dconf->flags &= ~DENY_FLAGS_REALNAME;
722 MyFree(dconf->hostmask);
723 MyFree(dconf->usermask);
724 if ((h = strchr(yylval.text, '@')) == NULL)
734 DupString(dconf->hostmask, h);
735 DupString(dconf->usermask, u);
736 if (strchr(yylval.text, '.'))
742 dconf->flags |= DENY_FLAGS_IP;
743 c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
744 &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
746 dconf->bits = c_class * 8;
751 ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
753 dconf->address = inet_addr(ipname);
757 killreal: REAL '=' QSTRING ';'
759 dconf->flags &= ~DENY_FLAGS_IP;
760 dconf->flags |= DENY_FLAGS_REALNAME;
761 MyFree(dconf->hostmask);
762 /* Leave usermask so you can specify user and real... */
763 DupString(dconf->hostmask, yylval.text);
766 killreason: REASON '=' QSTRING ';'
768 dconf->flags &= DENY_FLAGS_FILE;
769 MyFree(dconf->message);
770 DupString(dconf->message, yylval.text);
773 killreasonfile: TFILE '=' QSTRING ';'
775 dconf->flags |= DENY_FLAGS_FILE;
776 MyFree(dconf->message);
777 DupString(dconf->message, yylval.text);
786 struct CRuleNode *node;
787 if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
789 struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
794 p->next = cruleConfList;
804 cruleitems: cruleitem cruleitems | cruleitem;
805 cruleitem: cruleserver | crulerule | cruleall;
807 cruleserver: SERVER '=' QSTRING ';'
810 collapse(yylval.text);
811 DupString(host, yylval.text);
814 crulerule: RULE '=' QSTRING ';'
817 DupString(pass, yylval.text);
820 cruleall: ALL '=' YES ';'
832 if (host != NULL && pass != NULL)
833 motd_add(host, pass);
839 motditems: motditem motditems | motditem;
840 motditem: motdhost | motdfile;
841 motdhost: HOST '=' QSTRING ';'
843 DupString(host, yylval.text);
846 motdfile: TFILE '=' QSTRING ';'
848 DupString(pass, yylval.text);
851 featuresblock: FEATURES '{' featureitems '}' ';';
852 featureitems: featureitems featureitem | featureitem;
858 } '=' stringlist ';';
866 feature_set(NULL, (const char * const *)stringlist, stringno);
868 posextrastrings: /* empty */ | extrastrings;
869 extrastrings: extrastrings extrastring | extrastring;
872 if (stringno < MAX_STRINGS)
873 stringlist[stringno++] = $1;
876 quarantineblock: QUARANTINE '{'
879 qconf = (struct qline*) MyMalloc(sizeof(*qconf));
882 if (qconf->chname != NULL)
883 MyFree(qconf->chname);
884 if (qconf->reason != NULL)
885 MyFree(qconf->reason);
887 memset(qconf, 0, sizeof(*qconf));
888 } quarantineitems '}' ';'
890 if (qconf->chname == NULL || qconf->reason == NULL)
892 log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
896 qconf->next = GlobalQuarantineList;
897 GlobalQuarantineList = qconf;
901 quarantineitems: CHANNEL NAME '=' QSTRING ';'
903 DupString(qconf->chname, yylval.text);
904 } | REASON '=' QSTRING ';'
906 DupString(qconf->reason, yylval.text);