2010-02-15 21:58:34 +01:00
|
|
|
/*
|
|
|
|
* charybdis: an advanced Internet Relay Chat Daemon(ircd).
|
|
|
|
* tgchange.c - code for restricting private messages
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 Lee Hardy <lee@leeh.co.uk>
|
|
|
|
* Copyright (C) 2005-2010 Jilles Tjoelker <jilles@stack.nl>
|
|
|
|
* Copyright (C) 2004-2005 ircd-ratbox development team
|
2016-08-24 01:55:37 +02:00
|
|
|
* Copyright (C) 2016 Charybdis Development Team
|
2010-02-15 21:58:34 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
namespace ircd {
|
|
|
|
namespace tgchange {
|
2016-08-13 05:05:54 +02:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
static bool add_target(client &source, const uint32_t &hashv);
|
2010-08-29 01:26:00 +02:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
} // namespace tgchange
|
|
|
|
} // namespace ircd;
|
|
|
|
|
|
|
|
namespace tgchange = ircd::tgchange;
|
|
|
|
using ircd::client::client;
|
|
|
|
using ircd::chan::chan;
|
|
|
|
|
|
|
|
chan *
|
|
|
|
tgchange::find_allowing_channel(client &source,
|
|
|
|
const client &target)
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
2016-08-24 01:55:37 +02:00
|
|
|
for(const auto &pit : chans(user(source)))
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto &chan(*pit.first);
|
2016-08-24 01:55:37 +02:00
|
|
|
const auto &member(*pit.second);
|
|
|
|
if((is_chanop(member) || is_voiced(member)) && is_member(chan, target))
|
2016-08-20 02:32:26 +02:00
|
|
|
return &chan;
|
2010-02-15 21:58:34 +01:00
|
|
|
}
|
2016-08-20 02:32:26 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2010-02-15 21:58:34 +01:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
const chan *
|
|
|
|
tgchange::find_allowing_channel(const client &source,
|
|
|
|
const client &target)
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
2016-08-24 01:55:37 +02:00
|
|
|
for(const auto &pit : chans(user(source)))
|
|
|
|
{
|
|
|
|
const auto &chan(*pit.first);
|
|
|
|
const auto &member(*pit.second);
|
|
|
|
if((is_chanop(member) || is_voiced(member)) && is_member(chan, target))
|
|
|
|
return &chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-02-15 21:58:34 +01:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
bool
|
|
|
|
tgchange::add_target(client &source,
|
|
|
|
const client &target)
|
|
|
|
{
|
2010-02-15 21:58:34 +01:00
|
|
|
/* can msg themselves or services without using any target slots */
|
2016-08-24 01:55:37 +02:00
|
|
|
if(source == target || is(target, umode::SERVICE))
|
|
|
|
return true;
|
2010-02-15 21:58:34 +01:00
|
|
|
|
|
|
|
/* special condition for those who have had PRIVMSG crippled to allow them
|
|
|
|
* to talk to IRCops still.
|
|
|
|
*
|
|
|
|
* XXX: is this controversial?
|
|
|
|
*/
|
2016-08-24 01:55:37 +02:00
|
|
|
if(source.localClient->target_last > rb_current_time() && is(target, umode::OPER))
|
|
|
|
return true;
|
2010-02-15 21:58:34 +01:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
const auto hashv(fnv_hash_upper(use_id(target), 32));
|
|
|
|
return add_target(source, hashv);
|
2010-08-29 01:26:00 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
bool
|
|
|
|
tgchange::add_target(client &source,
|
|
|
|
const chan &target)
|
2010-08-29 01:26:00 +02:00
|
|
|
{
|
2014-08-08 11:57:09 +02:00
|
|
|
if(!ConfigChannel.channel_target_change)
|
2016-08-24 01:55:37 +02:00
|
|
|
return true;
|
2014-08-08 11:57:09 +02:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
const auto hashv(fnv_hash_upper(name(target).c_str(), 32));
|
|
|
|
return add_target(source, hashv);
|
2010-08-29 01:26:00 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
void
|
|
|
|
tgchange::add_reply_target(client &source,
|
|
|
|
const client &target)
|
|
|
|
{
|
|
|
|
/* can msg themselves or services without using any target slots */
|
|
|
|
if(source == target || is(target, umode::SERVICE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto &targets(source.localClient->targets);
|
|
|
|
static_assert(NUM + REPLY == sizeof(targets) / sizeof(uint32_t), "");
|
|
|
|
|
|
|
|
/* check for existing target, and move it to the first reply slot
|
|
|
|
* if it is in a reply slot
|
|
|
|
*/
|
|
|
|
const auto hashv(fnv_hash_upper(use_id(target), 32));
|
|
|
|
for(int i(0); i < NUM + REPLY; i++)
|
|
|
|
{
|
|
|
|
if(targets[i] == hashv)
|
|
|
|
{
|
|
|
|
if(i > NUM)
|
|
|
|
{
|
|
|
|
for(int j(i); j > NUM; j--)
|
|
|
|
targets[j] = targets[j - 1];
|
|
|
|
targets[NUM] = hashv;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i(NUM + REPLY - 1); i > NUM; i--)
|
|
|
|
targets[i] = targets[i - 1];
|
|
|
|
targets[NUM] = hashv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
tgchange::add_target(client &source,
|
|
|
|
const uint32_t &hashv)
|
2010-08-29 01:26:00 +02:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
uint32_t *targets;
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
targets = source.localClient->targets;
|
2010-02-15 21:58:34 +01:00
|
|
|
|
|
|
|
/* check for existing target, and move it to the head */
|
2016-08-24 01:55:37 +02:00
|
|
|
for(i = 0; i < NUM + REPLY; i++)
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
|
|
|
if(targets[i] == hashv)
|
|
|
|
{
|
|
|
|
for(j = i; j > 0; j--)
|
|
|
|
targets[j] = targets[j - 1];
|
|
|
|
targets[0] = hashv;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
if(source.localClient->targets_free < NUM)
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
|
|
|
/* first message after connect, we may only start clearing
|
|
|
|
* slots after this message --anfl
|
|
|
|
*/
|
2016-08-24 01:55:37 +02:00
|
|
|
if(!is_tg_change(source))
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
2016-08-24 01:55:37 +02:00
|
|
|
set_tg_change(source);
|
|
|
|
source.localClient->target_last = rb_current_time();
|
2010-02-15 21:58:34 +01:00
|
|
|
}
|
|
|
|
/* clear as many targets as we can */
|
2016-08-24 01:55:37 +02:00
|
|
|
else if((i = (rb_current_time() - source.localClient->target_last) / 60))
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
2016-08-24 01:55:37 +02:00
|
|
|
if(i + source.localClient->targets_free > NUM)
|
|
|
|
source.localClient->targets_free = NUM;
|
2010-02-15 21:58:34 +01:00
|
|
|
else
|
2016-08-24 01:55:37 +02:00
|
|
|
source.localClient->targets_free += i;
|
2010-02-15 21:58:34 +01:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
source.localClient->target_last = rb_current_time();
|
2010-02-15 21:58:34 +01:00
|
|
|
}
|
|
|
|
/* cant clear any, full target list */
|
2016-08-24 01:55:37 +02:00
|
|
|
else if(source.localClient->targets_free == 0)
|
2010-02-15 21:58:34 +01:00
|
|
|
{
|
|
|
|
ServerStats.is_tgch++;
|
2016-08-24 01:55:37 +02:00
|
|
|
add_tgchange(source.sockhost);
|
2011-05-17 00:29:09 +02:00
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
if (!is_tg_excessive(source))
|
2011-05-17 00:29:09 +02:00
|
|
|
{
|
2016-08-24 01:55:37 +02:00
|
|
|
set_tg_excessive(source);
|
2012-03-18 02:18:57 +01:00
|
|
|
/* This is sent to L_ALL because it's regenerated on all servers
|
|
|
|
* that have the TGINFO module loaded.
|
|
|
|
*/
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::BOTS, L_ALL,
|
2011-05-17 00:29:09 +02:00
|
|
|
"Excessive target change from %s (%s@%s)",
|
2016-08-24 01:55:37 +02:00
|
|
|
source.name, source.username,
|
|
|
|
source.orighost);
|
2011-05-17 00:29:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
sendto_match_servs(&source, "*", CAP_ENCAP, NOCAPS, "ENCAP * TGINFO 0");
|
|
|
|
return false;
|
2010-02-15 21:58:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no targets in use, reset their target_last so that they cant
|
|
|
|
* abuse a long idle to get targets back more quickly
|
|
|
|
*/
|
|
|
|
else
|
|
|
|
{
|
2016-08-24 01:55:37 +02:00
|
|
|
source.localClient->target_last = rb_current_time();
|
|
|
|
set_tg_change(source);
|
2010-02-15 21:58:34 +01:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:55:37 +02:00
|
|
|
for(i = NUM + REPLY - 1; i > 0; i--)
|
2010-02-15 21:58:34 +01:00
|
|
|
targets[i] = targets[i - 1];
|
|
|
|
targets[0] = hashv;
|
2016-08-24 01:55:37 +02:00
|
|
|
source.localClient->targets_free--;
|
|
|
|
return true;
|
2016-08-13 05:05:54 +02:00
|
|
|
}
|