2008-07-29 00:09:03 +02:00
|
|
|
/*
|
|
|
|
* m_sendbans.c: sends all permanent resvs and xlines to given server
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Jilles Tjoelker
|
|
|
|
* Copyright (C) 2008 charybdis development team
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1.Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2.Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3.The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char sendbands_desc[] =
|
|
|
|
"Adds the ability to send all permanent RESVs and XLINEs to given server";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void mo_sendbans(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[]);
|
2008-07-29 00:09:03 +02:00
|
|
|
|
|
|
|
struct Message sendbans_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"SENDBANS", 0, 0, 0, 0,
|
2008-07-29 00:09:03 +02:00
|
|
|
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_sendbans, 2}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 sendbans_clist[] = {
|
|
|
|
&sendbans_msgtab,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-03-07 10:40:51 +01:00
|
|
|
DECLARE_MODULE_AV2(sendbans, NULL, NULL, sendbans_clist, NULL, NULL, NULL, NULL, sendbands_desc);
|
2008-07-29 00:09:03 +02:00
|
|
|
|
|
|
|
static const char *expand_xline(const char *mask)
|
|
|
|
{
|
|
|
|
static char buf[512];
|
|
|
|
const char *p;
|
|
|
|
char *q;
|
|
|
|
|
|
|
|
if (!strchr(mask, ' '))
|
|
|
|
return mask;
|
|
|
|
if (strlen(mask) > 250)
|
|
|
|
return NULL;
|
|
|
|
p = mask;
|
|
|
|
q = buf;
|
|
|
|
while (*p != '\0')
|
|
|
|
{
|
|
|
|
if (*p == ' ')
|
|
|
|
*q++ = '\\', *q++ = 's';
|
|
|
|
else
|
|
|
|
*q++ = *p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_sendbans(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2008-07-29 00:09:03 +02:00
|
|
|
{
|
|
|
|
struct ConfItem *aconf;
|
|
|
|
rb_dlink_node *ptr;
|
2016-03-22 02:52:40 +01:00
|
|
|
int count;
|
2008-07-29 00:09:03 +02:00
|
|
|
const char *target, *mask2;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *server_p;
|
2016-03-06 21:17:19 +01:00
|
|
|
struct rb_radixtree_iteration_state state;
|
2008-07-29 00:09:03 +02:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if (!IsOperRemoteBan(&source))
|
2008-07-29 00:09:03 +02:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source.name, "remoteban");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2008-07-29 00:09:03 +02:00
|
|
|
}
|
2016-08-23 02:37:07 +02:00
|
|
|
if (!IsOperXline(&source))
|
2008-07-29 00:09:03 +02:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source.name, "xline");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2008-07-29 00:09:03 +02:00
|
|
|
}
|
2016-08-23 02:37:07 +02:00
|
|
|
if (!IsOperResv(&source))
|
2008-07-29 00:09:03 +02:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source.name, "resv");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2008-07-29 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
target = parv[1];
|
|
|
|
count = 0;
|
|
|
|
RB_DLINK_FOREACH(ptr, global_serv_list.head)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
server_p = (client::client *)ptr->data;
|
2016-08-23 04:33:36 +02:00
|
|
|
if (is_me(*server_p))
|
2008-07-29 00:09:03 +02:00
|
|
|
continue;
|
|
|
|
if (match(target, server_p->name))
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count == 0)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHSERVER,
|
2008-07-29 00:09:03 +02:00
|
|
|
form_str(ERR_NOSUCHSERVER), target);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2008-07-29 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
2008-09-02 23:44:06 +02:00
|
|
|
"%s!%s@%s is sending resvs and xlines to %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name, source.username, source.host,
|
2008-09-02 23:44:06 +02:00
|
|
|
target);
|
2008-07-29 00:09:03 +02:00
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, resv_conf_list.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
aconf = (ConfItem *)ptr->data;
|
2008-07-29 00:09:03 +02:00
|
|
|
if (aconf->hold)
|
|
|
|
continue;
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_match_servs(&source, target,
|
2008-07-29 00:09:03 +02:00
|
|
|
CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s RESV 0 %s 0 :%s",
|
2010-01-08 18:46:29 +01:00
|
|
|
target, aconf->host, aconf->passwd);
|
2008-07-29 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
void *elem;
|
|
|
|
RB_RADIXTREE_FOREACH(elem, &state, resv_tree)
|
2008-07-29 00:09:03 +02:00
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
aconf = (ConfItem *)elem;
|
2008-07-29 00:09:03 +02:00
|
|
|
if (aconf->hold)
|
|
|
|
continue;
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_match_servs(&source, target,
|
2008-07-29 00:09:03 +02:00
|
|
|
CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s RESV 0 %s 0 :%s",
|
2010-01-08 18:46:29 +01:00
|
|
|
target, aconf->host, aconf->passwd);
|
2008-07-29 00:09:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, xline_conf_list.head)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
aconf = (ConfItem *)ptr->data;
|
2008-07-29 00:09:03 +02:00
|
|
|
if (aconf->hold)
|
|
|
|
continue;
|
2010-01-08 18:46:29 +01:00
|
|
|
mask2 = expand_xline(aconf->host);
|
2008-07-29 00:09:03 +02:00
|
|
|
if (mask2 == NULL)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_notice(&source, ":Skipping xline [%s]",
|
2010-01-08 18:46:29 +01:00
|
|
|
aconf->host);
|
2008-07-29 00:09:03 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_match_servs(&source, target,
|
2008-07-29 00:09:03 +02:00
|
|
|
CAP_ENCAP, NOCAPS,
|
|
|
|
"ENCAP %s XLINE 0 %s 2 :%s",
|
|
|
|
target, mask2, aconf->passwd);
|
|
|
|
}
|
|
|
|
}
|