]> jfr.im git - irc/quakenet/newserv.git/blame - whowas/whowas_commands.c
GLINES: fix null pointer deref in trustgline / trustungline
[irc/quakenet/newserv.git] / whowas / whowas_commands.c
CommitLineData
363e3ed0
GB
1#include <stdio.h>
2#include <string.h>
3#include "../core/hooks.h"
4#include "../control/control.h"
5#include "../irc/irc.h"
6#include "../lib/irc_string.h"
7#include "../lib/version.h"
8#include "whowas.h"
9
10MODULE_VERSION("");
11
4030a47e 12static int whowas_cmdwhowas(void *source, int cargc, char **cargv) {
56cab147 13 nick *sender = source;
363e3ed0
GB
14 char *pattern;
15 whowas *ww;
0eb4cbd3 16 nick *np;
0495c1d1 17 int i;
363e3ed0 18 char hostmask[WW_MASKLEN + 1];
363e3ed0
GB
19 int matches = 0, limit = 500;
20
21 if (cargc < 1)
22 return CMD_USAGE;
23
24 pattern = cargv[0];
25
26 if (cargc > 1)
27 limit = strtol(cargv[1], NULL, 10);
28
291fdf5f
CP
29 for (i = whowasoffset; i < whowasoffset + whowasmax; i++) {
30 ww = &whowasrecs[i % whowasmax];
0495c1d1
GB
31
32 if (ww->type == WHOWAS_UNUSED)
33 continue;
34
35 np = &ww->nick;
0eb4cbd3 36 snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", np->nick, np->ident, np->host->name->content);
363e3ed0
GB
37
38 if (match2strings(pattern, hostmask)) {
39 matches++;
40
dd33b9ca 41 if (matches <= limit) {
0eb4cbd3 42 controlreply(sender, "%s", whowas_format(ww));
dd33b9ca
GB
43 controlreply(sender, "%s", whowas_formatchannels(ww));
44 } else if (matches == limit + 1)
56cab147 45 controlreply(sender, "--- More than %d matches, skipping the rest", limit);
363e3ed0
GB
46 }
47 }
48
56cab147
GB
49 controlreply(sender, "--- Found %d entries.", matches);
50
51 return CMD_OK;
52}
53
54static int whowas_cmdwhowaschase(void *source, int cargc, char **cargv) {
55 nick *sender = source;
56 whowas *ww;
57
58 if (cargc < 1)
59 return CMD_USAGE;
60
61 ww = whowas_chase(cargv[0], 900);
62
63 if (!ww) {
64 controlreply(sender, "No whowas record found.");
65 return CMD_OK;
66 }
67
0eb4cbd3 68 controlreply(sender, "%s", whowas_format(ww));
dd33b9ca 69 controlreply(sender, "%s", whowas_formatchannels(ww));
56cab147 70 controlreply(sender, "Done.");
363e3ed0
GB
71
72 return CMD_OK;
73}
74
75void _init(void) {
4030a47e 76 registercontrolhelpcmd("whowas", NO_OPER, 2, &whowas_cmdwhowas, "Usage: whowas <mask> ?limit?\nLooks up information about recently disconnected users.");
56cab147 77 registercontrolhelpcmd("whowaschase", NO_OPER, 2, &whowas_cmdwhowaschase, "Usage: whowaschase <nick>\nFinds most-recent whowas record for a nick.");
363e3ed0
GB
78}
79
80void _fini(void) {
4030a47e 81 deregistercontrolcmd("whowas", &whowas_cmdwhowas);
56cab147 82 deregistercontrolcmd("whowaschase", &whowas_cmdwhowaschase);
363e3ed0 83}