]> jfr.im git - irc/quakenet/newserv.git/commitdiff
trustscommands as seperate module
authorPaul <redacted>
Sun, 5 Oct 2008 10:01:03 +0000 (11:01 +0100)
committerPaul <redacted>
Sun, 5 Oct 2008 10:01:03 +0000 (11:01 +0100)
--HG--
branch : paul

core/hooks.h
trusts2/Makefile.in
trusts2/trusts.c
trusts2/trusts.h
trusts2/trusts_commands.c [moved from trusts2/trustscmd.c with 98% similarity]
trusts2/trusts_db.c
trusts2/trusts_handlers.c
trusts2/trusts_ident.c
trusts_newsearch/formats.c

index ced5f689f7507c8451a42b6417645f3e80445047..424e7a03ef0e3f30ba19255257df57af363a2b77 100644 (file)
@@ -88,6 +88,8 @@
 #define HOOK_TRUSTS_MODIFYGROUP    910 /* Argument is trustgroup* */
 #define HOOK_TRUSTS_LOSTHOST       911 /* Argument is trusthost* */
 
+#define HOOK_TRUSTS_DBLOADED       1000
+
 #define PRIORITY_DEFAULT           0
 
 #define PRIORITY_MAX               LONG_MIN
index 65a1cb7b0cffd852d702ba41c183df0a3ee41e58..5eb5ce61ad572192419211c957d3c60ae677c4a6 100644 (file)
@@ -5,6 +5,8 @@ LDFLAGS+=$(LIBDBAPI)
 
 .PHONY: all
 
-all: trusts.so
+all: trusts.so trusts_commands.so
 
-trusts.so: trusts_ident.o trusts_hosts.o trusts_groups.o trusts_alloc.o trusts.o trusts_handlers.o trusts_hash.o trusts_db.o trustscmd.o
+trusts.so: trusts_ident.o trusts_hosts.o trusts_groups.o trusts_alloc.o trusts.o trusts_handlers.o trusts_hash.o trusts_db.o
+trusts_commands.so: trusts_commands.o
index 417e9d344c603e6cb4560900c7b3887f8e52963c..ee1eb3158a62fdb7747e0529f99ddc5ada25ff20 100644 (file)
@@ -5,9 +5,14 @@
 #include "../core/nsmalloc.h"
 
 int tgh_ext;
-static int trusts_loaded;
+unsigned long trusts_lasttrustgroupid;
+unsigned long trusts_lasttrusthostid;
+unsigned long trusts_lasttrustblockid;
+int trusts_loaded;
+int removeusers = 0;
 
 static void trusts_status(int hooknum, void *arg);
