[cvslog] [CVS] Module eggdrop1.6: Change committed

cvs at eggheads.org cvs at eggheads.org
Thu Jan 7 07:48:41 CST 2010


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.6
Commit time: 2010-01-07 13:48:41 UTC
Committer  : Rumen Stoyanov <pseudo at egg6.net>

Modified files:
     eggdrop.conf doc/Changes1.6 doc/tcl-commands.doc
     doc/html/egg-core.html doc/html/tcl-commands.html
     doc/settings/core.settings help/set/cmds1.help src/match.c
     src/modules.c src/patch.h src/proto.h src/tcl.c src/tclmisc.c
     src/userent.c src/userrec.c src/users.c src/mod/module.h
     src/mod/channels.mod/channels.c src/mod/channels.mod/cmdschan.c
     src/mod/channels.mod/userchan.c src/mod/irc.mod/chan.c
     src/mod/irc.mod/irc.c src/mod/irc.mod/mode.c

Log message:

Added CIDR support to eggdrop. This includes accepting and matching b/e/I masks and user hosts in cidr notation.

Moved rfc_toupper from wild_match() to the new addr_match().

Added two new Tcl commands - matchaddr and matchcidr to provide interface to the new internal host matching.

Patch by: pseudo

---------------------- diff included ----------------------
Index: eggdrop1.6/doc/Changes1.6
diff -u eggdrop1.6/doc/Changes1.6:1.54 eggdrop1.6/doc/Changes1.6:1.55
--- eggdrop1.6/doc/Changes1.6:1.54	Mon Jan  4 12:38:26 2010
+++ eggdrop1.6/doc/Changes1.6	Thu Jan  7 07:48:30 2010
@@ -1,4 +1,4 @@
-$Id: Changes1.6,v 1.54 2010/01/04 18:38:26 pseudo Exp $
+$Id: Changes1.6,v 1.55 2010/01/07 13:48:30 pseudo Exp $
 
 Eggdrop Changes (since version 1.6.0)
 
@@ -6,6 +6,13 @@
 
 1.6.20 (CVS):
 
+  - Added CIDR support to eggdrop. This includes accepting and matching b/e/I
+    masks and user hosts in cidr notation.
+  - Moved rfc_toupper from wild_match() to the new addr_match().
+  - Added two new Tcl commands - matchaddr and matchcidr to provide interface
+    to the new internal host matching.
+    Patch by: pseudo
+
   - Changed GetInt / GetIntFromObj's Tcl_Interp argument to NULL in
     tcl_resultint() to avoid an unneeded error message being stored in the
     interp result.
Index: eggdrop1.6/doc/html/egg-core.html
diff -u eggdrop1.6/doc/html/egg-core.html:1.45 eggdrop1.6/doc/html/egg-core.html:1.46
--- eggdrop1.6/doc/html/egg-core.html:1.45	Sun Jan  3 07:27:23 2010
+++ eggdrop1.6/doc/html/egg-core.html	Thu Jan  7 07:48:30 2010
@@ -1,5 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!-- $Id: egg-core.html,v 1.45 2010/01/03 13:27:23 pseudo Exp $ -->
+<!-- $Id: egg-core.html,v 1.46 2010/01/07 13:48:30 pseudo Exp $ -->
 
 <html>
   <head>
@@ -845,6 +845,18 @@
           bot will wait dupwait-timeout seconds before it checks again and
           then finally reject the bot.</p>
         </dd>
+        
+        <dt><strong>set cidr-support 0</strong></dt>
+        
+        <dd>
+          <p>Enables cidr support for b/e/I modes if set to 1. This means
+          the bot will understand and match modes in cidr notation, and will
+          be able to put and enforce such bans or unban itself, if banned with
+          a cidr mask.</p>
+
+          <p>Do NOT set this, if your network/server does not support cidr!</p>
+        </dd>
+
       </dl>
     </blockquote>
 
Index: eggdrop1.6/doc/html/tcl-commands.html
diff -u eggdrop1.6/doc/html/tcl-commands.html:1.64 eggdrop1.6/doc/html/tcl-commands.html:1.65
--- eggdrop1.6/doc/html/tcl-commands.html:1.64	Sun Jan  3 08:48:39 2010
+++ eggdrop1.6/doc/html/tcl-commands.html	Thu Jan  7 07:48:30 2010
@@ -1,5 +1,5 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!-- $Id: tcl-commands.html,v 1.64 2010/01/03 14:48:39 pseudo Exp $ -->
+<!-- $Id: tcl-commands.html,v 1.65 2010/01/07 13:48:30 pseudo Exp $ -->
 
 <html>
   <head>
@@ -3643,7 +3643,34 @@
           </blockquote>
 
           <p><strong>Returns:</strong> the stripped string</p>
+        </dd>
+
+
+        <dt><strong><a name="cmd_matchaddr"></a>matchaddr &lt;hostmask&gt;
+        &lt;address&gt;</strong></dt>*
+
+        <dd>
+          <p><strong>Description:</strong> checks if the address matches the
+          hostmask given. The address should be in the form nick!user at host.</p>
+
+          <p><strong>Returns:</strong> 1 if the address matches the
+          hostmask, 0 otherwise.</p>
+          
+          <p><strong>Module:</strong> core</p>
+        </dd>
+
+
+        <dt><strong><a name="cmd_matchcidr"></a>matchcidr &lt;block&gt;
+        &lt;address&gt; &lt;prefix&gt;</strong></dt>*
 
+        <dd>
+          <p><strong>Description:</strong> performs a cidr match on the
+          specified ip addresses. IPv6 is supported, if enabled at compile
+          time.</p>
+
+          <p><strong>Returns:</strong> 1 if the address matches the
+          block prefix, 0 otherwise.</p>
+          
           <p><strong>Module:</strong> core</p>
         </dd>
       </dl>
