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;
137 %type <num> timespec, timefactor, factoredtimes, factoredtime
148 /* Blocks in the config file... */
149 blocks: blocks block | block;
150 block: adminblock | generalblock | classblock | connectblock |
151 serverblock | operblock | portblock | jupeblock | clientblock |
152 killblock | cruleblock | motdblock | featuresblock;
154 /* The timespec, sizespec and expr was ripped straight from
156 timespec: expr | factoredtimes;
158 factoredtimes: factoredtimes factoredtime
163 factoredtime: expr timefactor
168 timefactor: SECONDS { $$ = 1; }
169 | MINUTES { $$ = 60; }
170 | HOURS { $$ = 60 * 60; }
171 | DAYS { $$ = 60 * 60 * 24; }
172 | WEEKS { $$ = 60 * 60 * 24 * 7; }
173 | MONTHS { $$ = 60 * 60 * 24 * 7 * 4; }
174 | YEARS { $$ = 60 * 60 * 24 * 365; }
175 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
192 $$ = $1 * 1024 * 1024;
196 $$ = $1 * 1024 * 1024 * 1024;
200 $$ = $1 * 1024 * 1024 * 1024;
204 /* this is an arithmatic expression */
225 /* leave this out until we find why it makes BSD yacc dump core -larne
236 jupeblock: JUPE '{' jupeitems '}' ';' ;
237 jupeitems: jupeitem jupeitems | jupeitem;
239 jupenick: NICK '=' QSTRING
241 addNickJupes(yylval.text);
244 generalblock: GENERAL '{' generalitems '}' ';' ;
245 generalitems: generalitem generalitems | generalitem;
246 generalitem: generalnumeric | generalname | generalvhost | generaldesc;
247 generalnumeric: NUMERIC '=' NUMBER ';'
249 if (localConf.numeric == 0)
250 localConf.numeric = yylval.num;
253 generalname: NAME '=' QSTRING ';'
255 if (localConf.name == NULL)
256 DupString(localConf.name, yylval.text);
259 generaldesc: DESCRIPTION '=' QSTRING ';'
261 MyFree(localConf.description);
262 DupString(localConf.description, yylval.text);
265 generalvhost: VHOST '=' QSTRING ';'
268 (localConf.vhost_address.s_addr = inet_addr(yylval.text)))
269 localConf.vhost_address.s_addr = INADDR_ANY;
272 adminblock: ADMIN '{' adminitems '}'
274 if (localConf.location1 == NULL)
275 DupString(localConf.location1, "");
276 if (localConf.location2 == NULL)
277 DupString(localConf.location2, "");
278 if (localConf.contact == NULL)
279 DupString(localConf.contact, "");
281 adminitems: adminitems adminitem | adminitem;
282 adminitem: adminlocation | admincontact;
283 adminlocation: LOCATION '=' QSTRING ';'
285 if (localConf.location1 == NULL)
286 DupString(localConf.location1, yylval.text);
287 else if (localConf.location2 == NULL)
288 DupString(localConf.location2, yylval.text);
289 /* Otherwise just drop it. -A1kmm */
291 admincontact: CONTACT '=' QSTRING ';'
293 if (localConf.contact != NULL)
294 free(localConf.contact);
295 DupString(localConf.contact, yylval.text);
308 add_class(name, tping, tconn, maxlinks, sendq);
311 classitems: classitem classitems | classitem;
312 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
314 classname: NAME '=' QSTRING ';'
317 DupString(name, yylval.text);
319 classpingfreq: PINGFREQ '=' timespec ';'
323 classconnfreq: CONNECTFREQ '=' timespec ';'
327 classmaxlinks: MAXLINKS '=' expr ';'
329 maxlinks = yylval.num;
331 classsendq: SENDQ '=' sizespec ';'
336 connectblock: CONNECT
338 name = pass = host = NULL;
341 } '{' connectitems '}'
343 if (name != NULL && pass != NULL && host != NULL && class != NULL &&
344 /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
347 aconf = MyMalloc(sizeof(*aconf));
348 aconf->status = CONF_SERVER;
350 aconf->passwd = pass;
351 aconf->conn_class = class;
353 aconf->status = CONF_SERVER;
355 aconf->next = GlobalConfList;
356 GlobalConfList = aconf;
357 printf("Server added: %s\n", name);
358 /* ccount++; -- XXX fixme --- A1kmm */
365 name = pass = host = NULL;
368 connectitems: connectitem connectitems | connectitem;
369 connectitem: connectname | connectpass | connectclass | connecthost
371 connectname: NAME '=' QSTRING ';'
374 DupString(name, yylval.text);
376 connectpass: PASS '=' QSTRING ';'
379 DupString(pass, yylval.text);
381 connectclass: CLASS '=' QSTRING ';'
383 class = find_class(yylval.text);
385 connecthost: HOST '=' QSTRING ';'
388 DupString(host, yylval.text);
390 connectport: PORT '=' NUMBER ';'
397 aconf = MyMalloc(sizeof(*aconf));
398 memset(aconf, 0, sizeof(*aconf));
399 } '{' serveritems '}'
401 if (aconf->status == 0)
410 aconf->next = GlobalConfList;
411 GlobalConfList = aconf;
414 serveritems: serveritem serveritems | serveritem;
415 serveritem: servername | servermask | serverhub | serverleaf |
417 servername: NAME '=' QSTRING
420 DupString(aconf->name, yylval.text);
422 servermask: MASK '=' QSTRING
425 DupString(aconf->host, yylval.text);
427 /* XXX - perhaps we should do this the hybrid way in connect blocks
429 serverhub: HUB '=' YES ';'
431 aconf->status |= CONF_HUB;
432 aconf->status &= ~CONF_LEAF;
436 aconf->status &= ~CONF_HUB;
438 serverleaf: LEAF '=' YES ';'
440 if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
441 aconf->status |= CONF_LEAF;
445 aconf->status &= ~CONF_LEAF;
447 serveruworld: UWORLD '=' YES ';'
449 aconf->status |= CONF_UWORLD;
450 aconf->status &= ~CONF_LEAF;
454 aconf->status &= ~CONF_UWORLD;
459 aconf = MyMalloc(sizeof(*aconf));
460 memset(aconf, 0, sizeof(*aconf));
461 aconf->status = CONF_OPERATOR;
462 } '{' operitems '}' ';'
464 if (aconf->name != NULL && aconf->passwd != NULL && aconf->host != NULL)
466 aconf->next = GlobalConfList;
467 GlobalConfList = aconf;
472 MyFree(aconf->passwd);
478 operitems: operitem | operitems operitem;
479 operitem: opername | operpass | operlocal | operhost | operclass;
481 opername: NAME '=' QSTRING ';'
484 DupString(aconf->name, yylval.text);
487 operpass: PASS '=' QSTRING ';'
489 MyFree(aconf->passwd);
490 DupString(aconf->passwd, yylval.text);
493 operlocal: LOCAL '=' YES ';'
495 /* XXX it would be good to get rid of local operators and add same
496 * permission values here. But for now, I am just going with local
498 aconf->status = CONF_LOCOP;
501 aconf->status = CONF_OPERATOR;
504 operhost: HOST '=' QSTRING ';'
507 if (!strchr(yylval.text, '@'))
510 char *b = MyMalloc((uh_len = strlen(yylval.text)+3));
511 ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
515 DupString(aconf->host, yylval.text);
518 operclass: CLASS '=' QSTRING ';'
520 aconf->conn_class = find_class(yylval.text);
523 /* The port block... */
527 /* Hijack these for is_server, is_hidden to cut down on globals... */
530 /* and this for mask... */
532 } '{' portitems '}' ';'
534 if (port > 0 && port <= 0xFFFF)
536 add_listener(port, host, pass, tconn, tping);
545 portitems: portitem portitems | portitem;
546 portitem: portnumber | portvhost | portmask | portserver | porthidden;
547 portnumber: PORT '=' NUMBER ';'
552 portvhost: VHOST '=' QSTRING ';'
555 DupString(host, yylval.text);
558 portmask: MASK '=' QSTRING ';'
561 DupString(pass, yylval.text);
564 portserver: SERVER '=' YES ';'
567 } | SERVER '=' NO ';'
572 porthidden: HIDDEN '=' YES ';'
575 } | HIDDEN '=' NO ';'
582 aconf = MyMalloc(sizeof(*aconf));
583 memset(aconf, 0, sizeof(*aconf));
584 aconf->status = CONF_CLIENT;
585 } '{' clientitems '}'
587 if ((aconf->host != NULL || aconf->name!=NULL))
589 if (aconf->host == NULL)
590 DupString(aconf->host, "");
591 if (aconf->name == NULL)
592 DupString(aconf->name, "");
593 if (aconf->conn_class == NULL)
594 aconf->conn_class = find_class("default");
595 aconf->next = GlobalConfList;
596 GlobalConfList = aconf;
602 MyFree(aconf->passwd);
607 clientitems: clientitem clientitems | clientitem;
608 clientitem: clienthost | clientclass | clientpass | clientip;
609 clientip: IP '=' QSTRING ';'
612 DupString(aconf->host, yylval.text);
615 clienthost: HOST '=' QSTRING ';'
618 DupString(aconf->name, yylval.text);
621 clientclass: CLASS '=' QSTRING ';'
623 aconf->conn_class = find_class(yylval.text);
626 clientpass: PASS '=' QSTRING ';'
628 MyFree(aconf->passwd);
629 DupString(aconf->passwd, yylval.text);
634 dconf = MyMalloc(sizeof(*dconf));
635 memset(dconf, 0, sizeof(*dconf));
638 if (dconf->hostmask != NULL)
640 if (dconf->usermask == NULL)
641 DupString(dconf->usermask, "*");
642 dconf->next = denyConfList;
643 denyConfList = dconf;
648 MyFree(dconf->hostmask);
649 MyFree(dconf->message);
654 killitems: killitem killitems | killitem;
655 killitem: killuhost | killreal | killreasonfile | killreason;
656 killuhost: HOST '=' QSTRING ';'
659 dconf->flags &= ~DENY_FLAGS_REALNAME;
660 MyFree(dconf->hostmask);
661 MyFree(dconf->usermask);
662 if ((h = strchr(yylval.text, '@')) == NULL)
672 DupString(dconf->hostmask, h);
673 DupString(dconf->usermask, u);
674 if (strchr(yylval.text, '.'))
680 dconf->flags |= DENY_FLAGS_IP;
681 c_class = sscanf(dconf->hostmask, "%d.%d.%d.%d/%d",
682 &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
684 dconf->bits = c_class * 8;
689 ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
691 dconf->address = inet_addr(ipname);
695 killreal: REAL '=' QSTRING ';'
697 dconf->flags &= ~DENY_FLAGS_IP;
698 dconf->flags |= DENY_FLAGS_REALNAME;
699 MyFree(dconf->hostmask);
700 /* Leave usermask so you can specify user and real... */
701 DupString(dconf->hostmask, yylval.text);
704 killreason: REASON '=' QSTRING ';'
706 dconf->flags &= DENY_FLAGS_FILE;
707 MyFree(dconf->message);
708 DupString(dconf->message, yylval.text);
711 killreasonfile: TFILE '=' QSTRING ';'
713 dconf->flags |= DENY_FLAGS_FILE;
714 MyFree(dconf->message);
715 DupString(dconf->message, yylval.text);
724 struct CRuleNode *node;
725 if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
727 struct CRuleConf *p = MyMalloc(sizeof(*p));
732 p->next = cruleConfList;
742 cruleitems: cruleitem cruleitems | cruleitem;
743 cruleitem: cruleserver | crulerule | cruleall;
745 cruleserver: SERVER '=' QSTRING ';'
748 collapse(yylval.text);
749 DupString(host, yylval.text);
752 crulerule: RULE '=' QSTRING ';'
755 DupString(pass, yylval.text);
758 cruleall: ALL '=' YES ';'
770 if (host != NULL && pass != NULL)
771 motd_add(host, pass);
777 motditems: motditem motditems | motditem;
778 motditem: motdhost | motdfile;
779 motdhost: HOST '=' QSTRING ';'
781 DupString(host, yylval.text);
784 motdfile: TFILE '=' QSTRING ';'
786 DupString(pass, yylval.text);
789 featuresblock: FEATURES '{' featureitems '}' ';';
790 featureitems: featureitems featureitem | featureitem;
795 } '=' stringlist ';';
803 feature_set(NULL, (const char * const *)stringlist, stringno);
805 posextrastrings: /* empty */ | extrastrings;
806 extrastrings: extrastrings extrastring | extrastring;
809 if (stringno < MAX_STRINGS)
810 stringlist[stringno++] = $1;