2010-03-05 18:36:44 +01:00
|
|
|
/*
|
|
|
|
* charybdis: An advanced ircd.
|
|
|
|
* m_ban.c: Propagates network bans across servers.
|
2014-03-03 05:25:47 +01:00
|
|
|
*
|
2010-03-05 18:36:44 +01:00
|
|
|
* Copyright (C) 2010 Jilles Tjoelker
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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-07-01 05:04:00 +02:00
|
|
|
#include <ircd/stdinc.h>
|
|
|
|
#include <ircd/send.h>
|
|
|
|
#include <ircd/channel.h>
|
|
|
|
#include <ircd/client.h>
|
|
|
|
#include <ircd/defaults.h>
|
|
|
|
#include <ircd/ircd.h>
|
|
|
|
#include <ircd/match.h>
|
|
|
|
#include <ircd/s_conf.h>
|
|
|
|
#include <ircd/s_newconf.h>
|
|
|
|
#include <ircd/msg.h>
|
|
|
|
#include <ircd/modules.h>
|
|
|
|
#include <ircd/hash.h>
|
|
|
|
#include <ircd/s_serv.h>
|
|
|
|
#include <ircd/operhash.h>
|
|
|
|
#include <ircd/reject.h>
|
|
|
|
#include <ircd/hostmask.h>
|
|
|
|
#include <ircd/logger.h>
|
2010-03-05 18:36:44 +01:00
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char ban_desc[] = "Provides the TS6 BAN command for propagating network-wide bans";
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void m_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
|
|
|
static void ms_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
2010-03-05 18:36:44 +01:00
|
|
|
|
|
|
|
struct Message ban_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"BAN", 0, 0, 0, 0,
|
2010-08-29 15:16:47 +02:00
|
|
|
{mg_unreg, {m_ban, 0}, {ms_ban, 9}, {ms_ban, 9}, mg_ignore, {m_ban, 0}}
|
2010-03-05 18:36:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 ban_clist[] = { &ban_msgtab, NULL };
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2016-03-07 07:46:56 +01:00
|
|
|
DECLARE_MODULE_AV2(ban, NULL, NULL, ban_clist, NULL, NULL, NULL, NULL, ban_desc);
|
2010-03-05 18:36:44 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
m_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-08-29 15:16:47 +02:00
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":The BAN command is not user-accessible.");
|
|
|
|
sendto_one_notice(source_p, ":To ban a user from a channel, see /QUOTE HELP CMODE");
|
|
|
|
if (IsOper(source_p))
|
|
|
|
sendto_one_notice(source_p, ":To ban a user from a server or from the network, see /QUOTE HELP KLINE");
|
|
|
|
}
|
|
|
|
|
2010-03-05 18:36:44 +01:00
|
|
|
/* ms_ban()
|
|
|
|
*
|
2010-03-05 22:51:47 +01:00
|
|
|
* parv[1] - type
|
|
|
|
* parv[2] - username mask or *
|
|
|
|
* parv[3] - hostname mask
|
|
|
|
* parv[4] - creation TS
|
|
|
|
* parv[5] - duration (relative to creation)
|
|
|
|
* parv[6] - lifetime (relative to creation)
|
|
|
|
* parv[7] - oper or *
|
|
|
|
* parv[8] - reason (possibly with |operreason)
|
2010-03-05 18:36:44 +01:00
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
ms_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-03-05 18:36:44 +01:00
|
|
|
{
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
struct ConfItem *aconf;
|
|
|
|
unsigned int ntype;
|
|
|
|
const char *oper, *stype;
|
2014-09-21 18:28:24 +02:00
|
|
|
time_t now, created, hold, lifetime;
|
2010-03-05 18:36:44 +01:00
|
|
|
char *p;
|
|
|
|
int act;
|
2010-03-27 16:13:57 +01:00
|
|
|
int valid;
|
2010-03-05 18:36:44 +01:00
|
|
|
|
2014-09-21 18:28:24 +02:00
|
|
|
now = rb_current_time();
|
2010-03-05 22:51:47 +01:00
|
|
|
if (strlen(parv[1]) != 1)
|
2010-03-05 18:36:44 +01:00
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
|
|
|
"Unknown BAN type %s from %s",
|
2010-03-05 22:51:47 +01:00
|
|
|
parv[1], source_p->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
2010-03-05 22:51:47 +01:00
|
|
|
switch (parv[1][0])
|
2010-03-05 18:36:44 +01:00
|
|
|
{
|
|
|
|
case 'K':
|
|
|
|
ntype = CONF_KILL;
|
|
|
|
stype = "K-Line";
|
|
|
|
break;
|
2010-03-16 23:05:50 +01:00
|
|
|
case 'X':
|
|
|
|
ntype = CONF_XLINE;
|
|
|
|
stype = "X-Line";
|
|
|
|
break;
|
2010-03-27 16:13:57 +01:00
|
|
|
case 'R':
|
|
|
|
ntype = IsChannelName(parv[3]) ? CONF_RESV_CHANNEL :
|
|
|
|
CONF_RESV_NICK;
|
|
|
|
stype = "RESV";
|
|
|
|
break;
|
2010-03-05 18:36:44 +01:00
|
|
|
default:
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
|
|
|
|
"Unknown BAN type %s from %s",
|
2010-03-05 22:51:47 +01:00
|
|
|
parv[1], source_p->name);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
2010-03-05 22:51:47 +01:00
|
|
|
created = atol(parv[4]);
|
|
|
|
hold = created + atoi(parv[5]);
|
|
|
|
lifetime = created + atoi(parv[6]);
|
|
|
|
if (!strcmp(parv[7], "*"))
|
2010-03-05 18:36:44 +01:00
|
|
|
oper = IsServer(source_p) ? source_p->name : get_oper_name(source_p);
|
|
|
|
else
|
2010-03-05 22:51:47 +01:00
|
|
|
oper = parv[7];
|
|
|
|
ptr = find_prop_ban(ntype, parv[2], parv[3]);
|
2010-03-05 18:36:44 +01:00
|
|
|
if (ptr != NULL)
|
|
|
|
{
|
2010-04-29 00:26:49 +02:00
|
|
|
/* We already know about this ban mask. */
|
2016-07-13 07:17:21 +02:00
|
|
|
aconf = (ConfItem *)ptr->data;
|
2010-03-05 23:16:28 +01:00
|
|
|
if (aconf->created > created ||
|
|
|
|
(aconf->created == created &&
|
|
|
|
aconf->lifetime >= lifetime))
|
2010-03-05 18:36:44 +01:00
|
|
|
{
|
|
|
|
if (IsPerson(source_p))
|
|
|
|
sendto_one_notice(source_p,
|
|
|
|
":Your %s [%s%s%s] has been superseded",
|
|
|
|
stype,
|
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? "@" : "",
|
|
|
|
aconf->host);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
2010-04-29 00:26:49 +02:00
|
|
|
/* act indicates if something happened (from the oper's
|
|
|
|
* point of view). This is the case if the ban was
|
|
|
|
* previously active (not deleted) or if the new ban
|
|
|
|
* is not a removal and not already expired.
|
|
|
|
*/
|
2010-03-05 22:51:47 +01:00
|
|
|
act = !(aconf->status & CONF_ILLEGAL) || (hold != created &&
|
2014-09-21 18:28:24 +02:00
|
|
|
hold > now);
|
2010-03-05 18:36:44 +01:00
|
|
|
if (lifetime > aconf->lifetime)
|
|
|
|
aconf->lifetime = lifetime;
|
|
|
|
/* already expired, hmm */
|
2014-09-21 18:28:24 +02:00
|
|
|
if (aconf->lifetime <= now)
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2010-04-29 00:26:49 +02:00
|
|
|
/* Deactivate, it will be reactivated later if appropriate. */
|
2014-09-21 18:28:24 +02:00
|
|
|
deactivate_conf(aconf, ptr, now);
|
2010-03-05 18:36:44 +01:00
|
|
|
rb_free(aconf->user);
|
|
|
|
aconf->user = NULL;
|
|
|
|
rb_free(aconf->host);
|
|
|
|
aconf->host = NULL;
|
|
|
|
operhash_delete(aconf->info.oper);
|
|
|
|
aconf->info.oper = NULL;
|
|
|
|
rb_free(aconf->passwd);
|
|
|
|
aconf->passwd = NULL;
|
|
|
|
rb_free(aconf->spasswd);
|
|
|
|
aconf->spasswd = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-29 00:26:49 +02:00
|
|
|
/* New ban mask. */
|
2010-03-05 18:36:44 +01:00
|
|
|
aconf = make_conf();
|
|
|
|
aconf->status = CONF_ILLEGAL | ntype;
|
|
|
|
aconf->lifetime = lifetime;
|
|
|
|
rb_dlinkAddAlloc(aconf, &prop_bans);
|
2014-09-21 18:28:24 +02:00
|
|
|
act = hold != created && hold > now;
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
|
|
|
aconf->flags &= ~CONF_FLAGS_MYOPER;
|
|
|
|
aconf->flags |= CONF_FLAGS_TEMPORARY;
|
2010-03-05 22:51:47 +01:00
|
|
|
aconf->user = ntype == CONF_KILL ? rb_strdup(parv[2]) : NULL;
|
|
|
|
aconf->host = rb_strdup(parv[3]);
|
2010-03-05 18:36:44 +01:00
|
|
|
aconf->info.oper = operhash_add(oper);
|
|
|
|
aconf->created = created;
|
|
|
|
aconf->hold = hold;
|
2016-07-13 07:17:21 +02:00
|
|
|
if (ntype != CONF_KILL || (p = (char *)strchr(parv[parc - 1], '|')) == NULL)
|
2010-03-05 18:36:44 +01:00
|
|
|
aconf->passwd = rb_strdup(parv[parc - 1]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aconf->passwd = rb_strndup(parv[parc - 1], p - parv[parc - 1] + 1);
|
|
|
|
aconf->spasswd = rb_strdup(p + 1);
|
|
|
|
}
|
2010-04-29 00:26:49 +02:00
|
|
|
/* The ban is fully filled in and in the prop_bans list
|
|
|
|
* but still deactivated. Now determine if it should be activated
|
|
|
|
* and send the server notices.
|
|
|
|
*/
|
|
|
|
/* We only reject *@* and the like here.
|
|
|
|
* Otherwise malformed bans are fairly harmless and can be removed.
|
|
|
|
*/
|
2010-03-27 16:13:57 +01:00
|
|
|
switch (ntype)
|
|
|
|
{
|
|
|
|
case CONF_KILL:
|
|
|
|
valid = valid_wild_card(aconf->user, aconf->host);
|
|
|
|
break;
|
|
|
|
case CONF_RESV_CHANNEL:
|
|
|
|
valid = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
valid = valid_wild_card_simple(aconf->host);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (act && hold != created && !valid)
|
2010-03-06 01:45:41 +01:00
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"Ignoring global %d min. %s from %s%s%s for [%s%s%s]: too few non-wildcard characters",
|
2014-09-21 18:28:24 +02:00
|
|
|
(int)((hold - now) / 60),
|
2010-03-06 01:45:41 +01:00
|
|
|
stype,
|
|
|
|
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
|
|
|
|
strcmp(parv[7], "*") ? " on behalf of " : "",
|
|
|
|
strcmp(parv[7], "*") ? parv[7] : "",
|
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? "@" : "",
|
|
|
|
aconf->host);
|
|
|
|
if(IsPerson(source_p))
|
|
|
|
sendto_one_notice(source_p,
|
|
|
|
":Your %s [%s%s%s] has too few non-wildcard characters",
|
|
|
|
stype,
|
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? "@" : "",
|
|
|
|
aconf->host);
|
|
|
|
/* Propagate it, but do not apply it locally. */
|
|
|
|
}
|
|
|
|
else if (act && hold != created)
|
2010-03-05 18:36:44 +01:00
|
|
|
{
|
|
|
|
/* Keep the notices in sync with modules/m_kline.c etc. */
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"%s added global %d min. %s%s%s for [%s%s%s] [%s]",
|
|
|
|
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
|
2014-09-21 18:28:24 +02:00
|
|
|
(int)((hold - now) / 60),
|
2010-03-05 18:36:44 +01:00
|
|
|
stype,
|
2010-03-05 22:51:47 +01:00
|
|
|
strcmp(parv[7], "*") ? " from " : "",
|
|
|
|
strcmp(parv[7], "*") ? parv[7] : "",
|
2010-03-05 18:36:44 +01:00
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? "@" : "",
|
|
|
|
aconf->host,
|
|
|
|
parv[parc - 1]);
|
2010-03-16 23:05:50 +01:00
|
|
|
ilog(L_KLINE, "%s %s %d %s%s%s %s", parv[1],
|
2010-03-05 18:36:44 +01:00
|
|
|
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
|
2014-09-21 18:28:24 +02:00
|
|
|
(int)((hold - now) / 60),
|
2010-03-16 23:05:50 +01:00
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? " " : "",
|
|
|
|
aconf->host,
|
2010-03-05 18:36:44 +01:00
|
|
|
parv[parc - 1]);
|
2010-03-05 22:51:47 +01:00
|
|
|
aconf->status &= ~CONF_ILLEGAL;
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
|
|
|
else if (act)
|
|
|
|
{
|
|
|
|
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
|
|
|
"%s has removed the global %s for: [%s%s%s]%s%s",
|
|
|
|
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
|
|
|
|
stype,
|
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? "@" : "",
|
|
|
|
aconf->host,
|
2010-03-05 22:51:47 +01:00
|
|
|
strcmp(parv[7], "*") ? " on behalf of " : "",
|
|
|
|
strcmp(parv[7], "*") ? parv[7] : "");
|
2010-03-16 23:05:50 +01:00
|
|
|
ilog(L_KLINE, "U%s %s %s%s %s", parv[1],
|
2010-03-05 18:36:44 +01:00
|
|
|
IsServer(source_p) ? source_p->name : get_oper_name(source_p),
|
2010-03-16 23:05:50 +01:00
|
|
|
aconf->user ? aconf->user : "",
|
|
|
|
aconf->user ? " " : "",
|
|
|
|
aconf->host);
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
2010-04-29 00:26:49 +02:00
|
|
|
/* If CONF_ILLEGAL is still set at this point, remove entries from the
|
|
|
|
* reject cache (for klines and xlines).
|
|
|
|
* If CONF_ILLEGAL is not set, add the ban to the type-specific data
|
|
|
|
* structure and take action on matched clients/channels.
|
|
|
|
*/
|
2010-03-05 18:36:44 +01:00
|
|
|
switch (ntype)
|
|
|
|
{
|
|
|
|
case CONF_KILL:
|
|
|
|
if (aconf->status & CONF_ILLEGAL)
|
|
|
|
remove_reject_mask(aconf->user, aconf->host);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
|
|
|
|
if(ConfigFileEntry.kline_delay ||
|
|
|
|
(IsServer(source_p) &&
|
|
|
|
!HasSentEob(source_p)))
|
|
|
|
{
|
|
|
|
if(kline_queued == 0)
|
|
|
|
{
|
|
|
|
rb_event_addonce("check_klines", check_klines_event, NULL,
|
2014-08-17 11:06:01 +02:00
|
|
|
ConfigFileEntry.kline_delay ?
|
|
|
|
ConfigFileEntry.kline_delay : 1);
|
2010-03-05 18:36:44 +01:00
|
|
|
kline_queued = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
check_klines();
|
|
|
|
}
|
|
|
|
break;
|
2010-03-16 23:05:50 +01:00
|
|
|
case CONF_XLINE:
|
|
|
|
if (aconf->status & CONF_ILLEGAL)
|
|
|
|
remove_reject_mask(aconf->host, NULL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb_dlinkAddAlloc(aconf, &xline_conf_list);
|
|
|
|
check_xlines();
|
|
|
|
}
|
|
|
|
break;
|
2010-03-27 16:13:57 +01:00
|
|
|
case CONF_RESV_CHANNEL:
|
|
|
|
if (!(aconf->status & CONF_ILLEGAL))
|
|
|
|
{
|
|
|
|
add_to_resv_hash(aconf->host, aconf);
|
2014-09-21 18:28:24 +02:00
|
|
|
resv_chan_forcepart(aconf->host, aconf->passwd, hold - now);
|
2010-03-27 16:13:57 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CONF_RESV_NICK:
|
|
|
|
if (!(aconf->status & CONF_ILLEGAL))
|
|
|
|
rb_dlinkAddAlloc(aconf, &resv_conf_list);
|
|
|
|
break;
|
2010-03-05 18:36:44 +01:00
|
|
|
}
|
2010-03-05 22:53:35 +01:00
|
|
|
sendto_server(client_p, NULL, CAP_BAN|CAP_TS6, NOCAPS,
|
2010-03-05 22:51:47 +01:00
|
|
|
":%s BAN %s %s %s %s %s %s %s :%s",
|
2010-03-05 18:36:44 +01:00
|
|
|
source_p->id,
|
|
|
|
parv[1],
|
|
|
|
parv[2],
|
|
|
|
parv[3],
|
|
|
|
parv[4],
|
|
|
|
parv[5],
|
|
|
|
parv[6],
|
|
|
|
parv[7],
|
|
|
|
parv[parc - 1]);
|
|
|
|
}
|