From: Paul Date: Sun, 5 Oct 2008 10:01:03 +0000 (+0100) Subject: trustscommands as seperate module X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/9a8ffb84639404f58fa47be88baae000a3b8866f trustscommands as seperate module --HG-- branch : paul --- diff --git a/core/hooks.h b/core/hooks.h index ced5f689..424e7a03 100644 --- a/core/hooks.h +++ b/core/hooks.h @@ -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 diff --git a/trusts2/Makefile.in b/trusts2/Makefile.in index 65a1cb7b..5eb5ce61 100644 --- a/trusts2/Makefile.in +++ b/trusts2/Makefile.in @@ -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 + diff --git a/trusts2/trusts.c b/trusts2/trusts.c index 417e9d34..ee1eb315 100644 --- a/trusts2/trusts.c +++ b/trusts2/trusts.c @@ -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); diff --git a/trusts2/trusts.h b/trusts2/trusts.h index 4b96f09d..d2085642 100644 --- a/trusts2/trusts.h +++ b/trusts2/trusts.h @@ -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, ...); diff --git a/trusts2/trustscmd.c b/trusts2/trusts_commands.c similarity index 98% rename from trusts2/trustscmd.c rename to trusts2/trusts_commands.c index c271617f..f3cbf4d0 100644 --- a/trusts2/trustscmd.c +++ b/trusts2/trusts_commands.c @@ -4,8 +4,24 @@ #include "../control/control.h" #include "trusts.h" #include +#include +#include -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*/ diff --git a/trusts2/trusts_db.c b/trusts2/trusts_db.c index 4d5a07b7..ab162de0 100644 --- a/trusts2/trusts_db.c +++ b/trusts2/trusts_db.c @@ -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); } diff --git a/trusts2/trusts_handlers.c b/trusts2/trusts_handlers.c index 8efd4e7a..fa0c15f8 100644 --- a/trusts2/trusts_handlers.c +++ b/trusts2/trusts_handlers.c @@ -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" */ } diff --git a/trusts2/trusts_ident.c b/trusts2/trusts_ident.c index 448cd55d..d4a9be13 100644 --- a/trusts2/trusts_ident.c +++ b/trusts2/trusts_ident.c @@ -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++; diff --git a/trusts_newsearch/formats.c b/trusts_newsearch/formats.c index 0133736a..95956090 100644 --- a/trusts_newsearch/formats.c +++ b/trusts_newsearch/formats.c @@ -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];