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