1 |
/* |
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 |
* $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 "fdlist.h" |
35 |
#include "s_bsd.h" |
36 |
#include "log.h" |
37 |
#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 |
#include "conf_db.h" |
45 |
#include "memory.h" |
46 |
|
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 |
static int remove_xline_match(const char *); |
52 |
|
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 |
struct MaskItem *conf = NULL; |
72 |
char *target_server = NULL; |
73 |
time_t tkline_time = 0; |
74 |
|
75 |
if (!HasOFlag(source_p, OPER_FLAG_X)) |
76 |
{ |
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 |
if (match(target_server, me.name)) |
104 |
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 |
if ((conf = find_matching_name_conf(CONF_XLINE, gecos, |
120 |
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 |
conf->name, conf->reason); |
125 |
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 |
struct MaskItem *conf = NULL; |
185 |
int t_sec; |
186 |
|
187 |
t_sec = atoi(parv[3]); |
188 |
|
189 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
190 |
"XLINE %s %s %s :%s", |
191 |
parv[1], parv[2], parv[3], parv[4]); |
192 |
|
193 |
if (match(parv[1], me.name)) |
194 |
return; |
195 |
|
196 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
197 |
source_p->username, source_p->host, |
198 |
SHARED_XLINE)) |
199 |
{ |
200 |
if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], |
201 |
NULL, NULL, 0)) != NULL) |
202 |
{ |
203 |
sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", |
204 |
ID_or_name(&me, source_p->from), |
205 |
ID_or_name(source_p, source_p->from), |
206 |
parv[2], conf->name, conf->reason); |
207 |
return; |
208 |
} |
209 |
|
210 |
write_xline(source_p, parv[2], parv[4], t_sec); |
211 |
} |
212 |
} |
213 |
|
214 |
/* mo_unxline() |
215 |
* |
216 |
* inputs - pointer to server |
217 |
* - pointer to client |
218 |
* - parameter count |
219 |
* - parameter list |
220 |
* output - |
221 |
* side effects - removes a xline |
222 |
*/ |
223 |
static void |
224 |
mo_unxline(struct Client *client_p, struct Client *source_p, |
225 |
int parc, char *parv[]) |
226 |
{ |
227 |
char *gecos = NULL; |
228 |
char *target_server = NULL; |
229 |
|
230 |
if (!HasOFlag(source_p, OPER_FLAG_X)) |
231 |
{ |
232 |
sendto_one(source_p, form_str(ERR_NOPRIVS), |
233 |
me.name, source_p->name, "unxline"); |
234 |
return; |
235 |
} |
236 |
|
237 |
/* UNXLINE bill ON irc.server.com */ |
238 |
if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos, |
239 |
NULL, NULL, &target_server, NULL) < 0) |
240 |
return; |
241 |
|
242 |
if (target_server != NULL) |
243 |
{ |
244 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
245 |
"UNXLINE %s %s", target_server, gecos); |
246 |
|
247 |
/* Allow ON to apply local unxline as well if it matches */ |
248 |
if (match(target_server, me.name)) |
249 |
return; |
250 |
} |
251 |
else |
252 |
cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE, |
253 |
"%s", gecos); |
254 |
|
255 |
remove_xline(source_p, gecos); |
256 |
} |
257 |
|
258 |
/* ms_unxline() |
259 |
* |
260 |
* inputs - oper, target server, gecos |
261 |
* outputs - none |
262 |
* side effects - propagates unxline, applies it if we are a target |
263 |
*/ |
264 |
static void |
265 |
ms_unxline(struct Client *client_p, struct Client *source_p, |
266 |
int parc, char *parv[]) |
267 |
{ |
268 |
if (parc != 3) |
269 |
return; |
270 |
|
271 |
if (!IsClient(source_p) || EmptyString(parv[2])) |
272 |
return; |
273 |
|
274 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
275 |
"UNXLINE %s %s", parv[1], parv[2]); |
276 |
|
277 |
if (match(parv[1], me.name)) |
278 |
return; |
279 |
|
280 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
281 |
source_p->username, source_p->host, |
282 |
SHARED_UNXLINE)) |
283 |
remove_xline(source_p, parv[2]); |
284 |
} |
285 |
|
286 |
/* valid_xline() |
287 |
* |
288 |
* inputs - client to complain to, gecos, reason, whether to complain |
289 |
* outputs - 1 for valid, else 0 |
290 |
* side effects - complains to client, when warn != 0 |
291 |
*/ |
292 |
static int |
293 |
valid_xline(struct Client *source_p, char *gecos, char *reason, int warn) |
294 |
{ |
295 |
if (EmptyString(reason)) |
296 |
{ |
297 |
if (warn) |
298 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
299 |
me.name, source_p->name, "XLINE"); |
300 |
return 0; |
301 |
} |
302 |
|
303 |
if (!valid_wild_card_simple(gecos)) |
304 |
{ |
305 |
if (warn) |
306 |
sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the xline", |
307 |
me.name, source_p->name, ConfigFileEntry.min_nonwildcard_simple); |
308 |
|
309 |
return 0; |
310 |
} |
311 |
|
312 |
return 1; |
313 |
} |
314 |
|
315 |
/* write_xline() |
316 |
* |
317 |
* inputs - client taking credit for xline, gecos, reason, xline type |
318 |
* outputs - none |
319 |
* side effects - when successful, adds an xline to the conf |
320 |
*/ |
321 |
static void |
322 |
write_xline(struct Client *source_p, char *gecos, char *reason, |
323 |
time_t tkline_time) |
324 |
{ |
325 |
struct MaskItem *conf = conf_make(CONF_XLINE); |
326 |
|
327 |
collapse(gecos); |
328 |
conf->name = xstrdup(gecos); |
329 |
conf->reason = xstrdup(reason); |
330 |
conf->setat = CurrentTime; |
331 |
|
332 |
SetConfDatabase(conf); |
333 |
|
334 |
if (tkline_time != 0) |
335 |
{ |
336 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
337 |
"%s added temporary %d min. X-Line for [%s] [%s]", |
338 |
get_oper_name(source_p), (int)tkline_time/60, |
339 |
conf->name, conf->reason); |
340 |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]", |
341 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
342 |
source_p->name, (int)tkline_time/60, conf->name); |
343 |
ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]", |
344 |
source_p->name, (int)tkline_time/60, |
345 |
conf->name, conf->reason); |
346 |
conf->until = CurrentTime + tkline_time; |
347 |
} |
348 |
else |
349 |
{ |
350 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
351 |
"%s added X-Line for [%s] [%s]", |
352 |
get_oper_name(source_p), conf->name, |
353 |
conf->reason); |
354 |
sendto_one(source_p, |
355 |
":%s NOTICE %s :Added X-Line [%s] [%s]", |
356 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
357 |
source_p->name, conf->name, conf->reason); |
358 |
ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]", |
359 |
get_oper_name(source_p), conf->name, conf->reason); |
360 |
} |
361 |
|
362 |
rehashed_klines = 1; |
363 |
} |
364 |
|
365 |
static void |
366 |
remove_xline(struct Client *source_p, char *gecos) |
367 |
{ |
368 |
if (remove_xline_match(gecos)) |
369 |
{ |
370 |
sendto_one(source_p, |
371 |
":%s NOTICE %s :X-Line for [%s] is removed", |
372 |
me.name, source_p->name, gecos); |
373 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
374 |
"%s has removed the X-Line for: [%s]", |
375 |
get_oper_name(source_p), gecos); |
376 |
ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]", |
377 |
get_oper_name(source_p), gecos); |
378 |
} |
379 |
else |
380 |
sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s", |
381 |
me.name, source_p->name, gecos); |
382 |
} |
383 |
|
384 |
/* static int remove_tkline_match(const char *host, const char *user) |
385 |
* |
386 |
* Inputs: gecos |
387 |
* Output: returns YES on success, NO if no tkline removed. |
388 |
* Side effects: Any matching tklines are removed. |
389 |
*/ |
390 |
static int |
391 |
remove_xline_match(const char *gecos) |
392 |
{ |
393 |
dlink_node *ptr = NULL, *next_ptr = NULL; |
394 |
|
395 |
DLINK_FOREACH_SAFE(ptr, next_ptr, xconf_items.head) |
396 |
{ |
397 |
struct MaskItem *conf = ptr->data; |
398 |
|
399 |
if (!IsConfDatabase(conf)) |
400 |
continue; |
401 |
|
402 |
if (!irccmp(gecos, conf->name)) |
403 |
{ |
404 |
conf_free(conf); |
405 |
return 1; |
406 |
} |
407 |
} |
408 |
|
409 |
return 0; |
410 |
} |
411 |
|
412 |
static struct Message xline_msgtab = { |
413 |
"XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
414 |
{ m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore } |
415 |
}; |
416 |
|
417 |
static struct Message unxline_msgtab = { |
418 |
"UNXLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
419 |
{ m_unregistered, m_not_oper, ms_unxline, m_ignore, mo_unxline, m_ignore } |
420 |
}; |
421 |
|
422 |
static void |
423 |
module_init(void) |
424 |
{ |
425 |
mod_add_cmd(&xline_msgtab); |
426 |
mod_add_cmd(&unxline_msgtab); |
427 |
} |
428 |
|
429 |
static void |
430 |
module_exit(void) |
431 |
{ |
432 |
mod_del_cmd(&xline_msgtab); |
433 |
mod_del_cmd(&unxline_msgtab); |
434 |
} |
435 |
|
436 |
struct module module_entry = { |
437 |
.node = { NULL, NULL, NULL }, |
438 |
.name = NULL, |
439 |
.version = "$Revision$", |
440 |
.handle = NULL, |
441 |
.modinit = module_init, |
442 |
.modexit = module_exit, |
443 |
.flags = 0 |
444 |
}; |