2 * m_sendbans.c: sends all permanent resvs and xlines to given server
4 * Copyright (C) 2008 Jilles Tjoelker
5 * Copyright (C) 2008 charybdis development team
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1.Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2.Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3.The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
40 #include "s_newconf.h"
46 #include "irc_radixtree.h"
48 static int mo_sendbans(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
50 struct Message sendbans_msgtab
= {
51 "SENDBANS", 0, 0, 0, MFLG_SLOW
,
52 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, mg_ignore
, {mo_sendbans
, 2}}
55 mapi_clist_av1 sendbans_clist
[] = {
60 DECLARE_MODULE_AV1(sendbans
, NULL
, NULL
, sendbans_clist
, NULL
, NULL
, "$Revision$");
62 static const char *expand_xline(const char *mask
)
68 if (!strchr(mask
, ' '))
70 if (strlen(mask
) > 250)
77 *q
++ = '\\', *q
++ = 's';
86 static int mo_sendbans(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
88 struct ConfItem
*aconf
;
91 const char *target
, *mask2
;
92 struct Client
*server_p
;
93 struct irc_radixtree_iteration_state state
;
95 if (!IsOperRemoteBan(source_p
))
97 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
98 me
.name
, source_p
->name
, "remoteban");
101 if (!IsOperXline(source_p
))
103 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
104 me
.name
, source_p
->name
, "xline");
107 if (!IsOperResv(source_p
))
109 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
110 me
.name
, source_p
->name
, "resv");
116 RB_DLINK_FOREACH(ptr
, global_serv_list
.head
)
118 server_p
= ptr
->data
;
121 if (match(target
, server_p
->name
))
126 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
127 form_str(ERR_NOSUCHSERVER
), target
);
131 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
132 "%s!%s@%s is sending resvs and xlines to %s",
133 source_p
->name
, source_p
->username
, source_p
->host
,
136 RB_DLINK_FOREACH(ptr
, resv_conf_list
.head
)
141 sendto_match_servs(source_p
, target
,
143 "ENCAP %s RESV 0 %s 0 :%s",
144 target
, aconf
->host
, aconf
->passwd
);
147 IRC_RADIXTREE_FOREACH(aconf
, &state
, resv_tree
)
151 sendto_match_servs(source_p
, target
,
153 "ENCAP %s RESV 0 %s 0 :%s",
154 target
, aconf
->host
, aconf
->passwd
);
157 RB_DLINK_FOREACH(ptr
, xline_conf_list
.head
)
162 mask2
= expand_xline(aconf
->host
);
165 sendto_one_notice(source_p
, ":Skipping xline [%s]",
169 sendto_match_servs(source_p
, target
,
171 "ENCAP %s XLINE 0 %s 2 :%s",
172 target
, mask2
, aconf
->passwd
);