Fix bugs spotted in beta testing: Quarantine blocks not working or
[ircu2.10.12-pk.git] / ircd / ircd_parser.y
index c042702d51ea73a96573a3236fc62f38fb9542c1..4d0692c9dba392cc624eebe8954b678cccc57d61 100644 (file)
   int yylex(void);
   /* Now all the globals we need :/... */
   int tping, tconn, maxlinks, sendq, port, invert, stringno;
-  char *name, *pass, *host, *origin, *hub_limit;
+  char *name, *pass, *host, *ip, *username, *origin, *hub_limit;
   char *stringlist[MAX_STRINGS];
   struct ConnectionClass *c_class;
   struct DenyConf *dconf;
   struct ServerConf *sconf;
-  struct qline *qconf = NULL;
   struct s_map *smap;
   struct Privs privs;
   struct Privs privs_dirty;
@@ -108,6 +107,8 @@ static void parse_error(char *pattern,...) {
 %token SENDQ
 %token NAME
 %token HOST
+%token IP
+%token USERNAME
 %token PASS
 %token LOCAL
 %token SECONDS
@@ -147,7 +148,6 @@ static void parse_error(char *pattern,...) {
 %token TFILE
 %token RULE
 %token ALL
-%token IP
 %token FEATURES
 %token QUARANTINE
 %token PSEUDO
@@ -155,14 +155,15 @@ static void parse_error(char *pattern,...) {
 %token USERMODE
 %token IAUTH
 %token TIMEOUT
-/* and now a lot of priviledges... */
+%token FAST
+/* and now a lot of privileges... */
 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
 %token TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
 %token TPRIV_GLINE TPRIV_LOCAL_GLINE TPRIV_LOCAL_JUPE TPRIV_LOCAL_BADCHAN
 %token TPRIV_LOCAL_OPMODE TPRIV_OPMODE TPRIV_SET TPRIV_WHOX TPRIV_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_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE
+%token TPRIV_FORCE_OPMODE TPRIV_FORCE_LOCAL_OPMODE TPRIV_APASS_OPMODE
 /* and some types... */
 %type <num> sizespec
 %type <num> timespec timefactor factoredtimes factoredtime
@@ -227,7 +228,7 @@ sizespec:   expr    {
                }
                ;
 
-/* this is an arithmatic expression */
+/* this is an arithmetic expression */
 expr: NUMBER
                { 
                        $$ = $1;
@@ -245,8 +246,7 @@ expr: NUMBER
                        $$ = $1 / $3;
                }
 /* leave this out until we find why it makes BSD yacc dump core -larne
-               | '-' expr  %prec NEG
-               = {
+               | '-' expr  %prec NEG {
                        $$ = -$2;
                } */
                | '(' expr ')' {
@@ -298,7 +298,13 @@ generaldesc: DESCRIPTION '=' QSTRING ';'
 
 generalvhost: VHOST '=' QSTRING ';'
 {
-  ircd_aton(&VirtualHost.addr, $3);
+  struct irc_in_addr addr;
+  if (!ircd_aton(&addr, $3))
+      parse_error("Invalid virtual host '%s'.", $3);
+  else if (irc_in_addr_is_ipv4(&addr))
+    memcpy(&VirtualHost_v4.addr, &addr, sizeof(addr));
+  else
+    memcpy(&VirtualHost_v6.addr, &addr, sizeof(addr));
 };
 
 adminblock: ADMIN '{' adminitems '}'
@@ -328,14 +334,7 @@ admincontact: CONTACT '=' QSTRING ';'
 };
 
 classblock: CLASS {
-  name = NULL;
   tping = 90;
-  tconn = 0;
-  maxlinks = 0;
-  sendq = 0;
-  pass = NULL;
-  memset(&privs, 0, sizeof(privs));
-  memset(&privs_dirty, 0, sizeof(privs_dirty));
 } '{' classitems '}'
 {
   if (name != NULL)
@@ -350,7 +349,13 @@ classblock: CLASS {
   else {
    parse_error("Missing name in class block");
   }
+  name = NULL;
   pass = NULL;
+  tconn = 0;
+  maxlinks = 0;
+  sendq = 0;
+  memset(&privs, 0, sizeof(privs));
+  memset(&privs_dirty, 0, sizeof(privs_dirty));
 } ';';
 classitems: classitem classitems | classitem;
 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
@@ -378,16 +383,12 @@ classsendq: SENDQ '=' sizespec ';'
 };
 classusermode: USERMODE '=' QSTRING ';'
 {
-  if (pass)
-    MyFree(pass);
+  MyFree(pass);
   DupString(pass, $3);
 };
 
 connectblock: CONNECT
 {
- name = pass = host = origin = hub_limit = NULL;
- c_class = NULL;
- port = 0;
  maxlinks = 65535;
 } '{' connectitems '}'
 {
@@ -414,6 +415,9 @@ connectblock: CONNECT
    MyFree(hub_limit);
    parse_error("Bad connect block");
  }
+ name = pass = host = origin = hub_limit = NULL;
+ c_class = NULL;
+ port = 0;
 }';';
 connectitems: connectitem connectitems | connectitem;
 connectitem: connectname | connectpass | connectclass | connecthost
@@ -464,20 +468,21 @@ connecthublimit: HUB '=' QSTRING ';'
 connectmaxhops: MAXHOPS '=' expr ';'
 {
   maxlinks = $3;
-}
+};
 
 uworldblock: UWORLD '{' uworlditems '}' ';'
 {
  if (name)
  {
   struct ConfItem *aconf = make_conf(CONF_UWORLD);
-  aconf->name = name;
+  aconf->host = name;
  }
  else
  {
   MyFree(name);
   parse_error("Bad UWorld block");
  }
+ name = NULL;
 };
 uworlditems: uworlditem uworlditems | uworlditem;
 uworlditem: uworldname | error;
@@ -487,20 +492,14 @@ uworldname: NAME '=' QSTRING ';'
  DupString(name, $3);
 };
 
