Author: Perry Lorier <isomer@undernet.org>
[ircu2.10.12-pk.git] / ircd / ircd_parser.y
index 920cf473db9f94b0ba6c889a90e9c7eb91527198..c2205973e3a93ecdec258621162410f8faa2350b 100644 (file)
@@ -65,7 +65,6 @@
   extern struct ServerConf* serverConfList;
   extern struct s_map*      GlobalServiceMapList;
   extern struct qline*      GlobalQuarantineList;
-  extern struct irc_sockaddr ResolverAddr;
 
   int yylex(void);
   /* Now all the globals we need :/... */
@@ -136,7 +135,6 @@ static void parse_error(char *pattern,...) {
 %token NO
 %token OPER
 %token VHOST
-%token RESOLVER
 %token HIDDEN
 %token MOTD
 %token JUPE
@@ -273,7 +271,7 @@ generalblock: GENERAL '{' generalitems '}'
     parse_error("Your General block must contain a numeric (between 1 and 4095).");
 } ';' ;
 generalitems: generalitem generalitems | generalitem;
-generalitem: generalnumeric | generalname | generalvhost | generalresolver | generaldesc | error;
+generalitem: generalnumeric | generalname | generalvhost | generaldesc | error;
 generalnumeric: NUMERIC '=' NUMBER ';'
 {
   if (localConf.numeric == 0)
@@ -301,12 +299,13 @@ generaldesc: DESCRIPTION '=' QSTRING ';'
 
 generalvhost: VHOST '=' QSTRING ';'
 {
-  ircd_aton(&VirtualHost.addr, $3);
-};
-
-generalresolver: RESOLVER '=' QSTRING ';'
-{
-  ircd_aton(&ResolverAddr.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 '}'
@@ -470,14 +469,14 @@ 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
  {
@@ -511,7 +510,7 @@ operblock: OPER '{' operitems '}' ';'
   }
   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);
@@ -651,38 +650,62 @@ clientblock: CLIENT
 }
 '{' clientitems '}' ';'
 {
-  struct ConfItem *aconf = make_conf(CONF_CLIENT);
+  struct irc_in_addr addr;
   unsigned char addrbits;
-  aconf->username = username;
-  aconf->host = host;
-  if (ip && ipmask_parse(ip, &aconf->address.addr, &addrbits))
+
+  if (ip && !ipmask_parse(ip, &addr, &addrbits)) {
+    parse_error("Invalid IP address in block");
+    MyFree(username);
+    MyFree(host);
+    MyFree(ip);
+  } else {
+    struct ConfItem *aconf = make_conf(CONF_CLIENT);
+    aconf->username = username;
+    aconf->host = host;
+    memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
     aconf->addrbits = addrbits;
-  else
-    aconf->addrbits = -1;
-  aconf->conn_class = c_class ? c_class : find_class("default");
-  aconf->maximum = maxlinks;
+    aconf->name = ip;
+    aconf->conn_class = c_class ? c_class : find_class("default");
+    aconf->maximum = maxlinks;
+  }
   host = NULL;
   username = NULL;
   c_class = NULL;
-  MyFree(ip);
+  ip = NULL;
 };
 clientitems: clientitem clientitems | clientitem;
 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);
+  }
 };
 clientip: IP '=' QSTRING ';'
 {
+  char *sep = strchr($3, '@');
   MyFree(ip);
-  DupString(ip, $3);
-}
+  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 ';'
 {
   c_class = find_class($3);
@@ -752,7 +775,7 @@ killreal: REAL '=' QSTRING ';'
 
 killreason: REASON '=' QSTRING ';'
 {
- dconf->flags &= DENY_FLAGS_FILE;
+ dconf->flags &= ~DENY_FLAGS_FILE;
  MyFree(dconf->message);
  DupString(dconf->message, $3);
 };
@@ -787,6 +810,7 @@ cruleblock: CRULE
     parse_error("Bad CRule block");
   }
   host = pass = NULL;
+  tconn = 0;
 };
 
 cruleitems: cruleitem cruleitems | cruleitem;
@@ -866,8 +890,7 @@ quarantineblock: QUARANTINE '{'
 {
   if (qconf->chname == NULL || qconf->reason == NULL)
   {
-    log_write(LS_CONFIG, L_ERROR, 0, "quarantine blocks need a channel name "
-              "and a reason.");
+    parse_error("quarantine blocks need a channel name and a reason.");
     return 0;
   }
   qconf->next = GlobalQuarantineList;
@@ -892,7 +915,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))
@@ -947,14 +970,14 @@ iauthblock: IAUTH '{'
 } 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 = 0;
+  port = tconn = tping = 0;
 };
 
 iauthitems: iauthitem iauthitems | iauthitem;