3 * Copyright (C) 2002-2003 Lee Hardy <lee@leeh.co.uk>
4 * Copyright (C) 2002-2005 ircd-ratbox development team
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
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.
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.
51 #include "s_newconf.h"
56 static int mo_xline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
57 static int ms_xline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
58 static int me_xline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
59 static int mo_unxline(struct Client
*client_p
, struct Client
*source_p
, int parc
,
61 static int ms_unxline(struct Client
*client_p
, struct Client
*source_p
, int parc
,
63 static int me_unxline(struct Client
*client_p
, struct Client
*source_p
, int parc
,
66 struct 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}}
71 struct 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}}
76 mapi_clist_av1 xline_clist
[] = { &xline_msgtab
, &unxline_msgtab
, NULL
};
78 DECLARE_MODULE_AV1(xline
, NULL
, NULL
, xline_clist
, NULL
, NULL
, "$Revision$");
80 static int valid_xline(struct Client
*, const char *, const char *);
81 static void apply_xline(struct Client
*client_p
, const char *name
,
82 const char *reason
, int temp_time
, int propagated
);
83 static void propagate_xline(struct Client
*source_p
, const char *target
,
84 int temp_time
, const char *name
, const char *type
, const char *reason
);
85 static void cluster_xline(struct Client
*source_p
, int temp_time
,
86 const char *name
, const char *reason
);
88 static void handle_remote_xline(struct Client
*source_p
, int temp_time
,
89 const char *name
, const char *reason
);
90 static void handle_remote_unxline(struct Client
*source_p
, const char *name
);
92 static void remove_xline(struct Client
*source_p
, const char *name
,
98 * parv[1] - thing to xline
99 * parv[2] - optional type/reason
103 mo_xline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
105 struct ConfItem
*aconf
;
108 const char *target_server
= NULL
;
111 int propagated
= ConfigFileEntry
.use_propagated_bans
;
113 if(!IsOperXline(source_p
))
115 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "xline");
119 if((temp_time
= valid_temp_time(parv
[loc
])) >= 0)
121 /* we just set temp_time to -1! */
128 /* XLINE <gecos> ON <server> :<reason> */
129 if(parc
>= loc
+ 2 && !irccmp(parv
[loc
], "ON"))
131 if(!IsOperRemoteBan(source_p
))
133 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
134 me
.name
, source_p
->name
, "remoteban");
138 target_server
= parv
[loc
+ 1];
142 if(parc
<= loc
|| EmptyString(parv
[loc
]))
144 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
145 me
.name
, source_p
->name
, "XLINE");
151 if(target_server
!= NULL
)
153 propagate_xline(source_p
, target_server
, temp_time
, name
, "2", reason
);
155 if(!match(target_server
, me
.name
))
158 /* Set as local-only. */
161 else if(!propagated
&& rb_dlink_list_length(&cluster_conf_list
) > 0)
162 cluster_xline(source_p
, temp_time
, name
, reason
);
164 if((aconf
= find_xline_mask(name
)) != NULL
)
166 sendto_one(source_p
, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
167 me
.name
, source_p
->name
, name
, aconf
->host
, aconf
->passwd
);
171 if(!valid_xline(source_p
, name
, reason
))
174 if(propagated
&& temp_time
== 0)
176 sendto_one_notice(source_p
, ":Cannot set a permanent global ban");
180 apply_xline(source_p
, name
, reason
, temp_time
, propagated
);
187 * handles a remote xline
190 ms_xline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
192 /* parv[0] parv[1] parv[2] parv[3] parv[4]
193 * oper target serv xline type reason
195 propagate_xline(source_p
, parv
[1], 0, parv
[2], parv
[3], parv
[4]);
197 if(!IsPerson(source_p
))
200 /* destined for me? */
201 if(!match(parv
[1], me
.name
))
204 handle_remote_xline(source_p
, 0, parv
[2], parv
[4]);
209 me_xline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
211 /* time name type :reason */
212 if(!IsPerson(source_p
))
215 handle_remote_xline(source_p
, atoi(parv
[1]), parv
[2], parv
[4]);
220 handle_remote_xline(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
222 struct ConfItem
*aconf
;
224 if(!find_shared_conf(source_p
->username
, source_p
->host
,
225 source_p
->servptr
->name
,
226 (temp_time
> 0) ? SHARED_TXLINE
: SHARED_PXLINE
))
229 if(!valid_xline(source_p
, name
, reason
))
233 if((aconf
= find_xline_mask(name
)) != NULL
)
235 sendto_one_notice(source_p
, ":[%s] already X-Lined by [%s] - %s", name
, aconf
->host
,
240 apply_xline(source_p
, name
, reason
, temp_time
, 0);
245 * inputs - client xlining, gecos, reason and whether to warn
247 * side effects - checks the xline for validity, erroring if needed
250 valid_xline(struct Client
*source_p
, const char *gecos
, const char *reason
)
252 if(EmptyString(reason
))
254 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
255 get_id(&me
, source_p
), get_id(source_p
, source_p
), "XLINE");
259 if(!valid_wild_card_simple(gecos
))
261 sendto_one_notice(source_p
,
262 ":Please include at least %d non-wildcard "
263 "characters with the xline",
264 ConfigFileEntry
.min_nonwildcard_simple
);
272 apply_xline(struct Client
*source_p
, const char *name
, const char *reason
, int temp_time
, int propagated
)
274 struct ConfItem
*aconf
;
277 aconf
->status
= CONF_XLINE
;
278 aconf
->created
= rb_current_time();
279 aconf
->host
= rb_strdup(name
);
280 aconf
->passwd
= rb_strdup(reason
);
281 collapse(aconf
->host
);
283 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
287 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
288 aconf
->hold
= rb_current_time() + temp_time
;
289 aconf
->lifetime
= aconf
->hold
;
291 replace_old_ban(aconf
);
292 rb_dlinkAddAlloc(aconf
, &prop_bans
);
294 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
295 "%s added global %d min. X-Line for [%s] [%s]",
296 get_oper_name(source_p
), temp_time
/ 60,
297 aconf
->host
, reason
);
298 ilog(L_KLINE
, "X %s %d %s %s",
299 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
300 sendto_one_notice(source_p
, ":Added global %d min. X-Line [%s]",
301 temp_time
/ 60, aconf
->host
);
302 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
303 ":%s BAN X * %s %lu %d %d * :%s",
304 source_p
->id
, aconf
->host
,
305 (unsigned long)aconf
->created
,
306 (int)(aconf
->hold
- aconf
->created
),
307 (int)(aconf
->lifetime
- aconf
->created
),
310 else if(temp_time
> 0)
312 aconf
->hold
= rb_current_time() + temp_time
;
314 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
315 "%s added temporary %d min. X-Line for [%s] [%s]",
316 get_oper_name(source_p
), temp_time
/ 60,
317 aconf
->host
, reason
);
318 ilog(L_KLINE
, "X %s %d %s %s",
319 get_oper_name(source_p
), temp_time
/ 60, name
, reason
);
320 sendto_one_notice(source_p
, ":Added temporary %d min. X-Line [%s]",
321 temp_time
/ 60, aconf
->host
);
325 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s added X-Line for [%s] [%s]",
326 get_oper_name(source_p
), aconf
->host
, aconf
->passwd
);
327 sendto_one_notice(source_p
, ":Added X-Line for [%s] [%s]",
328 aconf
->host
, aconf
->passwd
);
330 bandb_add(BANDB_XLINE
, source_p
, aconf
->host
, NULL
, aconf
->passwd
, NULL
, 0);
331 ilog(L_KLINE
, "X %s 0 %s %s", get_oper_name(source_p
), name
, aconf
->passwd
);
334 rb_dlinkAddAlloc(aconf
, &xline_conf_list
);
339 propagate_xline(struct Client
*source_p
, const char *target
,
340 int temp_time
, const char *name
, const char *type
, const char *reason
)
344 sendto_match_servs(source_p
, target
, CAP_CLUSTER
, NOCAPS
,
345 "XLINE %s %s %s :%s", target
, name
, type
, reason
);
346 sendto_match_servs(source_p
, target
, CAP_ENCAP
, CAP_CLUSTER
,
347 "ENCAP %s XLINE %d %s 2 :%s", target
, temp_time
, name
, reason
);
350 sendto_match_servs(source_p
, target
, CAP_ENCAP
, NOCAPS
,
351 "ENCAP %s XLINE %d %s %s :%s",
352 target
, temp_time
, name
, type
, reason
);
356 cluster_xline(struct Client
*source_p
, int temp_time
, const char *name
, const char *reason
)
358 struct remote_conf
*shared_p
;
361 RB_DLINK_FOREACH(ptr
, cluster_conf_list
.head
)
363 shared_p
= ptr
->data
;
365 /* old protocol cant handle temps, and we dont really want
366 * to convert them to perm.. --fl
370 if(!(shared_p
->flags
& SHARED_PXLINE
))
373 sendto_match_servs(source_p
, shared_p
->server
, CAP_CLUSTER
, NOCAPS
,
374 "XLINE %s %s 2 :%s", shared_p
->server
, name
, reason
);
375 sendto_match_servs(source_p
, shared_p
->server
, CAP_ENCAP
, CAP_CLUSTER
,
376 "ENCAP %s XLINE 0 %s 2 :%s",
377 shared_p
->server
, name
, reason
);
379 else if(shared_p
->flags
& SHARED_TXLINE
)
380 sendto_match_servs(source_p
, shared_p
->server
, CAP_ENCAP
, NOCAPS
,
381 "ENCAP %s XLINE %d %s 2 :%s",
382 shared_p
->server
, temp_time
, name
, reason
);
388 * parv[1] - thing to unxline
391 mo_unxline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
395 if(!IsOperXline(source_p
))
397 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "xline");
401 if(parc
== 4 && !(irccmp(parv
[2], "ON")))
403 if(!IsOperRemoteBan(source_p
))
405 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
406 me
.name
, source_p
->name
, "remoteban");
410 propagate_generic(source_p
, "UNXLINE", parv
[3], CAP_CLUSTER
, "%s", parv
[1]);
412 if(match(parv
[3], me
.name
) == 0)
417 /* cluster{} moved to remove_xline */
419 remove_xline(source_p
, parv
[1], propagated
);
426 * handles a remote unxline
429 ms_unxline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
431 /* parv[0] parv[1] parv[2]
432 * oper target server gecos
434 propagate_generic(source_p
, "UNXLINE", parv
[1], CAP_CLUSTER
, "%s", parv
[2]);
436 if(!match(parv
[1], me
.name
))
439 if(!IsPerson(source_p
))
442 handle_remote_unxline(source_p
, parv
[2]);
447 me_unxline(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
450 if(!IsPerson(source_p
))
453 handle_remote_unxline(source_p
, parv
[1]);
458 handle_remote_unxline(struct Client
*source_p
, const char *name
)
460 if(!find_shared_conf(source_p
->username
, source_p
->host
,
461 source_p
->servptr
->name
, SHARED_UNXLINE
))
464 remove_xline(source_p
, name
, 0);
470 remove_xline(struct Client
*source_p
, const char *name
, int propagated
)
472 struct ConfItem
*aconf
;
475 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
479 if(!irccmp(aconf
->host
, name
))
485 sendto_one_notice(source_p
, ":Cannot remove global X-Line %s on specific servers", name
);
488 ptr
= rb_dlinkFind(aconf
, &prop_bans
);
491 sendto_one_notice(source_p
, ":X-Line for [%s] is removed", name
);
492 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
493 "%s has removed the global X-Line for: [%s]",
494 get_oper_name(source_p
), name
);
495 ilog(L_KLINE
, "UX %s %s", get_oper_name(source_p
), name
);
496 if(aconf
->created
< rb_current_time())
497 aconf
->created
= rb_current_time();
500 aconf
->hold
= aconf
->created
;
501 operhash_delete(aconf
->info
.oper
);
502 aconf
->info
.oper
= operhash_add(get_oper_name(source_p
));
503 aconf
->flags
|= CONF_FLAGS_MYOPER
| CONF_FLAGS_TEMPORARY
;
504 sendto_server(NULL
, NULL
, CAP_BAN
|CAP_TS6
, NOCAPS
,
505 ":%s BAN X * %s %lu %d %d * :*",
506 source_p
->id
, aconf
->host
,
507 (unsigned long)aconf
->created
,
509 (int)(aconf
->lifetime
- aconf
->created
));
510 remove_reject_mask(aconf
->host
, NULL
);
511 deactivate_conf(aconf
, ptr
);
514 else if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
515 cluster_generic(source_p
, "UNXLINE", SHARED_UNXLINE
, CAP_CLUSTER
, "%s", name
);
518 bandb_del(BANDB_XLINE
, aconf
->host
, NULL
);
520 sendto_one_notice(source_p
, ":X-Line for [%s] is removed", aconf
->host
);
521 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
522 "%s has removed the X-Line for: [%s]",
523 get_oper_name(source_p
), aconf
->host
);
524 ilog(L_KLINE
, "UX %s %s", get_oper_name(source_p
), aconf
->host
);
528 sendto_one_notice(source_p
, ":X-Line for [%s] is removed", name
);
529 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
530 "%s has removed the temporary X-Line for: [%s]",
531 get_oper_name(source_p
), name
);
532 ilog(L_KLINE
, "UX %s %s", get_oper_name(source_p
), name
);
535 remove_reject_mask(aconf
->host
, NULL
);
537 rb_dlinkDestroy(ptr
, &xline_conf_list
);
542 if(propagated
&& rb_dlink_list_length(&cluster_conf_list
))
543 cluster_generic(source_p
, "UNXLINE", SHARED_UNXLINE
, CAP_CLUSTER
, "%s", name
);
545 sendto_one_notice(source_p
, ":No X-Line for %s", name
);