]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trojanscan/trojanscan.c
sync http://hg.quakenet.org/snircd/diff/6a655306abe8/ircd/ircd_string.c
[irc/quakenet/newserv.git] / trojanscan / trojanscan.c
index 597643db621d5457295eed337e27df74738d6282..ea24e8eb8e531061ef6c56d4667312365ec91b0b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Trojanscan version 2
  *
- * Trojanscan  copyright (C) Chris Porter 2002-2007
+ * Trojanscan  copyright (C) Chris Porter 2002-2009
  * Newserv bits copyright (C) David Mansell 2002-2003
  * 
  * TODO: CHECK::
@@ -15,6 +15,7 @@
 #include "../lib/strlfunc.h"
 #include "../lib/version.h"
 #include "../core/nsmalloc.h"
+#include <stdint.h>
 
 #define tmalloc(x)     nsmalloc(POOL_TROJANSCAN, x)
 #define tfree(x)       nsfree(POOL_TROJANSCAN, x)
@@ -215,12 +216,12 @@ void trojanscan_connect(void *arg) {
   trojanscan_database.glines = 0;
   trojanscan_database.detections = 0;
     
-  dbhost = getcopyconfigitem("trojanscan", "dbhost", "localhost", HOSTLEN);
-  dbuser = getcopyconfigitem("trojanscan", "dbuser", "", NICKLEN);
-  dbpass = getcopyconfigitem("trojanscan", "dbpass", "", REALLEN);
-  db = getcopyconfigitem("trojanscan", "db", "", NICKLEN);
+  dbhost = getcopyconfigitem("trojanscan", "dbhost", "localhost", 100);
+  dbuser = getcopyconfigitem("trojanscan", "dbuser", "moo", 100);
+  dbpass = getcopyconfigitem("trojanscan", "dbpass", "changeme", 100);
+  db = getcopyconfigitem("trojanscan", "db", "moo", 100);
   
-  dbport = getcopyconfigitem("trojanscan", "dbport", "3306", ACCOUNTLEN);
+  dbport = getcopyconfigitem("trojanscan", "dbport", "3306", 10);
   
   length = snprintf(buf, sizeof(buf) - 1, "%d", TROJANSCAN_DEFAULT_MAXCHANS);
   temp = getcopyconfigitem("trojanscan", "maxchans", buf, length);
@@ -740,7 +741,7 @@ int trojanscan_whois(void *sender, int cargc, char **cargv) {
     for(i=0;i<TROJANSCAN_CLONE_TOTAL;i++) {
       if(trojanscan_swarm[i].clone->nick && !ircd_strcmp(trojanscan_swarm[i].clone->nick, np2->nick)) {
         trojanscan_reply(np, "Nickname   : %s", np2->nick);
-        trojanscan_reply(np, "Swarm      : yes", trojanscan_swarm[i].clone->nick);
+        trojanscan_reply(np, "Swarm      : yes");
         return CMD_OK;
       }
     }
@@ -776,9 +777,9 @@ void trojanscan_privmsg_chan_or_nick(channel *cp, nick *np, char *message, ...)
   va_end(va);
   
   if (cp) {
-    sendmessagetochannel(trojanscan_nick, cp, buf);
+    sendmessagetochannel(trojanscan_nick, cp, "%s", buf);
   } else {
-    sendmessagetouser(trojanscan_nick, np, buf);
+    sendmessagetouser(trojanscan_nick, np, "%s", buf);
   }
 
 }
@@ -1997,16 +1998,14 @@ static int trojanscan_hostcount(nick *sender, int hostmode, char *mask, int mask
   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++;
+    usercount = sender->ipnode->usercount;
 
   if(usercount > TROJANSCAN_MAX_HOST_GLINE) {
     hostmode = 0;
     usercount = 0;
   }
 
+  /* should really go through the ipnode I guess */
   if(!hostmode)
     for (j=0;j<NICKHASHSIZE;j++)
       for (np=nicktable[j];np;np=np->next)
@@ -2080,7 +2079,7 @@ void trojanscan_phrasematch(channel *chp, nick *sender, trojanscan_phrases *phra
     trojanscan_database_query("INSERT INTO hits (nickname, ident, host, phrase, messagetype, glined) VALUES ('%s', '%s', '%s', %d, '%c', %d)", enick, eident, ehost, phrase->id, messagetype, glining);
     trojanscan_database.glines++;
     
-    irc_send("%s GL * +%s %d %d :You (%s!%s@%s) are infected with a trojan (%s/%d), see %s%d for details - banned for %d hours\r\n", mynumeric->content, glinemask, glinetime * 3600, time(NULL), sender->nick, sender->ident, sender->host->name->content, worm->name->content, phrase->id, TROJANSCAN_URL_PREFIX, worm->id, glinetime);
+    irc_send("%s GL * +%s %d %jd :You (%s!%s@%s) are infected with a trojan (%s/%d), see %s%d for details - banned for %d hours\r\n", mynumeric->content, glinemask, glinetime * 3600, (intmax_t)time(NULL), sender->nick, sender->ident, sender->host->name->content, worm->name->content, phrase->id, TROJANSCAN_URL_PREFIX, worm->id, glinetime);
 
     trojanscan_mainchanmsg("g: *!%s t: %c u: %s!%s@%s%s%s c: %d w: %s%s p: %d f: %d%s%s", glinemask, messagetype, sender->nick, sender->ident, sender->host->name->content, messagetype=='N'||messagetype=='M'||messagetype=='P'?" #: ":"", messagetype=='N'||messagetype=='M'||messagetype=='P'?chp->index->name->content:"", usercount, worm->name->content, worm->epidemic?"(E)":"", phrase->id, frequency, matchbuf[0]?" --: ":"", matchbuf[0]?matchbuf:"");
   }
@@ -2383,6 +2382,16 @@ host *trojanscan_selecthost(void) {
   return NULL;
 }
 
+static int specialuseronhost(host *hp) {
+  nick *np;
+
+  for(np=hp->nicks;np;np=np->nextbyhost)
+    if(IsOper(np) || IsService(np) || IsXOper(np) || NickOnServiceServer(np))
+      return 1;
+
+  return 0;
+}
+
 void trojanscan_generatehost(char *buf, int maxsize, patricia_node_t **fakeip) {
   struct irc_in_addr ipaddress;
 
@@ -2394,7 +2403,7 @@ void trojanscan_generatehost(char *buf, int maxsize, patricia_node_t **fakeip) {
 
     do {
       hp = trojanscan_selecthost();
-      if(hp && (hp->clonecount <= TROJANSCAN_MAX_CLONE_COUNT) && !trojanscan_isip(hp->name->content)) {
+      if(hp && (hp->clonecount <= TROJANSCAN_MAX_CLONE_COUNT) && !trojanscan_isip(hp->name->content) && !specialuseronhost(hp)) {
         strlcpy(buf, hp->name->content, maxsize + 1);
         if(hp->nicks) {
           *fakeip = hp->nicks->ipnode;