]> jfr.im git - irc/quakenet/newserv.git/blobdiff - bans/bans.c
jupe: Clean up single list code.
[irc/quakenet/newserv.git] / bans / bans.c
index b7fc500e300c90f998e3ab41d198cc7517a6cb24..1a34cbbb756668cf4527e6ed960acad7eca6371b 100644 (file)
@@ -10,6 +10,9 @@
 #include "../irc/irc_config.h"
 #include "../core/nsmalloc.h"
 #include "../lib/flags.h"
+#include "../lib/version.h"
+
+MODULE_VERSION("")
 
 #define ALLOCUNIT 100
 
@@ -66,10 +69,7 @@ void freechanban(chanban *cbp) {
 chanban *makeban(const char *mask) {
   int len;
   int foundat=-1,foundbang=-1;
-  int dotcount=0;
-  int notip=0;
   int foundwild=0;
-  int foundslash=0;
   int i;
   int checklen;
   chanban *cbp;
@@ -109,38 +109,15 @@ chanban *makeban(const char *mask) {
         /* Special case: "@*" */
         cbp->flags |= CHANBAN_HOSTANY;
         cbp->host=NULL;      
-      } else if (foundslash) {
-        /* If we found a slash (/), this can only be a CIDR ban */
-        /* However, it might be broken, so we need to retain the exact string
-         * to track it accurately */
-        cbp->host=getsstring(&mask[i+1],HOSTLEN);
-        if ((notip || dotcount!=3) && !foundwild) {
-          cbp->flags |= (CHANBAN_INVALID | CHANBAN_HOSTEXACT);
-        } else if (foundwild) {
-          cbp->flags |= (CHANBAN_INVALID | CHANBAN_HOSTMASK);
-        } else {
-          unsigned int a,b,c,d,l;
-          /* CIDR bans have to match this pattern.  */
-          if ((sscanf(&mask[i+1], "%u.%u.%u.%u/%u",&a,&b,&c,&d,&l) != 5) ||
-               (a>255) || (b>255) || (c>255) || (d>255) || (l>32) ) {
-            cbp->flags |= (CHANBAN_HOSTEXACT | CHANBAN_INVALID);
-          } else {
-            /* Save the IP address and mask for later */
-            cbp->ipaddr=(a<<24)|(b<<16)|(c<<8)|d;
-            cbp->mask=0xffffffff;
-            if (l==0) {
-              cbp->mask=0;
-            } else if (l<32) {
-              cbp->mask<<=(32-l);
-            }
-            /* pre-AND the IP with the mask here. */
-            cbp->ipaddr &= cbp->mask;
-            cbp->flags |= (CHANBAN_HOSTEXACT | CHANBAN_CIDR);
-          }
-        }
       } else {
         /* We have some string with between 1 and HOSTLEN characters.. */
         cbp->host=getsstring(&mask[i+1],HOSTLEN);
+
+        /* If it matches an IP address, flag it as such */
+        if (ipmask_parse(cbp->host->content, &(cbp->ipaddr), &(cbp->prefixlen))) {
+          cbp->flags |= CHANBAN_IP;
+        }
+
         if (foundwild) {
           /* We check all characters after the last wildcard (if any).. if they match
            * the corresponding bits of the hidden host string we mark it accordingly */
@@ -157,38 +134,20 @@ chanban *makeban(const char *mask) {
             }
           }
           cbp->flags |= CHANBAN_HOSTMASK;
-          if (!notip && dotcount<=3)
-            cbp->flags |= CHANBAN_IP;
         } else {
           /* Exact host: see if it ends with the "hidden host" string */
           cbp->flags |= CHANBAN_HOSTEXACT;
           if ((cbp->host->length > (strlen(HIS_HIDDENHOST)+1)) && 
               !ircd_strcmp(cbp->host->content+(cbp->host->length-strlen(HIS_HIDDENHOST)), HIS_HIDDENHOST)) {
             cbp->flags |= CHANBAN_HIDDENHOST;
-          } else if (!notip && dotcount==3) {
-            unsigned int a,b,c,d;
-            if ((sscanf(&mask[i+1], "%u.%u.%u.%u",&a,&b,&c,&d) != 4) ||
-                  (a > 255) || (b > 255) || (c > 255) || (d > 255) ) {
-              /* Something with only numbers and exactly 3 dots that isn't an IP address can't match anything. */
-              cbp->flags |= CHANBAN_INVALID; 
-            } else {
-              cbp->ipaddr=(a<<24)|(b<<16)|(c<<8)|d;
-              cbp->flags |= CHANBAN_IP;
-            }
           }
         }
       }
       foundat=i;
       break;
-    } else if (mask[i]=='/') {
-      foundslash=1;
-    } else if (mask[i]=='.') {
-      dotcount++;
     } else if (mask[i]=='?' || mask[i]=='*') {
       if (!foundwild)  /* Mark last wildcard in string */
         foundwild=i;
-    } else if (mask[i]<'0' || mask[i]>'9') {
-      notip=1;
     }
   }
 
@@ -461,9 +420,9 @@ char *bantostring(chanban *bp) {
   strpos += sprintf(outstring+strpos,"@");
 
   if (bp->flags & CHANBAN_HOSTANY) {
-    strpos += sprintf(outstring+strpos,"*");
+    sprintf(outstring+strpos,"*");
   } else if (bp->host) {
-    strpos += sprintf(outstring+strpos,"%s",bp->host->content);
+    sprintf(outstring+strpos,"%s",bp->host->content);
   }
 
   return outstring;
@@ -493,12 +452,11 @@ char *bantostringdebug(chanban *bp) {
   }
 
   if (bp->host) {
-    strpos += sprintf(outstring+strpos, "host=%s ",bp->host->content);
+    sprintf(outstring+strpos, "host=%s ",bp->host->content);
   } else {
-    strpos += sprintf(outstring+strpos, "nohost ");
+    sprintf(outstring+strpos, "nohost ");
   }
 
-
   return outstring;
 }