Author: Perry Lorier <isomer@undernet.org>
[ircu2.10.12-pk.git] / ircd / ircd_parser.y
index 6b6469dd2401cb5c1a5a07bf59d18e4c0cea144f..c2205973e3a93ecdec258621162410f8faa2350b 100644 (file)
@@ -69,7 +69,7 @@
   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;
@@ -108,6 +108,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 +149,6 @@ static void parse_error(char *pattern,...) {
 %token TFILE
 %token RULE
 %token ALL
-%token IP
 %token FEATURES
 %token QUARANTINE
 %token PSEUDO
@@ -298,7 +299,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 '}'
@@ -462,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
  {
@@ -493,7 +500,7 @@ operblock: OPER '{' operitems '}' ';'
     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));
@@ -503,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);
@@ -643,35 +650,61 @@ clientblock: CLIENT
 }
 '{' clientitems '}' ';'
 {
-  if (host && name)
-  {
+  struct irc_in_addr addr;
+  unsigned char 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;
-    aconf->name = name;
+    memcpy(&aconf->address.addr, &addr, sizeof(aconf->address.addr));
+    aconf->addrbits = addrbits;
+    aconf->name = ip;
     aconf->conn_class = c_class ? c_class : find_class("default");
     aconf->maximum = maxlinks;
   }
-  else
-  {
-    MyFree(host);
-    MyFree(name);
-    parse_error("Bad client block");
-  }
-  host = name = NULL;
+  host = NULL;
+  username = NULL;
   c_class = NULL;
+  ip = 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 ';'
 {
@@ -742,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);
 };
@@ -777,6 +810,7 @@ cruleblock: CRULE
     parse_error("Bad CRule block");
   }
   host = pass = NULL;
+  tconn = 0;
 };
 
 cruleitems: cruleitem cruleitems | cruleitem;
@@ -856,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;
@@ -882,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))
@@ -937,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;