]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_xline.c
Add option general::use_propagated_bans to allow disabling new KLINE.
[irc/rqf/shadowircd.git] / modules / m_xline.c
CommitLineData
212380e3 1/* modules/m_xline.c
2 *
3 * Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk>
4 * Copyright (C) 2002-2005 ircd-ratbox development team
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * 1.Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2.Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3.The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
d8a4c5f6 30 * $Id$
212380e3 31 */
32
33#include "stdinc.h"
212380e3 34#include "send.h"
35#include "channel.h"
36#include "client.h"
37#include "common.h"
38#include "config.h"
39#include "class.h"
40#include "ircd.h"
41#include "numeric.h"
d3455e2c 42#include "logger.h"
212380e3 43#include "s_serv.h"
44#include "whowas.h"
13ae2f4b 45#include "match.h"
212380e3 46#include "hash.h"
47#include "msg.h"
48#include "parse.h"
49#include "modules.h"
50#include "s_conf.h"
51#include "s_newconf.h"
35f6f850 52#include "reject.h"
d8a4c5f6 53#include "bandbi.h"
a0f4c418 54#include "operhash.h"
212380e3 55
56static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
57static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
58static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
d8a4c5f6
WP
59static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc,
60 const char *parv[]);
61static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc,
62 const char *parv[]);
63static int me_unxline(struct Client *client_p, struct Client *source_p, int parc,
64 const char *parv[]);
212380e3 65
66struct Message xline_msgtab = {
67 "XLINE", 0, 0, 0, MFLG_SLOW,
68 {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}}
69};
d8a4c5f6 70
212380e3 71struct Message unxline_msgtab = {
72 "UNXLINE", 0, 0, 0, MFLG_SLOW,
73 {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}}
74};
75
d8a4c5f6
WP
76mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL };
77
78DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision$");
212380e3 79
d8a4c5f6
WP
80static int valid_xline(struct Client *, const char *, const char *);
81static void apply_xline(struct Client *client_p, const char *name,
212380e3 82 const char *reason, int temp_time);
212380e3 83static void propagate_xline(struct Client *source_p, const char *target,
d8a4c5f6 84 int temp_time, const char *name, const char *type, const char *reason);
212380e3 85static void cluster_xline(struct Client *source_p, int temp_time,
d8a4c5f6 86 const char *name, const char *reason);
212380e3 87
88static void handle_remote_xline(struct Client *source_p, int temp_time,
89 const char *name, const char *reason);
90static void handle_remote_unxline(struct Client *source_p, const char *name);
91
60c96e64 92static void remove_xline(struct Client *source_p, const char *name);
212380e3 93
94
95/* m_xline()
96 *
97 * parv[1] - thing to xline
98 * parv[2] - optional type/reason
99 * parv[3] - reason
100 */
101static int
102mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
103{
104 struct ConfItem *aconf;
105 const char *name;
106 const char *reason;
107 const char *target_server = NULL;
108 int temp_time;
109 int loc = 1;
110
111 if(!IsOperXline(source_p))
112 {
d8a4c5f6 113 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
212380e3 114 return 0;
115 }
116
117 if((temp_time = valid_temp_time(parv[loc])) >= 0)
118 loc++;
119 /* we just set temp_time to -1! */
120 else
121 temp_time = 0;
122
123 name = parv[loc];
124 loc++;
125
126 /* XLINE <gecos> ON <server> :<reason> */
d8a4c5f6 127 if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
212380e3 128 {
129 if(!IsOperRemoteBan(source_p))
130 {
131 sendto_one(source_p, form_str(ERR_NOPRIVS),
d8a4c5f6 132 me.name, source_p->name, "remoteban");
212380e3 133 return 0;
134 }
135
d8a4c5f6 136 target_server = parv[loc + 1];
212380e3 137 loc += 2;
138 }
139
140 if(parc <= loc || EmptyString(parv[loc]))
141 {
142 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
d8a4c5f6 143 me.name, source_p->name, "XLINE");
212380e3 144 return 0;
145 }
146
147 reason = parv[loc];
148
149 if(target_server != NULL)
150 {
d8a4c5f6 151 propagate_xline(source_p, target_server, temp_time, name, "2", reason);
212380e3 152
153 if(!match(target_server, me.name))
154 return 0;
155 }
08d11e34 156 else if(rb_dlink_list_length(&cluster_conf_list) > 0)
d8a4c5f6 157 cluster_xline(source_p, temp_time, name, reason);
212380e3 158
d8a4c5f6 159 if((aconf = find_xline_mask(name)) != NULL)
212380e3 160 {
161 sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
ff0482a9 162 me.name, source_p->name, name, aconf->host, aconf->passwd);
212380e3 163 return 0;
164 }
165
d8a4c5f6 166 if(!valid_xline(source_p, name, reason))
212380e3 167 return 0;
168
d8a4c5f6 169 apply_xline(source_p, name, reason, temp_time);
212380e3 170
171 return 0;
172}
173
174/* ms_xline()
175 *
176 * handles a remote xline
177 */
178static int
179ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
180{
d8a4c5f6
WP
181 /* parv[0] parv[1] parv[2] parv[3] parv[4]
182 * oper target serv xline type reason
212380e3 183 */
184 propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]);
185
186 if(!IsPerson(source_p))
187 return 0;
188
189 /* destined for me? */
190 if(!match(parv[1], me.name))
191 return 0;
192
193 handle_remote_xline(source_p, 0, parv[2], parv[4]);
194 return 0;
195}
196
197static int
198me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
199{
200 /* time name type :reason */
201 if(!IsPerson(source_p))
202 return 0;
203
204 handle_remote_xline(source_p, atoi(parv[1]), parv[2], parv[4]);
205 return 0;
206}
207
208static void
d8a4c5f6 209handle_remote_xline(struct Client *source_p, int temp_time, const char *name, const char *reason)
212380e3 210{
211 struct ConfItem *aconf;
212
213 if(!find_shared_conf(source_p->username, source_p->host,
d8a4c5f6
WP
214 source_p->servptr->name,
215 (temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE))
212380e3 216 return;
217
d8a4c5f6 218 if(!valid_xline(source_p, name, reason))
212380e3 219 return;
220
221 /* already xlined */
0fdb2570 222 if((aconf = find_xline_mask(name)) != NULL)
212380e3 223 {
ff0482a9 224 sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->host,
d8a4c5f6 225 aconf->passwd);
212380e3 226 return;
227 }
228
229 apply_xline(source_p, name, reason, temp_time);
230}
231
232/* valid_xline()
233 *
d8a4c5f6 234 * inputs - client xlining, gecos, reason and whether to warn
212380e3 235 * outputs -
236 * side effects - checks the xline for validity, erroring if needed
237 */
238static int
d8a4c5f6 239valid_xline(struct Client *source_p, const char *gecos, const char *reason)
212380e3 240{
241 if(EmptyString(reason))
242 {
243 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
d8a4c5f6 244 get_id(&me, source_p), get_id(source_p, source_p), "XLINE");
b6c85cc6
JT
245 return 0;
246 }
247
212380e3 248 if(strchr(reason, ':') != NULL)
249 {
d8a4c5f6 250 sendto_one_notice(source_p, ":Invalid character ':' in comment");
212380e3 251 return 0;
252 }
253
254 if(strchr(reason, '"'))
255 {
d8a4c5f6 256 sendto_one_notice(source_p, ":Invalid character '\"' in comment");
212380e3 257 return 0;
258 }
259
260 if(!valid_wild_card_simple(gecos))
261 {
262 sendto_one_notice(source_p,
263 ":Please include at least %d non-wildcard "
264 "characters with the xline",
265 ConfigFileEntry.min_nonwildcard_simple);
266 return 0;
267 }
268
269 return 1;
270}
271
272void
d8a4c5f6 273apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time)
212380e3 274{
275 struct ConfItem *aconf;
276
277 aconf = make_conf();
278 aconf->status = CONF_XLINE;
ce60772d 279 aconf->created = rb_current_time();
c2e61538 280 aconf->host = rb_strdup(name);
d8a4c5f6 281 aconf->passwd = rb_strdup(reason);
ff0482a9 282 collapse(aconf->host);
212380e3 283
a0f4c418
JT
284 aconf->info.oper = operhash_add(get_oper_name(source_p));
285
d8a4c5f6 286 if(temp_time > 0)
212380e3 287 {
d8a4c5f6 288 aconf->hold = rb_current_time() + temp_time;
212380e3 289
d8a4c5f6
WP
290 sendto_realops_snomask(SNO_GENERAL, L_ALL,
291 "%s added temporary %d min. X-Line for [%s] [%s]",
292 get_oper_name(source_p), temp_time / 60,
ff0482a9 293 aconf->host, reason);
d8a4c5f6
WP
294 ilog(L_KLINE, "X %s %d %s %s",
295 get_oper_name(source_p), temp_time / 60, name, reason);
296 sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]",
ff0482a9 297 temp_time / 60, aconf->host);
d8a4c5f6
WP
298 }
299 else
212380e3 300 {
d8a4c5f6 301 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]",
ff0482a9 302 get_oper_name(source_p), aconf->host, aconf->passwd);
d8a4c5f6 303 sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]",
ff0482a9 304 aconf->host, aconf->passwd);
d8a4c5f6 305
ff0482a9 306 bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, aconf->passwd, NULL, 0);
03368cb9 307 ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, aconf->passwd);
212380e3 308 }
d8a4c5f6
WP
309
310 rb_dlinkAddAlloc(aconf, &xline_conf_list);
311 check_xlines();
212380e3 312}
313
d8a4c5f6 314static void
212380e3 315propagate_xline(struct Client *source_p, const char *target,
d8a4c5f6 316 int temp_time, const char *name, const char *type, const char *reason)
212380e3 317{
318 if(!temp_time)
319 {
320 sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS,
d8a4c5f6 321 "XLINE %s %s %s :%s", target, name, type, reason);
212380e3 322 sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER,
d8a4c5f6 323 "ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason);
212380e3 324 }
325 else
326 sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS,
d8a4c5f6
WP
327 "ENCAP %s XLINE %d %s %s :%s",
328 target, temp_time, name, type, reason);
212380e3 329}
d8a4c5f6 330
212380e3 331static void
d8a4c5f6 332cluster_xline(struct Client *source_p, int temp_time, const char *name, const char *reason)
212380e3 333{
334 struct remote_conf *shared_p;
08d11e34 335 rb_dlink_node *ptr;
212380e3 336
08d11e34 337 RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
212380e3 338 {
339 shared_p = ptr->data;
340
341 /* old protocol cant handle temps, and we dont really want
342 * to convert them to perm.. --fl
343 */
344 if(!temp_time)
345 {
346 if(!(shared_p->flags & SHARED_PXLINE))
347 continue;
348
349 sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS,
d8a4c5f6 350 "XLINE %s %s 2 :%s", shared_p->server, name, reason);
212380e3 351 sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER,
d8a4c5f6
WP
352 "ENCAP %s XLINE 0 %s 2 :%s",
353 shared_p->server, name, reason);
212380e3 354 }
355 else if(shared_p->flags & SHARED_TXLINE)
356 sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS,
d8a4c5f6
WP
357 "ENCAP %s XLINE %d %s 2 :%s",
358 shared_p->server, temp_time, name, reason);
212380e3 359 }
360}
361
362/* mo_unxline()
363 *
364 * parv[1] - thing to unxline
365 */
366static int
367mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
368{
369 if(!IsOperXline(source_p))
370 {
d8a4c5f6 371 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
212380e3 372 return 0;
373 }
374
375 if(parc == 4 && !(irccmp(parv[2], "ON")))
376 {
377 if(!IsOperRemoteBan(source_p))
378 {
379 sendto_one(source_p, form_str(ERR_NOPRIVS),
d8a4c5f6 380 me.name, source_p->name, "remoteban");
212380e3 381 return 0;
382 }
383
d8a4c5f6 384 propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]);
212380e3 385
386 if(match(parv[3], me.name) == 0)
387 return 0;
388 }
08d11e34 389 else if(rb_dlink_list_length(&cluster_conf_list))
d8a4c5f6 390 cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", parv[1]);
212380e3 391
212380e3 392 remove_xline(source_p, parv[1]);
393
394 return 0;
395}
396
397/* ms_unxline()
398 *
399 * handles a remote unxline
400 */
401static int
402ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
403{
d8a4c5f6
WP
404 /* parv[0] parv[1] parv[2]
405 * oper target server gecos
212380e3 406 */
d8a4c5f6 407 propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]);
212380e3 408
409 if(!match(parv[1], me.name))
410 return 0;
411
412 if(!IsPerson(source_p))
413 return 0;
414
415 handle_remote_unxline(source_p, parv[2]);
416 return 0;
417}
418
419static int
420me_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
421{
422 /* name */
423 if(!IsPerson(source_p))
424 return 0;
425
426 handle_remote_unxline(source_p, parv[1]);
427 return 0;
428}
429
430static void
431handle_remote_unxline(struct Client *source_p, const char *name)
432{
433 if(!find_shared_conf(source_p->username, source_p->host,
d8a4c5f6 434 source_p->servptr->name, SHARED_UNXLINE))
212380e3 435 return;
436
212380e3 437 remove_xline(source_p, name);
438
439 return;
440}
441
60c96e64 442static void
5408b484 443remove_xline(struct Client *source_p, const char *name)
212380e3 444{
445 struct ConfItem *aconf;
08d11e34 446 rb_dlink_node *ptr;
212380e3 447
08d11e34 448 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
212380e3 449 {
450 aconf = ptr->data;
451
ff0482a9 452 if(!irccmp(aconf->host, name))
212380e3 453 {
d8a4c5f6 454 if(!aconf->hold)
5408b484 455 {
d8a4c5f6
WP
456 bandb_del(BANDB_XLINE, aconf->host, NULL);
457
458 sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host);
459 sendto_realops_snomask(SNO_GENERAL, L_ALL,
460 "%s has removed the X-Line for: [%s]",
461 get_oper_name(source_p), aconf->host);
462 ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host);
5408b484
JT
463 }
464 else
465 {
d8a4c5f6 466 sendto_one_notice(source_p, ":X-Line for [%s] is removed", name);
5408b484 467 sendto_realops_snomask(SNO_GENERAL, L_ALL,
d8a4c5f6
WP
468 "%s has removed the temporary X-Line for: [%s]",
469 get_oper_name(source_p), name);
470 ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name);
5408b484 471 }
d8a4c5f6 472
ff0482a9 473 remove_reject_mask(aconf->host, NULL);
212380e3 474 free_conf(aconf);
9f6c3353 475 rb_dlinkDestroy(ptr, &xline_conf_list);
60c96e64 476 return;
212380e3 477 }
478 }
479
d8a4c5f6 480 sendto_one_notice(source_p, ":No X-Line for %s", name);
5408b484 481
60c96e64 482 return;
212380e3 483}