1 |
adx |
30 |
/* |
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 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "channel.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "common.h" |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "sprintf_irc.h" |
32 |
|
|
#include "ircd.h" |
33 |
|
|
#include "hostmask.h" |
34 |
|
|
#include "numeric.h" |
35 |
|
|
#include "fdlist.h" |
36 |
|
|
#include "s_bsd.h" |
37 |
|
|
#include "s_conf.h" |
38 |
|
|
#include "s_log.h" |
39 |
|
|
#include "s_misc.h" |
40 |
|
|
#include "send.h" |
41 |
|
|
#include "hash.h" |
42 |
|
|
#include "handlers.h" |
43 |
|
|
#include "s_serv.h" |
44 |
|
|
#include "msg.h" |
45 |
|
|
#include "s_gline.h" |
46 |
|
|
#include "parse.h" |
47 |
|
|
#include "modules.h" |
48 |
michael |
611 |
#include "irc_getnameinfo.h" |
49 |
adx |
30 |
|
50 |
michael |
611 |
|
51 |
adx |
30 |
static void me_kline(struct Client *, struct Client *, int, char **); |
52 |
|
|
static void mo_kline(struct Client *, struct Client *, int, char **); |
53 |
|
|
static void ms_kline(struct Client *, struct Client *, int, char **); |
54 |
|
|
static void mo_dline(struct Client *, struct Client *, int, char **); |
55 |
|
|
static void me_unkline(struct Client *, struct Client *, int, char **); |
56 |
|
|
static void mo_unkline(struct Client *, struct Client *, int, char **); |
57 |
|
|
static void ms_unkline(struct Client *, struct Client *, int, char **); |
58 |
|
|
static void mo_undline(struct Client *, struct Client *, int, char **); |
59 |
|
|
|
60 |
|
|
static int remove_tkline_match(const char *, const char *); |
61 |
|
|
static int remove_tdline_match(const char *); |
62 |
|
|
|
63 |
|
|
struct Message kline_msgtab = { |
64 |
|
|
"KLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
65 |
|
|
{m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore} |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
struct Message dline_msgtab = { |
69 |
|
|
"DLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
70 |
michael |
946 |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore} |
71 |
adx |
30 |
}; |
72 |
|
|
|
73 |
|
|
struct Message unkline_msgtab = { |
74 |
|
|
"UNKLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
75 |
|
|
{m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore} |
76 |
|
|
}; |
77 |
|
|
|
78 |
|
|
struct Message undline_msgtab = { |
79 |
|
|
"UNDLINE", 0, 0, 2, 0, MFLG_SLOW, 0, |
80 |
michael |
946 |
{m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore} |
81 |
adx |
30 |
}; |
82 |
|
|
|
83 |
|
|
#ifndef STATIC_MODULES |
84 |
|
|
void |
85 |
|
|
_modinit(void) |
86 |
|
|
{ |
87 |
|
|
mod_add_cmd(&kline_msgtab); |
88 |
|
|
mod_add_cmd(&unkline_msgtab); |
89 |
|
|
mod_add_cmd(&dline_msgtab); |
90 |
|
|
mod_add_cmd(&undline_msgtab); |
91 |
|
|
add_capability("KLN", CAP_KLN, 1); |
92 |
|
|
add_capability("UNKLN", CAP_UNKLN, 1); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
void |
96 |
|
|
_moddeinit(void) |
97 |
|
|
{ |
98 |
|
|
mod_del_cmd(&kline_msgtab); |
99 |
|
|
mod_del_cmd(&unkline_msgtab); |
100 |
|
|
mod_del_cmd(&dline_msgtab); |
101 |
|
|
mod_del_cmd(&undline_msgtab); |
102 |
|
|
delete_capability("UNKLN"); |
103 |
|
|
delete_capability("KLN"); |
104 |
|
|
} |
105 |
|
|
|
106 |
knight |
31 |
const char *_version = "$Revision$"; |
107 |
adx |
30 |
#endif |
108 |
|
|
|
109 |
|
|
/* Local function prototypes */ |
110 |
|
|
static int already_placed_kline(struct Client *, const char *, const char *, int); |
111 |
|
|
static void apply_kline(struct Client *, struct ConfItem *, const char *, time_t); |
112 |
|
|
static void apply_tkline(struct Client *, struct ConfItem *, int); |
113 |
|
|
|
114 |
|
|
static char buffer[IRCD_BUFSIZE]; |
115 |
|
|
|
116 |
|
|
/* mo_kline() |
117 |
|
|
* |
118 |
|
|
* inputs - pointer to server |
119 |
|
|
* - pointer to client |
120 |
|
|
* - parameter count |
121 |
|
|
* - parameter list |
122 |
|
|
* output - |
123 |
|
|
* side effects - k line is added |
124 |
|
|
*/ |
125 |
|
|
static void |
126 |
|
|
mo_kline(struct Client *client_p, struct Client *source_p, |
127 |
|
|
int parc, char **parv) |
128 |
|
|
{ |
129 |
|
|
char *reason = NULL; |
130 |
|
|
char *oper_reason; |
131 |
|
|
char *user = NULL; |
132 |
|
|
char *host = NULL; |
133 |
|
|
const char *current_date; |
134 |
|
|
char *target_server = NULL; |
135 |
|
|
struct ConfItem *conf; |
136 |
|
|
struct AccessItem *aconf; |
137 |
|
|
time_t tkline_time = 0; |
138 |
|
|
time_t cur_time; |
139 |
|
|
|
140 |
|
|
if (!IsOperK(source_p)) |
141 |
|
|
{ |
142 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
143 |
|
|
me.name, source_p->name, "kline"); |
144 |
|
|
return; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
if (parse_aline("KLINE", source_p, parc, parv, |
148 |
|
|
AWILD, &user, &host, &tkline_time, &target_server, &reason) < 0) |
149 |
|
|
return; |
150 |
|
|
|
151 |
|
|
if (target_server != NULL) |
152 |
|
|
{ |
153 |
|
|
if (HasID(source_p)) |
154 |
|
|
{ |
155 |
michael |
885 |
sendto_server(NULL, NULL, CAP_KLN|CAP_TS6, NOCAPS, |
156 |
adx |
30 |
":%s KLINE %s %lu %s %s :%s", |
157 |
|
|
source_p->id, target_server, (unsigned long)tkline_time, |
158 |
|
|
user, host, reason); |
159 |
michael |
885 |
sendto_server(NULL, NULL, CAP_KLN, CAP_TS6, |
160 |
adx |
30 |
":%s KLINE %s %lu %s %s :%s", |
161 |
|
|
source_p->name, target_server, (unsigned long)tkline_time, |
162 |
|
|
user, host, reason); |
163 |
|
|
} |
164 |
|
|
else |
165 |
michael |
885 |
sendto_server(NULL, NULL, CAP_KLN, NOCAPS, |
166 |
adx |
30 |
":%s KLINE %s %lu %s %s :%s", |
167 |
|
|
source_p->name, target_server, (unsigned long)tkline_time, |
168 |
|
|
user, host, reason); |
169 |
|
|
|
170 |
|
|
/* Allow ON to apply local kline as well if it matches */ |
171 |
|
|
if (!match(target_server, me.name)) |
172 |
|
|
return; |
173 |
|
|
} |
174 |
|
|
else |
175 |
|
|
cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE, |
176 |
|
|
"%d %s %s :%s", tkline_time, user, host, reason); |
177 |
|
|
|
178 |
|
|
if (already_placed_kline(source_p, user, host, YES)) |
179 |
|
|
return; |
180 |
|
|
|
181 |
|
|
/* Look for an oper reason */ |
182 |
|
|
if ((oper_reason = strchr(reason, '|')) != NULL) |
183 |
|
|
*oper_reason++ = '\0'; |
184 |
|
|
|
185 |
|
|
cur_time = CurrentTime; |
186 |
|
|
current_date = smalldate(cur_time); |
187 |
|
|
conf = make_conf_item(KLINE_TYPE); |
188 |
|
|
aconf = map_to_conf(conf); |
189 |
|
|
|
190 |
|
|
DupString(aconf->host, host); |
191 |
|
|
DupString(aconf->user, user); |
192 |
|
|
|
193 |
|
|
if (tkline_time != 0) |
194 |
|
|
{ |
195 |
|
|
ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)", |
196 |
|
|
(int)(tkline_time/60), reason, current_date); |
197 |
|
|
DupString(aconf->reason, buffer); |
198 |
|
|
|
199 |
|
|
if (oper_reason != NULL) |
200 |
|
|
DupString(aconf->oper_reason, oper_reason); |
201 |
|
|
apply_tkline(source_p, conf, tkline_time); |
202 |
|
|
} |
203 |
|
|
else |
204 |
|
|
{ |
205 |
|
|
ircsprintf(buffer, "%s (%s)", reason, current_date); |
206 |
|
|
DupString(aconf->reason, buffer); |
207 |
|
|
|
208 |
|
|
if (oper_reason != NULL) |
209 |
|
|
DupString(aconf->oper_reason, oper_reason); |
210 |
|
|
apply_kline(source_p, conf, current_date, cur_time); |
211 |
|
|
} |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
/* me_kline - handle remote kline. no propagation */ |
215 |
|
|
static void |
216 |
|
|
me_kline(struct Client *client_p, struct Client *source_p, |
217 |
|
|
int parc, char *parv[]) |
218 |
|
|
{ |
219 |
|
|
struct ConfItem *conf=NULL; |
220 |
|
|
struct AccessItem *aconf=NULL; |
221 |
|
|
int tkline_time; |
222 |
|
|
const char* current_date; |
223 |
|
|
time_t cur_time; |
224 |
|
|
char *kuser, *khost, *kreason, *oper_reason; |
225 |
|
|
|
226 |
michael |
352 |
if (parc != 6 || EmptyString(parv[5])) |
227 |
adx |
30 |
return; |
228 |
|
|
|
229 |
|
|
if (!match(parv[1], me.name)) |
230 |
|
|
return; |
231 |
|
|
|
232 |
|
|
tkline_time = valid_tkline(parv[2], TK_SECONDS); |
233 |
|
|
kuser = parv[3]; |
234 |
|
|
khost = parv[4]; |
235 |
|
|
kreason = parv[5]; |
236 |
|
|
|
237 |
|
|
if ((oper_reason = strchr(kreason, '|')) != NULL) |
238 |
|
|
*oper_reason++ = '\0'; |
239 |
|
|
|
240 |
|
|
cur_time = CurrentTime; |
241 |
|
|
current_date = smalldate(cur_time); |
242 |
|
|
|
243 |
|
|
if (find_matching_name_conf(ULINE_TYPE, source_p->servptr->name, |
244 |
|
|
source_p->username, source_p->host, |
245 |
|
|
SHARED_KLINE)) |
246 |
|
|
{ |
247 |
|
|
if (!IsClient(source_p) || |
248 |
|
|
already_placed_kline(source_p, kuser, khost, YES)) |
249 |
|
|
return; |
250 |
|
|
|
251 |
|
|
conf = make_conf_item(KLINE_TYPE); |
252 |
|
|
aconf = map_to_conf(conf); |
253 |
|
|
DupString(aconf->host, khost); |
254 |
|
|
DupString(aconf->user, kuser); |
255 |
|
|
|
256 |
|
|
if (tkline_time != 0) |
257 |
|
|
{ |
258 |
|
|
ircsprintf(buffer, "Temporary K-line %d min. - %s (%s)", |
259 |
|
|
(int)(tkline_time/60), kreason, current_date); |
260 |
|
|
DupString(aconf->reason, buffer); |
261 |
|
|
|
262 |
|
|
if (oper_reason != NULL) |
263 |
|
|
DupString(aconf->oper_reason, oper_reason); |
264 |
|
|
apply_tkline(source_p, conf, tkline_time); |
265 |
|
|
} |
266 |
|
|
else |
267 |
|
|
{ |
268 |
|
|
ircsprintf(buffer, "%s (%s)", kreason, current_date); |
269 |
|
|
DupString(aconf->reason, buffer); |
270 |
|
|
|
271 |
|
|
if (oper_reason != NULL) |
272 |
|
|
DupString(aconf->oper_reason, oper_reason); |
273 |
|
|
apply_kline(source_p, conf, current_date, cur_time); |
274 |
|
|
} |
275 |
|
|
} |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
static void |
279 |
|
|
ms_kline(struct Client *client_p, struct Client *source_p, |
280 |
|
|
int parc, char *parv[]) |
281 |
|
|
{ |
282 |
michael |
352 |
if (parc != 6 || EmptyString(parv[5])) |
283 |
adx |
30 |
return; |
284 |
|
|
|
285 |
|
|
/* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */ |
286 |
|
|
/* oper target_server tkline_time user host reason */ |
287 |
|
|
sendto_match_servs(source_p, parv[1], CAP_KLN, |
288 |
|
|
"KLINE %s %s %s %s :%s", |
289 |
|
|
parv[1], parv[2], parv[3], parv[4], parv[5]); |
290 |
|
|
|
291 |
|
|
me_kline(client_p, source_p, parc, parv); |
292 |
|
|
} |
293 |
|
|
|
294 |
|
|
/* apply_kline() |
295 |
|
|
* |
296 |
|
|
* inputs - |
297 |
|
|
* output - NONE |
298 |
|
|
* side effects - kline as given, is added to the hashtable |
299 |
|
|
* and conf file |
300 |
|
|
*/ |
301 |
|
|
static void |
302 |
|
|
apply_kline(struct Client *source_p, struct ConfItem *conf, |
303 |
|
|
const char *current_date, time_t cur_time) |
304 |
|
|
{ |
305 |
|
|
struct AccessItem *aconf = map_to_conf(conf); |
306 |
|
|
|
307 |
|
|
add_conf_by_address(CONF_KILL, aconf); |
308 |
|
|
write_conf_line(source_p, conf, current_date, cur_time); |
309 |
|
|
/* Now, activate kline against current online clients */ |
310 |
|
|
rehashed_klines = 1; |
311 |
|
|
} |
312 |
|
|
|
313 |
|
|
/* apply_tkline() |
314 |
|
|
* |
315 |
|
|
* inputs - |
316 |
|
|
* output - NONE |
317 |
|
|
* side effects - tkline as given is placed |
318 |
|
|
*/ |
319 |
|
|
static void |
320 |
|
|
apply_tkline(struct Client *source_p, struct ConfItem *conf, |
321 |
|
|
int tkline_time) |
322 |
|
|
{ |
323 |
|
|
struct AccessItem *aconf; |
324 |
|
|
|
325 |
|
|
aconf = (struct AccessItem *)map_to_conf(conf); |
326 |
|
|
aconf->hold = CurrentTime + tkline_time; |
327 |
|
|
add_temp_line(conf); |
328 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
329 |
|
|
"%s added temporary %d min. K-Line for [%s@%s] [%s]", |
330 |
|
|
get_oper_name(source_p), tkline_time/60, |
331 |
|
|
aconf->user, aconf->host, |
332 |
|
|
aconf->reason); |
333 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. K-Line [%s@%s]", |
334 |
|
|
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
335 |
|
|
source_p->name, tkline_time/60, aconf->user, aconf->host); |
336 |
|
|
ilog(L_TRACE, "%s added temporary %d min. K-Line for [%s@%s] [%s]", |
337 |
|
|
source_p->name, tkline_time/60, |
338 |
|
|
aconf->user, aconf->host, aconf->reason); |
339 |
|
|
log_oper_action(LOG_TEMP_KLINE_TYPE, source_p, "[%s@%s] [%s]\n", |
340 |
|
|
aconf->user, aconf->host, aconf->reason); |
341 |
|
|
rehashed_klines = 1; |
342 |
|
|
} |
343 |
|
|
|
344 |
|
|
/* apply_tdline() |
345 |
|
|
* |
346 |
|
|
* inputs - |
347 |
|
|
* output - NONE |
348 |
|
|
* side effects - tkline as given is placed |
349 |
|
|
*/ |
350 |
|
|
static void |
351 |
|
|
apply_tdline(struct Client *source_p, struct ConfItem *conf, |
352 |
|
|
const char *current_date, int tkline_time) |
353 |
|
|
{ |
354 |
|
|
struct AccessItem *aconf; |
355 |
|
|
|
356 |
|
|
aconf = map_to_conf(conf); |
357 |
|
|
aconf->hold = CurrentTime + tkline_time; |
358 |
|
|
|
359 |
|
|
add_temp_line(conf); |
360 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
361 |
|
|
"%s added temporary %d min. D-Line for [%s] [%s]", |
362 |
|
|
get_oper_name(source_p), tkline_time/60, |
363 |
|
|
aconf->host, aconf->reason); |
364 |
|
|
|
365 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]", |
366 |
|
|
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
367 |
|
|
source_p->name, tkline_time/60, aconf->host); |
368 |
|
|
ilog(L_TRACE, "%s added temporary %d min. D-Line for [%s] [%s]", |
369 |
|
|
source_p->name, tkline_time/60, aconf->host, aconf->reason); |
370 |
|
|
log_oper_action(LOG_TEMP_DLINE_TYPE, source_p, "[%s@%s] [%s]\n", |
371 |
|
|
aconf->user, aconf->host, aconf->reason); |
372 |
|
|
rehashed_klines = 1; |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
/* mo_dline() |
376 |
|
|
* |
377 |
|
|
* inputs - pointer to server |
378 |
|
|
* - pointer to client |
379 |
|
|
* - parameter count |
380 |
|
|
* - parameter list |
381 |
|
|
* output - |
382 |
|
|
* side effects - D line is added |
383 |
|
|
* |
384 |
|
|
*/ |
385 |
|
|
static void |
386 |
|
|
mo_dline(struct Client *client_p, struct Client *source_p, |
387 |
|
|
int parc, char *parv[]) |
388 |
|
|
{ |
389 |
|
|
char def_reason[] = "No reason"; |
390 |
|
|
char *dlhost, *oper_reason, *reason; |
391 |
|
|
const char *creason; |
392 |
michael |
611 |
const struct Client *target_p = NULL; |
393 |
adx |
30 |
struct irc_ssaddr daddr; |
394 |
|
|
struct ConfItem *conf=NULL; |
395 |
|
|
struct AccessItem *aconf=NULL; |
396 |
|
|
time_t tkline_time=0; |
397 |
|
|
int bits, t; |
398 |
michael |
611 |
const char *current_date = NULL; |
399 |
adx |
30 |
time_t cur_time; |
400 |
michael |
611 |
char hostip[HOSTIPLEN]; |
401 |
adx |
30 |
|
402 |
|
|
if (!IsOperK(source_p)) |
403 |
|
|
{ |
404 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
405 |
|
|
me.name, source_p->name, "kline"); |
406 |
|
|
return; |
407 |
|
|
} |
408 |
|
|
|
409 |
michael |
611 |
if (parse_aline("DLINE", source_p, parc, parv, AWILD, &dlhost, |
410 |
|
|
NULL, &tkline_time, NULL, &reason) < 0) |
411 |
adx |
30 |
return; |
412 |
|
|
|
413 |
|
|
if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST) |
414 |
|
|
{ |
415 |
michael |
611 |
if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL) |
416 |
|
|
return; |
417 |
adx |
30 |
|
418 |
michael |
611 |
if (!MyConnect(target_p)) |
419 |
|
|
{ |
420 |
|
|
sendto_one(source_p, |
421 |
|
|
":%s NOTICE %s :Can't DLINE nick on another server", |
422 |
|
|
me.name, source_p->name); |
423 |
|
|
return; |
424 |
|
|
} |
425 |
adx |
30 |
|
426 |
michael |
611 |
if (IsExemptKline(target_p)) |
427 |
|
|
{ |
428 |
|
|
sendto_one(source_p, |
429 |
|
|
":%s NOTICE %s :%s is E-lined", me.name, |
430 |
|
|
source_p->name, target_p->name); |
431 |
|
|
return; |
432 |
|
|
} |
433 |
adx |
30 |
|
434 |
michael |
611 |
irc_getnameinfo((struct sockaddr *)&target_p->localClient->ip, |
435 |
|
|
target_p->localClient->ip.ss_len, hostip, |
436 |
|
|
sizeof(hostip), NULL, 0, NI_NUMERICHOST); |
437 |
adx |
30 |
|
438 |
michael |
611 |
dlhost = hostip; |
439 |
|
|
t = parse_netmask(dlhost, NULL, &bits); |
440 |
|
|
assert(t == HM_IPV4 || t == HM_IPV6); |
441 |
|
|
} |
442 |
adx |
30 |
|
443 |
|
|
if (bits < 8) |
444 |
|
|
{ |
445 |
|
|
sendto_one(source_p, |
446 |
michael |
611 |
":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.", |
447 |
|
|
me.name, source_p->name); |
448 |
adx |
30 |
return; |
449 |
|
|
} |
450 |
|
|
|
451 |
|
|
#ifdef IPV6 |
452 |
|
|
if (t == HM_IPV6) |
453 |
|
|
t = AF_INET6; |
454 |
|
|
else |
455 |
|
|
#endif |
456 |
|
|
t = AF_INET; |
457 |
|
|
|
458 |
|
|
parse_netmask(dlhost, &daddr, NULL); |
459 |
|
|
|
460 |
|
|
if ((aconf = find_dline_conf(&daddr, t)) != NULL) |
461 |
|
|
{ |
462 |
|
|
creason = aconf->reason ? aconf->reason : def_reason; |
463 |
|
|
if (IsConfExemptKline(aconf)) |
464 |
|
|
sendto_one(source_p, |
465 |
|
|
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", |
466 |
|
|
me.name, source_p->name, dlhost, aconf->host, creason); |
467 |
|
|
else |
468 |
|
|
sendto_one(source_p, |
469 |
|
|
":%s NOTICE %s :[%s] already D-lined by [%s] - %s", |
470 |
|
|
me.name, source_p->name, dlhost, aconf->host, creason); |
471 |
|
|
return; |
472 |
|
|
} |
473 |
|
|
|
474 |
|
|
cur_time = CurrentTime; |
475 |
|
|
current_date = smalldate(cur_time); |
476 |
|
|
|
477 |
|
|
/* Look for an oper reason */ |
478 |
|
|
if ((oper_reason = strchr(reason, '|')) != NULL) |
479 |
|
|
*oper_reason++ = '\0'; |
480 |
|
|
|
481 |
|
|
if (!valid_comment(source_p, reason, YES)) |
482 |
|
|
return; |
483 |
|
|
|
484 |
|
|
conf = make_conf_item(DLINE_TYPE); |
485 |
|
|
aconf = map_to_conf(conf); |
486 |
|
|
DupString(aconf->host, dlhost); |
487 |
|
|
|
488 |
|
|
if (tkline_time != 0) |
489 |
|
|
{ |
490 |
|
|
ircsprintf(buffer, "Temporary D-line %d min. - %s (%s)", |
491 |
|
|
(int)(tkline_time/60), reason, current_date); |
492 |
|
|
DupString(aconf->reason, buffer); |
493 |
|
|
if (oper_reason != NULL) |
494 |
|
|
DupString(aconf->oper_reason, oper_reason); |
495 |
|
|
apply_tdline(source_p, conf, current_date, tkline_time); |
496 |
|
|
} |
497 |
|
|
else |
498 |
|
|
{ |
499 |
|
|
ircsprintf(buffer, "%s (%s)", reason, current_date); |
500 |
|
|
DupString(aconf->reason, buffer); |
501 |
|
|
if (oper_reason != NULL) |
502 |
|
|
DupString(aconf->oper_reason, oper_reason); |
503 |
|
|
add_conf_by_address(CONF_DLINE, aconf); |
504 |
|
|
write_conf_line(source_p, conf, current_date, cur_time); |
505 |
|
|
} |
506 |
|
|
|
507 |
|
|
rehashed_klines = 1; |
508 |
michael |
611 |
} |
509 |
adx |
30 |
|
510 |
|
|
/* already_placed_kline() |
511 |
|
|
* inputs - user to complain to, username & host to check for |
512 |
|
|
* outputs - returns 1 on existing K-line, 0 if doesn't exist |
513 |
|
|
* side effects - notifies source_p if the K-line already exists |
514 |
|
|
*/ |
515 |
|
|
/* |
516 |
|
|
* Note: This currently works if the new K-line is a special case of an |
517 |
|
|
* existing K-line, but not the other way round. To do that we would |
518 |
|
|
* have to walk the hash and check every existing K-line. -A1kmm. |
519 |
|
|
*/ |
520 |
|
|
static int |
521 |
|
|
already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn) |
522 |
|
|
{ |
523 |
|
|
const char *reason; |
524 |
|
|
struct irc_ssaddr iphost, *piphost; |
525 |
|
|
struct AccessItem *aconf; |
526 |
|
|
int t; |
527 |
|
|
|
528 |
|
|
if ((t = parse_netmask(lhost, &iphost, &t)) != HM_HOST) |
529 |
|
|
{ |
530 |
|
|
#ifdef IPV6 |
531 |
|
|
if (t == HM_IPV6) |
532 |
|
|
t = AF_INET6; |
533 |
|
|
else |
534 |
|
|
#endif |
535 |
|
|
t = AF_INET; |
536 |
|
|
piphost = &iphost; |
537 |
|
|
} |
538 |
|
|
else |
539 |
|
|
{ |
540 |
|
|
t = 0; |
541 |
|
|
piphost = NULL; |
542 |
|
|
} |
543 |
|
|
|
544 |
|
|
if ((aconf = find_conf_by_address(lhost, piphost, CONF_KILL, t, luser, NULL))) |
545 |
|
|
{ |
546 |
|
|
if (warn) |
547 |
|
|
{ |
548 |
|
|
reason = aconf->reason ? aconf->reason : "No reason"; |
549 |
|
|
sendto_one(source_p, |
550 |
|
|
":%s NOTICE %s :[%s@%s] already K-Lined by [%s@%s] - %s", |
551 |
|
|
me.name, source_p->name, luser, lhost, aconf->user, |
552 |
|
|
aconf->host, reason); |
553 |
|
|
} |
554 |
|
|
return(1); |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
return(0); |
558 |
|
|
} |
559 |
|
|
|
560 |
|
|
/* |
561 |
|
|
** mo_unkline |
562 |
|
|
** Added Aug 31, 1997 |
563 |
|
|
** common (Keith Fralick) fralick@gate.net |
564 |
|
|
** |
565 |
|
|
** parv[0] = sender |
566 |
|
|
** parv[1] = address to remove |
567 |
|
|
* |
568 |
|
|
* |
569 |
|
|
*/ |
570 |
|
|
static void |
571 |
|
|
mo_unkline(struct Client *client_p,struct Client *source_p, |
572 |
|
|
int parc, char *parv[]) |
573 |
|
|
{ |
574 |
|
|
char *target_server = NULL; |
575 |
|
|
char *user, *host; |
576 |
|
|
|
577 |
|
|
if (!IsOperUnkline(source_p)) |
578 |
|
|
{ |
579 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
580 |
|
|
me.name, source_p->name, "unkline"); |
581 |
|
|
return; |
582 |
|
|
} |
583 |
|
|
|
584 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
585 |
|
|
{ |
586 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
587 |
|
|
me.name, source_p->name, "UNKLINE"); |
588 |
|
|
return; |
589 |
|
|
} |
590 |
|
|
|
591 |
|
|
if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user, |
592 |
|
|
&host, NULL, &target_server, NULL) < 0) |
593 |
|
|
return; |
594 |
|
|
|
595 |
|
|
if (target_server != NULL) |
596 |
|
|
{ |
597 |
|
|
sendto_match_servs(source_p, target_server, CAP_UNKLN, |
598 |
|
|
"UNKLINE %s %s %s", |
599 |
|
|
target_server, user, host); |
600 |
|
|
|
601 |
|
|
/* Allow ON to apply local unkline as well if it matches */ |
602 |
|
|
if (!match(target_server, me.name)) |
603 |
|
|
return; |
604 |
|
|
} |
605 |
|
|
else |
606 |
|
|
cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE, |
607 |
|
|
"%s %s", user, host); |
608 |
|
|
|
609 |
|
|
if (remove_tkline_match(host, user)) |
610 |
|
|
{ |
611 |
|
|
sendto_one(source_p, |
612 |
|
|
":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines", |
613 |
|
|
me.name, source_p->name, user, host); |
614 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
615 |
|
|
"%s has removed the temporary K-Line for: [%s@%s]", |
616 |
|
|
get_oper_name(source_p), user, host); |
617 |
|
|
ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]", |
618 |
|
|
source_p->name, user, host); |
619 |
|
|
return; |
620 |
|
|
} |
621 |
|
|
|
622 |
|
|
if (remove_conf_line(KLINE_TYPE, source_p, user, host) > 0) |
623 |
|
|
{ |
624 |
|
|
sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed", |
625 |
|
|
me.name, source_p->name, user,host); |
626 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
627 |
|
|
"%s has removed the K-Line for: [%s@%s]", |
628 |
|
|
get_oper_name(source_p), user, host); |
629 |
|
|
ilog(L_NOTICE, "%s removed K-Line for [%s@%s]", |
630 |
|
|
source_p->name, user, host); |
631 |
|
|
} |
632 |
|
|
else |
633 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found", |
634 |
|
|
me.name, source_p->name, user, host); |
635 |
|
|
} |
636 |
|
|
|
637 |
|
|
/* me_unkline() |
638 |
|
|
* |
639 |
|
|
* inputs - server |
640 |
|
|
* - client |
641 |
|
|
* - parc |
642 |
|
|
* - parv |
643 |
|
|
* outputs - none |
644 |
|
|
* side effects - if server is authorized, kline is removed |
645 |
|
|
* does not propagate message |
646 |
|
|
*/ |
647 |
|
|
static void |
648 |
|
|
me_unkline(struct Client *client_p, struct Client *source_p, |
649 |
|
|
int parc, char *parv[]) |
650 |
|
|
{ |
651 |
|
|
const char *kuser, *khost; |
652 |
|
|
|
653 |
|
|
if (parc != 4) |
654 |
|
|
return; |
655 |
|
|
|
656 |
|
|
kuser = parv[2]; |
657 |
|
|
khost = parv[3]; |
658 |
|
|
|
659 |
|
|
if (!IsClient(source_p) || !match(parv[1], me.name)) |
660 |
|
|
return; |
661 |
|
|
|
662 |
|
|
if (find_matching_name_conf(ULINE_TYPE, |
663 |
|
|
source_p->servptr->name, |
664 |
|
|
source_p->username, source_p->host, |
665 |
|
|
SHARED_UNKLINE)) |
666 |
|
|
{ |
667 |
|
|
if (remove_tkline_match(khost, kuser)) |
668 |
|
|
{ |
669 |
|
|
sendto_one(source_p, |
670 |
|
|
":%s NOTICE %s :Un-klined [%s@%s] from temporary K-Lines", |
671 |
|
|
me.name, source_p->name, kuser, khost); |
672 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
673 |
|
|
"%s has removed the temporary K-Line for: [%s@%s]", |
674 |
|
|
get_oper_name(source_p), kuser, khost); |
675 |
|
|
ilog(L_NOTICE, "%s removed temporary K-Line for [%s@%s]", |
676 |
|
|
source_p->name, kuser, khost); |
677 |
|
|
return; |
678 |
|
|
} |
679 |
|
|
|
680 |
|
|
if (remove_conf_line(KLINE_TYPE, source_p, kuser, khost) > 0) |
681 |
|
|
{ |
682 |
|
|
sendto_one(source_p, ":%s NOTICE %s :K-Line for [%s@%s] is removed", |
683 |
|
|
me.name, source_p->name, kuser, khost); |
684 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
685 |
|
|
"%s has removed the K-Line for: [%s@%s]", |
686 |
|
|
get_oper_name(source_p), kuser, khost); |
687 |
|
|
|
688 |
|
|
ilog(L_NOTICE, "%s removed K-Line for [%s@%s]", |
689 |
|
|
source_p->name, kuser, khost); |
690 |
|
|
} |
691 |
|
|
else |
692 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No K-Line for [%s@%s] found", |
693 |
|
|
me.name, source_p->name, kuser, khost); |
694 |
|
|
} |
695 |
|
|
} |
696 |
|
|
|
697 |
|
|
/* ms_unkline - propagates and handles a remote unkline message */ |
698 |
|
|
static void |
699 |
|
|
ms_unkline(struct Client *client_p, struct Client *source_p, |
700 |
|
|
int parc, char *parv[]) |
701 |
|
|
{ |
702 |
|
|
if (parc != 4) |
703 |
|
|
return; |
704 |
|
|
|
705 |
|
|
sendto_match_servs(source_p, parv[1], CAP_UNKLN, |
706 |
|
|
"UNKLINE %s %s %s", |
707 |
|
|
parv[1], parv[2], parv[3]); |
708 |
|
|
|
709 |
|
|
me_unkline(client_p, source_p, parc, parv); |
710 |
|
|
} |
711 |
|
|
|
712 |
|
|
/* static int remove_tkline_match(const char *host, const char *user) |
713 |
|
|
* Input: A hostname, a username to unkline. |
714 |
|
|
* Output: returns YES on success, NO if no tkline removed. |
715 |
|
|
* Side effects: Any matching tklines are removed. |
716 |
|
|
*/ |
717 |
|
|
static int |
718 |
|
|
remove_tkline_match(const char *host, const char *user) |
719 |
|
|
{ |
720 |
|
|
struct AccessItem *tk_c; |
721 |
|
|
dlink_node *tk_n; |
722 |
|
|
struct irc_ssaddr addr, caddr; |
723 |
|
|
int nm_t, cnm_t, bits, cbits; |
724 |
|
|
nm_t = parse_netmask(host, &addr, &bits); |
725 |
|
|
|
726 |
|
|
DLINK_FOREACH(tk_n, temporary_klines.head) |
727 |
|
|
{ |
728 |
|
|
tk_c = map_to_conf(tk_n->data); |
729 |
|
|
cnm_t = parse_netmask(tk_c->host, &caddr, &cbits); |
730 |
|
|
if (cnm_t != nm_t || irccmp(user, tk_c->user)) |
731 |
|
|
continue; |
732 |
|
|
if ((nm_t==HM_HOST && !irccmp(tk_c->host, host)) || |
733 |
|
|
(nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits)) |
734 |
|
|
#ifdef IPV6 |
735 |
|
|
|| (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits)) |
736 |
|
|
#endif |
737 |
|
|
) |
738 |
|
|
{ |
739 |
|
|
dlinkDelete(tk_n, &temporary_klines); |
740 |
|
|
delete_one_address_conf(tk_c->host, tk_c); |
741 |
|
|
return(YES); |
742 |
|
|
} |
743 |
|
|
} |
744 |
|
|
|
745 |
|
|
return(NO); |
746 |
|
|
} |
747 |
|
|
|
748 |
|
|
/* static int remove_tdline_match(const char *host, const char *user) |
749 |
|
|
* Input: An ip to undline. |
750 |
|
|
* Output: returns YES on success, NO if no tdline removed. |
751 |
|
|
* Side effects: Any matching tdlines are removed. |
752 |
|
|
*/ |
753 |
|
|
static int |
754 |
|
|
remove_tdline_match(const char *cidr) |
755 |
|
|
{ |
756 |
|
|
struct AccessItem *td_conf; |
757 |
|
|
dlink_node *td_node; |
758 |
|
|
struct irc_ssaddr addr, caddr; |
759 |
|
|
int nm_t, cnm_t, bits, cbits; |
760 |
|
|
nm_t = parse_netmask(cidr, &addr, &bits); |
761 |
|
|
|
762 |
|
|
DLINK_FOREACH(td_node, temporary_dlines.head) |
763 |
|
|
{ |
764 |
|
|
td_conf = map_to_conf(td_node->data); |
765 |
|
|
cnm_t = parse_netmask(td_conf->host, &caddr, &cbits); |
766 |
|
|
|
767 |
|
|
if (cnm_t != nm_t) |
768 |
|
|
continue; |
769 |
|
|
|
770 |
|
|
if((nm_t==HM_HOST && !irccmp(td_conf->host, cidr)) || |
771 |
|
|
(nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits)) |
772 |
|
|
#ifdef IPV6 |
773 |
|
|
|| (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits)) |
774 |
|
|
#endif |
775 |
|
|
) |
776 |
|
|
{ |
777 |
|
|
dlinkDelete(td_node, &temporary_dlines); |
778 |
|
|
delete_one_address_conf(td_conf->host, td_conf); |
779 |
|
|
return(YES); |
780 |
|
|
} |
781 |
|
|
} |
782 |
|
|
|
783 |
|
|
return(NO); |
784 |
|
|
} |
785 |
|
|
|
786 |
|
|
/* |
787 |
|
|
** m_undline |
788 |
|
|
** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk> |
789 |
|
|
** based totally on m_unkline |
790 |
|
|
** added to hybrid-7 7/11/2000 --is |
791 |
|
|
** |
792 |
|
|
** parv[0] = sender nick |
793 |
|
|
** parv[1] = dline to remove |
794 |
|
|
*/ |
795 |
|
|
static void |
796 |
|
|
mo_undline(struct Client *client_p, struct Client *source_p, |
797 |
|
|
int parc, char *parv[]) |
798 |
|
|
{ |
799 |
|
|
const char *cidr; |
800 |
|
|
|
801 |
|
|
if (!IsOperUnkline(source_p)) |
802 |
|
|
{ |
803 |
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS), |
804 |
|
|
me.name, source_p->name, "undline"); |
805 |
|
|
return; |
806 |
|
|
} |
807 |
|
|
|
808 |
|
|
cidr = parv[1]; |
809 |
|
|
|
810 |
|
|
if (remove_tdline_match(cidr)) |
811 |
|
|
{ |
812 |
|
|
sendto_one(source_p, |
813 |
|
|
":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines", |
814 |
|
|
me.name, source_p->name, cidr); |
815 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
816 |
|
|
"%s has removed the temporary D-Line for: [%s]", |
817 |
|
|
get_oper_name(source_p), cidr); |
818 |
|
|
ilog(L_NOTICE, "%s removed temporary D-Line for [%s]", source_p->name, cidr); |
819 |
|
|
return; |
820 |
|
|
} |
821 |
|
|
|
822 |
|
|
if (remove_conf_line(DLINE_TYPE, source_p, cidr, NULL) > 0) |
823 |
|
|
{ |
824 |
|
|
sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", |
825 |
|
|
me.name, source_p->name, cidr); |
826 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
827 |
|
|
"%s has removed the D-Line for: [%s]", |
828 |
|
|
get_oper_name(source_p), cidr); |
829 |
|
|
ilog(L_NOTICE, "%s removed D-Line for [%s]", |
830 |
|
|
get_oper_name(source_p), cidr); |
831 |
|
|
} |
832 |
|
|
else |
833 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found", |
834 |
|
|
me.name, source_p->name, cidr); |
835 |
|
|
} |