Debian Codegraph @

modules/contrib/src/os_akillnicklist.c

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