Index: eggdrop1.6/doc/settings/core.settings
diff -u eggdrop1.6/doc/settings/core.settings:1.39 eggdrop1.6/doc/settings/core.settings:1.40
--- eggdrop1.6/doc/settings/core.settings:1.39	Sun Jan  3 07:27:23 2010
+++ eggdrop1.6/doc/settings/core.settings	Thu Jan  7 07:48:30 2010
@@ -1,4 +1,4 @@
-$Id: core.settings,v 1.39 2010/01/03 13:27:23 pseudo Exp $
+$Id: core.settings,v 1.40 2010/01/07 13:48:30 pseudo Exp $
 
 Eggdrop Core Settings
 Last revised: April 17, 2003
@@ -494,6 +494,12 @@
       reject the bot.
 
 
+    set cidr-support 0
+      Enables cidr support for b/e/I modes if set to 1. This means the bot
+      will understand and match modes in cidr notation, and will be able to
+      put and enforce such bans or unban itself, if banned with a cidr mask.
+      Do NOT set this, if your network/server does not support cidr!
+
 
   ##### MODULES #####
 
Index: eggdrop1.6/doc/tcl-commands.doc
diff -u eggdrop1.6/doc/tcl-commands.doc:1.130 eggdrop1.6/doc/tcl-commands.doc:1.131
--- eggdrop1.6/doc/tcl-commands.doc:1.130	Sun Jan  3 08:48:39 2010
+++ eggdrop1.6/doc/tcl-commands.doc	Thu Jan  7 07:48:30 2010
@@ -1,4 +1,4 @@
-$Id: tcl-commands.doc,v 1.130 2010/01/03 14:48:39 pseudo Exp $
+$Id: tcl-commands.doc,v 1.131 2010/01/07 13:48:30 pseudo Exp $
 
 Eggdrop Tcl Commands
 Last revised: November 23, 2009
@@ -1574,6 +1574,18 @@
     Returns: the stripped string.
     Module: core
 
+| matchaddr <hostmask> <address>
+|   Description: checks if the address matches the hostmask given. The
+|     address should be in the form nick!user at host.
+|   Returns: 1 if the address matches the hostmask, 0 otherwise.
+|   Module: core
+
+|  matchcidr <block> <address> <prefix>
+|   Description: performs a cidr match on the specified ip addresses.
+|     IPv6 is supported, if enabled at compile time.
+|       Example: matchcidr 192.168.0.0 192.168.1.17 16
+|   Returns: 1 if the address matches the block prefix, 0 otherwise.
+|   Module: core
 
 *** GLOBAL VARIABLES ***
 
Index: eggdrop1.6/eggdrop.conf
diff -u eggdrop1.6/eggdrop.conf:1.58 eggdrop1.6/eggdrop.conf:1.59
--- eggdrop1.6/eggdrop.conf:1.58	Mon Nov 23 03:42:01 2009
+++ eggdrop1.6/eggdrop.conf	Thu Jan  7 07:48:30 2010
@@ -1,7 +1,7 @@
 #! /path/to/executable/eggdrop
 # ^- This should contain a fully qualified path to your Eggdrop executable.
 #
-# $Id: eggdrop.conf,v 1.58 2009/11/23 09:42:01 pseudo Exp $
+# $Id: eggdrop.conf,v 1.59 2010/01/07 13:48:30 pseudo Exp $
 #
 # This is a sample Eggdrop configuration file which includes all possible
 # settings that can be used to configure your bot.
@@ -400,6 +400,12 @@
 # seconds before it checks again and then finally reject the bot.
 set dupwait-timeout 5
 
+# Enable cidr support for b/e/I modes. This means the bot will understand
+# and match modes in cidr notation, and will be able to put and enforce such
+# bans or unban itself, if banned with a cidr mask.
+# Do NOT set this, if your network/server does not support cidr!
+set cidr-support 0
+
 # You MUST remove this line for your bot to start. This has been added to
 # prevent you from starting up a bot that is not fully configured. Bots
 # that have not been fully configured may join the wrong IRC network, the
Index: eggdrop1.6/help/set/cmds1.help
diff -u eggdrop1.6/help/set/cmds1.help:1.11 eggdrop1.6/help/set/cmds1.help:1.12
--- eggdrop1.6/help/set/cmds1.help:1.11	Sun Oct 25 09:19:06 2009
+++ eggdrop1.6/help/set/cmds1.help	Thu Jan  7 07:48:31 2010
@@ -235,6 +235,14 @@
 ###  %bset share-unlinks%b 0/1
    This setting prohibits remote bots from telling your Eggdrop to
    unlink from share bots.
+%{help=set cidr-support}%{+n}
+###  %bset cidr-support%b <0/1>
+   Enables cidr support for b/e/I modes if set to 1. This means the
+   bot will understand and match modes in cidr notation, and will
+   be able to put and enforce such bans or unban itself, if banned 
+   with a cidr mask.
+     Warning: enabling this on servers which don't support cidr may
+   result in kick floods or other problems.
 %{help=set allow-dk-cmds}%{+n}
 ###  %bset allow-dk-cmds%b <0/1>
    Enable this setting if you want +d & +k users to use commands
Index: eggdrop1.6/src/match.c
diff -u eggdrop1.6/src/match.c:1.13 eggdrop1.6/src/match.c:1.14
--- eggdrop1.6/src/match.c:1.13	Sat Oct 31 09:18:03 2009
+++ eggdrop1.6/src/match.c	Thu Jan  7 07:48:31 2010
@@ -1,8 +1,10 @@
 /*
  * match.c
  *   wildcard matching functions
+ *   hostmask matching
+ *   cidr matching
  *
- * $Id: match.c,v 1.13 2009/10/31 15:18:03 thommey Exp $
+ * $Id: match.c,v 1.14 2010/01/07 13:48:31 pseudo Exp $
  *
  * Once this code was working, I added support for % so that I could
  * use the same code both in Eggdrop and in my IrcII client.
@@ -34,6 +36,8 @@
 #define MATCH (match+sofar)
 #define PERMATCH (match+saved+sofar)
 
+int cidr_support = 0;
+
 int casecharcmp(unsigned char a, unsigned char b)
 {
   return (rfc_toupper(a) - rfc_toupper(b));
@@ -149,6 +153,7 @@
   return (*m) ? NOMATCH : PERMATCH;     /* End of both = match */
 }
 