-operblock: OPER
-{
-  name = pass = host = NULL;
-  c_class = NULL;
-  memset(&privs, 0, sizeof(privs));
-  memset(&privs_dirty, 0, sizeof(privs_dirty));
-} '{' operitems '}' ';'
+operblock: OPER '{' operitems '}' ';'
 {
   if (name && pass && host && c_class)
   {
     struct ConfItem *aconf = make_conf(CONF_OPERATOR);
     aconf->name = name;
     aconf->passwd = pass;
-    aconf->host = host;
+    conf_parse_userhost(aconf, host);
     aconf->conn_class = c_class;
     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
@@ -510,11 +509,15 @@ operblock: OPER
   }
   else
   {
-    log_write(LS_CONFIG, L_ERROR, 0, "operator blocks need a name, password, and host.");
+    parse_error("operator blocks need a name, password, class and host.");
     MyFree(name);
     MyFree(pass);
     MyFree(host);
   }
+  name = pass = host = NULL;
+  c_class = NULL;
+  memset(&privs, 0, sizeof(privs));
+  memset(&privs_dirty, 0, sizeof(privs_dirty));
 };
 operitems: operitem | operitems operitem;
 operitem: opername | operpass | operhost | operclass | priv | error;
@@ -574,7 +577,7 @@ privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
           TPRIV_SET { $$ = PRIV_SET; } |
           TPRIV_WHOX { $$ = PRIV_WHOX; } |
           TPRIV_BADCHAN { $$ = PRIV_BADCHAN; } |
-          TPRIV_LOCAL_BADCHAN { $$ = TPRIV_LOCAL_BADCHAN; } |
+          TPRIV_LOCAL_BADCHAN { $$ = PRIV_LOCAL_BADCHAN; } |
           TPRIV_SEE_CHAN { $$ = PRIV_SEE_CHAN; } |
           TPRIV_SHOW_INVIS { $$ = PRIV_SHOW_INVIS; } |
           TPRIV_SHOW_ALL_INVIS { $$ = PRIV_SHOW_ALL_INVIS; } |
@@ -585,20 +588,13 @@ privtype: TPRIV_CHAN_LIMIT { $$ = PRIV_CHAN_LIMIT; } |
           TPRIV_WIDE_GLINE { $$ = PRIV_WIDE_GLINE; } |
           LOCAL { $$ = PRIV_PROPAGATE; invert = 1; } |
           TPRIV_FORCE_OPMODE { $$ = PRIV_FORCE_OPMODE; } |
-          TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; };
+          TPRIV_FORCE_LOCAL_OPMODE { $$ = PRIV_FORCE_LOCAL_OPMODE; } |
+          TPRIV_APASS_OPMODE { $$ = PRIV_APASS_OPMODE; } ;
 
 yesorno: YES { $$ = 1; } | NO { $$ = 0; };
 
 /* The port block... */
