1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_kline.c: Bans a user. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "channel.h" |
28 |
#include "client.h" |
29 |
#include "irc_string.h" |
30 |
#include "ircd.h" |
31 |
#include "conf.h" |
32 |
#include "hostmask.h" |
33 |
#include "numeric.h" |
34 |
#include "s_bsd.h" |
35 |
#include "log.h" |
36 |
#include "s_misc.h" |
37 |
#include "send.h" |
38 |
#include "hash.h" |
39 |
#include "s_serv.h" |
40 |
#include "parse.h" |
41 |
#include "modules.h" |
42 |
#include "conf_db.h" |
43 |
#include "memory.h" |
44 |
#include "xsnprintf.h" |
45 |
|
46 |
static int already_placed_kline(struct Client *, const char *, const char *, int); |
47 |
static void m_kline_add_kline(struct Client *, struct MaskItem *, time_t); |
48 |
|
49 |
static char buffer[IRCD_BUFSIZE]; |
50 |
static int remove_kline_match(const char *, const char *); |
51 |
|
52 |
|
53 |
/* mo_kline() |
54 |
* |
55 |
* inputs - pointer to server |
56 |
* - pointer to client |
57 |
* - parameter count |
58 |
* - parameter list |
59 |
* output - |
60 |
* side effects - k line is added |
61 |
*/ |
62 |
static int |
63 |
mo_kline(struct Client *client_p, struct Client *source_p, |
64 |
int parc, char *parv[]) |
65 |
{ |
66 |
char *reason = NULL; |
67 |
char *user = NULL; |
68 |
char *host = NULL; |
69 |
const char *current_date; |
70 |
char *target_server = NULL; |
71 |
struct MaskItem *conf; |
72 |
time_t tkline_time = 0; |
73 |
time_t cur_time; |
74 |
|
75 |
if (!HasOFlag(source_p, OPER_FLAG_K)) |
76 |
{ |
77 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
78 |
me.name, source_p->name, "kline"); |
79 |
return 0; |
80 |
} |
81 |
|
82 |
if (parse_aline("KLINE", source_p, parc, parv, |
83 |
AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0) |
84 |
return 0; |
85 |
|
86 |
if (target_server != NULL) |
87 |
{ |
88 |
if (HasID(source_p)) |
89 |
{ |
90 |
sendto_server(NULL, CAP_KLN|CAP_TS6, NOCAPS, |
91 |
":%s KLINE %s %Tu %s %s :%s", |
92 |
source_p->id, target_server, tkline_time, |
93 |
user, host, reason); |
94 |
sendto_server(NULL, CAP_KLN, CAP_TS6, |
95 |
":%s KLINE %s %Tu %s %s :%s", |
96 |
source_p->name, target_server, tkline_time, |
97 |
user, host, reason); |
98 |
} |
99 |
else |
100 |
sendto_server(NULL, CAP_KLN, NOCAPS, |
101 |
":%s KLINE %s %Tu %s %s :%s", |
102 |
source_p->name, target_server, tkline_time, |
103 |
user, host, reason); |
104 |
|
105 |
/* Allow ON to apply local kline as well if it matches */ |
106 |
if (match(target_server, me.name)) |
107 |
return 0; |
108 |
} |
109 |
else |
110 |
cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE, |
111 |
"%d %s %s :%s", tkline_time, user, host, reason); |
112 |
|
113 |
if (already_placed_kline(source_p, user, host, 1)) |
114 |
return 0; |
115 |
|
116 |
cur_time = CurrentTime; |
117 |
current_date = smalldate(cur_time); |
118 |
conf = conf_make(CONF_KLINE); |
119 |
|
120 |
conf->host = xstrdup(host); |
121 |
conf->user = xstrdup(user); |
122 |
|
123 |
if (tkline_time != 0) |
124 |
xsnprintf(NULL, buffer, sizeof(buffer), "Temporary K-line %Tu min. - %s (%s)", |
125 |
(tkline_time/60), reason, current_date); |
126 |
else |
127 |
xsnprintf(NULL, buffer, sizeof(buffer), "%s (%s)", reason, current_date); |
128 |
|
129 |
conf->reason = xstrdup(buffer); |
130 |
m_kline_add_kline(source_p, conf, tkline_time); |
131 |
return 0; |
132 |
} |
133 |
|
134 |
/* me_kline - handle remote kline. no propagation */ |
135 |
static int |
136 |
me_kline(struct Client *client_p, struct Client *source_p, |
137 |
int parc, char *parv[]) |
138 |
{ |
139 |
struct MaskItem *conf = NULL; |
140 |
int tkline_time = 0; |
141 |
const char* current_date; |
142 |
time_t cur_time; |
143 |
char *kuser, *khost, *kreason; |
144 |
|
145 |
if (parc != 6 || EmptyString(parv[5])) |
146 |
return 0; |
147 |
|
148 |
if (match(parv[1], me.name)) |
149 |
return 0; |
150 |
|
151 |
tkline_time = valid_tkline(parv[2], TK_SECONDS); |
152 |
kuser = parv[3]; |
153 |
khost = parv[4]; |
154 |
kreason = parv[5]; |
155 |
|
156 |
cur_time = CurrentTime; |
157 |
current_date = smalldate(cur_time); |
158 |
|
159 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
160 |
source_p->username, source_p->host, |
161 |
SHARED_KLINE)) |
162 |
{ |
163 |
if (!IsClient(source_p) || |
164 |
already_placed_kline(source_p, kuser, khost, 1)) |
165 |
return 0; |
166 |
|
167 |
conf = conf_make(CONF_KLINE); |
168 |
conf->host = xstrdup(khost); |
169 |
conf->user = xstrdup(kuser); |
170 |
|
171 |
if (tkline_time != 0) |
172 |
snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)", |
173 |
(int)(tkline_time/60), kreason, current_date); |
174 |
else |
175 |
snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date); |
176 |
|
177 |
conf->reason = xstrdup(buffer); |
178 |
m_kline_add_kline(source_p, conf, tkline_time); |
179 |
} |
180 |
|
181 |
return 0; |
182 |
} |
183 |
|
184 |
static int |
185 |
ms_kline(struct Client *client_p, struct Client *source_p, |
186 |
int parc, char *parv[]) |
187 |
{ |
188 |
if (parc != 6 || EmptyString(parv[5])) |
189 |
return 0; |
190 |
|
191 |
/* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */ |
192 |
/* oper target_server tkline_time user host reason */ |
193 |
sendto_match_servs(source_p, parv[1], CAP_KLN, |
194 |
"KLINE %s %s %s %s :%s", |
195 |
parv[1], parv[2], parv[3], parv[4], parv[5]); |
196 |
|
197 |
return me_kline(client_p, source_p, parc, parv); |
198 |
} |
199 |
|
200 |
/* apply_tkline() |
201 |
* |
202 |
* inputs - |
203 |
* output - NONE |
204 |
* side effects - tkline as given is placed |
205 |
*/ |
206 |
static void |
207 |
m_kline_add_kline(struct Client *source_p, struct MaskItem *conf, |
208 |
time_t tkline_time) |
209 |
{ |
210 |
if (tkline_time) |
211 |
{ |
212 |
conf->until = CurrentTime + tkline_time; |
213 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
214 |
"%s added temporary %d min. K-Line for [%s@%s] [%s]", |
215 |
get_oper_name(source_p), tkline_time/60, |
216 |
conf->user, conf->host, |
217 |
conf->reason); |
218 |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", |
219 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
220 |
source_p->name, tkline_time/60, conf->user, conf->host); |
221 |
ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
222 |
get_oper_name(source_p), tkline_time/60, |
223 |
conf->user, conf->host, conf->reason); |
224 |
} |
225 |
else |
226 |
{ |
227 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
228 |
"%s added K-Line for [%s@%s] [%s]", |
229 |
get_oper_name(source_p), |
230 |
conf->user, conf->host, conf->reason); |
231 |
sendto_one(source_p, ":%s NOTICE %s :Added K-Line [%s@%s]", |
232 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
233 |
source_p->name, conf->user, conf->host); |
234 |
ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]", |
235 |
get_oper_name(source_p), conf->user, conf->host, conf->reason); |
236 |
} |
237 |
|
238 |
conf->setat = CurrentTime; |
239 |
SetConfDatabase(conf); |
240 |
|
241 |
add_conf_by_address(CONF_KLINE, conf); |
242 |
rehashed_klines = 1; |
243 |
} |
244 |
|
245 |
/* already_placed_kline() |
246 |
* inputs - user to complain to, username & host to check for |
247 |
* outputs - returns 1 on existing K-line, 0 if doesn't exist |
248 |
* side effects - notifies source_p if the K-line already exists |
249 |
*/ |
250 |
/* |
251 |
* Note: This currently works if the new K-line is a special case of an |
252 |
* existing K-line, but not the other way round. To do that we would |
253 |
* have to walk the hash and check every existing K-line. -A1kmm. |
254 |
*/ |
255 |
static int |
256 |
already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn) |
257 |
{ |
258 |
const char *reason; |
259 |
struct irc_ssaddr iphost, *piphost; |
260 |
struct MaskItem *conf = NULL; |
261 |
int t = 0; |
262 |
int aftype = 0; |
263 |
|
264 |
if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST) |
265 |
{ |
266 |
if (t == HM_IPV6) |
267 |
aftype = AF_INET6; |
268 |
else |
269 |
aftype = AF_INET; |
270 |
piphost = &iphost; |
271 |
} |
272 |
else |
273 |
piphost = NULL; |
274 |
|
275 |
if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0))) |
276 |
{ |
277 |
if (warn) |
278 |
{ |
279 |
reason = conf->reason ? conf->reason : CONF_NOREASON; |
280 |
sendto_one(source_p, |
281 |
":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s", |
282 |
me.name, source_p->name, luser, lhost, conf->user, |
283 |
conf->host, reason); |
284 |
} |
285 |
|
286 |
return 1; |
287 |
} |
288 |
|
289 |
return 0; |
290 |
} |
291 |
|
292 |
/* |
293 |
** mo_unkline |
294 |
** Added Aug 31, 1997 |
295 |
** common (Keith Fralick) fralick@gate.net |
296 |
** |
297 |
** parv[0] = sender |
298 |
** parv[1] = address to remove |
299 |
* |
300 |
* |
301 |
*/ |
302 |
static int |
303 |
mo_unkline(struct Client *client_p,struct Client *source_p, |
304 |
int parc, char *parv[]) |
305 |
{ |
306 |
char *target_server = NULL; |
307 |
char *user, *host; |
308 |
|
309 |
if (!HasOFlag(source_p, OPER_FLAG_UNKLINE)) |
310 |
{ |
311 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
312 |
me.name, source_p->name, "unkline"); |
313 |
return 0; |
314 |
} |
315 |
|
316 |
if (EmptyString(parv[1])) |
317 |
{ |
318 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
319 |
me.name, source_p->name, "UNKLINE"); |
320 |
return 0; |
321 |
} |
322 |
|
323 |
if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user, |
324 |
&host, NULL, &target_server, NULL) < 0) |
325 |
return 0; |
326 |
|
327 |
if (target_server != NULL) |
328 |
{ |
329 |
sendto_match_servs(source_p, target_server, CAP_UNKLN, |
330 |
"UNKLINE %s %s %s", |
331 |
target_server, user, host); |
332 |
|
333 |
/* Allow ON to apply local unkline as well if it matches */ |
334 |
if (match(target_server, me.name)) |
335 |
return 0; |
336 |
} |
337 |
else |
338 |
cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE, |
339 |
"%s %s", user, host); |
340 |
|
341 |
if (remove_kline_match(host, user)) |
342 |
{ |
343 |
sendto_one(source_p, |
344 |
":%s NOTICE %s :K-Line for [%s@%s] is removed", |
345 |
me.name, source_p->name, user, host); |
346 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
347 |
"%s has removed the K-Line for: [%s@%s]", |
348 |
get_oper_name(source_p), user, host); |
349 |
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
350 |
get_oper_name(source_p), user, host); |
351 |
} |
352 |
else |
353 |
sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found", |
354 |
me.name, source_p->name, user, host); |
355 |
return 0; |
356 |
} |
357 |
|
358 |
/* me_unkline() |
359 |
* |
360 |
* inputs - server |
361 |
* - client |
362 |
* - parc |
363 |
* - parv |
364 |
* outputs - none |
365 |
* side effects - if server is authorized, kline is removed |
366 |
* does not propagate message |
367 |
*/ |
368 |
static int |
369 |
me_unkline(struct Client *client_p, struct Client *source_p, |
370 |
int parc, char *parv[]) |
371 |
{ |
372 |
const char *kuser, *khost; |
373 |
|
374 |
if (parc != 4) |
375 |
return 0; |
376 |
|
377 |
kuser = parv[2]; |
378 |
khost = parv[3]; |
379 |
|
380 |
if (!IsClient(source_p) || match(parv[1], me.name)) |
381 |
return 0; |
382 |
|
383 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, |
384 |
source_p->servptr->name, |
385 |
source_p->username, source_p->host, |
386 |
SHARED_UNKLINE)) |
387 |
{ |
388 |
if (remove_kline_match(khost, kuser)) |
389 |
{ |
390 |
sendto_one(source_p, |
391 |
":%s NOTICE %s :K-Line for [%s@%s] is removed", |
392 |
me.name, source_p->name, kuser, khost); |
393 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
394 |
"%s has removed the K-Line for: [%s@%s]", |
395 |
get_oper_name(source_p), kuser, khost); |
396 |
ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]", |
397 |
get_oper_name(source_p), kuser, khost); |
398 |
} |
399 |
else |
400 |
sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found", |
401 |
me.name, source_p->name, kuser, khost); |
402 |
} |
403 |
|
404 |
return 0; |
405 |
} |
406 |
|
407 |
/* ms_unkline - propagates and handles a remote unkline message */ |
408 |
static int |
409 |
ms_unkline(struct Client *client_p, struct Client *source_p, |
410 |
int parc, char *parv[]) |
411 |
{ |
412 |
if (parc != 4) |
413 |
return 0; |
414 |
|
415 |
sendto_match_servs(source_p, parv[1], CAP_UNKLN, |
416 |
"UNKLINE %s %s %s", |
417 |
parv[1], parv[2], parv[3]); |
418 |
|
419 |
return me_unkline(client_p, source_p, parc, parv); |
420 |
} |
421 |
|
422 |
/* static int remove_tkline_match(const char *host, const char *user) |
423 |
* Input: A hostname, a username to unkline. |
424 |
* Output: returns YES on success, NO if no tkline removed. |
425 |
* Side effects: Any matching tklines are removed. |
426 |
*/ |
427 |
static int |
428 |
remove_kline_match(const char *host, const char *user) |
429 |
{ |
430 |
struct irc_ssaddr iphost, *piphost; |
431 |
struct MaskItem *conf; |
432 |
int t = 0; |
433 |
int aftype = 0; |
434 |
|
435 |
if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST) |
436 |
{ |
437 |
if (t == HM_IPV6) |
438 |
aftype = AF_INET6; |
439 |
else |
440 |
aftype = AF_INET; |
441 |
piphost = &iphost; |
442 |
} |
443 |
else |
444 |
piphost = NULL; |
445 |
|
446 |
if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0))) |
447 |
{ |
448 |
if (IsConfDatabase(conf)) |
449 |
{ |
450 |
delete_one_address_conf(host, conf); |
451 |
return 1; |
452 |
} |
453 |
} |
454 |
|
455 |
return 0; |
456 |
} |
457 |
|
458 |
static struct Message kline_msgtab = |
459 |
{ |
460 |
"KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
461 |
{m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore} |
462 |
}; |
463 |
|
464 |
static struct Message unkline_msgtab = |
465 |
{ |
466 |
"UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
467 |
{m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore} |
468 |
}; |
469 |
|
470 |
static void |
471 |
module_init(void) |
472 |
{ |
473 |
mod_add_cmd(&kline_msgtab); |
474 |
mod_add_cmd(&unkline_msgtab); |
475 |
add_capability("KLN", CAP_KLN, 1); |
476 |
add_capability("UNKLN", CAP_UNKLN, 1); |
477 |
} |
478 |
|
479 |
static void |
480 |
module_exit(void) |
481 |
{ |
482 |
mod_del_cmd(&kline_msgtab); |
483 |
mod_del_cmd(&unkline_msgtab); |
484 |
delete_capability("UNKLN"); |
485 |
delete_capability("KLN"); |
486 |
} |
487 |
|
488 |
struct module module_entry = |
489 |
{ |
490 |
.node = { NULL, NULL, NULL }, |
491 |
.name = NULL, |
492 |
.version = "$Revision$", |
493 |
.handle = NULL, |
494 |
.modinit = module_init, |
495 |
.modexit = module_exit, |
496 |
.flags = 0 |
497 |
}; |