forked from XthemeOrg/xtheme-contrib-modules
/
os_akillnicklist.c
191 lines (152 loc) · 4.6 KB
/
os_akillnicklist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright (c) 2014-2016 Xtheme Development Group (Xtheme.org)
* Copyright (c) 2010 William Pitcock, et al.
* The rights to this code are as documented under doc/LICENSE.
*
* Automatically AKILL a list of clients, given their operating parameters.
*
* Basically this builds a keyword patricia. O(NICKLEN) lookups at the price
* of a longer startup process.
*
*
* Default AKILL time is 24 hours (86400 seconds)
*
* Configuration.
* ==============
*
* This module adds a new block to the config file:
*
* nicklists {
* all = "/home/nenolod/atheme-production.hg4576/etc/nicklists/azn.txt";
* nick = "/home/nenolod/atheme-production.hg4576/etc/nicklists/bottler-nicks.txt";
* user = "/home/nenolod/atheme-production.hg4576/etc/nicklists/bottler-users.txt";
* real = "/home/nenolod/atheme-production.hg4576/etc/nicklists/bottler-gecos.txt";
* };
*
* You can add multiple all, nick, user and real entries. The entries will be merged.
* I would also like to say: fuck you GNAA, you guys need to go play in fucking traffic.
* Thanks for reading my crappy docs, and have a nice day.
*/
#include "atheme-compat.h"
DECLARE_MODULE_V1
(
"contrib/os_akillnicklist", false, _modinit, _moddeinit,
"0.1",
"Xtheme Development Group <http://www.Xtheme.org>"
);
static mowgli_patricia_t *akillalllist = NULL;
static mowgli_patricia_t *akillnicklist = NULL;
static mowgli_patricia_t *akilluserlist = NULL;
static mowgli_patricia_t *akillreallist = NULL;
static mowgli_list_t conft = { NULL, NULL, 0 };
static void
add_contents_of_file_to_list(const char *filename, mowgli_patricia_t *list)
{
char value[BUFSIZE];
FILE *f;
f = fopen(filename, "r");
if (!f)
return;
while (fgets(value, BUFSIZE, f) != NULL)
{
strip(value);
if (!*value)
continue;
mowgli_patricia_add(list, value, (void *) 0x1);
}
fclose(f);
}
static int
nicklist_config_handler_all(mowgli_config_file_entry_t *entry)
{
add_contents_of_file_to_list(entry->vardata, akillalllist);
return 0;
}
static int
nicklist_config_handler_nick(mowgli_config_file_entry_t *entry)
{
add_contents_of_file_to_list(entry->vardata, akillnicklist);
return 0;
}
static int
nicklist_config_handler_user(mowgli_config_file_entry_t *entry)
{
add_contents_of_file_to_list(entry->vardata, akilluserlist);
return 0;
}
static int
nicklist_config_handler_real(mowgli_config_file_entry_t *entry)
{
add_contents_of_file_to_list(entry->vardata, akillreallist);
return 0;
}
static void
aknl_nickhook(hook_user_nick_t *data)
{
user_t *u;
bool doit = false;
const char *username;
kline_t *k;
service_t *svs;
svs = service_find("operserv");
return_if_fail(data != NULL);
if (!data->u)
return;
u = data->u;
if (is_internal_client(u))
return;
if (is_autokline_exempt(u))
return;
username = u->user;
if (*username == '~')
username++;
if (mowgli_patricia_retrieve(akillalllist, u->nick) != NULL &&
mowgli_patricia_retrieve(akillalllist, username) != NULL &&
mowgli_patricia_retrieve(akillalllist, u->gecos) != NULL)
doit = true;
if (mowgli_patricia_retrieve(akillnicklist, u->nick) != NULL)
doit = true;
if (mowgli_patricia_retrieve(akilluserlist, username) != NULL)
doit = true;
if (mowgli_patricia_retrieve(akillreallist, u->gecos) != NULL)
doit = true;
if (!doit)
return;
if (! (u->flags & UF_KLINESENT)) {
slog(LG_INFO, "AKNL: akilling \2%s\2!*@%s (%s) [%s] due to matching AUTO AKILL criteria.", u->nick, u->host, u->ip, u->gecos);
k = kline_add("*", u->ip, "AUTO (Matches AUTO AKILL)", 86400, svs->me->nick);
u->flags |= UF_KLINESENT;
}
}
void
_modinit(module_t *m)
{
add_subblock_top_conf("NICKLISTS", &conft);
add_conf_item("ALL", &conft, nicklist_config_handler_all);
add_conf_item("NICK", &conft, nicklist_config_handler_nick);
add_conf_item("USER", &conft, nicklist_config_handler_user);
add_conf_item("REAL", &conft, nicklist_config_handler_real);
akillalllist = mowgli_patricia_create(strcasecanon);
akillnicklist = mowgli_patricia_create(strcasecanon);
akilluserlist = mowgli_patricia_create(strcasecanon);
akillreallist = mowgli_patricia_create(strcasecanon);
hook_add_event("user_add");
hook_add_user_add(aknl_nickhook);
hook_add_event("user_nickchange");
hook_add_user_nickchange(aknl_nickhook);
service_t *svs;
svs = service_find("operserv");
}
void
_moddeinit(module_unload_intent_t intent)
{
hook_del_user_add(aknl_nickhook);
hook_del_user_nickchange(aknl_nickhook);
del_conf_item("ALL", &conft);
del_conf_item("NICK", &conft);
del_conf_item("USER", &conft);
del_conf_item("REAL", &conft);
del_top_conf("NICKLISTS");
service_t *svs;
svs = service_find("operserv");
}