X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/24e572a95ac1b295c18a24c13da7b448a7eb2d22..3e1b768066a16c4b899b9cbdd7911be883151a05:/newsearch/ns-gline.c diff --git a/newsearch/ns-gline.c b/newsearch/ns-gline.c index 9c782192..f989633d 100644 --- a/newsearch/ns-gline.c +++ b/newsearch/ns-gline.c @@ -13,6 +13,7 @@ #include "../irc/irc.h" /* irc_send() */ #include "../lib/irc_string.h" /* IPtostr(), longtoduration(), durationtolong() */ #include "../lib/strlfunc.h" +#include "../glines/glines.h" /* used for *_free functions that need to warn users of certain things i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */ @@ -42,52 +43,73 @@ struct searchNode *gline_parse(searchCtx *ctx, int argc, char **argv) { localdata->marker = nextchanmarker(); else if (ctx->searchcmd == reg_nicksearch) localdata->marker = nextnickmarker(); + else if (ctx->searchcmd == reg_whowassearch) + localdata->marker = nextwhowasmarker(); else { + free(localdata); parseError = "gline: invalid search type"; return NULL; } - switch (argc) { - case 0: + /* default duration, default reason */ + if(argc == 0) { localdata->duration = NSGLINE_DURATION; strlcpy(localdata->reason, defaultreason, sizeof(localdata->reason)); - break; + } else if(argc > 2) { + free(localdata); + parseError = "gline: invalid number of arguments"; + return NULL; + } else { + char *argzerop, *reasonp, *durationp; + struct searchNode *durationsn, *reasonsn, *argzerosn; + + if (!(argzerosn=argtoconststr("gline", ctx, argv[0], &argzerop))) { + free(localdata); + return NULL; + } - case 1: - if (strchr(argv[0], ' ') == NULL) { /* no space == duration specified */ - localdata->duration = durationtolong(argv[0]); - /* error checking on gline duration */ - if (localdata->duration == 0) { - parseError = "gline duration invalid."; - free(localdata); - return NULL; + if(argc == 1) { + durationp = reasonp = NULL; + durationsn = reasonsn = NULL; + + /* if we have a space it's a reason */ + if(strchr(argzerop, ' ')) { + reasonsn = argzerosn; + reasonp = argzerop; + } else { + durationsn = argzerosn; + durationp = argzerop; } + } else { + durationsn = argzerosn; + durationp = argzerop; - strlcpy(localdata->reason, defaultreason, sizeof(localdata->reason)); + if (!(reasonsn=argtoconststr("gline", ctx, argv[1], &reasonp))) { + durationsn->free(ctx, durationsn); + free(localdata); + return NULL; + } } - else { /* reason specified */ - localdata->duration = NSGLINE_DURATION; - - strlcpy(localdata->reason, argv[0], sizeof(localdata->reason)); + + if(!reasonp) { + strlcpy(localdata->reason, defaultreason, sizeof(localdata->reason)); + } else { + strlcpy(localdata->reason, reasonp, sizeof(localdata->reason)); + reasonsn->free(ctx, reasonsn); } - break; - case 2: - localdata->duration = durationtolong(argv[0]); - /* error checking on gline duration */ - if (localdata->duration == 0) { - parseError = "gline duration invalid."; - free(localdata); - return NULL; + if(!durationp) { + localdata->duration = NSGLINE_DURATION; + } else { + localdata->duration = durationtolong(durationp); + durationsn->free(ctx, durationsn); + + if (localdata->duration == 0) { + parseError = "gline duration invalid."; + free(localdata); + return NULL; + } } - - strlcpy(localdata->reason, argv[1], sizeof(localdata->reason)); - - break; - default: - free(localdata); - parseError = "gline: invalid number of arguments"; - return NULL; } if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { @@ -109,31 +131,35 @@ void *gline_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { struct gline_localdata *localdata; nick *np; chanindex *cip; + whowas *ww; localdata = thenode->localdata; if (ctx->searchcmd == reg_chansearch) { cip = (chanindex *)theinput; cip->marker = localdata->marker; - localdata->count += cip->channel->users->totalusers; + if (cip->channel != NULL) + localdata->count += cip->channel->users->totalusers; } else { np = (nick *)theinput; - np->marker = localdata->marker; + if (ctx->searchcmd == reg_nicksearch) + np->marker = localdata->marker; + else { + ww = (whowas *)np->next; + ww->marker = localdata->marker; + } localdata->count++; } return (void *)1; } -static int glineuser(nick *np, struct gline_localdata *localdata, time_t ti) { +static int glineuser(glinebuf *gbuf, nick *np, struct gline_localdata *localdata, time_t ti) { char msgbuf[512]; if (!IsOper(np) && !IsService(np) && !IsXOper(np)) { nssnprintf(msgbuf, sizeof(msgbuf), localdata->reason, np); - if (np->host->clonecount <= NSMAX_GLINE_CLONES) - irc_send("%s GL * +*@%s %u %jd :%s", mynumeric->content, IPtostr(np->p_ipaddr), localdata->duration, (intmax_t)ti, msgbuf); - else - irc_send("%s GL * +%s@%s %u %jd :%s", mynumeric->content, np->ident, IPtostr(np->p_ipaddr), localdata->duration, (intmax_t)ti, msgbuf); + glinebufaddbynick(gbuf, np, 0, "newsearch", msgbuf, getnettime() + localdata->duration, getnettime(), getnettime() + localdata->duration); return 1; } @@ -144,8 +170,10 @@ void gline_free(searchCtx *ctx, struct searchNode *thenode) { struct gline_localdata *localdata; nick *np, *nnp; chanindex *cip, *ncip; - int i, j, safe=0; + whowas *ww; + int i, j, hits, safe=0; time_t ti = time(NULL); + glinebuf gbuf; localdata = thenode->localdata; @@ -157,6 +185,8 @@ void gline_free(searchCtx *ctx, struct searchNode *thenode) { return; } + glinebufinit(&gbuf, 0); + if (ctx->searchcmd == reg_chansearch) { for (i=0;ichannel->users->content[j]))) { - if(!glineuser(np, localdata, ti)) + if(!glineuser(&gbuf, np, localdata, ti)) safe++; } } } } } - } - else { + } else if (ctx->searchcmd == reg_nicksearch) { for (i=0;inext; if (np->marker == localdata->marker) { - if(!glineuser(np, localdata, ti)) + if(!glineuser(&gbuf, np, localdata, ti)) safe++; } } } + } else { + for (i = whowasoffset; i < whowasoffset + whowasmax; i++) { + ww = &whowasrecs[i % whowasmax]; + + if (ww->type == WHOWAS_UNUSED) + continue; + + if (ww->marker == localdata->marker) { + if(!glineuser(&gbuf, &ww->nick, localdata, ti)) + safe++; + } + } } + + glinebufcounthits(&gbuf, &hits, NULL); + glinebufcommit(&gbuf, 1); + if (safe) ctx->reply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe); /* notify opers of the action */