+/* Generic string matching, use addr_match() for hostmasks! */
 int _wild_match(register unsigned char *m, register unsigned char *n)
 {
   unsigned char *ma = m, *na = n, *lsm = 0, *lsn = 0;
@@ -196,7 +201,7 @@
       n--;
       continue;                 /* '?' always matches */
     }
-    if (rfc_toupper(*m) == rfc_toupper(*n)) {   /* If matching char */
+    if (toupper(*m) == toupper(*n)) {   /* If matching char */
       m--;
       n--;
       sofar++;                  /* Tally the match */
@@ -216,3 +221,145 @@
     m--;                        /* Zap leftover %s & *s */
   return (m >= ma) ? NOMATCH : MATCH;   /* Start of both = match */
 }
+
+/* cidr and RFC1459 compatible host matching
+ * Returns: 1 if the address in n matches the hostmask in m.
+ * If cmp != 0, m and n will be compared as masks. Returns 1
+ * if m is broader, 0 otherwise.
+ * If user != 0, the masks are eggdrop user hosts and should
+ * be matched regardless of the cidr_support variable.
+ * This is required as userhost matching shouldn't depend on
+ * server support of cidr.
+ */
+int addr_match(char *m, char *n, int user, int cmp)
+{
+  char *p, *q, *r = 0, *s = 0;
+  char mu[UHOSTLEN], nu[UHOSTLEN];
+
+  /* copy the strings into our own buffers
+     and convert to rfc uppercase */
+  for (p = mu; *m && (p - mu < UHOSTLEN - 1); m++) {
+    if (*m == '@')
+      r = p;
+    *p++ = rfc_toupper(*m);
+  }
+  for (q = nu; *n && (q - nu < UHOSTLEN - 1); n++) {
+    if (*n == '@')
+      s = q;
+    *q++ = rfc_toupper(*n);
+  }
+  *p = *q = 0;
+  if ((!user && !cidr_support) || !r || !s)
+    return wild_match(mu, nu) ? 1 : NOMATCH;
+  
+  *r++ = *s++ = 0;
+  if (!wild_match(mu, nu))
+    return NOMATCH; /* nick!ident parts don't match */
+  if (!*r && !*s)
+    return 1; /* end of nonempty strings */
+
+  /* check for CIDR notation and perform
+     generic string matching if not found */
+  if (!(p = strrchr(r, '/')))
+    return wild_match(r, s) ? 1 : NOMATCH;
+  /* if the two strings are both cidr masks,
+     use the broader prefix */
+  if (cmp && (q = strrchr(s, '/'))) {
+    if (atoi(p + 1) > atoi(q + 1))
+      return NOMATCH;
+    *q = 0;
+  }
+  *p = 0;
+  /* looks like a cidr mask */
+  return cidr_match(r, s, atoi(p + 1));
+}
+
+/* Checks for overlapping masks
+ * Returns: > 0 if the two masks in m and n overlap, 0 otherwise.
+ */
+int mask_match(char *m, char *n)
+{
+  int prefix;
+  char *p, *q, *r = 0, *s = 0;
+  char mu[UHOSTLEN], nu[UHOSTLEN];
+
+  for (p = mu; *m && (p - mu < UHOSTLEN - 1); m++) {
+    if (*m == '@')
+      r = p;
+    *p++ = rfc_toupper(*m);
+  }
+  for (q = nu; *n && (q - nu < UHOSTLEN - 1); n++) {
+    if (*n == '@')
+      s = q;
+    *q++ = rfc_toupper(*n);
+  }
+  *p = *q = 0;
+  if (!cidr_support || !r || !s)
+    return (wild_match(mu, nu) || wild_match(nu, mu));
+  
+  *r++ = *s++ = 0;
+  if (!wild_match(mu, nu) && !wild_match(nu, mu))
+    return 0;
+
+  if (!*r && !*s)
+    return 1;
+  p = strrchr(r, '/');
+  q = strrchr(s, '/');
+  if (!p && !q)
+    return (wild_match(r, s) || wild_match(s, r));
+
+  if (p) {
+    *p = 0;
+    prefix = atoi(p + 1);
+  } else
+    prefix = (strchr(r, ':') ? 128 : 32);
+  if (q) {
+    *q = 0;
+    if (atoi(q + 1) < prefix)
+      prefix = atoi(q + 1);
+  }
+  return cidr_match(r, s, prefix);
+}
+
+/* Performs bitwise comparison of two IP addresses stored in presentation
+ * (string) format. IPs are first internally converted to binary form.
+ * Returns: 1 if the first count bits are equal, 0 otherwise.
+ */
+int cidr_match(char *m, char *n, int count)
+{
+#ifdef IPV6
+  int c, af = AF_INET;
+  u_8bit_t block[16], addr[16];
+  
+  if (count < 1)
+    return NOMATCH;
+  if (strchr(m, ':') || strchr(n, ':')) {
+    af = AF_INET6;
+    if (count > 128)
+      return NOMATCH;
+  } else if (count > 32)
+      return NOMATCH;
+  if (inet_pton(af, m, &block) != 1 ||
+      inet_pton(af, n, &addr) != 1)
+    return NOMATCH;
+  for (c = 0; c < (count / 8); c++)
+    if (block[c] != addr[c])
+      return NOMATCH;
+  if (!(count % 8))
+    return 1;
+  count = 8 - (count % 8);
+  return ((block[c] >> count) == (addr[c] >> count));
+  
+#else
+  IP block, addr;
+  
+  if (count < 1 || count > 32)
+    return NOMATCH;
+  block = ntohl(inet_addr(m));
+  addr = ntohl(inet_addr(n));
+  if (block == INADDR_NONE || addr == INADDR_NONE)
+    return NOMATCH;
+  count = 32 - count;
+  return ((block >> count) == (addr >> count));
+#endif
+}
Index: eggdrop1.6/src/mod/channels.mod/channels.c
diff -u eggdrop1.6/src/mod/channels.mod/channels.c:1.100 eggdrop1.6/src/mod/channels.mod/channels.c:1.101
--- eggdrop1.6/src/mod/channels.mod/channels.c:1.100	Sun Jan  3 07:27:40 2010
+++ eggdrop1.6/src/mod/channels.mod/channels.c	Thu Jan  7 07:48:31 2010
@@ -2,7 +2,7 @@
  * channels.c -- part of channels.mod
  *   support for channels within the bot
  *
- * $Id: channels.c,v 1.100 2010/01/03 13:27:40 pseudo Exp $
+ * $Id: channels.c,v 1.101 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -258,7 +258,7 @@
 static int ismasked(masklist *m, char *user)
 {
   for (; m && m->mask[0]; m = m->next)
-    if (wild_match(m->mask, user))
+    if (match_addr(m->mask, user))
       return 1;
   return 0;
 }
Index: eggdrop1.6/src/mod/channels.mod/cmdschan.c
diff -u eggdrop1.6/src/mod/channels.mod/cmdschan.c:1.78 eggdrop1.6/src/mod/channels.mod/cmdschan.c:1.79
--- eggdrop1.6/src/mod/channels.mod/cmdschan.c:1.78	Sun Jan  3 07:27:40 2010
+++ eggdrop1.6/src/mod/channels.mod/cmdschan.c	Thu Jan  7 07:48:31 2010
@@ -2,7 +2,7 @@
  * cmdschan.c -- part of channels.mod
  *   commands from a user via dcc that cause server interaction
  *
- * $Id: cmdschan.c,v 1.78 2010/01/03 13:27:40 pseudo Exp $
+ * $Id: cmdschan.c,v 1.79 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -114,7 +114,7 @@
                    me->funcs[SERVER_BOTUSERHOST]);
     else
       egg_snprintf(s1, sizeof s1, "%s!%s@%s", origbotname, botuser, hostname);
