1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2003-2014 ircd-hybrid development team |
5 |
* |
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 |
/*! \file m_xline.c |
23 |
* \brief Includes required functions for processing the XLINE/UNXLINE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "channel.h" |
30 |
#include "client.h" |
31 |
#include "irc_string.h" |
32 |
#include "ircd.h" |
33 |
#include "conf.h" |
34 |
#include "hostmask.h" |
35 |
#include "numeric.h" |
36 |
#include "fdlist.h" |
37 |
#include "s_bsd.h" |
38 |
#include "log.h" |
39 |
#include "s_misc.h" |
40 |
#include "send.h" |
41 |
#include "hash.h" |
42 |
#include "s_serv.h" |
43 |
#include "parse.h" |
44 |
#include "modules.h" |
45 |
#include "resv.h" |
46 |
#include "conf_db.h" |
47 |
#include "memory.h" |
48 |
|
49 |
|
50 |
static int valid_xline(struct Client *, char *, char *, int); |
51 |
static void write_xline(struct Client *, char *, char *, time_t); |
52 |
static void remove_xline(struct Client *, char *); |
53 |
static int remove_xline_match(const char *); |
54 |
|
55 |
static void relay_xline(struct Client *, char *[]); |
56 |
|
57 |
/* mo_xline() |
58 |
* |
59 |
* inputs - pointer to server |
60 |
* - pointer to client |
61 |
* - parameter count |
62 |
* - parameter list |
63 |
* output - |
64 |
* side effects - x line is added |
65 |
* |
66 |
*/ |
67 |
static int |
68 |
mo_xline(struct Client *client_p, struct Client *source_p, |
69 |
int parc, char *parv[]) |
70 |
{ |
71 |
char *reason = NULL; |
72 |
char *gecos = NULL; |
73 |
struct MaskItem *conf = NULL; |
74 |
char *target_server = NULL; |
75 |
time_t tkline_time = 0; |
76 |
|
77 |
if (!HasOFlag(source_p, OPER_FLAG_X)) |
78 |
{ |
79 |
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, |
80 |
source_p->name, "xline"); |
81 |
return 0; |
82 |
} |
83 |
|
84 |
/* |
85 |
* XLINE <gecos> <time> ON <mask> :<reason> |
86 |
* XLINE <gecos> ON <mask> :<reason> |
87 |
*/ |
88 |
if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL, |
89 |
&tkline_time, &target_server, &reason) < 0) |
90 |
return 0; |
91 |
|
92 |
if (target_server != NULL) |
93 |
{ |
94 |
/* if a given expire time is given, ENCAP it */ |
95 |
if (tkline_time != 0) |
96 |
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
97 |
"ENCAP %s XLINE %d %s 0 :%s", |
98 |
target_server, (int)tkline_time, gecos, reason); |
99 |
else |
100 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
101 |
"XLINE %s %s %d :%s", |
102 |
target_server, gecos, (int)tkline_time, reason); |
103 |
|
104 |
/* Allow ON to apply local xline as well if it matches */ |
105 |
if (match(target_server, me.name)) |
106 |
return 0; |
107 |
} |
108 |
else |
109 |
{ |
110 |
if (tkline_time != 0) |
111 |
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE, |
112 |
"XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason); |
113 |
else |
114 |
cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE, |
115 |
"%s 0 :%s", gecos, reason); |
116 |
} |
117 |
|
118 |
if (!valid_xline(source_p, gecos, reason, 0)) |
119 |
return 0; |
120 |
|
121 |
if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0))) |
122 |
{ |
123 |
sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", |
124 |
me.name, source_p->name, gecos, |
125 |
conf->name, conf->reason); |
126 |
return 0; |
127 |
} |
128 |
|
129 |
write_xline(source_p, gecos, reason, tkline_time); |
130 |
return 0; |
131 |
} |
132 |
|
133 |
/* ms_xline() |
134 |
* |
135 |
* inputs - oper, target server, xline, {type}, reason |
136 |
* |
137 |
* outputs - none |
138 |
* side effects - propagates xline, applies it if we are a target |
139 |
*/ |
140 |
static int |
141 |
ms_xline(struct Client *client_p, struct Client *source_p, |
142 |
int parc, char *parv[]) |
143 |
{ |
144 |
if (parc != 5 || EmptyString(parv[4])) |
145 |
return 0; |
146 |
|
147 |
if (!IsClient(source_p)) |
148 |
return 0; |
149 |
|
150 |
if (!valid_xline(source_p, parv[2], parv[4], 0)) |
151 |
return 0; |
152 |
|
153 |
relay_xline(source_p, parv); |
154 |
return 0; |
155 |
} |
156 |
|
157 |
/* me_xline() |
158 |
* |
159 |
* inputs - server |
160 |
* - client (oper) |
161 |
* - parc number of arguments |
162 |
* - parv list of arguments |
163 |
* via parv[] |
164 |
* parv[1] = target server |
165 |
* parv[2] = xline |
166 |
* parv[3] = time |
167 |
* parv[4] = reason |
168 |
* |
169 |
* outputs - none |
170 |
* side effects - |
171 |
*/ |
172 |
static int |
173 |
me_xline(struct Client *client_p, struct Client *source_p, |
174 |
int parc, char *parv[]) |
175 |
{ |
176 |
if (!IsClient(source_p) || parc != 5) |
177 |
return 0; |
178 |
|
179 |
relay_xline(source_p, parv); |
180 |
return 0; |
181 |
} |
182 |
|
183 |
static void |
184 |
relay_xline(struct Client *source_p, char *parv[]) |
185 |
{ |
186 |
struct MaskItem *conf = NULL; |
187 |
int t_sec; |
188 |
|
189 |
t_sec = atoi(parv[3]); |
190 |
|
191 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
192 |
"XLINE %s %s %s :%s", |
193 |
parv[1], parv[2], parv[3], parv[4]); |
194 |
|
195 |
if (match(parv[1], me.name)) |
196 |
return; |
197 |
|
198 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
199 |
source_p->username, source_p->host, |
200 |
SHARED_XLINE)) |
201 |
{ |
202 |
if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0))) |
203 |
{ |
204 |
sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s", |
205 |
ID_or_name(&me, source_p->from), |
206 |
ID_or_name(source_p, source_p->from), |
207 |
parv[2], conf->name, conf->reason); |
208 |
return; |
209 |
} |
210 |
|
211 |
write_xline(source_p, parv[2], parv[4], t_sec); |
212 |
} |
213 |
} |
214 |
|
215 |
/* mo_unxline() |
216 |
* |
217 |
* inputs - pointer to server |
218 |
* - pointer to client |
219 |
* - parameter count |
220 |
* - parameter list |
221 |
* output - |
222 |
* side effects - removes a xline |
223 |
*/ |
224 |
static int |
225 |
mo_unxline(struct Client *client_p, struct Client *source_p, |
226 |
int parc, char *parv[]) |
227 |
{ |
228 |
char *gecos = NULL; |
229 |
char *target_server = NULL; |
230 |
|
231 |
if (!HasOFlag(source_p, OPER_FLAG_X)) |
232 |
{ |
233 |
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, |
234 |
source_p->name, "xline"); |
235 |
return 0; |
236 |
} |
237 |
|
238 |
/* UNXLINE bill ON irc.server.com */ |
239 |
if (parse_aline("UNXLINE", source_p, parc, parv, 0, &gecos, |
240 |
NULL, NULL, &target_server, NULL) < 0) |
241 |
return 0; |
242 |
|
243 |
if (target_server != NULL) |
244 |
{ |
245 |
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
246 |
"UNXLINE %s %s", target_server, gecos); |
247 |
|
248 |
/* Allow ON to apply local unxline as well if it matches */ |
249 |
if (match(target_server, me.name)) |
250 |
return 0; |
251 |
} |
252 |
else |
253 |
cluster_a_line(source_p, "UNXLINE", CAP_CLUSTER, SHARED_UNXLINE, |
254 |
"%s", gecos); |
255 |
|
256 |
remove_xline(source_p, gecos); |
257 |
return 0; |
258 |
} |
259 |
|
260 |
/* ms_unxline() |
261 |
* |
262 |
* inputs - oper, target server, gecos |
263 |
* outputs - none |
264 |
* side effects - propagates unxline, applies it if we are a target |
265 |
*/ |
266 |
static int |
267 |
ms_unxline(struct Client *client_p, struct Client *source_p, |
268 |
int parc, char *parv[]) |
269 |
{ |
270 |
if (parc != 3) |
271 |
return 0; |
272 |
|
273 |
if (!IsClient(source_p) || EmptyString(parv[2])) |
274 |
return 0; |
275 |
|
276 |
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
277 |
"UNXLINE %s %s", parv[1], parv[2]); |
278 |
|
279 |
if (match(parv[1], me.name)) |
280 |
return 0; |
281 |
|
282 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
283 |
source_p->username, source_p->host, |
284 |
SHARED_UNXLINE)) |
285 |
remove_xline(source_p, parv[2]); |
286 |
return 0; |
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 |
struct MaskItem *conf = conf_make(CONF_XLINE); |
329 |
|
330 |
collapse(gecos); |
331 |
conf->name = xstrdup(gecos); |
332 |
conf->reason = xstrdup(reason); |
333 |
conf->setat = CurrentTime; |
334 |
|
335 |
SetConfDatabase(conf); |
336 |
|
337 |
if (tkline_time != 0) |
338 |
{ |
339 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
340 |
"%s added temporary %d min. X-Line for [%s] [%s]", |
341 |
get_oper_name(source_p), (int)tkline_time/60, |
342 |
conf->name, conf->reason); |
343 |
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. X-Line [%s]", |
344 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
345 |
source_p->name, (int)tkline_time/60, conf->name); |
346 |
ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]", |
347 |
source_p->name, (int)tkline_time/60, conf->name, conf->reason); |
348 |
conf->until = CurrentTime + tkline_time; |
349 |
} |
350 |
else |
351 |
{ |
352 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
353 |
"%s added X-Line for [%s] [%s]", |
354 |
get_oper_name(source_p), conf->name, |
355 |
conf->reason); |
356 |
sendto_one(source_p, |
357 |
":%s NOTICE %s :Added X-Line [%s] [%s]", |
358 |
MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from), |
359 |
source_p->name, conf->name, conf->reason); |
360 |
ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]", |
361 |
get_oper_name(source_p), conf->name, conf->reason); |
362 |
} |
363 |
|
364 |
rehashed_klines = 1; |
365 |
} |
366 |
|
367 |
static void |
368 |
remove_xline(struct Client *source_p, char *gecos) |
369 |
{ |
370 |
if (remove_xline_match(gecos)) |
371 |
{ |
372 |
sendto_one(source_p, |
373 |
":%s NOTICE %s :X-Line for [%s] is removed", |
374 |
me.name, source_p->name, gecos); |
375 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
376 |
"%s has removed the X-Line for: [%s]", |
377 |
get_oper_name(source_p), gecos); |
378 |
ilog(LOG_TYPE_XLINE, "%s removed X-Line for [%s]", |
379 |
get_oper_name(source_p), gecos); |
380 |
} |
381 |
else |
382 |
sendto_one(source_p, ":%s NOTICE %s :No X-Line for %s", |
383 |
me.name, source_p->name, gecos); |
384 |
} |
385 |
|
386 |
/* static int remove_tkline_match(const char *host, const char *user) |
387 |
* |
388 |
* Inputs: gecos |
389 |
* Output: returns YES on success, NO if no tkline removed. |
390 |
* Side effects: Any matching tklines are removed. |
391 |
*/ |
392 |
static int |
393 |
remove_xline_match(const char *gecos) |
394 |
{ |
395 |
dlink_node *ptr = NULL, *next_ptr = NULL; |
396 |
|
397 |
DLINK_FOREACH_SAFE(ptr, next_ptr, xconf_items.head) |
398 |
{ |
399 |
struct MaskItem *conf = ptr->data; |
400 |
|
401 |
if (!IsConfDatabase(conf)) |
402 |
continue; |
403 |
|
404 |
if (!irccmp(gecos, conf->name)) |
405 |
{ |
406 |
conf_free(conf); |
407 |
return 1; |
408 |
} |
409 |
} |
410 |
|
411 |
return 0; |
412 |
} |
413 |
|
414 |
static struct Message xline_msgtab = |
415 |
{ |
416 |
"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 |
static struct Message unxline_msgtab = |
421 |
{ |
422 |
"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 |
struct module module_entry = |
441 |
{ |
442 |
.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 |
}; |