Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2007-03-18 03:26:41 UTC

Modified files:
     ircd/s_conf.c ircd/listener.c ircd/list.c ircd/ircd_parser.y
     doc/example.conf ChangeLog

Log message:

Merge u2_10_12_branch support for multiple hosts in config blocks
(plus related bug fixes).

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.841 ircu2.10/ChangeLog:1.842
--- ircu2.10/ChangeLog:1.841    Sat Mar 17 14:33:37 2007
+++ ircu2.10/ChangeLog  Sat Mar 17 20:26:30 2007
@@ -1,3 +1,46 @@
+2007-03-17  Michael Poole <[EMAIL PROTECTED]>
+
+       * doc/example.conf (Port): Document the optional additional field
+       for vhost entries.  Document the support for multiple vhost
+       entries in a single Port block.
+
+       * ircd/ircd_parser.y (USE_IPV4): Shift up by 16 bytes.
+       (USE_IPV6): Likewise.
+       (portblock): Iterate over hosts rather than using the single host.
+       (portitem): Add portvhostnumber alternative production.
+       (portnumber): Check port number here.  If valid, combine address
+       family and port number in "port" variable.  If a port-less item
+       exists in "hosts", set its port number.
+       (portvhost): Prepend mask to "hosts" list.
+       (portvhostnumber): New production.
+
+2007-03-17  Michael Poole <[EMAIL PROTECTED]>
+
+       * ircd/listener.c (add_listener): Only try to create IPv6 sockets
+       for IPv6-compatible addresses; likewise for IPv4.
+
+2007-03-17  Michael Poole <[EMAIL PROTECTED]>
+
+       * doc/example.conf (Operator): Update documentation to mention
+       more than one host entry is allowed.
+       (Motd): Likewise.
+
+       * ircd/ircd_parser.y (hosts): New file-scope variable.
+       (free_slist): New helper function.
+       (operblock): Iterate over hosts instead of using the single host.
+       (operhost): Prepend the mask to hosts.
+       (motdblock): Iterate over hosts instead of using the single host.
+       (motdhost): Prepend the mask to hosts.
+       (motdfile): Fix possible leak of "pass" string (the filename).
+
+       * ircd/s_conf.c (conf_parse_userhost): Stop freeing the host
+       string; operblock (the only caller) frees it now.
+
+2007-03-17  Michael Poole <[EMAIL PROTECTED]>
+
+       * ircd/list.c (free_link): Only decrement the in-use count of
+       links if we free a link.
+
 2007-03-16  Michael Poole <[EMAIL PROTECTED]>
 
        * doc/example.conf (Class): Move the "Recommended client classes"
Index: ircu2.10/doc/example.conf
diff -u ircu2.10/doc/example.conf:1.80 ircu2.10/doc/example.conf:1.81
--- ircu2.10/doc/example.conf:1.80      Sat Mar 17 14:33:37 2007
+++ ircu2.10/doc/example.conf   Sat Mar 17 20:26:30 2007
@@ -370,6 +370,10 @@
 #  file = "path/to/motd/file";
 # };
 #
+# More than one host = "mask"; entry may be present in one block; this
+# has the same effect as one Motd block for each host entry, but makes
+# it easier to update the messages's filename.
+#
 # DPATH/net_com.motd contains a special MOTD where users are encouraged
 # to register their domains and get their own client{} lines if they're in
 # Europe, or move to US.UnderNet.org if they're in the USA.
@@ -593,6 +597,11 @@
 # is not not passed along to other servers. On Undernet, this prevents
 # them from using Uworld as well.
 #
+# More than one host = "mask"; entry may be present in one block; this
+# has the same effect as one Operator block for each host entry, but
+# makes it easier to update operator nicks, passwords, classes, and
+# privileges.
+#
 # Operator {
 #  host = "host/IP mask";
 #  name = "opername";
@@ -649,11 +658,14 @@
 # IANA says we should use port 194, but that requires us to run as root,
 # so we don't do that.
 #
+#
 # Port {
 #  port = [ipv4] [ipv6] number;
 #  mask = "ipmask";
 #  # Use this to control the interface you bind to.
 #  vhost = [ipv4] [ipv6] "virtualhostip";
+#  # You can specify both virtual host and port number in one entry.
+#  vhost = [ipv4] [ipv6] "virtualhostip" number;
 #  # Setting to yes makes this server only.
 #  server = yes;
 #  # Setting to yes makes the port "hidden" from stats.
