]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Refactor T's host counting code and fix a counting bug.
authorChris Porter <redacted>
Sun, 3 Feb 2008 18:30:31 +0000 (18:30 +0000)
committerChris Porter <redacted>
Sun, 3 Feb 2008 18:30:31 +0000 (18:30 +0000)
trojanscan/trojanscan.c
trojanscan/trojanscan.h

index f68304646873dcce8adf5472f2cc5555b230e04b..beb8c05f776c837aefbbce7f1caaa9e4a81b8d57 100644 (file)
@@ -1956,39 +1956,49 @@ static void trojanscan_part_watch(int hook, void *arg) {
   trojanscan_process(np, cp, trojanscan_getmtfromhooktype(hook), reason);
 }
 
+static int trojanscan_hostcount(nick *sender, int hostmode, char *mask, int masklen) {
+  int usercount = 0, j;
+  nick *np = NULL; /* sigh at warnings */
+
+  if(hostmode)
+    for (j=0;j<NICKHASHSIZE;j++)
+      for (np=nicktable[j];np;np=np->next)
+        if (np->ipnode==sender->ipnode)
+          usercount++;
+
+  if(usercount > TROJANSCAN_MAX_HOST_GLINE) {
+    hostmode = 0;
+    usercount = 0;
+  }
+
+  if(!hostmode)
+    for (j=0;j<NICKHASHSIZE;j++)
+      for (np=nicktable[j];np;np=np->next)
+        if (np->ipnode==sender->ipnode && !ircd_strcmp(np->ident, sender->ident))
+          usercount++;
+
+  if(mask)
+    snprintf(mask, masklen, "%s@%s", hostmode?"*":sender->ident, IPtostr(sender->p_ipaddr));
+
+  return usercount;
+}
+
 void trojanscan_phrasematch(channel *chp, nick *sender, trojanscan_phrases *phrase, char messagetype, char *matchbuf) {
   char glinemask[HOSTLEN + USERLEN + NICKLEN + 4], enick[TROJANSCAN_QUERY_TEMP_BUF_SIZE], eident[TROJANSCAN_QUERY_TEMP_BUF_SIZE], ehost[TROJANSCAN_QUERY_TEMP_BUF_SIZE];
   char *userbit;
-  unsigned int j, usercount, frequency;
-  int glining = 1;
+  unsigned int frequency;
+  int glining = 0, usercount;
   struct trojanscan_worms *worm = phrase->worm;
 
-  nick *np = NULL; /* sigh at warnings */
-  
   trojanscan_database.detections++;
   
   usercount = 0;
   if (worm->monitor) {
-    glining = 0;
     usercount = -1;
-  } else if (worm->glinehost) {
-    snprintf(glinemask, sizeof(glinemask) - 1, "*@%s", IPtostr(sender->p_ipaddr));
-    for (j=0;j<NICKHASHSIZE;j++)
-      for (np=nicktable[j];np;np=np->next)
-        if (np->ipnode==sender->ipnode)
-          usercount++;
-  }
-  if (worm->glineuser || (worm->glinehost && usercount > TROJANSCAN_MAX_HOST_GLINE)) {
-    userbit = sender->ident;
-/*
-    if(userbit[0] == '~')
-      userbit++;
-*/
-    snprintf(glinemask, sizeof(glinemask) - 1, "%s@%s", userbit, IPtostr(sender->p_ipaddr));
-    for (j=0;j<NICKHASHSIZE;j++)
-      for (np=nicktable[j];np;np=np->next)
-        if ((np->ipnode==sender->ipnode) && (!ircd_strcmp(np->ident,sender->ident)))
-          usercount++;
+  } else if(worm->glinehost || worm->glineuser) {
+    glining = 1;
+
+    usercount = trojanscan_hostcount(sender, worm->glinehost, glinemask, sizeof(glinemask));
   }
   
   if (!usercount) {
index 3ff26be62c7cc00ff013375ebcea79f955bbd3b4..367ab92093f2a1d8a200ea71039eb0e4637a3417 100644 (file)
@@ -18,7 +18,7 @@
 #include <ctype.h>
 #include <strings.h>
 
-#define TROJANSCAN_VERSION "2.68"
+#define TROJANSCAN_VERSION "2.69"
 
 #define TROJANSCAN_MAX_HOST_GLINE   5