From: Paul Date: Thu, 1 Jan 2009 23:43:08 +0000 (+0000) Subject: trusts changes X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/0ac8476dedc12fb3f91b567fe0c17a95e3e51ad6?ds=sidebyside trusts changes --HG-- branch : paul --- diff --git a/trusts_newsearch/Makefile.in b/trusts_newsearch/Makefile.in index e40294e0..09cd2163 100644 --- a/trusts_newsearch/Makefile.in +++ b/trusts_newsearch/Makefile.in @@ -8,5 +8,5 @@ LDFLAGS+=$(LIBDBAPI) all: trusts_newsearch.so -trusts_newsearch.so: formats.o tsns-ownerid.o tsns-tgmaxperident.o tsns-thcreated.o tsns-thmodified.o trusts_newsearch.o tsns-tgcreated.o tsns-tgmaxperip.o tsns-thexpire.o tsns-thstartdate.o tsns-currenton.o tsns-tgexpire.o tsns-tgmaxusage.o tsns-thid.o tsns-trusted.o tsns-enforceident.o tsns-tgid.o tsns-tgmodified.o tsns-thlastused.o tsns-maxclones.o tsns-tglastused.o tsns-tgstartdate.o tsns-thmaxusage.o +trusts_newsearch.so: formats.o tsns-ownerid.o tsns-tgmaxperident.o tsns-thcreated.o tsns-thmodified.o trusts_newsearch.o tsns-tgcreated.o tsns-tgmaxperip.o tsns-thexpire.o tsns-thstartdate.o tsns-currenton.o tsns-tgexpire.o tsns-tgmaxusage.o tsns-thid.o tsns-trusted.o tsns-enforceident.o tsns-tgid.o tsns-tgmodified.o tsns-thlastused.o tsns-maxclones.o tsns-tglastused.o tsns-tgstartdate.o tsns-thmaxusage.o tsns-tbid.o tsns-istrusted.o trusts_searchcommands.o diff --git a/trusts_newsearch/formats.c b/trusts_newsearch/formats.c index 95956090..9504ad4f 100644 --- a/trusts_newsearch/formats.c +++ b/trusts_newsearch/formats.c @@ -11,9 +11,28 @@ void printtrust_group(searchCtx *ctx, nick *sender, patricia_node_t *node) { if (tgh) { tg = tgh->trustgroup; - ctx->reply(sender,"%s | [%lu] | %lu/%lu", IPtostr(node->prefix->sin), tg->id, tg->currenton, tg->maxusage); + ctx->reply(sender,"%s/%d | [%lu] | %lu/%lu", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)), tg->id, tg->currenton, tg->maxusage); } else { - ctx->reply(sender,"%s | ", IPtostr(node->prefix->sin)); + ctx->reply(sender,"%s/%d | ", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen))); } } +void printtrust_block(searchCtx *ctx, nick *sender, patricia_node_t *node) { + trustblock_t *tb = node->exts[tgb_ext]; + + if (tb) { + ctx->reply(sender,"%s/%d | [%lu] | %s", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)), tb->id, tb->reason_public ? tb->reason_public->content : ""); + } else { + ctx->reply(sender,"%s/%d | ", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen))); + } +} + +void printtrust_blockprivate(searchCtx *ctx, nick *sender, patricia_node_t *node) { + trustblock_t *tb = node->exts[tgb_ext]; + + if (tb) { + ctx->reply(sender,"%s/%d | [%lu] | %s", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen)), tb->id, tb->reason_private ? tb->reason_private->content : ""); + } else { + ctx->reply(sender,"%s/%d | ", IPtostr(node->prefix->sin), irc_bitlen(&(node->prefix->sin),(node->prefix->bitlen))); + } +} diff --git a/trusts_newsearch/trusts_newsearch.c b/trusts_newsearch/trusts_newsearch.c index 14997181..ac52f904 100644 --- a/trusts_newsearch/trusts_newsearch.c +++ b/trusts_newsearch/trusts_newsearch.c @@ -3,11 +3,13 @@ #include #include "trusts_newsearch.h" -#include "../trusts/trusts.h" +#include "../trusts2/trusts.h" void _init(void) { regdisp(reg_nodesearch, "tg", printtrust_group, 0, ""); + regdisp(reg_nodesearch, "tb", printtrust_block, 0, ""); + regdisp(reg_nodesearch, "tbprivate", printtrust_blockprivate, 0, ""); /* TRUSTGROUP */ registersearchterm(reg_tgsearch, "tgid", tsns_tgid_parse, 0, "Trustgroup ID"); @@ -54,10 +56,19 @@ void _init(void) { registersearchterm(reg_nodesearch, "thcreated", tsns_thcreated_parse, 0, "trust host creation timestamp (note: we also store a startdate timestamp)"); registersearchterm(reg_nodesearch, "thmodified", tsns_thmodified_parse, 0, "trust host last modified timestamp"); + registersearchterm(reg_nodesearch, "tbid", tsns_tbid_parse, 0, "Trust Block ID"); + + registersearchterm(reg_nicksearch, "istrusted", tsns_istrusted_parse, 0, "user is on a trusted host"); + + registercontrolhelpcmd("trustlist",10,1,tsns_dotrustlist, "Usage: trustlist "); + registercontrolhelpcmd("trustdenylist",10,1,tsns_dotrustdenylist, "Usage: trustdenylist "); + } void _fini(void) { unregdisp(reg_nodesearch, "tg", printtrust_group); + unregdisp(reg_nodesearch, "tb", printtrust_block); + unregdisp(reg_nodesearch, "tbprivate", printtrust_blockprivate); deregistersearchterm(reg_tgsearch, "tgid", tsns_tgid_parse); deregistersearchterm(reg_tgsearch, "tgstartdate", tsns_tgstartdate_parse); @@ -103,5 +114,11 @@ void _fini(void) { deregistersearchterm(reg_nodesearch, "thcreated", tsns_thcreated_parse); deregistersearchterm(reg_nodesearch, "thmodified", tsns_thmodified_parse); + deregistersearchterm(reg_nodesearch, "tbid", tsns_tbid_parse); + + deregistersearchterm(reg_nicksearch, "istrusted", tsns_istrusted_parse); + + deregistercontrolcmd("trustlist",tsns_dotrustlist); + } diff --git a/trusts_newsearch/trusts_newsearch.h b/trusts_newsearch/trusts_newsearch.h index 4d937de4..852c8351 100644 --- a/trusts_newsearch/trusts_newsearch.h +++ b/trusts_newsearch/trusts_newsearch.h @@ -2,10 +2,12 @@ #define __TRUSTS_NEWSEARCH_H #include "../patriciasearch/patriciasearch.h" -#include "../trusts/trusts.h" +#include "../trusts2/trusts.h" #include "../trusts_search/trusts_search.h" void printtrust_group(searchCtx *ctx, nick *sender, patricia_node_t *node); +void printtrust_block(searchCtx *ctx, nick *sender, patricia_node_t *node); +void printtrust_blockprivate(searchCtx *ctx, nick *sender, patricia_node_t *node); struct searchNode *tsns_trusted_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *tsns_tgid_parse(searchCtx *ctx, int argc, char **argv); @@ -30,4 +32,11 @@ struct searchNode *tsns_thmaxusage_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *tsns_thmodified_parse(searchCtx *ctx, int argc, char **argv); struct searchNode *tsns_thstartdate_parse(searchCtx *ctx, int argc, char **argv); +struct searchNode *tsns_tbid_parse(searchCtx *ctx, int argc, char **argv); + +struct searchNode *tsns_istrusted_parse(searchCtx *ctx, int argc, char **argv); + +int tsns_dotrustlist(void *source, int cargc, char **cargv); +int tsns_dotrustdenylist(void *source, int cargc, char **cargv); + #endif diff --git a/trusts_newsearch/trusts_searchcommands.c b/trusts_newsearch/trusts_searchcommands.c new file mode 100644 index 00000000..fc3656a3 --- /dev/null +++ b/trusts_newsearch/trusts_searchcommands.c @@ -0,0 +1,59 @@ +#include "trusts_newsearch.h" +#include "../newsearch/newsearch.h" + +static void tsnsmessagewrapper(nick *np, char *format, ...) { + char buf[1024]; + va_list ap; + + va_start(ap, format); + vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + + controlreply(np, "%s", buf); +} + +static void tsnswallwrapper(int level, char *format, ...) { + char buf[1024]; + va_list ap; + + va_start(ap, format); + vsnprintf(buf, sizeof(buf), format, ap); + va_end(ap); + + controlwall(NO_OPER, level, "%s", buf); +} + +int tsns_dotrustlist(void *source, int cargc, char **cargv) { + searchASTExpr tree; + searchASTExpr nodes[2]; + + if(cargc < 1) { + controlreply(source,"Syntax: trustlist <#groupid>"); + return CMD_ERROR; + } + + if(cargv[0][0]== '#'){ + tree = NSASTNode(eq_parse, NSASTNode(tsns_tgid_parse), NSASTLiteral(&cargv[0][1])); + } else { + tree = NSASTNode(eq_parse, NSASTNode(tsns_tgid_parse), NSASTLiteral(cargv[0])); + } + +// nodes[0] = NSASTNode(tsns_tgid_parse); +// nodes[1] = cargv[0]; +// tree = +// NSASTManualNode(eq_parse, 2, nodes +// ); + return ast_tgsearch(&tree, tsnsmessagewrapper , source, tsnswallwrapper, printtgfull, NULL, NULL, 1); +} + +int tsns_dotrustdenylist(void *source, int cargc, char **cargv) { + searchASTExpr tree; + + tree = NSASTNode(gt_parse, NSASTNode(tsns_tbid_parse), NSASTLiteral("0")); + + if(cargc == 1){ /* just assume -private */ + return ast_nodesearch(&tree, tsnsmessagewrapper , source, tsnswallwrapper, printtrust_blockprivate, NULL, NULL, 500); + } else { + return ast_nodesearch(&tree, tsnsmessagewrapper , source, tsnswallwrapper, printtrust_block, NULL, NULL, 500); + } +} diff --git a/trusts_newsearch/tsns-istrusted.c b/trusts_newsearch/tsns-istrusted.c new file mode 100644 index 00000000..d9b51c67 --- /dev/null +++ b/trusts_newsearch/tsns-istrusted.c @@ -0,0 +1,38 @@ +#include "trusts_newsearch.h" + +#include +#include + +void *tsns_istrusted_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void tsns_istrusted_free(searchCtx *ctx, struct searchNode *thenode); + +struct searchNode *tsns_istrusted_parse(searchCtx *ctx, int argc, char **argv) { + struct searchNode *thenode; + + if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { + parseError = "malloc: could not allocate memory for this search."; + return NULL; + } + + thenode->returntype = RETURNTYPE_BOOL; + thenode->localdata = NULL; + thenode->exe = tsns_istrusted_exe; + thenode->free = tsns_istrusted_free; + + return thenode; +} + +void *tsns_istrusted_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { + nick *np = theinput; + + trusthost_t *tgh = np->exts[tgn_ext]; + + if (!tgh) + return (void *)0; + + return (void *)1; +} + +void tsns_istrusted_free(searchCtx *ctx, struct searchNode *thenode) { + free(thenode); +} diff --git a/trusts_newsearch/tsns-tbid.c b/trusts_newsearch/tsns-tbid.c new file mode 100644 index 00000000..b5d1beed --- /dev/null +++ b/trusts_newsearch/tsns-tbid.c @@ -0,0 +1,37 @@ +#include "trusts_newsearch.h" + +#include +#include + +void *tsns_tbid_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void tsns_tbid_free(searchCtx *ctx, struct searchNode *thenode); + +struct searchNode *tsns_tbid_parse(searchCtx *ctx, int argc, char **argv) { + struct searchNode *thenode; + + if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { + parseError = "malloc: could not allocate memory for this search."; + return NULL; + } + + thenode->returntype = RETURNTYPE_INT; + thenode->localdata = NULL; + thenode->exe = tsns_tbid_exe; + thenode->free = tsns_tbid_free; + + return thenode; +} + +void *tsns_tbid_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { + patricia_node_t *node; + + node = (patricia_node_t *)theinput; + if (node->exts[tgb_ext] != NULL) + return (void *)(((trustblock_t *)node->exts[tgb_ext])->id); + else + return (void *)0; /* will cast to a FALSE */ +} + +void tsns_tbid_free(searchCtx *ctx, struct searchNode *thenode) { + free(thenode); +}