1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 2003-2014 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 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_xline.c |
23 |
|
|
* \brief Includes required functions for processing the XLINE/UNXLINE command. |
24 |
|
|
* \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 |
adx |
30 |
#include "numeric.h" |
34 |
michael |
1309 |
#include "log.h" |
35 |
adx |
30 |
#include "send.h" |
36 |
|
|
#include "s_serv.h" |
37 |
|
|
#include "parse.h" |
38 |
|
|
#include "modules.h" |
39 |
michael |
1622 |
#include "conf_db.h" |
40 |
michael |
1666 |
#include "memory.h" |
41 |
adx |
30 |
|
42 |
|
|
|
43 |
michael |
2877 |
static void |
44 |
|
|
check_xline(struct MaskItem *conf) |
45 |
|
|
{ |
46 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
47 |
|
|
|
48 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head) |
49 |
|
|
{ |
50 |
|
|
struct Client *client_p = ptr->data; |
51 |
|
|
|
52 |
|
|
if (IsDead(client_p)) |
53 |
|
|
continue; |
54 |
|
|
|
55 |
|
|
if (!match(conf->name, client_p->username)) |
56 |
|
|
conf_try_ban(client_p, conf); |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
|
60 |
michael |
2974 |
/* static int remove_tkline_match(const char *host, const char *user) |
61 |
|
|
* |
62 |
|
|
* Inputs: gecos |
63 |
|
|
* Output: returns YES on success, NO if no tkline removed. |
64 |
|
|
* Side effects: Any matching tklines are removed. |
65 |
|
|
*/ |
66 |
|
|
static int |
67 |
|
|
remove_xline_match(const char *gecos) |
68 |
|
|
{ |
69 |
|
|
dlink_node *ptr = NULL, *next_ptr = NULL; |
70 |
|
|
|
71 |
|
|
DLINK_FOREACH_SAFE(ptr, next_ptr, xconf_items.head) |
72 |
|
|
{ |
73 |
|
|
struct MaskItem *conf = ptr->data; |
74 |
|
|
|
75 |
|
|
if (!IsConfDatabase(conf)) |
76 |
|
|
continue; |
77 |
|
|
|
78 |
|
|
if (!irccmp(gecos, conf->name)) |
79 |
|
|
{ |
80 |
|
|
conf_free(conf); |
81 |
|
|
return 1; |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
return 0; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
static void |
89 |
|
|
remove_xline(struct Client *source_p, const char *gecos) |
90 |
|
|
{ |
91 |
|
|
if (remove_xline_match(gecos)) |
92 |
|
|
{ |
93 |
|
|
sendto_one(source_p, |
94 |
|
|
":%s NOTICE %s :X-Line for [%s] is removed", |
95 |
|
|
me.name, source_p->name, gecos); |
96 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
97 |
|
|
"%s has removed the X-Line for: [%s]", |
98 |
|
|
get_oper_name(source_p), gecos); |
99 |
|
|
ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]", |
100 |
|
|
get_oper_name(source_p), gecos); |
101 |
|
|
} |
102 |
|
|
else |
103 |
|
|
sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s", |
104 |
|
|
me.name, source_p->name, gecos); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
/* valid_xline() |
108 |
|
|
* |
109 |
|
|
* inputs - client to complain to, gecos, reason, whether to complain |
110 |
|
|
* outputs - 1 for valid, else 0 |
111 |
|
|
* side effects - complains to client, when warn != 0 |
112 |
|
|
*/ |
113 |
|
|
static int |
114 |
|
|
valid_xline(struct Client *source_p, const char *gecos, const char *reason, int warn) |
115 |
|
|
{ |
116 |
|
|
if (EmptyString(reason)) |
117 |
|
|
{ |
118 |
|
|
if (warn) |
119 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "XLINE"); |
120 |
michael |
2974 |
return 0; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
if (!valid_wild_card_simple(gecos)) |
124 |
|
|
{ |
125 |
|
|
if (warn) |
126 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the xline", |
127 |
|
|
me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple); |
128 |
|
|
|
129 |
|
|
return 0; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
return 1; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
/* write_xline() |
136 |
|
|
* |
137 |
|
|
* inputs - client taking credit for xline, gecos, reason, xline type |
138 |
|
|
* outputs - none |
139 |
|
|
* side effects - when successful, adds an xline to the conf |
140 |
|
|
*/ |
141 |
|
|
static void |
142 |
|
|
write_xline(struct Client *source_p, char *gecos, char *reason, |
143 |
|
|
time_t tkline_time) |
144 |
|
|
{ |
145 |
|
|
struct MaskItem *conf = conf_make(CONF_XLINE); |
146 |
|
|
|
147 |
|
|
collapse(gecos); |
148 |
|
|
conf->name = xstrdup(gecos); |
149 |
|
|
conf->reason = xstrdup(reason); |
150 |
|
|
conf->setat = CurrentTime; |
151 |
|
|
|
152 |
|
|
SetConfDatabase(conf); |
153 |
|
|
|
154 |
|
|
if (tkline_time != 0) |
155 |
|
|
{ |
156 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
157 |
|
|
"%s added temporary %d min. X-Line for [%s] [%s]", |
158 |
|
|
get_oper_name(source_p), (int)tkline_time/60, |
159 |
|
|
conf->name, conf->reason); |
160 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]", |
161 |
|
|
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p), |
162 |
|
|
source_p->name, (int)tkline_time/60, conf->name); |
163 |
|
|
ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]", |
164 |
|
|
source_p->name, (int)tkline_time/60, conf->name, conf->reason); |
165 |
|
|
conf->until = CurrentTime + tkline_time; |
166 |
|
|
} |
167 |
|
|
else |
168 |
|
|
{ |
169 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
170 |
|
|
"%s added X-Line for [%s] [%s]", |
171 |
|
|
get_oper_name(source_p), conf->name, |
172 |
|
|
conf->reason); |
173 |
|
|
sendto_one(source_p, |
174 |
|
|
":%s NOTICE %s :Added X-Line [%s] [%s]", |
175 |
|
|
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p), |
176 |
|
|
source_p->name, conf->name, conf->reason); |
177 |
|
|
ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]", |
178 |
|
|
get_oper_name(source_p), conf->name, conf->reason); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
check_xline(conf); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
static void |
185 |
|
|
relay_xline(struct Client *source_p, char *parv[]) |
186 |
|
|
{ |
187 |
|
|
struct MaskItem *conf = NULL; |
188 |
|
|
int t_sec; |
189 |
|
|
|
190 |
|
|
t_sec = atoi(parv[3]); |
191 |
|
|
|
192 |
|
|
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
193 |
|
|
"XLINE %s %s %s :%s", |
194 |
|
|
parv[1], parv[2], parv[3], parv[4]); |
195 |
|
|
|
196 |
|
|
if (match(parv[1], me.name)) |
197 |
|
|
return; |
198 |
|
|
|
199 |
|
|
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
200 |
|
|
source_p->username, source_p->host, |
201 |
|
|
SHARED_XLINE)) |
202 |
|
|
{ |
203 |
|
|
if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0))) |
204 |
|
|
{ |
205 |
|
|
sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", |
206 |
|
|
ID_or_name(&me, source_p), |
207 |
|
|
ID_or_name(source_p, source_p), |
208 |
|
|
parv[2], conf->name, conf->reason); |
209 |
|
|
return; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
write_xline(source_p, parv[2], parv[4], t_sec); |
213 |
|
|
} |
214 |
|
|
} |
215 |
|
|
|
216 |
adx |
30 |
/* mo_xline() |
217 |
|
|
* |
218 |
|
|
* inputs - pointer to server |
219 |
|
|
* - pointer to client |
220 |
|
|
* - parameter count |
221 |
|
|
* - parameter list |
222 |
|
|
* output - |
223 |
|
|
* side effects - x line is added |
224 |
|
|
* |
225 |
|
|
*/ |
226 |
michael |
2820 |
static int |
227 |
adx |
30 |
mo_xline(struct Client *client_p, struct Client *source_p, |
228 |
|
|
int parc, char *parv[]) |
229 |
|
|
{ |
230 |
|
|
char *reason = NULL; |
231 |
|
|
char *gecos = NULL; |
232 |
michael |
1632 |
struct MaskItem *conf = NULL; |
233 |
adx |
30 |
char *target_server = NULL; |
234 |
|
|
time_t tkline_time = 0; |
235 |
|
|
|
236 |
michael |
2852 |
if (!HasOFlag(source_p, OPER_FLAG_XLINE)) |
237 |
adx |
30 |
{ |
238 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline"); |
239 |
michael |
2820 |
return 0; |
240 |
adx |
30 |
} |
241 |
|
|
|
242 |
|
|
/* |
243 |
|
|
* XLINE <gecos> <time> ON <mask> :<reason> |
244 |
|
|
* XLINE <gecos> ON <mask> :<reason> |
245 |
|
|
*/ |
246 |
|
|
if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL, |
247 |
|
|
&tkline_time, &target_server, &reason) < 0) |
248 |
michael |
2820 |
return 0; |
249 |
adx |
30 |
|
250 |
|
|
if (target_server != NULL) |
251 |
|
|
{ |
252 |
|
|
/* if a given expire time is given, ENCAP it */ |
253 |
|
|
if (tkline_time != 0) |
254 |
|
|
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
255 |
michael |
2820 |
"ENCAP %s XLINE %d %s 0 :%s", |
256 |
|
|
target_server, (int)tkline_time, gecos, reason); |
257 |
adx |
30 |
else |
258 |
|
|
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
259 |
michael |
2820 |
"XLINE %s %s %d :%s", |
260 |
|
|
target_server, gecos, (int)tkline_time, reason); |
261 |
adx |
30 |
|
262 |
|
|
/* Allow ON to apply local xline as well if it matches */ |
263 |
michael |
1652 |
if (match(target_server, me.name)) |
264 |
michael |
2820 |
return 0; |
265 |
adx |
30 |
} |
266 |
michael |
2820 |
else |
267 |
adx |
30 |
{ |
268 |
|
|
if (tkline_time != 0) |
269 |
|
|
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE, |
270 |
michael |
2820 |
"XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason); |
271 |
adx |
30 |
else |
272 |
|
|
cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE, |
273 |
michael |
2820 |
"%s 0 :%s", gecos, reason); |
274 |
adx |
30 |
} |
275 |
|
|
|
276 |
|
|
if (!valid_xline(source_p, gecos, reason, 0)) |
277 |
michael |
2820 |
return 0; |
278 |
adx |
30 |
|
279 |
michael |
2820 |
if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0))) |
280 |
adx |
30 |
{ |
281 |
|
|
sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", |
282 |
|
|
me.name, source_p->name, gecos, |
283 |
michael |
1632 |
conf->name, conf->reason); |
284 |
michael |
2820 |
return 0; |
285 |
adx |
30 |
} |
286 |
|
|
|
287 |
|
|
write_xline(source_p, gecos, reason, tkline_time); |
288 |
michael |
2820 |
return 0; |
289 |
adx |
30 |
} |
290 |
|
|
|
291 |
|
|
/* ms_xline() |
292 |
|
|
* |
293 |
|
|
* inputs - oper, target server, xline, {type}, reason |
294 |
|
|
* |
295 |
|
|
* outputs - none |
296 |
|
|
* side effects - propagates xline, applies it if we are a target |
297 |
|
|
*/ |
298 |
michael |
2820 |
static int |
299 |
adx |
30 |
ms_xline(struct Client *client_p, struct Client *source_p, |
300 |
|
|
int parc, char *parv[]) |
301 |
|
|
{ |
302 |
|
|
if (parc != 5 || EmptyString(parv[4])) |
303 |
michael |
2820 |
return 0; |
304 |
adx |
30 |
|
305 |
|
|
if (!IsClient(source_p)) |
306 |
michael |
2820 |
return 0; |
307 |
adx |
30 |
|
308 |
|
|
if (!valid_xline(source_p, parv[2], parv[4], 0)) |
309 |
michael |
2820 |
return 0; |
310 |
adx |
30 |
|
311 |
|
|
relay_xline(source_p, parv); |
312 |
michael |
2820 |
return 0; |
313 |
adx |
30 |
} |
314 |
|
|
|
315 |
|
|
/* me_xline() |
316 |
|
|
* |
317 |
|
|
* inputs - server |
318 |
|
|
* - client (oper) |
319 |
|
|
* - parc number of arguments |
320 |
|
|
* - parv list of arguments |
321 |
|
|
* via parv[] |
322 |
michael |
2828 |
* parv[1] = target server |
323 |
|
|
* parv[2] = xline |
324 |
|
|
* parv[3] = time |
325 |
|
|
* parv[4] = reason |
326 |
adx |
30 |
* |
327 |
|
|
* outputs - none |
328 |
michael |
2820 |
* side effects - |
329 |
adx |
30 |
*/ |
330 |
michael |
2820 |
static int |
331 |
adx |
30 |
me_xline(struct Client *client_p, struct Client *source_p, |
332 |
|
|
int parc, char *parv[]) |
333 |
|
|
{ |
334 |
|
|
if (!IsClient(source_p) || parc != 5) |
335 |
michael |
2820 |
return 0; |
336 |
adx |
30 |
|
337 |
|
|
relay_xline(source_p, parv); |
338 |
michael |
2820 |
return 0; |
339 |
adx |
30 |
} |
340 |
|
|
|
341 |
|
|
/* mo_unxline() |
342 |
|
|
* |
343 |
|
|
* inputs - pointer to server |
344 |
|
|
* - pointer to client |
345 |
|
|
* - parameter count |
346 |
|
|
* - parameter list |
347 |
|
|
* output - |
348 |
|
|
* side effects - removes a xline |
349 |
|
|
*/ |
350 |
michael |
2820 |
static int |
351 |
adx |
30 |
mo_unxline(struct Client *client_p, struct Client *source_p, |
352 |
|
|
int parc, char *parv[]) |
353 |
|
|
{ |
354 |
|
|
char *gecos = NULL; |
355 |
|
|
char *target_server = NULL; |
356 |
|
|
|
357 |
michael |
2852 |
if (!HasOFlag(source_p, OPER_FLAG_UNXLINE)) |
358 |
adx |
30 |
{ |
359 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "unxline"); |
360 |
michael |
2820 |
return 0; |
361 |
adx |
30 |
} |
362 |
|
|
|
363 |
|
|
/* UNXLINE bill ON irc.server.com */ |
364 |
|
|
if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos, |
365 |
|
|
NULL, NULL, &target_server, NULL) < 0) |
366 |
michael |
2820 |
return 0; |
367 |
adx |
30 |
|
368 |
|
|
if (target_server != NULL) |
369 |
|
|
{ |
370 |
|
|
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
371 |
|
|
"UNXLINE %s %s", target_server, gecos); |
372 |
|
|
|
373 |
|
|
/* Allow ON to apply local unxline as well if it matches */ |
374 |
michael |
1652 |
if (match(target_server, me.name)) |
375 |
michael |
2820 |
return 0; |
376 |
adx |
30 |
} |
377 |
|
|
else |
378 |
|
|
cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE, |
379 |
michael |
2820 |
"%s", gecos); |
380 |
adx |
30 |
|
381 |
|
|
remove_xline(source_p, gecos); |
382 |
michael |
2820 |
return 0; |
383 |
adx |
30 |
} |
384 |
|
|
|
385 |
|
|
/* ms_unxline() |
386 |
|
|
* |
387 |
|
|
* inputs - oper, target server, gecos |
388 |
|
|
* outputs - none |
389 |
|
|
* side effects - propagates unxline, applies it if we are a target |
390 |
|
|
*/ |
391 |
michael |
2820 |
static int |
392 |
adx |
30 |
ms_unxline(struct Client *client_p, struct Client *source_p, |
393 |
|
|
int parc, char *parv[]) |
394 |
|
|
{ |
395 |
|
|
if (parc != 3) |
396 |
michael |
2820 |
return 0; |
397 |
adx |
30 |
|
398 |
|
|
if (!IsClient(source_p) || EmptyString(parv[2])) |
399 |
michael |
2820 |
return 0; |
400 |
adx |
30 |
|
401 |
|
|
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
402 |
|
|
"UNXLINE %s %s", parv[1], parv[2]); |
403 |
|
|
|
404 |
michael |
1652 |
if (match(parv[1], me.name)) |
405 |
michael |
2820 |
return 0; |
406 |
adx |
30 |
|
407 |
michael |
1632 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
408 |
adx |
30 |
source_p->username, source_p->host, |
409 |
|
|
SHARED_UNXLINE)) |
410 |
|
|
remove_xline(source_p, parv[2]); |
411 |
michael |
2820 |
return 0; |
412 |
adx |
30 |
} |
413 |
|
|
|
414 |
michael |
2820 |
static struct Message xline_msgtab = |
415 |
|
|
{ |
416 |
michael |
1230 |
"XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
417 |
|
|
{ m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore } |
418 |
|
|
}; |
419 |
|
|
|
420 |
michael |
2820 |
static struct Message unxline_msgtab = |
421 |
|
|
{ |
422 |
michael |
1230 |
"UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
423 |
|
|
{ m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore } |
424 |
|
|
}; |
425 |
|
|
|
426 |
|
|
static void |
427 |
|
|
module_init(void) |
428 |
|
|
{ |
429 |
|
|
mod_add_cmd(&xline_msgtab); |
430 |
|
|
mod_add_cmd(&unxline_msgtab); |
431 |
|
|
} |
432 |
|
|
|
433 |
|
|
static void |
434 |
|
|
module_exit(void) |
435 |
|
|
{ |
436 |
|
|
mod_del_cmd(&xline_msgtab); |
437 |
|
|
mod_del_cmd(&unxline_msgtab); |
438 |
|
|
} |
439 |
|
|
|
440 |
michael |
2820 |
struct module module_entry = |
441 |
|
|
{ |
442 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
443 |
|
|
.name = NULL, |
444 |
|
|
.version = "$Revision$", |
445 |
|
|
.handle = NULL, |
446 |
|
|
.modinit = module_init, |
447 |
|
|
.modexit = module_exit, |
448 |
|
|
.flags = 0 |
449 |
|
|
}; |