Author: Isomer <isomer@undernet.org>
[ircu2.10.12-pk.git] / ircd / ircd_parser.y
index 4e63ff98f3f3c06e6dc6a8a24c77daaa6f76f38b..2471248d0200458ce716b98235c1946a869b8cb4 100644 (file)
@@ -55,6 +55,7 @@
 #include "support.h"
 #include "sys.h"
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <arpa/inet.h>
 #define MAX_STRINGS 80 /* Maximum number of feature params. */
   int stringno;
   char *name, *pass, *host;
   char *stringlist[MAX_STRINGS];
-  struct ConnectionClass *class;
+  struct ConnectionClass *c_class;
   struct ConfItem *aconf;
   struct DenyConf *dconf;
   struct ServerConf *sconf;
   struct qline *qconf = NULL;
+
+static void parse_error(char *pattern,...) {
+       va_list vl;
+       struct VarData vd;
+       va_start(vl,pattern);
+       vd.vd_format = pattern;
+       vd.vd_args = vl;
+       sendto_opmask_butone(0, SNO_OLDSNO, "Config: %v", &vd);
+       va_end(vl);
+}
 %}
 
 %token <text> QSTRING
 %token FEATURES
 %token QUARANTINE
 /* and now a lot of priviledges... */
-%token TPRIV_CHAN_LIMIT, TPRIV_MODE_LCHAN, TPRIV_DEOP_LCHAN, TPRIV_WALK_LCHAN
-%token TPRIV_KILL, TPRIV_LOCAL_KILL, TPRIV_REHASH, TPRIV_RESTART, TPRIV_DIE
-%token TPRIV_GLINE, TPRIV_LOCAL_GLINE, TPRIV_JUPE, TPRIV_LOCAL_JUPE
-%token TPRIV_LOCAL_OPMODE, TPRIV_OPMODE, TPRIV_SET, TPRIV_WHOX, TPRIV_BADCHAN
+%token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
+%token TPRIV_KILL TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
+%token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_JUPE TPRIV_LOCAL_JUPE
+%token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_BADCHAN
 %token TPRIV_LOCAL_BADCHAN
-%token TPRIV_SEE_CHAN, TPRIV_SHOW_INVIS, TPRIV_SHOW_ALL_INVIS, TPRIV_PROPAGATE
-%token TPRIV_UNLIMIT_QUERY, TPRIV_DISPLAY, TPRIV_SEE_OPERS, TPRIV_WIDE_GLINE
+%token TPRIV_SEE_CHAN TPRIV_SHOW_INVIS TPRIV_SHOW_ALL_INVIS TPRIV_PROPAGATE
+%token TPRIV_UNLIMIT_QUERY TPRIV_DISPLAY TPRIV_SEE_OPERS TPRIV_WIDE_GLINE
 /* and some types... */
 %type <num> sizespec
-%type <num> timespec, timefactor, factoredtimes, factoredtime
-%type <num> expr, yesorno, privtype
+%type <num> timespec timefactor factoredtimes factoredtime
+%type <num> expr yesorno privtype
 %left '+' '-'
 %left '*' '/'
 
@@ -190,51 +201,41 @@ timefactor: SECONDS { $$ = 1; }
 | DECADES { $$ = 60 * 60 * 24 * 365 * 10; };
 
 