-portblock: PORT {
-  port = 0;
-  host = NULL;
-  /* Hijack these for is_server, is_hidden to cut down on globals... */
-  tconn = 0;
-  tping = 0;
-  /* and this for mask... */
-  pass = NULL;
-} '{' portitems '}' ';'
+portblock: PORT '{' portitems '}' ';'
 {
   if (port > 0 && port <= 0xFFFF)
   {
@@ -611,6 +607,7 @@ portblock: PORT {
   MyFree(host);
   MyFree(pass);
   host = pass = NULL;
+  port = tconn = tping = 0;
 };
 portitems: portitem portitems | portitem;
 portitem: portnumber | portvhost | portmask | portserver | porthidden | error;
@@ -649,39 +646,71 @@ porthidden: HIDDEN '=' YES ';'
 
 clientblock: CLIENT
 {
-  host = name = NULL;
-  c_class = NULL;
   maxlinks = 65535;
 }
 '{' clientitems '}' ';'
 {
-  if (host && name)
-  {
+  struct irc_in_addr addr;
+  unsigned char addrbits = 0;
+
+  if (ip && !ipmask_parse(ip, &addr, &addrbits)) {
+    parse_error("Invalid IP address in block");
+    MyFree(username);
+    MyFree(host);
+    MyFree(ip);
+    MyFree(pass);
+  } else {
     struct ConfItem *aconf = make_conf(CONF_CLIENT);
+    aconf->username = username;
     aconf->host = host;
-    aconf->name = name;
+    if (ip)
+      memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
+    else
+      memset(&aconf->address.addr, 0, sizeof(aconf->address.addr));
+    aconf->addrbits = addrbits;
+    aconf->name = ip;
     aconf->conn_class = c_class ? c_class : find_class("default");
     aconf->maximum = maxlinks;
+    aconf->passwd = pass;
   }
-  else
-  {
-    MyFree(host);
-    MyFree(name);
-    parse_error("Bad client block");
-  }
+  host = NULL;
+  username = NULL;
+  c_class = NULL;
+  ip = NULL;
+  pass = NULL;
 };
 clientitems: clientitem clientitems | clientitem;
-clientitem: clienthost | clientclass | clientpass | clientip
-  | clientmaxlinks | error;
-clientip: IP '=' QSTRING ';'
+clientitem: clienthost | clientip | clientusername | clientclass | clientpass | clientmaxlinks | error;
+clienthost: HOST '=' QSTRING ';'
 {
+  char *sep = strchr($3, '@');
   MyFree(host);
-  DupString(host, $3);
+  if (sep) {
+    *sep++ = '\0';
+    MyFree(username);
+    DupString(username, $3);
+    DupString(host, sep);
+  } else {
+    DupString(host, $3);
+  }
 };
-clienthost: HOST '=' QSTRING ';'
+clientip: IP '=' QSTRING ';'
 {
-  MyFree(name);
-  DupString(name, $3);
+  char *sep = strchr($3, '@');
+  MyFree(ip);
+  if (sep) {
+    *sep++ = '\0';
+    MyFree(username);
+    DupString(username, $3);
+    DupString(ip, sep);
+  } else {
+    DupString(ip, $3);
+  }
+};
+clientusername: USERNAME '=' QSTRING ';'
+{
+  MyFree(username);
+  DupString(username, $3);
 };
 clientclass: CLASS '=' QSTRING ';'
 {
@@ -699,8 +728,7 @@ clientmaxlinks: MAXLINKS '=' expr ';'
 
 killblock: KILL
 {
-  dconf = (struct DenyConf*) MyMalloc(sizeof(*dconf));
-  memset(dconf, 0, sizeof(*dconf));
+  dconf = (struct DenyConf*) MyCalloc(1, sizeof(*dconf));
 } '{' killitems '}'
 {
   if (dconf->hostmask != NULL)
@@ -709,16 +737,15 @@ killblock: KILL
       DupString(dconf->usermask, "*");
     dconf->next = denyConfList;
     denyConfList = dconf;
-    dconf = NULL;
   }
   else
   {
     MyFree(dconf->hostmask);
     MyFree(dconf->message);
     MyFree(dconf);
-    dconf = NULL;
     parse_error("Bad kill block");
   }
+  dconf = NULL;
 } ';';
 killitems: killitem killitems | killitem;
 killitem: killuhost | killreal | killreasonfile | killreason | error;
@@ -736,7 +763,7 @@ killuhost: HOST '=' QSTRING ';'
   else
   {
     u = $3;
-    h++;
+    *h++ = '\0';
   }
   DupString(dconf->hostmask, h);
   DupString(dconf->usermask, u);
@@ -754,7 +781,7 @@ killreal: REAL '=' QSTRING ';'
 
 killreason: REASON '=' QSTRING ';'
 {
- dconf->flags &= DENY_FLAGS_FILE;
+ dconf->flags &= ~DENY_FLAGS_FILE;
  MyFree(dconf->message);
  DupString(dconf->message, $3);
 };
@@ -768,9 +795,8 @@ killreasonfile: TFILE '=' QSTRING ';'
 
 cruleblock: CRULE
 {
-  host = pass = NULL;
   tconn = CRULE_AUTO;
-} '{' cruleitems '}'
+} '{' cruleitems '}' ';'
 {
   struct CRuleNode *node;
   if (host != NULL && pass != NULL && (node=crule_parse(pass)) != NULL)
@@ -789,7 +815,9 @@ cruleblock: CRULE
     MyFree(pass);
     parse_error("Bad CRule block");
   }
-} ';';
+  host = pass = NULL;
+  tconn = 0;
+};
 
 cruleitems: cruleitem cruleitems | cruleitem;
 cruleitem: cruleserver | crulerule | cruleall | error;