@@ -706,6 +718,14 @@
  port = 7000;
 };
 
+# More than one vhost may be present in a single Port block; in this case,
+# we recommend listing the port number on the vhost line for clarity.
+Port {
+ vhost = "172.16.0.1" 6667;
+ vhost = "172.16.3.1" 6668;
+ hidden = no;
+};
+
 # Quarantine blocks disallow operators from using OPMODE and CLEARMODE
 # on certain channels.  Opers with the force_opmode (for local
 # channels, force_local_opmode) privilege may override the quarantine
Index: ircu2.10/ircd/ircd_parser.y
diff -u ircu2.10/ircd/ircd_parser.y:1.72 ircu2.10/ircd/ircd_parser.y:1.73
--- ircu2.10/ircd/ircd_parser.y:1.72    Sun Feb 25 08:12:45 2007
+++ ircu2.10/ircd/ircd_parser.y Sat Mar 17 20:26:30 2007
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
- * $Id: ircd_parser.y,v 1.72 2007/02/25 16:12:45 entrope Exp $
+ * $Id: ircd_parser.y,v 1.73 2007/03/18 03:26:30 entrope Exp $
  */
 %{
 
@@ -59,8 +59,8 @@
 #include <arpa/inet.h>
 
 #define MAX_STRINGS 80 /* Maximum number of feature params. */
-#define USE_IPV4 (1 << 0)
-#define USE_IPV6 (1 << 1)
+#define USE_IPV4 (1 << 16)
+#define USE_IPV6 (1 << 17)
 
   extern struct LocalConf   localConf;
   extern struct DenyConf*   denyConfList;
@@ -75,6 +75,7 @@
   /* Now all the globals we need :/... */
   static int tping, tconn, maxlinks, sendq, port, invert, stringno, flags;
   static char *name, *pass, *host, *ip, *username, *origin, *hub_limit;
+  struct SLink *hosts;
   static char *stringlist[MAX_STRINGS];
   struct ListenerFlags listen_flags;
   static struct ConnectionClass *c_class;
@@ -140,6 +141,16 @@
   return 0;
 }
 
+static void free_slist(struct SLink **link) {
+  struct SLink *next;
+  while (*link != NULL) {
+    next = (*link)->next;
+    MyFree((*link)->value.cp);
+    free_link(*link);
+    *link = next;
+  }
+}
+
 %}
 
 %token <text> QSTRING
