Merge the mlock module into the services module.

This commit is contained in:
Sadie Powell 2024-02-27 16:49:57 +00:00
parent 97d333901e
commit 118f729e86
4 changed files with 25 additions and 75 deletions

View File

@ -1637,12 +1637,6 @@
# privmsg="1.0"
# tagmsg="0.2">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# MLOCK module: Adds support for server-side enforcement of services
# side MLOCKs. Basically, this module suppresses any mode change that
# would likely be immediately bounced by services.
#<module name="mlock">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Monitor module: Adds support for MONITOR which is used by clients to
# maintain notify lists.

View File

@ -683,6 +683,8 @@ std::vector<std::string> ServerConfig::GetModules() const
modules.push_back("help");
modules.push_back("helpmode");
}
else if (insp::equalsci(shortname, "mlock"))
modules.push_back("services");
else if (insp::equalsci(shortname, "namesx"))
modules.push_back("multiprefix");
else if (insp::equalsci(shortname, "regex_pcre2"))

View File

@ -1,68 +0,0 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2013, 2017 Sadie Powell <sadie@witchery.services>
* Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
* Copyright (C) 2012, 2014-2015 Attila Molnar <attilamolnar@hush.com>
* Copyright (C) 2012 Ariadne Conill <ariadne@dereferenced.org>
*
* This file is part of InspIRCd. InspIRCd 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, version 2.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "inspircd.h"
#include "extension.h"
enum
{
// From Charybdis.
ERR_MLOCKRESTRICTED = 742
};
class ModuleMLock final
: public Module
{
StringExtItem mlock;
public:
ModuleMLock()
: Module(VF_VENDOR, "Allows services to lock channel modes so that they can not be changed.")
, mlock(this, "mlock", ExtensionType::CHANNEL, true)
{
}
ModResult OnRawMode(User* source, Channel* channel, const Modes::Change& change) override
{
if (!channel)
return MOD_RES_PASSTHRU;
if (!IS_LOCAL(source))
return MOD_RES_PASSTHRU;
std::string* mlock_str = mlock.Get(channel);
if (!mlock_str)
return MOD_RES_PASSTHRU;
const char mode = change.mh->GetModeChar();
std::string::size_type p = mlock_str->find(mode);
if (p != std::string::npos)
{
source->WriteNumeric(ERR_MLOCKRESTRICTED, channel->name, mode, *mlock_str, "MODE cannot be set due to the channel having an active MLOCK restriction policy");
return MOD_RES_DENY;
}
return MOD_RES_PASSTHRU;
}
};
MODULE_INIT(ModuleMLock)

View File

@ -28,7 +28,10 @@
enum
{
// From UnrealIRCd.
ERR_KILLDENY = 485
ERR_KILLDENY = 485,
// From Charybdis.
ERR_MLOCKRESTRICTED = 742,
};
class RegisteredChannel final
@ -432,6 +435,7 @@ private:
ServiceTag servicetag;
ServProtect servprotectmode;
SVSHoldFactory svsholdfactory;
StringExtItem mlockext;
CommandSVSCMode svscmodecmd;
CommandSVSHold svsholdcmd;
CommandSVSJoin svsjoincmd;
@ -439,6 +443,20 @@ private:
CommandSVSPart svspartcmd;
bool accountoverrideshold;
bool HandleModeLock(User* user, Channel* chan, const Modes::Change& change)
{
const auto* mlock = mlockext.Get(chan);
if (!mlock)
return true; // No mode lock.
if (mlock->find(change.mh->GetModeChar()) == std::string::npos)
return true; // Mode is not locked.
user->WriteNumeric(ERR_MLOCKRESTRICTED, chan->name, change.mh->GetModeChar(), *mlock, INSP_FORMAT("Mode cannot be changed as it has been locked {} by services!",
chan->IsModeSet(change.mh) ? "on" : "off"));
return false;
}
bool HandleProtectedService(User* user, Channel* chan, const Modes::Change& change)
{
if (change.adding || change.param.empty())
@ -472,6 +490,7 @@ public:
, registeredumode(this)
, servicetag(this)
, servprotectmode(this)
, mlockext(this, "mlock", ExtensionType::CHANNEL, true)
, svscmodecmd(this)
, svsholdcmd(this)
, svsjoincmd(this)
@ -518,6 +537,9 @@ public:
if (!HandleProtectedService(user, chan, change))
return MOD_RES_DENY;
if (!HandleModeLock(user, chan, change))
return MOD_RES_DENY;
return MOD_RES_PASSTHRU;
}