-    if (wild_match(s, s1)) {
+    if (match_addr(s, s1)) {
       dprintf(idx, "I'm not going to ban myself.\n");
       putlog(LOG_CMDS, "*", "#%s# attempted +ban %s", dcc[idx].nick, s);
     } else {
Index: eggdrop1.6/src/mod/channels.mod/userchan.c
diff -u eggdrop1.6/src/mod/channels.mod/userchan.c:1.52 eggdrop1.6/src/mod/channels.mod/userchan.c:1.53
--- eggdrop1.6/src/mod/channels.mod/userchan.c:1.52	Sun Jan  3 07:27:41 2010
+++ eggdrop1.6/src/mod/channels.mod/userchan.c	Thu Jan  7 07:48:31 2010
@@ -1,7 +1,7 @@
 /*
  * userchan.c -- part of channels.mod
  *
- * $Id: userchan.c,v 1.52 2010/01/03 13:27:41 pseudo Exp $
+ * $Id: userchan.c,v 1.53 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -228,7 +228,7 @@
 static int u_match_mask(maskrec *rec, char *mask)
 {
   for (; rec; rec = rec->next)
-    if (wild_match(rec->mask, mask))
+    if (match_addr(rec->mask, mask))
       return 1;
   return 0;
 }
@@ -428,7 +428,7 @@
                    me->funcs[SERVER_BOTUSERHOST]);
   else
     simple_sprintf(s, "%s!%s@%s", origbotname, botuser, hostname);
-  if (wild_match(host, s)) {
+  if (match_addr(host, s)) {
     putlog(LOG_MISC, "*", IRC_IBANNEDME);
     return 0;
   }
@@ -822,7 +822,7 @@
     dprintf(idx, "%s:\n", BANS_GLOBAL);
   for (u = global_bans; u; u = u->next) {
     if (match[0]) {
-      if ((wild_match(match, u->mask)) ||
+      if ((match_addr(match, u->mask)) ||
           (wild_match(match, u->desc)) || (wild_match(match, u->user)))
         display_ban(idx, k, u, chan, 1);
       k++;
@@ -838,7 +838,7 @@
               BANS_BYCHANNEL, chan->dname, MODES_NOTBYBOT);
     for (u = chan->bans; u; u = u->next) {
       if (match[0]) {
-        if ((wild_match(match, u->mask)) ||
+        if ((match_addr(match, u->mask)) ||
             (wild_match(match, u->desc)) || (wild_match(match, u->user)))
           display_ban(idx, k, u, chan, 1);
         k++;
@@ -866,7 +866,7 @@
             sprintf(s, " (active %02d:%02d)", min, sec);
             strcat(fill, s);
           }
-          if ((!match[0]) || (wild_match(match, b->mask)))
+          if ((!match[0]) || (match_addr(match, b->mask)))
             dprintf(idx, "* [%3d] %s\n", k, fill);
           k++;
         }
@@ -911,7 +911,7 @@
     dprintf(idx, "%s:\n", EXEMPTS_GLOBAL);
   for (u = global_exempts; u; u = u->next) {
     if (match[0]) {
-      if ((wild_match(match, u->mask)) ||
+      if ((match_addr(match, u->mask)) ||
           (wild_match(match, u->desc)) || (wild_match(match, u->user)))
         display_exempt(idx, k, u, chan, 1);
       k++;
@@ -927,7 +927,7 @@
               EXEMPTS_BYCHANNEL, chan->dname, MODES_NOTBYBOT);
     for (u = chan->exempts; u; u = u->next) {
       if (match[0]) {
-        if ((wild_match(match, u->mask)) ||
+        if ((match_addr(match, u->mask)) ||
             (wild_match(match, u->desc)) || (wild_match(match, u->user)))
           display_exempt(idx, k, u, chan, 1);
         k++;
@@ -955,7 +955,7 @@
             sprintf(s, " (active %02d:%02d)", min, sec);
             strcat(fill, s);
           }
-          if ((!match[0]) || (wild_match(match, e->mask)))
+          if ((!match[0]) || (match_addr(match, e->mask)))
             dprintf(idx, "* [%3d] %s\n", k, fill);
           k++;
         }
@@ -1000,7 +1000,7 @@
     dprintf(idx, "%s:\n", INVITES_GLOBAL);
   for (u = global_invites; u; u = u->next) {
     if (match[0]) {
-      if ((wild_match(match, u->mask)) ||
+      if ((match_addr(match, u->mask)) ||
           (wild_match(match, u->desc)) || (wild_match(match, u->user)))
         display_invite(idx, k, u, chan, 1);
       k++;
@@ -1016,7 +1016,7 @@
               INVITES_BYCHANNEL, chan->dname, MODES_NOTBYBOT);
     for (u = chan->invites; u; u = u->next) {
       if (match[0]) {
-        if ((wild_match(match, u->mask)) ||
+        if ((match_addr(match, u->mask)) ||
             (wild_match(match, u->desc)) || (wild_match(match, u->user)))
           display_invite(idx, k, u, chan, 1);
         k++;
@@ -1044,7 +1044,7 @@
             sprintf(s, " (active %02d:%02d)", min, sec);
             strcat(fill, s);
           }
-          if ((!match[0]) || (wild_match(match, i->mask)))
+          if ((!match[0]) || (match_addr(match, i->mask)))
             dprintf(idx, "* [%3d] %s\n", k, fill);
           k++;
         }
@@ -1372,7 +1372,7 @@
         match = 0;
         b = chan->channel.ban;
         while (b->mask[0] && !match) {
-          if (wild_match(b->mask, u->mask) || wild_match(u->mask, b->mask))
+          if (mask_match(b->mask, u->mask))
             match = 1;
           else
             b = b->next;
@@ -1400,7 +1400,7 @@
         match = 0;
         b = chan->channel.ban;
         while (b->mask[0] && !match) {
-          if (wild_match(b->mask, u->mask) || wild_match(u->mask, b->mask))
+          if (mask_match(b->mask, u->mask))
             match = 1;
           else
             b = b->next;
Index: eggdrop1.6/src/mod/irc.mod/chan.c
diff -u eggdrop1.6/src/mod/irc.mod/chan.c:1.132 eggdrop1.6/src/mod/irc.mod/chan.c:1.133
--- eggdrop1.6/src/mod/irc.mod/chan.c:1.132	Sun Jan  3 07:27:54 2010
+++ eggdrop1.6/src/mod/irc.mod/chan.c	Thu Jan  7 07:48:31 2010
@@ -6,7 +6,7 @@
  *   user kickban, kick, op, deop
  *   idle kicking
  *
- * $Id: chan.c,v 1.132 2010/01/03 13:27:54 pseudo Exp $
+ * $Id: chan.c,v 1.133 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -153,7 +153,7 @@
     return;
 
   for (e = chan->channel.exempt; e->mask[0]; e = e->next)
-    if (wild_match(e->mask, from)) {
+    if (match_addr(e->mask, from)) {
       add_mode(chan, '-', 'e', e->mask);
       ok = 1;
     }
@@ -169,7 +169,7 @@
 static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char mode)
 {
   for (; m && m->mask[0]; m = m->next)
-    if (wild_match(mask, m->mask) && rfc_casecmp(mask, m->mask))
+    if (cmp_masks(mask, m->mask) && rfc_casecmp(mask, m->mask))
       add_mode(chan, '-', mode, m->mask);
   add_mode(chan, '+', mode, mask);
   flush_mode(chan, QUICK);
@@ -399,7 +399,7 @@
     sprintf(s, "%s!%s", m->nick, m->userhost);
     get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
     if ((me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) &&
-        wild_match(hostmask, s) && !chan_sentkick(m) &&
+        match_addr(hostmask, s) && !chan_sentkick(m) &&
         !match_my_nick(m->nick) && !chan_issplit(m) &&
         !glob_friend(fr) && !chan_friend(fr) && !(use_exempts && ((bantype &&
         isexempted(chan, s)) || (u_match_mask(global_exempts, s) ||
@@ -442,7 +442,7 @@
   /* Check global bans in first cycle and channel bans in second cycle. */
   for (cycle = 0; cycle < 2; cycle++) {
     for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
-      if (wild_match(b->mask, user)) {
+      if (match_addr(b->mask, user)) {
         struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
         char c[512];            /* The ban comment.     */
         char s[UHOSTLEN];
@@ -479,9 +479,9 @@
   /* Check global exempts in first cycle and channel exempts in second cycle. */
   for (cycle = 0; cycle < 2; cycle++) {
     for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
-      if (wild_match(user, e->mask) || wild_match(e->mask, user)) {
+      if (mask_match(user, e->mask)) {
         for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
-          if (wild_match(b->mask, user) || wild_match(user, b->mask)) {
+          if (mask_match(b->mask, user)) {
             if (e->lastactive < now - 60 && !isexempted(chan, e->mask)) {
               do_mask(chan, chan->channel.exempt, e->mask, 'e');
               e->lastactive = now;
@@ -501,7 +501,7 @@
   /* Check global invites in first cycle and channel invites in second cycle. */
   for (cycle = 0; cycle < 2; cycle++) {
     for (i = cycle ? chan->invites : global_invites; i; i = i->next) {
-      if (wild_match(i->mask, user) &&
+      if (match_addr(i->mask, user) &&
           ((i->flags & MASKREC_STICKY) || (chan->channel.mode & CHANINV))) {
         if (i->lastactive < now - 60 && !isinvited(chan, i->mask)) {
           do_mask(chan, chan->channel.invite, i->mask, 'I');
@@ -526,7 +526,7 @@
   simple_sprintf(me, "%s!%s", botname, botuserhost);
   /* Go through all bans, kicking the users. */
   for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
-    if (!wild_match(b->mask, me))
+    if (!match_addr(b->mask, me))
       if (!isexempted(chan, b->mask))
         kick_all(chan, b->mask, IRC_YOUREBANNED, 1);
   }
@@ -569,7 +569,7 @@
           (!channel_dynamicexempts(chan) || (e->flags & MASKREC_STICKY)))
         add_mode(chan, '+', 'e', e->mask);
       for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
-        if ((wild_match(b->mask, e->mask) || wild_match(e->mask, b->mask)) &&
+        if (mask_match(b->mask, e->mask) &&
             !isexempted(chan, e->mask))
           add_mode(chan, '+', 'e', e->mask);
         /* do_mask(chan, chan->channel.exempt, e->mask, 'e'); */
@@ -645,7 +645,7 @@
 
   for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
     sprintf(user, "%s!%s", m->nick, m->userhost);
-    if (wild_match(banmask, user) &&
+    if (match_addr(banmask, user) &&
         !(use_exempts &&
           (u_match_mask(global_exempts, user) ||
            u_match_mask(chan->exempts, user))))
@@ -855,7 +855,7 @@
       sprintf(s, "%s!%s", m->nick, m->userhost);
       u = m->user ? m->user : get_user_by_host(s);
       if ((u && !egg_strcasecmp(u->handle, hand) && delete < 2) ||
-          (!u && delete == 2 && wild_match(host, fixfrom(s)))) {
+          (!u && delete == 2 && match_addr(host, fixfrom(s)))) {
         u = delete ? NULL : u;
         get_user_flagrec(u, &fr, chan->dname);
         check_this_member(chan, m->nick, &fr);
@@ -1891,7 +1891,7 @@
               (!use_exempts || !isexempted(chan, from)) && (me_op(chan) ||
               (me_halfop(chan) && !chan_hasop(m)))) {
             for (b = chan->channel.ban; b->mask[0]; b = b->next) {
-              if (wild_match(b->mask, from)) {
+              if (match_addr(b->mask, from)) {
                 dprintf(DP_SERVER, "KICK %s %s :%s\n", chname, m->nick,
                         IRC_YOUREBANNED);
                 m->flags |= SENTKICK;
Index: eggdrop1.6/src/mod/irc.mod/irc.c
diff -u eggdrop1.6/src/mod/irc.mod/irc.c:1.116 eggdrop1.6/src/mod/irc.mod/irc.c:1.117
--- eggdrop1.6/src/mod/irc.mod/irc.c:1.116	Sun Jan  3 07:27:54 2010
+++ eggdrop1.6/src/mod/irc.mod/irc.c	Thu Jan  7 07:48:31 2010
@@ -2,7 +2,7 @@
  * irc.c -- part of irc.mod
  *   support for channels within the bot
  *
- * $Id: irc.c,v 1.116 2010/01/03 13:27:54 pseudo Exp $
+ * $Id: irc.c,v 1.117 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -633,8 +633,7 @@
               int match = 0;
 
               for (b = chan->channel.ban; b->mask[0]; b = b->next)
-                if (wild_match(b->mask, e->mask) ||
-                    wild_match(e->mask, b->mask)) {
+                if (mask_match(b->mask, e->mask)) {
                   match = 1;
                   break;
                 }
Index: eggdrop1.6/src/mod/irc.mod/mode.c
diff -u eggdrop1.6/src/mod/irc.mod/mode.c:1.88 eggdrop1.6/src/mod/irc.mod/mode.c:1.89
--- eggdrop1.6/src/mod/irc.mod/mode.c:1.88	Sun Jan  3 07:27:55 2010
+++ eggdrop1.6/src/mod/irc.mod/mode.c	Thu Jan  7 07:48:31 2010
@@ -4,7 +4,7 @@
  *   channel mode changes and the bot's reaction to them
  *   setting and getting the current wanted channel modes
  *
- * $Id: mode.c,v 1.88 2010/01/03 13:27:55 pseudo Exp $
+ * $Id: mode.c,v 1.89 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -772,7 +772,7 @@
   if (channel_pending(chan) || HALFOP_CANTDOMODE('b'))
     return;
 
-  if (wild_match(who, me) && !isexempted(chan, me)) {
+  if (match_addr(who, me) && !isexempted(chan, me)) {
     add_mode(chan, '-', 'b', who);
     reversing = 1;
     return;
@@ -785,7 +785,7 @@
     }
     for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
       egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
-      if (wild_match(who, s1)) {
+      if (match_addr(who, s1)) {
         targ = get_user_by_host(s1);
         if (targ) {
           get_user_flagrec(targ, &victim, chan->dname);
@@ -807,7 +807,7 @@
 
     for (cycle = 0; cycle < 2; cycle++) {
       for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
-        if (wild_match(b->mask, who)) {
+        if (match_addr(b->mask, who)) {
           if (b->desc && b->desc[0] != '@')
             egg_snprintf(resn, sizeof resn, "%s %s", IRC_PREBANNED, b->desc);
           else
@@ -919,7 +919,7 @@
   if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)) {
     b = chan->channel.ban;
     while (b->mask[0] && !match) {
-      if (wild_match(b->mask, who) || wild_match(who, b->mask)) {
+      if (mask_match(b->mask, who)) {
         add_mode(chan, '+', 'e', who);
         match = 1;
       } else
Index: eggdrop1.6/src/mod/module.h
diff -u eggdrop1.6/src/mod/module.h:1.90 eggdrop1.6/src/mod/module.h:1.91
--- eggdrop1.6/src/mod/module.h:1.90	Sun Jan  3 07:27:40 2010
+++ eggdrop1.6/src/mod/module.h	Thu Jan  7 07:48:31 2010
@@ -1,7 +1,7 @@
 /*
  * module.h
  *
- * $Id: module.h,v 1.90 2010/01/03 13:27:40 pseudo Exp $
+ * $Id: module.h,v 1.91 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -479,12 +479,19 @@
 /* 292 - 295 */
 #define str_isdigit ((int (*) (const char *))global[292])
 #define remove_crlf ((void (*) (char **))global[293])
-#define check_conflags ((int (*) (struct flag_record *, int))global[294])
+#define addr_match ((int (*)(const char *, const char *, int, int))global[294])
+#define mask_match ((int (*)(const char *, const char *))global[295])
+/* 296 - 299 */
+#define check_conflags ((int (*) (struct flag_record *, int))global[296])
 
 /* hostmasking */
 #define maskhost(a,b) maskaddr((a),(b),3)
 #define maskban(a,b) maskaddr((a),(b),3)
 
+/* host matching */
+#define match_addr(a,b) addr_match((a),(b),0,0)
+#define cmp_masks(a,b) addr_match((a),(b),0,1)
+
 /* This is for blowfish module, couldnt be bothered making a whole new .h
  * file for it ;)
  */
Index: eggdrop1.6/src/modules.c
diff -u eggdrop1.6/src/modules.c:1.103 eggdrop1.6/src/modules.c:1.104
--- eggdrop1.6/src/modules.c:1.103	Sun Jan  3 07:27:32 2010
+++ eggdrop1.6/src/modules.c	Thu Jan  7 07:48:31 2010
@@ -4,7 +4,7 @@
  *
  * by Darrin Smith (beldin at light.iinet.net.au)
  *
- * $Id: modules.c,v 1.103 2010/01/03 13:27:32 pseudo Exp $
+ * $Id: modules.c,v 1.104 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -571,6 +571,9 @@
   /* 292 - 295 */
   (Function) str_isdigit,
   (Function) remove_crlf,
+  (Function) addr_match,
+  (Function) mask_match,
+  /* 296 - 299 */
   (Function) check_conflags
 };
 
Index: eggdrop1.6/src/patch.h
diff -u eggdrop1.6/src/patch.h:1.1226 eggdrop1.6/src/patch.h:1.1227
--- eggdrop1.6/src/patch.h:1.1226	Mon Jan  4 07:15:41 2010
+++ eggdrop1.6/src/patch.h	Thu Jan  7 07:48:31 2010
@@ -10,7 +10,7 @@
  * statement, leave the rest of the file alone, this allows better
  * overlapping patches.
  *
- * $Id: patch.h,v 1.1226 2010/01/04 13:15:41 pseudo Exp $
+ * $Id: patch.h,v 1.1227 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -41,12 +41,12 @@
  *
  *
  */
-patch("1262610931");            /* current unixtime */
+patch("1262871604");            /* current unixtime */
 /*
  *
  *
  */
-patch("telnetfix");
+patch("cidr");
 /*
  *
  *
Index: eggdrop1.6/src/proto.h
diff -u eggdrop1.6/src/proto.h:1.78 eggdrop1.6/src/proto.h:1.79
--- eggdrop1.6/src/proto.h:1.78	Sun Jan  3 07:27:32 2010
+++ eggdrop1.6/src/proto.h	Thu Jan  7 07:48:31 2010
@@ -7,7 +7,7 @@
  * because they use structures in those
  * (saves including those .h files EVERY time) - Beldin
  *
- * $Id: proto.h,v 1.78 2010/01/03 13:27:32 pseudo Exp $
+ * $Id: proto.h,v 1.79 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -189,10 +189,20 @@
                     int (*)(unsigned char, unsigned char),
                     int (*)(unsigned char, unsigned char),
                     unsigned char *);
+int addr_match(char *, char *, int, int);
+int mask_match(char *, char *);
+int cidr_match(char *, char *, int);
 
 #define wild_match(a,b) _wild_match((unsigned char *)(a),(unsigned char *)(b))
-#define wild_match_per(a,b) _wild_match_per((unsigned char *)(a),(unsigned char *)(b),casecharcmp,NULL,NULL)
-#define wild_match_partial_case(a,b) _wild_match_per((unsigned char *)(a),(unsigned char *)(b),casecharcmp,charcmp,(unsigned char *)strchr((b),' '))
+#define wild_match_per(a,b) _wild_match_per((unsigned char *)(a),              \
+                            (unsigned char *)(b),casecharcmp,NULL,NULL)
+#define wild_match_partial_case(a,b) _wild_match_per((unsigned char *)(a),     \
+                            (unsigned char *)(b),casecharcmp,charcmp,          \
+                            (unsigned char *)strchr((b),' '))
+#define match_addr(a,b) addr_match((char *)(a),(char *)(b),0,0)
+#define match_useraddr(a,b) addr_match((char *)(a),(char *)(b),1,0)
+#define cmp_masks(a,b) addr_match((char *)(a),(char *)(b),0,1)
+#define cmp_usermasks(a,b) addr_match((char *)(a),(char *)(b),1,1)
 
 /* mem.c */
 void *n_malloc(int, const char *, int);
Index: eggdrop1.6/src/tcl.c
diff -u eggdrop1.6/src/tcl.c:1.92 eggdrop1.6/src/tcl.c:1.93
--- eggdrop1.6/src/tcl.c:1.92	Mon Jan  4 12:38:26 2010
+++ eggdrop1.6/src/tcl.c	Thu Jan  7 07:48:31 2010
@@ -4,7 +4,7 @@
  *   Tcl initialization
  *   getting and setting Tcl/eggdrop variables
  *
- * $Id: tcl.c,v 1.92 2010/01/04 18:38:26 pseudo Exp $
+ * $Id: tcl.c,v 1.93 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -59,7 +59,7 @@
            die_on_sigterm, max_logs, max_logsize, dcc_total, raw_log,
            identtimeout, dcc_sanitycheck, dupwait_timeout, egg_numver,
            share_unlinks, protect_telnet, sort_users, strict_host,
-           resolve_timeout, default_uflags, userfile_perm;
+           resolve_timeout, default_uflags, userfile_perm, cidr_support;
 
 extern struct dcc_t *dcc;
 extern tcl_timer_t *timer, *utimer;
@@ -549,6 +549,7 @@
   {"userfile-perm",         &userfile_perm,        0},
   {"copy-to-tmp",           &copy_to_tmp,          0},
   {"quiet-reject",          &quiet_reject,         0},
+  {"cidr-support",          &cidr_support,         0},
   {"strict-servernames",    &strict_servernames,   0}, /* compat */
   {"enable-simul",          &enable_simul,         0}, /* compat */
   {"debug-output",          &debug_output,         0}, /* compat */
Index: eggdrop1.6/src/tclmisc.c
diff -u eggdrop1.6/src/tclmisc.c:1.65 eggdrop1.6/src/tclmisc.c:1.66
--- eggdrop1.6/src/tclmisc.c:1.65	Sun Jan  3 07:27:32 2010
+++ eggdrop1.6/src/tclmisc.c	Thu Jan  7 07:48:31 2010
@@ -2,7 +2,7 @@
  * tclmisc.c -- handles:
  *   Tcl stubs for everything else
  *
- * $Id: tclmisc.c,v 1.65 2010/01/03 13:27:32 pseudo Exp $
+ * $Id: tclmisc.c,v 1.66 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -723,6 +723,28 @@
   return TCL_OK;
 }
 
+static int tcl_matchaddr STDVAR
+{
+  BADARGS(3, 3, " mask address");
+
+  if (match_addr(argv[1], argv[2]))
+    Tcl_AppendResult(irp, "1", NULL);
+  else
+    Tcl_AppendResult(irp, "0", NULL);
+  return TCL_OK;
+}
+
+static int tcl_matchcidr STDVAR
+{
+  BADARGS(4, 4, " block address prefix");
+
+  if (cidr_match(argv[1], argv[2], atoi(argv[3])))
+    Tcl_AppendResult(irp, "1", NULL);
+  else
+    Tcl_AppendResult(irp, "0", NULL);
+  return TCL_OK;
+}
+                    
 tcl_cmds tclmisc_objcmds[] = {
 #ifdef USE_TCL_OBJ
   {"md5", tcl_md5},
@@ -768,5 +790,7 @@
   {"binds",               tcl_binds},
   {"callevent",       tcl_callevent},
   {"stripcodes",     tcl_stripcodes},
+  {"matchaddr",       tcl_matchaddr},
+  {"matchcidr",       tcl_matchcidr},
   {NULL,                       NULL}
 };
Index: eggdrop1.6/src/userent.c
diff -u eggdrop1.6/src/userent.c:1.38 eggdrop1.6/src/userent.c:1.39
--- eggdrop1.6/src/userent.c:1.38	Sun Jan  3 07:27:32 2010
+++ eggdrop1.6/src/userent.c	Thu Jan  7 07:48:31 2010
@@ -2,7 +2,7 @@
  * userent.c -- handles:
  *   user-entry handling, new style more versatile.
  *
- * $Id: userent.c,v 1.38 2010/01/03 13:27:32 pseudo Exp $
+ * $Id: userent.c,v 1.39 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -1012,7 +1012,7 @@
     /* I'm surprised Raistlin hasn't gotten involved in this controversy */
     t = &(e->u.list);
     while (*t) {
-      if (wild_match(host, (*t)->extra)) {
+      if (cmp_usermasks(host, (*t)->extra)) {
         struct list_type *u;
 
         u = *t;
Index: eggdrop1.6/src/userrec.c
diff -u eggdrop1.6/src/userrec.c:1.59 eggdrop1.6/src/userrec.c:1.60
--- eggdrop1.6/src/userrec.c:1.59	Sun Jan  3 07:27:32 2010
+++ eggdrop1.6/src/userrec.c	Thu Jan  7 07:48:31 2010
@@ -4,7 +4,7 @@
  *   a bunch of functions to find and change user records
  *   change and check user (and channel-specific) flags
  *
- * $Id: userrec.c,v 1.59 2010/01/03 13:27:32 pseudo Exp $
+ * $Id: userrec.c,v 1.60 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -327,7 +327,7 @@
   for (u = userlist; u; u = u->next) {
     q = get_user(&USERENTRY_HOSTS, u);
     for (; q; q = q->next) {
-      i = wild_match(q->extra, host);
+      i = match_useraddr(q->extra, host);
       if (i > cnt) {
         ret = u;
         cnt = i;
Index: eggdrop1.6/src/users.c
diff -u eggdrop1.6/src/users.c:1.57 eggdrop1.6/src/users.c:1.58
--- eggdrop1.6/src/users.c:1.57	Sun Jan  3 07:27:32 2010
+++ eggdrop1.6/src/users.c	Thu Jan  7 07:48:31 2010
@@ -10,7 +10,7 @@
  *
  * dprintf'ized, 9nov1995
  *
- * $Id: users.c,v 1.57 2010/01/03 13:27:32 pseudo Exp $
+ * $Id: users.c,v 1.58 2010/01/07 13:48:31 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -58,7 +58,7 @@
   struct igrec *ir;
 
   for (ir = global_ign; ir; ir = ir->next)
-    if (wild_match(ir->igmask, uhost))
+    if (match_useraddr(ir->igmask, uhost))
       return 1;
   return 0;
 }
@@ -204,7 +204,7 @@
   dprintf(idx, "%s:\n", IGN_CURRENT);
   for (; u; u = u->next) {
     if (match[0]) {
-      if (wild_match(match, u->igmask) ||
+      if (cmp_usermasks(match, u->igmask) ||
           wild_match(match, u->msg) || wild_match(match, u->user))
         display_ignore(idx, k, u);
       k++;
----------------------- End of diff -----------------------


More information about the Changes mailing list