]> jfr.im git - irc/quakenet/newserv.git/commitdiff
trusts changes
authorPaul <redacted>
Thu, 1 Jan 2009 23:44:12 +0000 (23:44 +0000)
committerPaul <redacted>
Thu, 1 Jan 2009 23:44:12 +0000 (23:44 +0000)
--HG--
branch : paul

trusts2/trusts.c
trusts2/trusts.h
trusts2/trusts_blocks.c
trusts2/trusts_commands.c
trusts2/trusts_db.c
trusts2/trusts_handlers.c
trusts2/trusts_hosts.c
trusts2/trusts_ident.c

index 08fd390bf5f0e87c31f4c82784362f0b04b43df8..bb9b1dd9d6ad1ec7aed7c595eba1fe53e4c46fc3 100644 (file)
@@ -6,11 +6,12 @@
 
 int tgh_ext;
 int tgb_ext;
+int tgn_ext;
 
 unsigned long trusts_lasttrustgroupid;
 unsigned long trusts_lasttrusthostid;
 unsigned long trusts_lasttrustblockid;
-int trusts_loaded;
+int trusts_loaded = 0;
 int removeusers = 0;
 
 static void trusts_status(int hooknum, void *arg);
@@ -31,21 +32,23 @@ void _init(void) {
     return;
   }
 