+void trustsfinishinit(int hooknum, void *arg);
 
 void _init(void) {
   trusts_hash_init();
@@ -21,9 +26,17 @@ void _init(void) {
   if ( !trusts_load_db()) {
     return;
   }
-  trusts_loaded = 1;
  
-  trusts_cmdinit();
+  registerhook(HOOK_TRUSTS_DBLOADED, trustsfinishinit);
+
+  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);
@@ -43,8 +56,6 @@ void _fini(void) {
   releasenodeext(tgh_ext); 
 
   if ( trusts_loaded ) {
-    trusts_cmdfini();
-
     deregisterhook(HOOK_NICK_NEWNICK, &trusts_hook_newuser);
     deregisterhook(HOOK_NICK_LOSTNICK, &trusts_hook_lostuser);
 
index 4b96f09da13da740e80a32e821cb956a2f3ac7c9..d208564289766672f4ea6f7d4dbcdfa848d68792 100644 (file)
@@ -27,6 +27,8 @@
 #define TRUSTS_MAXGROUPNAMELEN 20
 
 extern int tgh_ext;
+extern int removeusers;
+extern int trusts_loaded;
 
 typedef struct trusthost_s {
         /* Details */
@@ -124,7 +126,7 @@ trustgroupidentcount_t* findtrustgroupcountbyident(char *ident, trustgroup_t *t)
 
 trustgroupidentcount_t *getnewtrustgroupidentcount(trustgroup_t *tg, char *ident);
 
-unsigned long trusts_lasttrustgroupid, trusts_lasttrusthostid, trusts_lasttrustblockid;
+extern unsigned long trusts_lasttrustgroupid, trusts_lasttrusthostid, trusts_lasttrustblockid;
 
 void trust_debug(char *format, ...);
 
similarity index 98%
rename from trusts2/trustscmd.c
rename to trusts2/trusts_commands.c
index c271617f4d6c05b81708a0ba3b262819fb9e6002..f3cbf4d088bb1ae76caa2ca81b5c01547a0fdb97 100644 (file)
@@ -4,8 +4,24 @@
 #include "../control/control.h"
 #include "trusts.h"
 #include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
 
-void trusts_cmdinit() {
+void _init(void) {
+  registerhook(HOOK_TRUSTS_DBLOADED, trusts_cmdinit);
+
+  /* Now that the database is in a separate module it might be loaded already. */
+  if (trusts_loaded)
+    trusts_cmdinit(HOOK_TRUSTS_DBLOADED, NULL);
+
+}
+
+void _fini(void) {
+  deregisterhook(HOOK_TRUSTS_DBLOADED, trusts_cmdinit);
+  trusts_cmdfini();
+}
+
+void trusts_cmdinit(int hooknum, void *arg) {
   registercontrolcmd("trustgroupadd",10,7,trust_groupadd);
   registercontrolcmd("trustgroupmodify",10,4,trust_groupmodify);
   registercontrolcmd("trustgroupdel",10,2,trust_groupdel);
@@ -21,6 +37,8 @@ void trusts_cmdinit() {
 
   registercontrolcmd("truststats",10,2,trust_stats);
   registercontrolcmd("trustdump",10,2,trust_dump);
+
+  removeusers = 1;
 }
 
 void trusts_cmdfini() {
@@ -39,6 +57,8 @@ void trusts_cmdfini() {
 
   deregistercontrolcmd("truststats",trust_stats);
   deregistercontrolcmd("trustdump",trust_dump);
+
+  removeusers = 0;
 }
 
 /*TODO*/
index 4d5a07b767f61032c20c8177536e473037ae65aa..ab162de0db89a43691e40eb0ba14f15d51cc7299 100644 (file)
@@ -226,6 +226,9 @@ void trusts_loadtrustblocks(DBConn *dbconn, void *arg) {
   Error("trusts",ERR_INFO,"Loaded %d trustblocks (highest ID was %lu)",rows,trusts_lasttrustblockid);
 
   dbclear(pgres);
+  
+  trusts_loaded = 1;
+  triggerhook(HOOK_TRUSTS_DBLOADED, NULL);
 }
 
 
index 8efd4e7af6d1cf505c349f0f300decf680647224..fa0c15f8099360f1ce9537139861577b85433d02 100644 (file)
@@ -55,20 +55,20 @@ void trusts_hook_newuser(int hook, void *arg) {
     tg = tgh->trustgroup;
     if(((((int)(np->ipnode->usercount))) > tg->maxperip) && tg->maxperip ) {
       /* user exceed ip trust limit - disconnect */
-      controlwall(NO_OPER, NL_TRUSTS, "KILL TG %lu: Exceeding IP limit (%d / %d) for %s!%s@%s", tg->id, (((int)(np->ipnode->usercount))), tg->maxperip, np->nick, np->ident, np->host->name->content);
+      controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Exceeding IP limit (%d / %d) for %s!%s@%s (%s)", tg->id, (((int)(np->ipnode->usercount))), tg->maxperip, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
       //killuser(NULL, np, "USER: Exceeding IP Limit.");
     }
     if( tg->maxclones >0 ) {
       if( (tg->currenton + 1) > tg->maxclones) {
         /* user exceeds trust group limit - disconnect */
         //killuser(NULL, np, "USER: Exceeding Trustgroup Limit.");
-        controlwall(NO_OPER, NL_TRUSTS, "KILL TG %lu: Exceeding trustgroup limit (%d / %d) for %s!%s@%s",tg->id, (tg->currenton + 1), tg->maxclones, np->nick, np->ident, np->host->name->content);
+        controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Exceeding trustgroup limit (%d / %d) for %s!%s@%s (%s)",tg->id, (tg->currenton + 1), tg->maxclones, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
       }
     }
     if ( np->ident[0] == '~')  {
       /* non-ident user */
       if (tg->enforceident ) {
-        controlwall(NO_OPER, NL_TRUSTS, "KILL TG %lu: Ident Required for %s!%s@%s", tg->id, np->nick, np->ident, np->host->name->content);
+        controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Ident Required for %s!%s@%s (%s)", tg->id, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
         //killuser(NULL, np, "USER: Ident Required From Your Host.");
         /*TODO: add short gline here - ~*@%s - "IDENTD required from your host", "MissingIDENT" */
       }
index 448cd55d1c4010fae104912188f8d561cb202e49..d4a9be1345f497a9491f3037f1fb2f3c78009b2e 100644 (file)
@@ -16,7 +16,7 @@ void increment_ident_count(nick *np, trustgroup_t *tg) {
   if(identcnt) {
     /* ident exists */
     if( tg->maxperident && (identcnt->currenton+1) > tg->maxperident) {
-      trust_debug("NEWNICK TRUSTED BAD USER: Exceeding User (%s) Ident Limit (%d/%d)",np->ident, identcnt->currenton+1, tg->maxperident);
+      controlwall(NO_OPER, NL_TRUSTS, "TG %lu: Exceeded Ident Limit (%d/%d) for %s!%s@%s (%s)",tg->id, identcnt->currenton+1, tg->maxperident, np->nick, np->ident, np->host->name->content, removeusers == 1 ? "disconnected": "ignored");
       //killuser(NULL, np, "USER: Exceeding User Ident Limit.");
     }
     identcnt->currenton++;
index 0133736a307e8ec38a81297221bf0504d5be6c61..9595609051d6897c2a6bde64c7deb01e91ed533e 100644 (file)
@@ -3,7 +3,7 @@
 #include "../newsearch/newsearch.h"
 #include "../control/control.h"
 #include "../lib/stringbuf.h"
-#include "../trusts/trusts.h"
+#include "../trusts2/trusts.h"
 
 void printtrust_group(searchCtx *ctx, nick *sender, patricia_node_t *node) {
   trusthost_t *tgh = node->exts[tgh_ext];