1 |
adx |
30 |
/* |
2 |
michael |
2810 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7006 |
* Copyright (c) 1997-2016 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2810 |
/*! \file m_kline.c |
23 |
michael |
3350 |
* \brief Includes required functions for processing the KLINE command. |
24 |
michael |
2810 |
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "client.h" |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "ircd.h" |
32 |
michael |
1632 |
#include "conf.h" |
33 |
michael |
7209 |
#include "conf_cluster.h" |
34 |
|
|
#include "conf_shared.h" |
35 |
adx |
30 |
#include "hostmask.h" |
36 |
|
|
#include "numeric.h" |
37 |
michael |
1309 |
#include "log.h" |
38 |
michael |
3347 |
#include "misc.h" |
39 |
adx |
30 |
#include "send.h" |
40 |
michael |
3347 |
#include "server.h" |
41 |
adx |
30 |
#include "parse.h" |
42 |
|
|
#include "modules.h" |
43 |
michael |
1666 |
#include "memory.h" |
44 |
adx |
30 |
|
45 |
michael |
1058 |
|
46 |
michael |
2811 |
static void |
47 |
michael |
5832 |
kline_check(struct AddressRec *arec) |
48 |
michael |
2811 |
{ |
49 |
michael |
4815 |
dlink_node *node = NULL, *node_next = NULL; |
50 |
michael |
2811 |
|
51 |
michael |
4815 |
DLINK_FOREACH_SAFE(node, node_next, local_client_list.head) |
52 |
michael |
2811 |
{ |
53 |
michael |
4815 |
struct Client *client_p = node->data; |
54 |
michael |
2811 |
|
55 |
michael |
2812 |
if (IsDead(client_p)) |
56 |
michael |
2811 |
continue; |
57 |
|
|
|
58 |
|
|
if (match(arec->username, client_p->username)) |
59 |
|
|
continue; |
60 |
|
|
|
61 |
|
|
switch (arec->masktype) |
62 |
|
|
{ |
63 |
|
|
case HM_IPV4: |
64 |
michael |
4588 |
if (client_p->connection->aftype == AF_INET) |
65 |
|
|
if (match_ipv4(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
66 |
michael |
7304 |
conf_try_ban(client_p, CLIENT_BAN_KLINE, arec->conf->reason); |
67 |
michael |
2811 |
break; |
68 |
|
|
case HM_IPV6: |
69 |
michael |
4588 |
if (client_p->connection->aftype == AF_INET6) |
70 |
|
|
if (match_ipv6(&client_p->connection->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits)) |
71 |
michael |
7304 |
conf_try_ban(client_p, CLIENT_BAN_KLINE, arec->conf->reason); |
72 |
michael |
2811 |
break; |
73 |
|
|
default: /* HM_HOST */ |
74 |
michael |
5387 |
if (!match(arec->Mask.hostname, client_p->host) || !match(arec->Mask.hostname, client_p->sockhost)) |
75 |
michael |
7304 |
conf_try_ban(client_p, CLIENT_BAN_KLINE, arec->conf->reason); |
76 |
michael |
2811 |
break; |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
michael |
7417 |
/* already_placed_kline() |
82 |
|
|
* inputs - user to complain to, username & host to check for |
83 |
|
|
* outputs - returns 1 on existing K-line, 0 if doesn't exist |
84 |
|
|
* side effects - notifies source_p if the K-line already exists |
85 |
|
|
*/ |
86 |
|
|
/* |
87 |
|
|
* Note: This currently works if the new K-line is a special case of an |
88 |
|
|
* existing K-line, but not the other way round. To do that we would |
89 |
|
|
* have to walk the hash and check every existing K-line. -A1kmm. |
90 |
|
|
*/ |
91 |
|
|
static int |
92 |
|
|
already_placed_kline(struct Client *source_p, const char *user, const char *host) |
93 |
|
|
{ |
94 |
|
|
struct irc_ssaddr iphost, *piphost; |
95 |
|
|
struct MaskItem *conf = NULL; |
96 |
|
|
int t = 0; |
97 |
|
|
int aftype = 0; |
98 |
|
|
|
99 |
|
|
if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST) |
100 |
|
|
{ |
101 |
|
|
if (t == HM_IPV6) |
102 |
|
|
aftype = AF_INET6; |
103 |
|
|
else |
104 |
|
|
aftype = AF_INET; |
105 |
|
|
|
106 |
|
|
piphost = &iphost; |
107 |
|
|
} |
108 |
|
|
else |
109 |
|
|
piphost = NULL; |
110 |
|
|
|
111 |
|
|
if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0))) |
112 |
|
|
{ |
113 |
|
|
if (IsClient(source_p)) |
114 |
|
|
sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s", |
115 |
|
|
user, host, conf->user, conf->host, conf->reason); |
116 |
|
|
return 1; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
return 0; |
120 |
|
|
} |
121 |
|
|
|
122 |
michael |
2810 |
/* apply_tkline() |
123 |
|
|
* |
124 |
|
|
* inputs - |
125 |
|
|
* output - NONE |
126 |
|
|
* side effects - tkline as given is placed |
127 |
|
|
*/ |
128 |
|
|
static void |
129 |
michael |
7417 |
kline_handle(struct Client *source_p, const char *user, const char *host, |
130 |
|
|
const char *reason, uintmax_t duration) |
131 |
michael |
2810 |
{ |
132 |
michael |
5828 |
char buf[IRCD_BUFSIZE]; |
133 |
|
|
|
134 |
michael |
7417 |
if (!HasFlag(source_p, FLAGS_SERVICE)) |
135 |
|
|
{ |
136 |
|
|
if (!valid_wild_card(source_p, 2, user, host)) |
137 |
|
|
return; |
138 |
|
|
|
139 |
|
|
int bits = 0; |
140 |
|
|
switch (parse_netmask(host, NULL, &bits)) |
141 |
|
|
{ |
142 |
|
|
case HM_IPV4: |
143 |
|
|
if ((unsigned int)bits < ConfigGeneral.kline_min_cidr) |
144 |
|
|
{ |
145 |
|
|
if (IsClient(source_p)) |
146 |
|
|
sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.", |
147 |
|
|
ConfigGeneral.kline_min_cidr); |
148 |
|
|
return; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
break; |
152 |
|
|
case HM_IPV6: |
153 |
|
|
if ((unsigned int)bits < ConfigGeneral.kline_min_cidr6) |
154 |
|
|
{ |
155 |
|
|
if (IsClient(source_p)) |
156 |
|
|
sendto_one_notice(source_p, &me, ":For safety, bitmasks less than %u require conf access.", |
157 |
|
|
ConfigGeneral.kline_min_cidr6); |
158 |
|
|
return; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
break; |
162 |
|
|
default: /* HM_HOST */ |
163 |
|
|
break; |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
if (already_placed_kline(source_p, user, host)) |
168 |
|
|
return; |
169 |
|
|
|
170 |
michael |
6458 |
if (duration) |
171 |
michael |
6782 |
snprintf(buf, sizeof(buf), "Temporary K-line %ju min. - %.*s (%s)", |
172 |
|
|
duration / 60, REASONLEN, reason, date_iso8601(0)); |
173 |
michael |
5828 |
else |
174 |
michael |
6422 |
snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, reason, date_iso8601(0)); |
175 |
michael |
5828 |
|
176 |
michael |
7076 |
struct MaskItem *conf = conf_make(CONF_KLINE); |
177 |
michael |
5828 |
conf->host = xstrdup(host); |
178 |
|
|
conf->user = xstrdup(user); |
179 |
|
|
conf->setat = CurrentTime; |
180 |
|
|
conf->reason = xstrdup(buf); |
181 |
|
|
SetConfDatabase(conf); |
182 |
|
|
|
183 |
michael |
6458 |
if (duration) |
184 |
michael |
2810 |
{ |
185 |
michael |
6458 |
conf->until = CurrentTime + duration; |
186 |
michael |
4635 |
|
187 |
|
|
if (IsClient(source_p)) |
188 |
michael |
6782 |
sendto_one_notice(source_p, &me, ":Added temporary %ju min. K-Line [%s@%s]", |
189 |
|
|
duration / 60, conf->user, conf->host); |
190 |
michael |
4890 |
|
191 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
192 |
michael |
6782 |
"%s added temporary %ju min. K-Line for [%s@%s] [%s]", |
193 |
|
|
get_oper_name(source_p), duration / 60, |
194 |
michael |
2810 |
conf->user, conf->host, |
195 |
|
|
conf->reason); |
196 |
michael |
6782 |
ilog(LOG_TYPE_KLINE, "%s added temporary %ju min. K-Line for [%s@%s] [%s]", |
197 |
|
|
get_oper_name(source_p), duration / 60, |
198 |
michael |
2810 |
conf->user, conf->host, conf->reason); |
199 |
|
|
} |
200 |
|
|
else |
201 |
|
|
{ |
202 |
michael |
4635 |
if (IsClient(source_p)) |
203 |
|
|
sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]", |
204 |
|
|
conf->user, conf->host); |
205 |
michael |
4890 |
|
206 |
michael |
6318 |
sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, |
207 |
michael |
2810 |
"%s added K-Line for [%s@%s] [%s]", |
208 |
|
|
get_oper_name(source_p), |
209 |
|
|
conf->user, conf->host, conf->reason); |
210 |
|
|
ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]", |
211 |
|
|
get_oper_name(source_p), conf->user, conf->host, conf->reason); |
212 |
|
|
} |
213 |
adx |
30 |
|
214 |
michael |
5832 |
kline_check(add_conf_by_address(CONF_KLINE, conf)); |
215 |
michael |
2810 |
} |
216 |
|
|
|
217 |
adx |
30 |
/* mo_kline() |
218 |
|
|
* |
219 |
|
|
* inputs - pointer to server |
220 |
|
|
* - pointer to client |
221 |
|
|
* - parameter count |
222 |
|
|
* - parameter list |
223 |
|
|
* output - |
224 |
|
|
* side effects - k line is added |
225 |
|
|
*/ |
226 |
michael |
2820 |
static int |
227 |
michael |
3156 |
mo_kline(struct Client *source_p, int parc, char *parv[]) |
228 |
adx |
30 |
{ |
229 |
|
|
char *reason = NULL; |
230 |
|
|
char *user = NULL; |
231 |
|
|
char *host = NULL; |
232 |
|
|
char *target_server = NULL; |
233 |
michael |
7330 |
uintmax_t duration = 0; |
234 |
adx |
30 |
|
235 |
michael |
4019 |
if (!HasOFlag(source_p, OPER_FLAG_KLINE)) |
236 |
adx |
30 |
{ |
237 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline"); |
238 |
michael |
2820 |
return 0; |
239 |
adx |
30 |
} |
240 |
|
|
|
241 |
michael |
5776 |
if (!parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host, |
242 |
michael |
6458 |
&duration, &target_server, &reason)) |
243 |
michael |
2820 |
return 0; |
244 |
adx |
30 |
|
245 |
michael |
3368 |
if (target_server) |
246 |
adx |
30 |
{ |
247 |
michael |
6782 |
sendto_match_servs(source_p, target_server, CAPAB_KLN, "KLINE %s %ju %s %s :%s", |
248 |
|
|
target_server, duration, |
249 |
michael |
2804 |
user, host, reason); |
250 |
adx |
30 |
|
251 |
|
|
/* Allow ON to apply local kline as well if it matches */ |
252 |
michael |
1652 |
if (match(target_server, me.name)) |
253 |
michael |
2820 |
return 0; |
254 |
adx |
30 |
} |
255 |
|
|
else |
256 |
michael |
7209 |
cluster_distribute(source_p, "KLINE", CAPAB_KLN, CLUSTER_KLINE, |
257 |
|
|
"%ju %s %s :%s", duration, user, host, reason); |
258 |
adx |
30 |
|
259 |
michael |
7417 |
kline_handle(source_p, user, host, reason, duration); |
260 |
michael |
2820 |
return 0; |
261 |
adx |
30 |
} |
262 |
|
|
|
263 |
michael |
7094 |
/*! \brief KLINE command handler |
264 |
|
|
* |
265 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
266 |
|
|
* originally comes from. This can be a local or remote client. |
267 |
|
|
* \param parc Integer holding the number of supplied arguments. |
268 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
269 |
|
|
* pointers. |
270 |
|
|
* \note Valid arguments for this command are: |
271 |
|
|
* - parv[0] = command |
272 |
|
|
* - parv[1] = target server mask |
273 |
|
|
* - parv[2] = duration in seconds |
274 |
|
|
* - parv[3] = user mask |
275 |
|
|
* - parv[4] = host mask |
276 |
|
|
* - parv[5] = reason |
277 |
|
|
*/ |
278 |
michael |
2820 |
static int |
279 |
michael |
4984 |
ms_kline(struct Client *source_p, int parc, char *parv[]) |
280 |
adx |
30 |
{ |
281 |
michael |
7330 |
uintmax_t duration = 0; |
282 |
michael |
5828 |
const char *user, *host, *reason; |
283 |
adx |
30 |
|
284 |
michael |
352 |
if (parc != 6 || EmptyString(parv[5])) |
285 |
michael |
2820 |
return 0; |
286 |
adx |
30 |
|
287 |
michael |
6354 |
sendto_match_servs(source_p, parv[1], CAPAB_KLN, "KLINE %s %s %s %s :%s", |
288 |
michael |
4984 |
parv[1], parv[2], parv[3], parv[4], parv[5]); |
289 |
|
|
|
290 |
michael |
1652 |
if (match(parv[1], me.name)) |
291 |
michael |
2820 |
return 0; |
292 |
adx |
30 |
|
293 |
michael |
6458 |
duration = valid_tkline(parv[2], TK_SECONDS); |
294 |
michael |
5828 |
user = parv[3]; |
295 |
|
|
host = parv[4]; |
296 |
|
|
reason = parv[5]; |
297 |
adx |
30 |
|
298 |
michael |
2810 |
if (HasFlag(source_p, FLAGS_SERVICE) || |
299 |
michael |
7209 |
shared_find(SHARED_KLINE, source_p->servptr->name, |
300 |
|
|
source_p->username, source_p->host)) |
301 |
michael |
7417 |
kline_handle(source_p, user, host, reason, duration); |
302 |
adx |
30 |
|
303 |
michael |
2820 |
return 0; |
304 |
adx |
30 |
} |
305 |
|
|
|
306 |
michael |
2810 |
static struct Message kline_msgtab = |
307 |
adx |
30 |
{ |
308 |
michael |
5881 |
.cmd = "KLINE", |
309 |
|
|
.args_min = 2, |
310 |
|
|
.args_max = MAXPARA, |
311 |
|
|
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
312 |
|
|
.handlers[CLIENT_HANDLER] = m_not_oper, |
313 |
|
|
.handlers[SERVER_HANDLER] = ms_kline, |
314 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
315 |
|
|
.handlers[OPER_HANDLER] = mo_kline |
316 |
michael |
1230 |
}; |
317 |
|
|
|
318 |
|
|
static void |
319 |
|
|
module_init(void) |
320 |
|
|
{ |
321 |
|
|
mod_add_cmd(&kline_msgtab); |
322 |
michael |
6354 |
add_capability("KLN", CAPAB_KLN); |
323 |
michael |
1230 |
} |
324 |
|
|
|
325 |
|
|
static void |
326 |
|
|
module_exit(void) |
327 |
|
|
{ |
328 |
|
|
mod_del_cmd(&kline_msgtab); |
329 |
|
|
delete_capability("KLN"); |
330 |
|
|
} |
331 |
|
|
|
332 |
michael |
2810 |
struct module module_entry = |
333 |
|
|
{ |
334 |
michael |
1230 |
.version = "$Revision$", |
335 |
|
|
.modinit = module_init, |
336 |
|
|
.modexit = module_exit, |
337 |
|
|
}; |