@@ -815,16 +843,14 @@ cruleall: ALL '=' YES ';'
  tconn = CRULE_AUTO;
 };
 
-motdblock: MOTD {
- pass = host = NULL;
-} '{' motditems '}'
+motdblock: MOTD '{' motditems '}' ';'
 {
   if (host != NULL && pass != NULL)
     motd_add(host, pass);
   MyFree(host);
   MyFree(pass);
   host = pass = NULL;
-} ';';
+};
 
 motditems: motditem motditems | motditem;
 motditem: motdhost | motdfile | error;
@@ -863,37 +889,15 @@ extrastring: QSTRING
     stringlist[stringno++] = $1;
 };
 
-quarantineblock: QUARANTINE '{'
+quarantineblock: QUARANTINE '{' quarantineitems '}' ';';
+quarantineitems: quarantineitems quarantineitem | quarantineitem;
+quarantineitem: QSTRING '=' QSTRING ';'
 {
-  if (qconf != NULL)
-    qconf = (struct qline*) MyMalloc(sizeof(*qconf));
-  else
-  {
-    if (qconf->chname != NULL)
-      MyFree(qconf->chname);
-    if (qconf->reason != NULL)
-      MyFree(qconf->reason);
-  }
-  memset(qconf, 0, sizeof(*qconf));
-} quarantineitems '}' ';'
-{
-  if (qconf->chname == NULL || qconf->reason == NULL)
-  {
-    log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
-              "and a reason.");
-    return 0;
-  }
+  struct qline *qconf = MyCalloc(1, sizeof(*qconf));
+  DupString(qconf->chname, $1);
+  DupString(qconf->reason, $3);
   qconf->next = GlobalQuarantineList;
   GlobalQuarantineList = qconf;
-  qconf = NULL;
-};
-
-quarantineitems: CHANNEL NAME '=' QSTRING ';'
-{
-  DupString(qconf->chname, $4);
-} | REASON '=' QSTRING ';'
-{
-  DupString(qconf->reason, $3);
 };
 
 pseudoblock: PSEUDO QSTRING '{'
@@ -905,7 +909,7 @@ pseudoitems '}' ';'
 {
   if (!smap->name || !smap->services)
   {
-    log_write(LS_CONFIG, L_ERROR, 0, "pseudo commands need a service name and list of target nicks.");
+    parse_error("pseudo commands need a service name and list of target nicks.");
     return 0;
   }
   if (register_mapping(smap))
@@ -930,7 +934,7 @@ pseudoitems '}' ';'
 };
 
 pseudoitems: pseudoitem pseudoitems | pseudoitem;
-pseudoitem: pseudoname | pseudoprepend | pseudonick | error;
+pseudoitem: pseudoname | pseudoprepend | pseudonick | pseudoflags | error;
 pseudoname: NAME '=' QSTRING ';'
 {
   DupString(smap->name, $3);
@@ -952,23 +956,26 @@ pseudonick: NICK '=' QSTRING ';'
     smap->services = nh;
   }
 };
+pseudoflags: FAST ';'
+{
+  smap->flags |= SMAP_FAST;
+};
 
 iauthblock: IAUTH '{'
 {
-  pass = host = NULL;
-  port = 0;
   tconn = 60;
   tping = 60;
 } iauthitems '}' ';'
 {
   if (!host || !port) {
-    log_write(LS_CONFIG, L_ERROR, 0, "IAuth block needs a server name and port.");
+    parse_error("IAuth block needs a server name and port.");
     return 0;
   }
   iauth_connect(host, port, pass, tconn, tping);
   MyFree(pass);
   MyFree(host);
   pass = host = NULL;
+  port = tconn = tping = 0;
 };
 
 iauthitems: iauthitem iauthitems | iauthitem;