From 5fe9da839cc387244f9d34aececd6aa28f551c90 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 19 Jan 2021 07:05:51 +0000 Subject: Refactor the globalload module. - Require that a non-empty last parameter is given to the commands. - Use WriteRemoteNumeric instead of WriteNumeric so opers actually see the response. - Store instead of looking it up every time. --- src/modules/m_globalload.cpp | 56 ++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'src/modules/m_globalload.cpp') diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp index 71a455a34..f1961f6b4 100644 --- a/src/modules/m_globalload.cpp +++ b/src/modules/m_globalload.cpp @@ -26,13 +26,13 @@ #include "inspircd.h" -/** Handle /GLOADMODULE - */ -class CommandGloadmodule : public Command +class CommandGLoadModule : public Command { public: - CommandGloadmodule(Module* Creator) : Command(Creator,"GLOADMODULE", 1) + CommandGLoadModule(Module* Creator) + : Command(Creator,"GLOADMODULE", 1) { + allow_empty_last_param = false; flags_needed = 'o'; syntax = " []"; } @@ -46,11 +46,11 @@ class CommandGloadmodule : public Command if (ServerInstance->Modules->Load(parameters[0].c_str())) { ServerInstance->SNO->WriteToSnoMask('a', "NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0].c_str(), user->nick.c_str()); - user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded."); + user->WriteRemoteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded."); } else { - user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError()); + user->WriteRemoteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError()); } } else @@ -65,23 +65,24 @@ class CommandGloadmodule : public Command } }; -/** Handle /GUNLOADMODULE - */ -class CommandGunloadmodule : public Command +class CommandGUnloadModule : public Command { public: - CommandGunloadmodule(Module* Creator) : Command(Creator,"GUNLOADMODULE", 1) + bool allowcoreunload; + + CommandGUnloadModule(Module* Creator) + : Command(Creator,"GUNLOADMODULE", 1) { + allow_empty_last_param = false; flags_needed = 'o'; syntax = " []"; } CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE { - if (!ServerInstance->Config->ConfValue("security")->getBool("allowcoreunload") && - InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map)) + if (!allowcoreunload && InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map)) { - user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!"); + user->WriteRemoteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!"); return CMD_FAILURE; } @@ -99,7 +100,7 @@ class CommandGunloadmodule : public Command } else { - user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], ServerInstance->Modules->LastError()); + user->WriteRemoteNumeric(ERR_CANTUNLOADMODULE, parameters[0], ServerInstance->Modules->LastError()); } } else @@ -117,13 +118,13 @@ class CommandGunloadmodule : public Command } }; -/** Handle /GRELOADMODULE - */ -class CommandGreloadmodule : public Command +class CommandGReloadModule : public Command { public: - CommandGreloadmodule(Module* Creator) : Command(Creator, "GRELOADMODULE", 1) + CommandGReloadModule(Module* Creator) + : Command(Creator, "GRELOADMODULE", 1) { + allow_empty_last_param = false; flags_needed = 'o'; syntax = " []"; } @@ -142,7 +143,7 @@ class CommandGreloadmodule : public Command } else { - user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Could not find module by that name"); + user->WriteRemoteNumeric(RPL_LOADEDMODULE, parameters[0], "Could not find module by that name"); return CMD_FAILURE; } } @@ -160,14 +161,23 @@ class CommandGreloadmodule : public Command class ModuleGlobalLoad : public Module { - CommandGloadmodule cmd1; - CommandGunloadmodule cmd2; - CommandGreloadmodule cmd3; + private: + CommandGLoadModule cmdgloadmodule; + CommandGUnloadModule cmdgunloadmodule; + CommandGReloadModule cmdgreloadmodule; public: ModuleGlobalLoad() - : cmd1(this), cmd2(this), cmd3(this) + : cmdgloadmodule(this) + , cmdgunloadmodule(this) + , cmdgreloadmodule(this) + { + } + + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { + ConfigTag* securitytag = ServerInstance->Config->ConfValue("security"); + cmdgunloadmodule.allowcoreunload = securitytag->getBool("allowcoreunload"); } Version GetVersion() CXX11_OVERRIDE -- cgit v1.3.1-10-gc9f91 From 28fef58b882e34369c935d56cb4ac50429cba8c7 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 19 Jan 2021 07:19:48 +0000 Subject: Send ERR_CANTUNLOADMODULE when unloading a module on reload fails. --- src/coremods/core_reloadmodule.cpp | 9 ++++++--- src/modules/m_globalload.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/modules/m_globalload.cpp') diff --git a/src/coremods/core_reloadmodule.cpp b/src/coremods/core_reloadmodule.cpp index 98bf2ab40..34eaeae18 100644 --- a/src/coremods/core_reloadmodule.cpp +++ b/src/coremods/core_reloadmodule.cpp @@ -736,7 +736,10 @@ class ReloadAction : public ActionBase ServerInstance->SNO->WriteGlobalSno('a', "RELOAD MODULE: %s %ssuccessfully reloaded", passedname.c_str(), result ? "" : "un"); User* user = ServerInstance->FindUUID(uuid); if (user) - user->WriteNumeric(RPL_LOADEDMODULE, passedname, InspIRCd::Format("Module %ssuccessfully reloaded.", (result ? "" : "un"))); + { + int numeric = result ? RPL_LOADEDMODULE : ERR_CANTUNLOADMODULE; + user->WriteNumeric(numeric, passedname, InspIRCd::Format("Module %ssuccessfully reloaded.", (result ? "" : "un"))); + } ServerInstance->GlobalCulls.AddItem(this); } @@ -747,7 +750,7 @@ CmdResult CommandReloadmodule::Handle(User* user, const Params& parameters) Module* m = ServerInstance->Modules->Find(parameters[0]); if (m == creator) { - user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "You cannot reload core_reloadmodule (unload and load it)"); + user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot reload core_reloadmodule (unload and load it)"); return CMD_FAILURE; } @@ -761,7 +764,7 @@ CmdResult CommandReloadmodule::Handle(User* user, const Params& parameters) } else { - user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Could not find module by that name"); + user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "Could not find module by that name"); return CMD_FAILURE; } } diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp index f1961f6b4..15c41502f 100644 --- a/src/modules/m_globalload.cpp +++ b/src/modules/m_globalload.cpp @@ -143,7 +143,7 @@ class CommandGReloadModule : public Command } else { - user->WriteRemoteNumeric(RPL_LOADEDMODULE, parameters[0], "Could not find module by that name"); + user->WriteRemoteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "Could not find module by that name"); return CMD_FAILURE; } } -- cgit v1.3.1-10-gc9f91