@@ -663,6 +674,8 @@
 operblock: OPER '{' operitems '}' ';'
 {
   struct ConfItem *aconf = NULL;
+  struct SLink *link;
+
   if (!permitted(BLOCK_OPER, 1))
     ;
   else if (name == NULL)
@@ -670,28 +683,26 @@
   else if (pass == NULL)
     parse_error("Missing password in operator block");
   /* Do not check password length because it may be crypted. */
-  else if (host == NULL)
-    parse_error("Missing host in operator block");
+  else if (hosts == NULL)
+    parse_error("Missing host(s) in operator block");
   else if (c_class == NULL)
     parse_error("Invalid or missing class in operator block");
   else if (!FlagHas(&privs_dirty, PRIV_PROPAGATE)
            && !FlagHas(&c_class->privs_dirty, PRIV_PROPAGATE))
     parse_error("Operator block for %s and class %s have no LOCAL setting", 
name, c_class->cc_name);
-  else {
+  else for (link = hosts; link != NULL; link = link->next) {
     aconf = make_conf(CONF_OPERATOR);
-    aconf->name = name;
-    aconf->passwd = pass;
-    conf_parse_userhost(aconf, host);
+    DupString(aconf->name, name);
+    DupString(aconf->passwd, pass);
+    conf_parse_userhost(aconf, link->value.cp);
     aconf->conn_class = c_class;
     memcpy(&aconf->privs, &privs, sizeof(aconf->privs));
     memcpy(&aconf->privs_dirty, &privs_dirty, sizeof(aconf->privs_dirty));
   }
-  if (!aconf) {
-    MyFree(name);
-    MyFree(pass);
-    MyFree(host);
-  }
-  name = pass = host = NULL;
+  MyFree(name);
+  MyFree(pass);
+  free_slist(&hosts);
+  name = pass = NULL;
   c_class = NULL;
   memset(&privs, 0, sizeof(privs));
   memset(&privs_dirty, 0, sizeof(privs_dirty));
@@ -710,16 +721,19 @@
 };
 operhost: HOST '=' QSTRING ';'
 {
- MyFree(host);
+ struct SLink *link;
+ link = make_link();
  if (!strchr($3, '@'))
  {
    int uh_len;
-   host = (char*) MyMalloc((uh_len = strlen($3)+3));
-   ircd_snprintf(0, host, uh_len, "[EMAIL PROTECTED]", $3);
-   MyFree($3);
+   link->value.cp = (char*) MyMalloc((uh_len = strlen($3)+3));
+   ircd_snprintf(0, link->value.cp, uh_len, "[EMAIL PROTECTED]", $3);
  }
  else
-   host = $3;
+   DupString(link->value.cp, $3);
+ MyFree($3);
+ link->next = hosts;
+ hosts = link;
 };
 operclass: CLASS '=' QSTRING ';'
 {
@@ -788,47 +802,69 @@
 /* The port block... */
 portblock: PORT '{' portitems '}' ';'
 {
+  struct ListenerFlags flags_here;
+  struct SLink *link;
   if (!permitted(BLOCK_PORT, 1))
     ;
-  else if (port > 0 && port <= 0xFFFF)
-  {
-    if (!FlagHas(&listen_flags, LISTEN_IPV4)
-        && !FlagHas(&listen_flags, LISTEN_IPV6))
-    {
-      FlagSet(&listen_flags, LISTEN_IPV4);
-      FlagSet(&listen_flags, LISTEN_IPV6);
+  else for (link = hosts; link != NULL; link = link->next) {
+    memcpy(&flags_here, &listen_flags, sizeof(&flags_here));
+    switch (link->flags & (USE_IPV4 | USE_IPV6)) {
+    case USE_IPV4:
+      FlagSet(&flags_here, LISTEN_IPV4);
+      break;
+    case USE_IPV6:
+      FlagSet(&flags_here, LISTEN_IPV6);
+      break;
+    default: /* 0 or USE_IPV4|USE_IPV6 */
+      FlagSet(&flags_here, LISTEN_IPV4);
+      FlagSet(&flags_here, LISTEN_IPV6);
+      break;
     }
-    add_listener(port, host, pass, &listen_flags);
+    if (link->flags & 65535)
+      port = link->flags & 65535;
+    add_listener(port, link->value.cp, pass, &flags_here);
   }
-  else
-    parse_error("Port %d is out of range", port);
-  MyFree(host);
+  free_slist(&hosts);
   MyFree(pass);
   memset(&listen_flags, 0, sizeof(listen_flags));
-  host = pass = NULL;
+  pass = NULL;
   port = 0;
 };
 portitems: portitem portitems | portitem;
-portitem: portnumber | portvhost | portmask | portserver | porthidden;
+portitem: portnumber | portvhost | portvhostnumber | portmask | portserver | 
porthidden;
 portnumber: PORT '=' address_family NUMBER ';'
 {
-  int families = $3;
-  if (families & USE_IPV4)
-    FlagSet(&listen_flags, LISTEN_IPV4);
-  else if (families & USE_IPV6)
-    FlagSet(&listen_flags, LISTEN_IPV6);
-  port = $4;
+  if ($4 < 1 || $4 > 65535) {
+    parse_error("Port %d is out of range", port);
+  } else {
+    port = $3 | $4;
+    if (hosts && (0 == (hosts->flags & 65535)))
+      hosts->flags = (hosts->flags & ~65535) | port;
+  }
 };
 
 portvhost: VHOST '=' address_family QSTRING ';'
 {
-  int families = $3;
-  if (families & USE_IPV4)
-    FlagSet(&listen_flags, LISTEN_IPV4);
-  else if (families & USE_IPV6)
-    FlagSet(&listen_flags, LISTEN_IPV6);
-  MyFree(host);
-  host = $4;
+  struct SLink *link;
+  link = make_link();
+  link->value.cp = $4;
+  link->flags = $3 | port;
+  link->next = hosts;
+  hosts = link;
+};
+
+portvhostnumber: VHOST '=' address_family QSTRING NUMBER ';'
+{
+  if ($5 < 1 || $5 > 65535) {
+    parse_error("Port %d is out of range", port);
+  } else {
+    struct SLink *link;
+    link = make_link();
+    link->value.cp = $4;
+    link->flags = $3 | $5;
+    link->next = hosts;
+    hosts = link;
+  }
 };
 
 portmask: MASK '=' QSTRING ';'
@@ -1061,22 +1097,30 @@
 
 motdblock: MOTD '{' motditems '}' ';'
 {
-  if (permitted(BLOCK_MOTD, 1) && host != NULL && pass != NULL)
-    motd_add(host, pass);
-  MyFree(host);
+  struct SLink *link;
+  if (permitted(BLOCK_MOTD, 1) && pass != NULL) {
+    for (link = hosts; link != NULL; link = link->next)
+      motd_add(link->value.cp, pass);
+  }
+  free_slist(&hosts);
   MyFree(pass);
-  host = pass = NULL;
+  pass = NULL;
 };
 
 motditems: motditem motditems | motditem;
 motditem: motdhost | motdfile;
 motdhost: HOST '=' QSTRING ';'
 {
-  host = $3;
+  struct SLink *link;
+  link = make_link();
+  link->value.cp = $3;
+  link->next = hosts;
+  hosts = link;
 };
 
 motdfile: TFILE '=' QSTRING ';'
 {
+  MyFree(pass);
   pass = $3;
 };
 
Index: ircu2.10/ircd/list.c
diff -u ircu2.10/ircd/list.c:1.38 ircu2.10/ircd/list.c:1.39
--- ircu2.10/ircd/list.c:1.38   Sun May 14 12:31:30 2006
+++ ircu2.10/ircd/list.c        Sat Mar 17 20:26:30 2007
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief Singly and doubly linked list manipulation implementation.
- * @version $Id: list.c,v 1.38 2006/05/14 19:31:30 entrope Exp $
+ * @version $Id: list.c,v 1.39 2007/03/18 03:26:30 entrope Exp $
  */
 #include "config.h"
 
@@ -452,8 +452,8 @@
   if (lp) {
     lp->next = slinkFreeList;
     slinkFreeList = lp;
+    links.inuse--;
   }
-  links.inuse--;
 }
 
 /** Add an element to a doubly linked list.
Index: ircu2.10/ircd/listener.c
diff -u ircu2.10/ircd/listener.c:1.34 ircu2.10/ircd/listener.c:1.35
--- ircu2.10/ircd/listener.c:1.34       Thu Dec  7 17:39:22 2006
+++ ircu2.10/ircd/listener.c    Sat Mar 17 20:26:30 2007
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief Implementation for handling listening sockets.
- * @version $Id: listener.c,v 1.34 2006/12/08 01:39:22 entrope Exp $
+ * @version $Id: listener.c,v 1.35 2007/03/18 03:26:30 entrope Exp $
  */
 #include "config.h"
 
@@ -315,7 +315,8 @@
     listener->mask_bits = 0;
 
 #ifdef IPV6
-  if (FlagHas(&listener->flags, LISTEN_IPV6)) {
+  if (FlagHas(&listener->flags, LISTEN_IPV6)
+      && (irc_in_addr_unspec(&vaddr) || !irc_in_addr_is_ipv4(&vaddr))) {
     if (listener->fd_v6 >= 0) {
       set_listener_options(listener, listener->fd_v6);
       okay = 1;
@@ -330,7 +331,8 @@
   }
 #endif
 
-  if (FlagHas(&listener->flags, LISTEN_IPV4)) {
+  if (FlagHas(&listener->flags, LISTEN_IPV4)
+      && (irc_in_addr_unspec(&vaddr) || irc_in_addr_is_ipv4(&vaddr))) {
     if (listener->fd_v4 >= 0) {
       set_listener_options(listener, listener->fd_v4);
       okay = 1;
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.96 ircu2.10/ircd/s_conf.c:1.97
--- ircu2.10/ircd/s_conf.c:1.96 Sat Mar 17 14:33:37 2007
+++ ircu2.10/ircd/s_conf.c      Sat Mar 17 20:26:30 2007
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.96 2007/03/17 21:33:37 entrope Exp $
+ * @version $Id: s_conf.c,v 1.97 2007/03/18 03:26:30 entrope Exp $
  */
 #include "config.h"
 
@@ -224,7 +224,6 @@
     aconf->addrbits = addrbits;
   else
     aconf->addrbits = -1;
-  MyFree(host);
 }
 
 /** Copies a completed DNS query into its ConfItem.
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to