]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_xline.c
Fix build: we need -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION=1
[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"
212380e3 54
55static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
56static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
57static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
d8a4c5f6
WP
58static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc,
59 const char *parv[]);
60static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc,
61 const char *parv[]);
62static int me_unxline(struct Client *client_p, struct Client *source_p, int parc,
63 const char *parv[]);
212380e3 64
65struct Message xline_msgtab = {
66 "XLINE", 0, 0, 0, MFLG_SLOW,
67 {mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}}
68};
d8a4c5f6 69
212380e3 70struct Message unxline_msgtab = {
71 "UNXLINE", 0, 0, 0, MFLG_SLOW,
72 {mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}}
73};
74
d8a4c5f6
WP
75mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL };
76
77DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision$");
212380e3 78
d8a4c5f6
WP
79static int valid_xline(struct Client *, const char *, const char *);
80static void apply_xline(struct Client *client_p, const char *name,
212380e3 81 const char *reason, int temp_time);
212380e3 82static void propagate_xline(struct Client *source_p, const char *target,
d8a4c5f6 83 int temp_time, const char *name, const char *type, const char *reason);
212380e3 84static void cluster_xline(struct Client *source_p, int temp_time,
d8a4c5f6 85 const char *name, const char *reason);
212380e3 86
87static void handle_remote_xline(struct Client *source_p, int temp_time,
88 const char *name, const char *reason);
89static void handle_remote_unxline(struct Client *source_p, const char *name);
90
60c96e64 91static void remove_xline(struct Client *source_p, const char *name);
212380e3 92
93
94/* m_xline()
95 *
96 * parv[1] - thing to xline
97 * parv[2] - optional type/reason
98 * parv[3] - reason
99 */
100static int
101mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
102{
103 struct ConfItem *aconf;
104 const char *name;
105 const char *reason;
106 const char *target_server = NULL;
107 int temp_time;
108 int loc = 1;
109
110 if(!IsOperXline(source_p))
111 {
d8a4c5f6 112 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
212380e3 113 return 0;
114 }
115
116 if((temp_time = valid_temp_time(parv[loc])) >= 0)
117 loc++;
118 /* we just set temp_time to -1! */
119 else
120 temp_time = 0;
121
122 name = parv[loc];
123 loc++;
124
125 /* XLINE <gecos> ON <server> :<reason> */
d8a4c5f6 126 if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
212380e3 127 {
128 if(!IsOperRemoteBan(source_p))
129 {
130 sendto_one(source_p, form_str(ERR_NOPRIVS),
d8a4c5f6 131 me.name, source_p->name, "remoteban");
212380e3 132 return 0;
133 }
134
d8a4c5f6 135 target_server = parv[loc + 1];
212380e3 136 loc += 2;
137 }
138
139 if(parc <= loc || EmptyString(parv[loc]))
140 {
141 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
d8a4c5f6 142 me.name, source_p->name, "XLINE");
212380e3 143 return 0;
144 }
145
146 reason = parv[loc];
147
148 if(target_server != NULL)
149 {
d8a4c5f6 150 propagate_xline(source_p, target_server, temp_time, name, "2", reason);
212380e3 151
152 if(!match(target_server, me.name))
153 return 0;
154 }
08d11e34 155 else if(rb_dlink_list_length(&cluster_conf_list) > 0)
d8a4c5f6 156 cluster_xline(source_p, temp_time, name, reason);
212380e3 157
d8a4c5f6 158 if((aconf = find_xline_mask(name)) != NULL)
212380e3 159 {
160 sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
ff0482a9 161 me.name, source_p->name, name, aconf->host, aconf->passwd);
212380e3 162 return 0;
163 }
164
d8a4c5f6 165 if(!valid_xline(source_p, name, reason))
212380e3 166 return 0;
167
d8a4c5f6 168 apply_xline(source_p, name, reason, temp_time);
212380e3 169
170 return 0;
171}
172
173/* ms_xline()
174 *
175 * handles a remote xline
176 */
177static int
178ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
179{
d8a4c5f6
WP
180 /* parv[0] parv[1] parv[2] parv[3] parv[4]
181 * oper target serv xline type reason
212380e3 182 */
183 propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]);
184
185 if(!IsPerson(source_p))
186 return 0;
187
188 /* destined for me? */
189 if(!match(parv[1], me.name))
190 return 0;
191
192 handle_remote_xline(source_p, 0, parv[2], parv[4]);
193 return 0;
194}
195
196static int
197me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
198{
199 /* time name type :reason */
200 if(!IsPerson(source_p))
201 return 0;
202
203 handle_remote_xline(source_p, atoi(parv[1]), parv[2], parv[4]);
204 return 0;
205}
206
207static void
d8a4c5f6 208handle_remote_xline(struct Client *source_p, int temp_time, const char *name, const char *reason)
212380e3 209{
210 struct ConfItem *aconf;
211
212 if(!find_shared_conf(source_p->username, source_p->host,
d8a4c5f6
WP
213 source_p->servptr->name,
214 (temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE))
212380e3 215 return;
216
d8a4c5f6 217 if(!valid_xline(source_p, name, reason))
212380e3 218 return;
219
220 /* already xlined */
0fdb2570 221 if((aconf = find_xline_mask(name)) != NULL)
212380e3 222 {
ff0482a9 223 sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->host,
d8a4c5f6 224 aconf->passwd);
212380e3 225 return;
226 }
227
228 apply_xline(source_p, name, reason, temp_time);
229}
230
231/* valid_xline()
232 *
d8a4c5f6 233 * inputs - client xlining, gecos, reason and whether to warn
212380e3 234 * outputs -
235 * side effects - checks the xline for validity, erroring if needed
236 */
237static int
d8a4c5f6 238valid_xline(struct Client *source_p, const char *gecos, const char *reason)
212380e3 239{
240 if(EmptyString(reason))
241 {
242 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
d8a4c5f6 243 get_id(&me, source_p), get_id(source_p, source_p), "XLINE");
b6c85cc6
JT
244 return 0;
245 }
246
212380e3 247 if(strchr(reason, ':') != NULL)
248 {
d8a4c5f6 249 sendto_one_notice(source_p, ":Invalid character ':' in comment");
212380e3 250 return 0;
251 }
252
253 if(strchr(reason, '"'))
254 {
d8a4c5f6 255 sendto_one_notice(source_p, ":Invalid character '\"' in comment");
212380e3 256 return 0;
257 }
258
259 if(!valid_wild_card_simple(gecos))
260 {
261 sendto_one_notice(source_p,
262 ":Please include at least %d non-wildcard "
263 "characters with the xline",
264 ConfigFileEntry.min_nonwildcard_simple);
265 return 0;
266 }
267
268 return 1;
269}
270
271void
d8a4c5f6 272apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time)
212380e3 273{
274 struct ConfItem *aconf;
275
276 aconf = make_conf();
277 aconf->status = CONF_XLINE;
278
d8a4c5f6 279 if(strstr(name, "\\s"))
212380e3 280 {
d8a4c5f6 281 char *tmp = LOCAL_COPY(name);
44bdc688 282 char *orig = tmp;
d8a4c5f6
WP
283 char *new = tmp;
284
44bdc688
JT
285 while(*orig)
286 {
287 if(*orig == '\\' && *(orig + 1) != '\0')
288 {
289 if(*(orig + 1) == 's')
290 {
291 *new++ = ' ';
d8a4c5f6 292 orig += 2;
44bdc688
JT
293 }
294 /* otherwise skip that and the escaped
295 * character after it, so we dont mistake
296 * \\s as \s --fl
297 */
298 else
d8a4c5f6 299 {
44bdc688
JT
300 *new++ = *orig++;
301 *new++ = *orig++;
302 }
303 }
304 else
305 *new++ = *orig++;
306 }
307
308 *new = '\0';
ff0482a9 309 aconf->host = rb_strdup(tmp);
212380e3 310 }
d8a4c5f6 311 else
ff0482a9 312 aconf->host = rb_strdup(name);
212380e3 313
d8a4c5f6 314 aconf->passwd = rb_strdup(reason);
ff0482a9 315 collapse(aconf->host);
212380e3 316
d8a4c5f6 317 if(temp_time > 0)
212380e3 318 {
d8a4c5f6 319 aconf->hold = rb_current_time() + temp_time;
212380e3 320
d8a4c5f6
WP
321 sendto_realops_snomask(SNO_GENERAL, L_ALL,
322 "%s added temporary %d min. X-Line for [%s] [%s]",
323 get_oper_name(source_p), temp_time / 60,
ff0482a9 324 aconf->host, reason);
d8a4c5f6
WP
325 ilog(L_KLINE, "X %s %d %s %s",
326 get_oper_name(source_p), temp_time / 60, name, reason);
327 sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]",
ff0482a9 328 temp_time / 60, aconf->host);
d8a4c5f6
WP
329 }
330 else
212380e3 331 {
d8a4c5f6 332 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]",
ff0482a9 333 get_oper_name(source_p), aconf->host, aconf->passwd);
d8a4c5f6 334 sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]",
ff0482a9 335 aconf->host, aconf->passwd);
d8a4c5f6 336
ff0482a9 337 bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, aconf->passwd, NULL, 0);
03368cb9 338 ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, aconf->passwd);
212380e3 339 }
d8a4c5f6
WP
340
341 rb_dlinkAddAlloc(aconf, &xline_conf_list);
342 check_xlines();
212380e3 343}
344
d8a4c5f6 345static void
212380e3 346propagate_xline(struct Client *source_p, const char *target,
d8a4c5f6 347 int temp_time, const char *name, const char *type, const char *reason)
212380e3 348{
349 if(!temp_time)
350 {
351 sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS,
d8a4c5f6 352 "XLINE %s %s %s :%s", target, name, type, reason);
212380e3 353 sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER,
d8a4c5f6 354 "ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason);
212380e3 355 }
356 else
357 sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS,
d8a4c5f6
WP
358 "ENCAP %s XLINE %d %s %s :%s",
359 target, temp_time, name, type, reason);
212380e3 360}
d8a4c5f6 361
212380e3 362static void
d8a4c5f6 363cluster_xline(struct Client *source_p, int temp_time, const char *name, const char *reason)
212380e3 364{
365 struct remote_conf *shared_p;
08d11e34 366 rb_dlink_node *ptr;
212380e3 367
08d11e34 368 RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
212380e3 369 {
370 shared_p = ptr->data;
371
372 /* old protocol cant handle temps, and we dont really want
373 * to convert them to perm.. --fl
374 */
375 if(!temp_time)
376 {
377 if(!(shared_p->flags & SHARED_PXLINE))
378 continue;
379
380 sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS,
d8a4c5f6 381 "XLINE %s %s 2 :%s", shared_p->server, name, reason);
212380e3 382 sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER,
d8a4c5f6
WP
383 "ENCAP %s XLINE 0 %s 2 :%s",
384 shared_p->server, name, reason);
212380e3 385 }
386 else if(shared_p->flags & SHARED_TXLINE)
387 sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS,
d8a4c5f6
WP
388 "ENCAP %s XLINE %d %s 2 :%s",
389 shared_p->server, temp_time, name, reason);
212380e3 390 }
391}
392
393/* mo_unxline()
394 *
395 * parv[1] - thing to unxline
396 */
397static int
398mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
399{
400 if(!IsOperXline(source_p))
401 {
d8a4c5f6 402 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
212380e3 403 return 0;
404 }
405
406 if(parc == 4 && !(irccmp(parv[2], "ON")))
407 {
408 if(!IsOperRemoteBan(source_p))
409 {
410 sendto_one(source_p, form_str(ERR_NOPRIVS),
d8a4c5f6 411 me.name, source_p->name, "remoteban");
212380e3 412 return 0;
413 }
414
d8a4c5f6 415 propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]);
212380e3 416
417 if(match(parv[3], me.name) == 0)
418 return 0;
419 }
08d11e34 420 else if(rb_dlink_list_length(&cluster_conf_list))
d8a4c5f6 421 cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", parv[1]);
212380e3 422
212380e3 423 remove_xline(source_p, parv[1]);
424
425 return 0;
426}
427
428/* ms_unxline()
429 *
430 * handles a remote unxline
431 */
432static int
433ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
434{
d8a4c5f6
WP
435 /* parv[0] parv[1] parv[2]
436 * oper target server gecos
212380e3 437 */
d8a4c5f6 438 propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]);
212380e3 439
440 if(!match(parv[1], me.name))
441 return 0;
442
443 if(!IsPerson(source_p))
444 return 0;
445
446 handle_remote_unxline(source_p, parv[2]);
447 return 0;
448}
449
450static int
451me_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
452{
453 /* name */
454 if(!IsPerson(source_p))
455 return 0;
456
457 handle_remote_unxline(source_p, parv[1]);
458 return 0;
459}
460
461static void
462handle_remote_unxline(struct Client *source_p, const char *name)
463{
464 if(!find_shared_conf(source_p->username, source_p->host,
d8a4c5f6 465 source_p->servptr->name, SHARED_UNXLINE))
212380e3 466 return;
467
212380e3 468 remove_xline(source_p, name);
469
470 return;
471}
472
60c96e64 473static void
5408b484 474remove_xline(struct Client *source_p, const char *name)
212380e3 475{
476 struct ConfItem *aconf;
08d11e34 477 rb_dlink_node *ptr;
212380e3 478
08d11e34 479 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
212380e3 480 {
481 aconf = ptr->data;
482
ff0482a9 483 if(!irccmp(aconf->host, name))
212380e3 484 {
d8a4c5f6 485 if(!aconf->hold)
5408b484 486 {
d8a4c5f6
WP
487 bandb_del(BANDB_XLINE, aconf->host, NULL);
488
489 sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host);
490 sendto_realops_snomask(SNO_GENERAL, L_ALL,
491 "%s has removed the X-Line for: [%s]",
492 get_oper_name(source_p), aconf->host);
493 ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host);
5408b484
JT
494 }
495 else
496 {
d8a4c5f6 497 sendto_one_notice(source_p, ":X-Line for [%s] is removed", name);
5408b484 498 sendto_realops_snomask(SNO_GENERAL, L_ALL,
d8a4c5f6
WP
499 "%s has removed the temporary X-Line for: [%s]",
500 get_oper_name(source_p), name);
501 ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name);
5408b484 502 }
d8a4c5f6 503
ff0482a9 504 remove_reject_mask(aconf->host, NULL);
212380e3 505 free_conf(aconf);
9f6c3353 506 rb_dlinkDestroy(ptr, &xline_conf_list);
60c96e64 507 return;
212380e3 508 }
509 }
510
d8a4c5f6 511 sendto_one_notice(source_p, ":No X-Line for %s", name);
5408b484 512
60c96e64 513 return;
212380e3 514}