-  if ( !trusts_load_db()) {
+  tgn_ext = registernickext("trustnick");
+  if ( !tgn_ext ) {
+    Error("trusts", ERR_FATAL, "Could not register a required nick extension (trustnick)");
     return;
   }
+
   registerhook(HOOK_TRUSTS_DBLOADED, trustsfinishinit);
 
+  if ( !trusts_load_db()) {
+    return;
+  }
   if (trusts_loaded) 
     trustsfinishinit(HOOK_TRUSTS_DBLOADED, NULL);
 }
 
 void trustsfinishinit(int hooknum, void *arg) {
-  Error("trusts",ERR_INFO,"Database loaded, finishing initialisation.");
-
-  deregisterhook(HOOK_TRUSTS_DBLOADED, trustsfinishinit);
-
   registerhook(HOOK_NICK_NEWNICK, &trusts_hook_newuser);
   registerhook(HOOK_NICK_LOSTNICK, &trusts_hook_lostuser);
 
@@ -57,15 +60,8 @@ void _fini(void) {
   trustgroupidentcount_t *t;
 
   int i;
-  for ( i = 0; i < TRUSTS_HASH_HOSTSIZE ; i++ ) {
-    for ( thptr = trusthostidtable[i]; thptr; thptr = thptr-> nextbyid ) {
-      derefnode(iptree,thptr->node);
-    }
-  }
-  if (tgh_ext)
-    releasenodeext(tgh_ext); 
-  if (tgb_ext)
-    releasenodeext(tgb_ext);
+
+  deregisterhook(HOOK_TRUSTS_DBLOADED, trustsfinishinit);
 
   if ( trusts_loaded ) {
     deregisterhook(HOOK_NICK_NEWNICK, &trusts_hook_newuser);
@@ -82,7 +78,20 @@ void _fini(void) {
     }
   }
 
-  trustblock_freeall();
+  patricia_node_t *node;
+  PATRICIA_WALK_CLEAR(iptree->head,node) {
+    if (node && node->exts[tgb_ext]) {
+      trustblock_free(node->exts[tgb_ext]);
+      node->exts[tgb_ext] = NULL;      
+    }
+  } PATRICIA_WALK_CLEAR_END;
+
+  if (tgh_ext)
+    releasenodeext(tgh_ext);
+  if (tgb_ext)
+    releasenodeext(tgb_ext);
+  if (tgn_ext)
+    releasenodeext(tgn_ext);
 
   /* @@@ CLOSE DB */
 
@@ -130,18 +139,6 @@ void decrement_trust_ipnode(patricia_node_t *node) {
   }
 }
 
-void trust_debug(char *format, ...) {
-  char buf[512];
-  va_list va;
-  channel *debugcp = findchannel("#qnet.trusts");
-  if(debugcp) {
-     va_start(va, format);
-     vsnprintf(buf, sizeof(buf), format, va);
-     va_end(va);
-    controlchanmsg(debugcp,buf);
-  }
-}
-
 static void trusts_status(int hooknum, void *arg) {
   if((long)arg > 10) {
     char message[100];
@@ -162,5 +159,13 @@ static void trusts_status(int hooknum, void *arg) {
     snprintf(message, sizeof(message), "Trusts  :%7d groups, %7d hosts", tgcount, thcount);
     triggerhook(HOOK_CORE_STATSREPLY, message);
   }
+}
 
+int trusts_ignore_np(nick *np) {
+  if(SIsService(&serverlist[homeserver(np->numeric)])) {
+    /* ANY user created by a server (nterface,fakeusers,Q) are ignored in relation to trusts */
+    /* NOTE: we might need to review this if we ever used newserv to handle client/user connections in some way */
+    return 1;
+  }
+  return 0;
 }
index f76a85ad80c22efb307b9f21d244f14ad0e17724..8707ebb5a6213b2852ee2cf17a8e58392e029290 100644 (file)
 
 #define TRUSTS_MAXGROUPNAMELEN 20
 
+/* node extensions */
 extern int tgh_ext;
 extern int tgb_ext;
+
+/* nick extensions */
+extern int tgn_ext;
+
 extern int removeusers;
 extern int trusts_loaded;
 
@@ -129,8 +134,6 @@ trustgroupidentcount_t *getnewtrustgroupidentcount(trustgroup_t *tg, char *ident
 
 extern unsigned long trusts_lasttrustgroupid, trusts_lasttrusthostid, trusts_lasttrustblockid;
 
-void trust_debug(char *format, ...);
-
 /* trusts alloc */
 trustgroup_t *newtrustgroup();
 void freetrustgroup (trustgroup_t *trustgroup);
@@ -146,7 +149,9 @@ int trusts_load_db(void);
 void trusts_create_tables(void);
 void trusts_cleanup_db(void);
 void trusts_loadtrustgroups(DBConn *dbconn, void *arg);
+void trusts_loadtrustgroupsmax(DBConn *dbconn, void *arg);
 void trusts_loadtrusthosts(DBConn *dbconn, void *arg);
+void trusts_loadtrusthostsmax(DBConn *dbconn, void *arg);
 void trusts_loadtrustblocks(DBConn *dbconn, void *arg);
 void trustsdb_addtrustgroup(trustgroup_t *t);
 void trustsdb_updatetrustgroup(trustgroup_t *t);
@@ -191,6 +196,7 @@ void decrement_ident_count(nick *np, trustgroup_t *tg);
 /* trusts */
 void decrement_trust_ipnode(patricia_node_t *node);
 void increment_trust_ipnode(patricia_node_t *node);
+int trusts_ignore_np(nick *np);
 
 /* trusts cmds */
 void trusts_cmdinit();
@@ -208,5 +214,7 @@ int trust_comment(void *source, int cargc, char **cargv);
 
 int trust_stats(void *source, int cargc, char **cargv);
 int trust_dump(void *source, int cargc, char **cargv);
+int trust_dotrustlog(void *source, int cargc, char **cargv);
+
 #endif
 
index 0ffc73e0b9c39658c4526b47621300767ef07da0..c2046b29aa38edf7afc5d750ca71bb694eb70a24 100644 (file)
@@ -41,6 +41,7 @@ void trustblock_free(trustblock_t* t)
     if (pst) {
       pst->next = st->next;
     } 
+
     derefnode(iptree,st->node);
     if (st->reason_public ) {
       freesstring(st->reason_public);
@@ -65,6 +66,7 @@ void trustblock_freeall() {
   while(tb) {
     ptb=tb;
     tb=tb->next;
+
     derefnode(iptree,ptb->node);
     if (ptb->reason_public ) {
       freesstring(ptb->reason_public);
@@ -72,5 +74,6 @@ void trustblock_freeall() {
     if (ptb->reason_private) {
       freesstring(ptb->reason_private);
     }
+    ptb->node->exts[tgb_ext] = NULL;
   }
 }
index ad1ad4bc9bbe10f8611cb67861eee12a68303d5c..bacba3953f18e75a72a653d4df28d5453dca865e 100644 (file)
@@ -7,6 +7,8 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
+static int commandsregistered;
+
 void _init(void) {
   registerhook(HOOK_TRUSTS_DBLOADED, trusts_cmdinit);
 
@@ -18,10 +20,12 @@ void _init(void) {
 
 void _fini(void) {
   deregisterhook(HOOK_TRUSTS_DBLOADED, trusts_cmdinit);
-  trusts_cmdfini();
+  trusts_cmdfini(0, NULL);
 }
 
 void trusts_cmdinit(int hooknum, void *arg) {
+  if(commandsregistered)
+    return;
   registercontrolcmd("trustgroupadd",10,7,trust_groupadd);
   registercontrolcmd("trustgroupmodify",10,4,trust_groupmodify);
   registercontrolcmd("trustgroupdel",10,2,trust_groupdel);
@@ -38,10 +42,16 @@ void trusts_cmdinit(int hooknum, void *arg) {
   registercontrolcmd("truststats",10,2,trust_stats);
   registercontrolcmd("trustdump",10,2,trust_dump);
 
+  registercontrolcmd("trustlog", 10,2, trust_dotrustlog);
+
+  commandsregistered = 1;
   removeusers = 0;
 }
 
 void trusts_cmdfini() {
+  if(!commandsregistered)
+    return;
+
   deregistercontrolcmd("trustgroupadd",trust_groupadd);
   deregistercontrolcmd("trustgroupmodify",trust_groupmodify);
   deregistercontrolcmd("trustgroupdel",trust_groupdel);
@@ -58,6 +68,9 @@ void trusts_cmdfini() {
   deregistercontrolcmd("truststats",trust_stats);
   deregistercontrolcmd("trustdump",trust_dump);
 
+  deregistercontrolcmd("trustlog", trust_dotrustlog);
+
+  commandsregistered = 0;
   removeusers = 0;
 }
 
@@ -87,7 +100,7 @@ int trust_groupadd(void *source, int cargc, char **cargv) {
   }
   expiry = durationtolong(cargv[1]);
   if (expiry > (365 * 86400) ) {
-    controlreply(sender,"ERROR: Invalid duration given - temporary trusts can not be longer then 1 year");
+    controlreply(sender,"ERROR: Invalid duration given - temporary trusts must be less than 1 year");
     return CMD_ERROR;
   }
   ownerid  = strtoul(cargv[6],NULL,10);
@@ -160,6 +173,11 @@ int trust_del(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
+  if (!is_normalized_ipmask(&sin,bits)) {
+    controlreply(sender, "ERROR: non-normalized mask.");
+    return CMD_ERROR;
+  }
+
   node = refnode(iptree, &sin, bits);
   if(!node->exts[tgh_ext]) {
     controlreply(sender,"ERROR: That CIDR was not trusted.");
@@ -213,6 +231,11 @@ int trust_add(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
+  if (!is_normalized_ipmask(&sin,bits)) {
+    controlreply(sender, "ERROR: non-normalized mask.");
+    return CMD_ERROR;
+  }
+
   if ( irc_in_addr_is_ipv4(&sin) ) {
     if (bits>128 || bits<112) {
       controlreply(sender,"ERROR: Not a valid netmask (needs to be between 16 and 32)");
@@ -288,6 +311,7 @@ int trust_add(void *source, int cargc, char **cargv) {
   th = trusthostadd(node, tg, expiry );
   if ( !th ) {
     controlreply(sender,"ERROR: Unable to add trusted host");
+    return CMD_ERROR;
   }
  
   trustsdb_addtrusthost(th);
@@ -400,6 +424,11 @@ int trust_denyadd(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
+  if (!is_normalized_ipmask(&sin,bits)) {
+    controlreply(sender, "ERROR: non-normalized mask.");
+    return CMD_ERROR;
+  }
+
   if ( irc_in_addr_is_ipv4(&sin) ) {
     if (bits>128 || bits<112) {
       controlreply(sender,"ERROR: Not a valid netmask (needs to be between 8 and 32)");
@@ -454,6 +483,11 @@ int trust_denycomment(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
+  if (!is_normalized_ipmask(&sin,bits)) {
+    controlreply(sender, "ERROR: non-normalized mask.");
+    return CMD_ERROR;
+  }
+
   if ( irc_in_addr_is_ipv4(&sin) ) {
     if (bits>128 || bits<112) {
       controlreply(sender,"ERROR: Not a valid netmask (needs to be between 8 and 32)");
@@ -497,6 +531,11 @@ int trust_denydel(void *source, int cargc, char **cargv) {
     controlreply(sender, "ERROR: Invalid mask.");
     return CMD_ERROR;
   }
+
+  if (!is_normalized_ipmask(&sin,bits)) {
+    controlreply(sender, "ERROR: non-normalized mask.");
+    return CMD_ERROR;
+  }
   
   node = refnode(iptree, &sin, bits);
   if(!node->exts[tgb_ext]) {
@@ -791,6 +830,7 @@ int trust_stats(void *source, int cargc, char **cargv) {
           maxthmask4 = (((patricia_node_t *)thptr->node)->prefix->bitlen-96);
         }
       } else {
+        controlreply(sender, "%s", IPtostr(((patricia_node_t *)thptr->node)->prefix->sin)); 
         netcount6[((patricia_node_t *)thptr->node)->prefix->bitlen]++;
         netucount6[((patricia_node_t *)thptr->node)->prefix->bitlen]+=thptr->node->usercount;
         netmcount6[((patricia_node_t *)thptr->node)->prefix->bitlen]+=thptr->maxused;
@@ -857,6 +897,29 @@ int trust_comment(void *source, int cargc, char **cargv) {
   controlwall(NO_OPER, NL_TRUSTS, "Comment: %s for trustgroup %lu", cargv[1], tg->id);
 
   return CMD_OK;
-
 }
 
+int trust_dotrustlog(void *source, int cargc, char **cargv) {
+  nick *np=source;
+  unsigned long interval;
+  int trustid; 
+
+  if (cargc < 1) {
+    controlreply(np,"Syntax: trustlog <#groupid> [duration]");
+    return CMD_ERROR;
+  }
+
+  if(cargv[0][0]== '#'){
+    trustid = strtol(&cargv[0][1],NULL,10);
+  } else {
+    trustid = strtol(cargv[0],NULL,10);
+  }
+
+  if (cargc > 1)
+    interval=getnettime() - durationtolong(cargv[1]);
+  else
+    interval=0;
+
+  trustsdb_retrievetrustlog(np, trustid, interval);
+  return CMD_OK;
+}
index df3e8fd4b6c449d090192852cc47d2edb1df2dd6..118e5cce5dffa12d5f13660014a3368611ac0c39 100644 (file)
@@ -8,6 +8,8 @@
 
 int trustdb_loaded = 0;
 
+static void trusts_dbtriggerdbloaded(void *arg);
+
 int trusts_load_db(void) {
   if(!dbconnected()) {
     Error("trusts", ERR_STOP, "Could not connect to database.");
@@ -23,8 +25,14 @@ int trusts_load_db(void) {
 
   dbasyncquery(trusts_loadtrustgroups, NULL,
     "SELECT trustid,maxusage,maxclones,maxperident,maxperip,enforceident,startdate,lastused,expires,owneruserid,type,created,modified FROM trusts.groups WHERE enddate = 0");
+  dbasyncquery(trusts_loadtrustgroupsmax, NULL,
+    "SELECT max(trustid) from trusts.groups");
+
   dbasyncquery(trusts_loadtrusthosts, NULL,
     "SELECT * FROM trusts.hosts WHERE enddate = 0");
+  dbasyncquery(trusts_loadtrusthostsmax, NULL,
+    "SELECT max(hostid) FROM trusts.hosts");
+
   dbasyncquery(trusts_loadtrustblocks, NULL,
     "SELECT * FROM trusts.blocks");
 
@@ -58,7 +66,7 @@ void trusts_create_tables(void) {
     "trustid    INT4 NOT NULL,"
     "startdate  INT4 NOT NULL,"
     "enddate    INT4,"
-    "host       INET NOT NULL,"
+    "host       VARCHAR NOT NULL,"
     "maxusage   INT4 NOT NULL,"
     "lastused   INT4,"
     "expires    INT4 NOT NULL,"
@@ -70,7 +78,7 @@ void trusts_create_tables(void) {
   dbcreatequery(
     "CREATE TABLE trusts.blocks ("
     "blockid        INT4 NOT NULL PRIMARY KEY,"
-    "block          INET NOT NULL,"
+    "block          VARCHAR NOT NULL,"
     "owner          INT4,"
     "expires        INT4,"
     "startdate      INT4,"
@@ -136,7 +144,31 @@ void trusts_loadtrustgroups(DBConn *dbconn, void *arg) {
     rows++;
   }
 
-  Error("trusts",ERR_INFO,"Loaded %d trusts (highest ID was %lu)",rows,trusts_lasttrustgroupid);
+  Error("trusts",ERR_INFO,"Loaded %d trusts (highest ID was %lu)",rows,trusts_lasttrustgroupid); 
+
+  dbclear(pgres);
+}
+
+void trusts_loadtrustgroupsmax(DBConn *dbconn, void *arg) {
+  DBResult *pgres = dbgetresult(dbconn);
+  unsigned long trustmax = 0;
+
+  if(!dbquerysuccessful(pgres)) {
+    Error("trusts", ERR_ERROR, "Error loading trustgroup max.");
+    dbclear(pgres);
+    return;
+  }
+
+  while(dbfetchrow(pgres)) {
+    trustmax = strtoul(dbgetvalue(pgres,0),NULL,10);
+  }
+
+  if ( trustmax < trusts_lasttrustgroupid ) {
+    Error("trusts",ERR_INFO,"trust max failed - %lu, %lu", trustmax, trusts_lasttrustgroupid);
+  }
+  trusts_lasttrustgroupid = trustmax;
+
+  Error("trusts",ERR_INFO,"Loaded Trust Max %lu", trusts_lasttrustgroupid);
 
   dbclear(pgres);
 }
@@ -160,7 +192,11 @@ void trusts_loadtrusthosts(DBConn *dbconn, void *arg) {
 
   while(dbfetchrow(pgres)) {
     /*node*/
-    ipmask_parse(dbgetvalue(pgres,4), &sin, &bits);
+    if( ipmask_parse(dbgetvalue(pgres,4), &sin, &bits) == 0) {
+      Error("trusts", ERR_ERROR, "Failed to parse trusthost: %s", dbgetvalue(pgres,4));
+      continue;
+    }
+
     node  = refnode(iptree, &sin, bits);
 
     /*tg*/
@@ -168,6 +204,11 @@ void trusts_loadtrusthosts(DBConn *dbconn, void *arg) {
     tg=findtrustgroupbyid(tgid);
     if (!tg) { 
       Error("trusts", ERR_ERROR, "Error loading trusthosts - invalid group: %d.", tgid);
+
+      /* update last hostid - although we probably should fail here more loudly */
+      if(t->id > trusts_lasttrusthostid)
+        trusts_lasttrusthostid = t->id;
+
       continue;
     }
 
@@ -199,6 +240,30 @@ void trusts_loadtrusthosts(DBConn *dbconn, void *arg) {
   dbclear(pgres);
 }
 
+void trusts_loadtrusthostsmax(DBConn *dbconn, void *arg) {
+  DBResult *pgres = dbgetresult(dbconn);
+  unsigned long trustmax = 0;
+
+  if(!dbquerysuccessful(pgres)) {
+    Error("trusts", ERR_ERROR, "Error loading trusthost max.");
+    dbclear(pgres);
+    return;
+  }
+
+  while(dbfetchrow(pgres)) {
+    trustmax = strtoul(dbgetvalue(pgres,0),NULL,10);
+  }
+
+  if ( trustmax < trusts_lasttrusthostid ) {
+    Error("trusts", ERR_FATAL, "trusthost max failed - %lu, %lu", trustmax, trusts_lasttrusthostid);
+  }
+  trusts_lasttrusthostid = trustmax;
+
+  Error("trusts",ERR_INFO,"Loaded Trust Host Max %lu", trusts_lasttrusthostid);
+
+  dbclear(pgres);
+}
+
 void trusts_loadtrustblocks(DBConn *dbconn, void *arg) {
   DBResult *pgres = dbgetresult(dbconn);
   int rows=0;
@@ -217,7 +282,10 @@ void trusts_loadtrustblocks(DBConn *dbconn, void *arg) {
 
   while(dbfetchrow(pgres)) {
     /*node*/
-    ipmask_parse(dbgetvalue(pgres,1), &sin, &bits);
+    if( ipmask_parse(dbgetvalue(pgres,1), &sin, &bits) == 0) {
+      Error("trusts", ERR_ERROR, "Failed to parse trustblock: %s", dbgetvalue(pgres,1));
+      continue;
+    } 
     node  = refnode(iptree, &sin, bits);
 
     t = createtrustblockfromdb(
@@ -247,9 +315,12 @@ void trusts_loadtrustblocks(DBConn *dbconn, void *arg) {
   dbclear(pgres);
   
   trusts_loaded = 1;
-  triggerhook(HOOK_TRUSTS_DBLOADED, NULL);
+  scheduleoneshot(time(NULL), trusts_dbtriggerdbloaded, NULL);
 }
 
+static void trusts_dbtriggerdbloaded(void *arg) {
+  triggerhook(HOOK_TRUSTS_DBLOADED, NULL);
+}
 
 /* trust group */
 void trustsdb_addtrustgroup(trustgroup_t *t) {
@@ -307,3 +378,65 @@ void trustsdb_logmessage(trustgroup_t *tg, unsigned long userid, int type, char
   dbescapestring(escmessage,message, strlen(message)); 
   dbquery("INSERT INTO trusts.log (trustid, timestamp, userid, type, message) VALUES ( %lu, %lu, %lu, %d, '%s')", tg->id, getnettime(), userid, type, escmessage);
 }
+
+void trust_dotrustlog_real(DBConn *dbconn, void *arg) {
+  nick *np=getnickbynumeric((unsigned long)arg);
+  DBResult *pgres;
+  unsigned long logid, trustid, userid, type;
+  time_t timestamp;
+  char *message;
+  char timebuf[30];
+  int header=0;
+
+  if(!dbconn)
+    return;
+
+  pgres=dbgetresult(dbconn);
+
+  if (!dbquerysuccessful(pgres)) {
+    Error("trusts", ERR_ERROR, "Error loading trusts log data.");
+    dbclear(pgres);
+    return;
+  }
+
+ if (dbnumfields(pgres) != 6) {
+    Error("trusts", ERR_ERROR, "trusts log data format error.");
+    dbclear(pgres);
+    return;
+  }
+
+  if (!np) {
+    dbclear(pgres);
+    return;
+  }
+
+  while(dbfetchrow(pgres)) {
+    logid=strtoul(dbgetvalue(pgres, 0), NULL, 10);
+    trustid=strtoul(dbgetvalue(pgres, 1), NULL, 10);
+    timestamp=strtoul(dbgetvalue(pgres, 2), NULL, 10);
+    userid=strtoul(dbgetvalue(pgres, 3), NULL, 10);
+    type=strtoul(dbgetvalue(pgres, 4), NULL, 10);
+    message=dbgetvalue(pgres, 5);
+
+    if (!header) {
+      header=1;
+      controlreply(np, "Display trustlog for trust %lu", trustid); 
+      controlreply(np, "ID  Time           OperID  Type Message"); 
+    }
+    strftime(timebuf, 30, "%d/%m/%y %H:%M", localtime(&timestamp));
+    controlreply(np, "%-3lu %s %-7lu %-2lu   %s", logid, timebuf, userid, type, message);  
+  }
+
+  if (!header) {
+    controlreply(np, "No trust log entries found."); 
+  } else {
+    controlreply(np, "End Of List.");
+  }
+  dbclear(pgres);
+}
+
+
+void trustsdb_retrievetrustlog(nick *np, unsigned int trustid, time_t starttime) {
+  dbasyncquery(trust_dotrustlog_real, (void *)np->numeric, "SELECT * FROM trusts.log WHERE trustid=%u AND timestamp>%lu order by timestamp desc limit 1000", trustid, starttime);
+  Error("trusts", ERR_ERROR, "SELECT * FROM trusts.log WHERE trustid=%u AND timestamp>%lu order by timestamp desc limit 1000", trustid, starttime);
+}
index fa0c15f8099360f1ce9537139861577b85433d02..f2f9cfb750ef2f502030bf76600e89849032a281 100644 (file)
@@ -7,6 +7,10 @@ void trusts_hook_newuser(int hook, void *arg) {
   trustgroup_t *tg = NULL;
   patricia_node_t *parent;
 
+  if (trusts_ignore_np(np)) {
+    return;
+  }
+
   if(np->ipnode->exts[tgh_ext]) {
     /* we have a new user on a trust group host */
     tgh = (trusthost_t *)np->ipnode->exts[tgh_ext];
@@ -79,6 +83,10 @@ void trusts_hook_newuser(int hook, void *arg) {
     }
     /* Trust Checks Passed: OK - increment counters */
     increment_trust_ipnode(np->ipnode);
+
+    /* set nick extension for user for future use */
+    np->exts[tgn_ext] = tgh; 
+
     return;
   }
   /* non trusted user - OK */
@@ -101,6 +109,10 @@ void trusts_hook_lostuser(int hook, void *arg) {
     Error("nodecount", ERR_ERROR, "np->ipnode->exts was NULL");
   }
 
+  if (trusts_ignore_np(np)) {
+    return;
+  }
+
   decrement_trust_ipnode(np->ipnode);
 
   if(np->ipnode->exts[tgh_ext]) {
@@ -123,5 +135,8 @@ void trusts_hook_lostuser(int hook, void *arg) {
       decrement_ident_count(np, tg);
     }
   }
+
+  /* clear nick extension */
+  np->exts[tgn_ext] = NULL;
 }
 
index dc7059afcc6841d869f6f58319236be75ae562c2..bbdc6b64f70500fcaca005f1d2739b1c9e4c7c8a 100644 (file)
@@ -31,6 +31,7 @@ trusthost_t *createtrusthost(unsigned long id, patricia_node_t* node, time_t exp
 void trusthost_free(trusthost_t* t)
 {
   trusts_removetrusthostfromhash(t);
+
   derefnode(iptree,t->node);
   freetrusthost(t);
 }
@@ -44,6 +45,7 @@ trusthost_t* trusthostadd(patricia_node_t *node, trustgroup_t* tg, time_t expire
   time_t timenow;
 
   if(!tgh) {
+    Error("trusts", ERR_FATAL, "trusthostadd failed to createtrusthost");
     return NULL;
   }
 
@@ -61,6 +63,9 @@ trusthost_t* trusthostadd(patricia_node_t *node, trustgroup_t* tg, time_t expire
     if (pnp ) {
       for (i = 0; i < PATRICIANICK_HASHSIZE; i++) {
         for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) {
+          if (trusts_ignore_np(np)) {
+            continue;
+          }
           increment_ident_count(np, tg);
         }
       }
@@ -90,7 +95,11 @@ void trusthost_addcounters(trusthost_t* tgh) {
     if (pnp ) {
       for (i = 0; i < PATRICIANICK_HASHSIZE; i++) {
         for (np = pnp->identhash[i]; np; np=np->exts[pnick_ext]) {
+          if (trusts_ignore_np(np)) {
+            continue;
+          }
           increment_ident_count(np, tg);
+          np->exts[tgn_ext] = tgh;
         }
       }
     }
index d4a9be1345f497a9491f3037f1fb2f3c78009b2e..7c0c042bb1175f492c070620142264d9525a263c 100644 (file)
@@ -3,7 +3,7 @@
 trustgroupidentcount_t *getnewtrustgroupidentcount(trustgroup_t *tg, char *ident) {
   trustgroupidentcount_t *tgic = newtrustgroupidentcount();
   tgic->ident = getsstring(ident,USERLEN);
-  tgic->currenton = 1;
+  tgic->currenton = 1; 
   tgic->trustgroup = tg;
 
   trusts_addtrustgroupidenttohash(tgic);