-sizespec:      expr    
-               = {
+sizespec:      expr    {
                        $$ = $1;
                }
-               | expr BYTES
-               = { 
+               | expr BYTES  { 
                        $$ = $1;
                }
-               | expr KBYTES
-               = {
+               | expr KBYTES {
                        $$ = $1 * 1024;
                }
-               | expr MBYTES
-               = {
+               | expr MBYTES {
                        $$ = $1 * 1024 * 1024;
                }
-               | expr GBYTES
-               = {
+               | expr GBYTES {
                        $$ = $1 * 1024 * 1024 * 1024;
                }
-               | expr TBYTES
-               = {
+               | expr TBYTES {
                        $$ = $1 * 1024 * 1024 * 1024;
                }
                ;
 
 /* this is an arithmatic expression */
 expr: NUMBER
-               
+               { 
                        $$ = $1;
                }
-               | expr '+' expr
-               = { 
+               | expr '+' expr { 
                        $$ = $1 + $3;
                }
-               | expr '-' expr
-               = { 
+               | expr '-' expr { 
                        $$ = $1 - $3;
                }
-               | expr '*' expr
-               = { 
+               | expr '*' expr { 
                        $$ = $1 * $3;
                }
-               | expr '/' expr
-               = { 
+               | expr '/' expr { 
                        $$ = $1 / $3;
                }
 /* leave this out until we find why it makes BSD yacc dump core -larne
@@ -242,8 +243,7 @@ expr: NUMBER
                = {
                        $$ = -$2;
                } */
-               | '(' expr ')'
-               = {
+               | '(' expr ')' {
                        $$ = $2;
                }
                ;
@@ -263,12 +263,18 @@ generalnumeric: NUMERIC '=' NUMBER ';'
 {
   if (localConf.numeric == 0)
     localConf.numeric = yylval.num;
+  else
+    parse_error("Redefinition of server numeric %i (%i)",yylval.num,
+               localConf.numeric);
 };
 
 generalname: NAME '=' QSTRING ';'
 {
   if (localConf.name == NULL)
     DupString(localConf.name, yylval.text);
+  else
+    parse_error("Redefinition of server name %s (%s)",yylval.text,
+               localConf.name);
 };
 
 generaldesc: DESCRIPTION '=' QSTRING ';'
@@ -323,6 +329,9 @@ classblock: CLASS {
   {
    add_class(name, tping, tconn, maxlinks, sendq);
   }
+  else {
+   parse_error("Missing name in class block");
+  }
 } ';';
 classitems: classitem classitems | classitem;
 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
@@ -352,11 +361,11 @@ classsendq: SENDQ '=' sizespec ';'
 connectblock: CONNECT
 {
  name = pass = host = NULL;
- class = NULL;
+ c_class = NULL;
  port = 0;
 } '{' connectitems '}'
 {
- if (name != NULL && pass != NULL && host != NULL && class != NULL && 
+ if (name != NULL && pass != NULL && host != NULL && c_class != NULL && 
      /*ccount < MAXCONFLINKS &&*/ !strchr(host, '*') &&
      !strchr(host, '?'))
  {
@@ -364,7 +373,7 @@ connectblock: CONNECT
    aconf->status = CONF_SERVER;
    aconf->name = name;
    aconf->passwd = pass;
-   aconf->conn_class = class;
+   aconf->conn_class = c_class;
    aconf->port = port;
    aconf->status = CONF_SERVER;
    aconf->host = host;
@@ -379,6 +388,7 @@ connectblock: CONNECT
    MyFree(pass);
    MyFree(host);
    name = pass = host = NULL;
+   parse_error("Bad connect block");
  }
 }';';
 connectitems: connectitem connectitems | connectitem;
@@ -396,7 +406,7 @@ connectpass: PASS '=' QSTRING ';'
 };
 connectclass: CLASS '=' QSTRING ';'
 {
- class = find_class(yylval.text);
+ c_class = find_class(yylval.text);
 };
 connecthost: HOST '=' QSTRING ';'
 {
@@ -410,7 +420,7 @@ connectport: PORT '=' NUMBER ';'
 
 serverblock: SERVER
 {
- aconf = MyMalloc(sizeof(*aconf));
+ aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
  memset(aconf, 0, sizeof(*aconf));
 } '{' serveritems '}'
 {
@@ -420,6 +430,7 @@ serverblock: SERVER
    MyFree(aconf->name);
    MyFree(aconf);
    aconf = NULL;
+   parse_error("Bad server block");
  }
  else
  {
@@ -455,6 +466,8 @@ serverleaf: LEAF '=' YES ';'
 {
  if (!(aconf->status & CONF_HUB && aconf->status & CONF_UWORLD))
   aconf->status |= CONF_LEAF;
+ else
+  parse_error("Server is both leaf and a hub");
 }
 | LEAF '=' NO ';'
 {
@@ -472,7 +485,7 @@ serveruworld: UWORLD '=' YES ';'
 
 operblock: OPER
 {
-  aconf = MyMalloc(sizeof(*aconf));
+  aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
   memset(aconf, 0, sizeof(*aconf));
   aconf->status = CONF_OPERATOR;
 } '{' operitems '}' ';'
@@ -524,7 +537,7 @@ operhost: HOST '=' QSTRING ';'
  if (!strchr(yylval.text, '@'))
  {
    int uh_len;
-   char *b = MyMalloc((uh_len = strlen(yylval.text)+3));
+   char *b = (char*) MyMalloc((uh_len = strlen(yylval.text)+3));
    ircd_snprintf(0, b, uh_len, "*@%s", yylval.text);
    aconf->host = b;
  }
@@ -601,6 +614,7 @@ portblock: PORT {
   {
     MyFree(host);
     MyFree(pass);
+    parse_error("Bad port block");
   }
 };
 portitems: portitem portitems | portitem;
@@ -640,7 +654,7 @@ porthidden: HIDDEN '=' YES ';'
 
 clientblock: CLIENT
 {
-  aconf = MyMalloc(sizeof(*aconf));
+  aconf = (struct ConfItem*) MyMalloc(sizeof(*aconf));
   memset(aconf, 0, sizeof(*aconf));
   aconf->status = CONF_CLIENT;
 } '{' clientitems '}'
@@ -663,6 +677,7 @@ clientblock: CLIENT
    MyFree(aconf->passwd);
    MyFree(aconf);
    aconf = NULL;
+   parse_error("Bad client block");
   }
 } ';';
 clientitems: clientitem clientitems | clientitem;
@@ -692,7 +707,7 @@ clientpass: PASS '=' QSTRING ';'
 
 killblock: KILL
 {
-  dconf = MyMalloc(sizeof(*dconf));
+  dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
   memset(dconf, 0, sizeof(*dconf));
 } '{' killitems '}'
 {
@@ -710,6 +725,7 @@ killblock: KILL
     MyFree(dconf->message);
     MyFree(dconf);
     dconf = NULL;
+    parse_error("Bad kill block");
   }
 } ';';
 killitems: killitem killitems | killitem;
@@ -785,7 +801,7 @@ cruleblock: CRULE
   struct CRuleNode *node;
   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
   {
-    struct CRuleConf *p = MyMalloc(sizeof(*p));
+    struct CRuleConf *p = (struct CRuleConf*) MyMalloc(sizeof(*p));
     p->hostmask = host;
     p->rule = pass;
     p->type = tconn;
@@ -797,6 +813,7 @@ cruleblock: CRULE
   {
     MyFree(host);
     MyFree(pass);
+    parse_error("Bad CRule block");
   }
 } ';';
 
@@ -875,7 +892,7 @@ extrastring: QSTRING
 quarantineblock: QUARANTINE '{'
 {
   if (qconf != NULL)
-    qconf = MyMalloc(sizeof(*qconf));
+    qconf = (struct qline*) MyMalloc(sizeof(*qconf));
   else
   {
     if (qconf->chname != NULL)
@@ -890,7 +907,7 @@ quarantineblock: QUARANTINE '{'
   {
     log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
               "and a reason.");
-    return;
+    return 0;
   }
   qconf->next = GlobalQuarantineList;
   GlobalQuarantineList = qconf;