diff options
| author | 2021-01-29 18:15:32 +0000 | |
|---|---|---|
| committer | 2021-01-29 18:15:32 +0000 | |
| commit | bb35650b5721e5d951f15060e4ecf474a8343ced (patch) | |
| tree | 315cfbd8ac4cf02c1f6ce608aed8f9530f784a0d /src | |
| parent | Allow using fixedpart/fixedquit with an empty message. (diff) | |
| parent | Remove unnecessary chdirs in the helper script. (diff) | |
| download | inspircd++-bb35650b5721e5d951f15060e4ecf474a8343ced.tar.gz inspircd++-bb35650b5721e5d951f15060e4ecf474a8343ced.tar.bz2 inspircd++-bb35650b5721e5d951f15060e4ecf474a8343ced.zip | |
Merge branch 'insp3' into master.
Diffstat (limited to 'src')
| -rw-r--r-- | src/coremods/core_dns.cpp | 56 | ||||
| -rw-r--r-- | src/coremods/core_reloadmodule.cpp | 9 | ||||
| -rw-r--r-- | src/modules/m_connectban.cpp | 14 | ||||
| -rw-r--r-- | src/modules/m_globalload.cpp | 46 | ||||
| -rw-r--r-- | src/socket.cpp | 2 |
5 files changed, 84 insertions, 43 deletions
diff --git a/src/coremods/core_dns.cpp b/src/coremods/core_dns.cpp index fd3ae2620..b42c0aa9e 100644 --- a/src/coremods/core_dns.cpp +++ b/src/coremods/core_dns.cpp @@ -421,6 +421,7 @@ class MyManager : public Manager, public Timer, public EventHandler ~MyManager() { // Ensure Process() will fail for new requests + Close(); unloading = true; for (unsigned int i = 0; i <= MAX_REQUEST_ID; ++i) @@ -437,11 +438,32 @@ class MyManager : public Manager, public Timer, public EventHandler } } + void Close() + { + // Shutdown the socket if it exists. + if (HasFd()) + { + SocketEngine::Shutdown(this, 2); + SocketEngine::Close(this); + } + + // Remove all entries from the cache. + cache.clear(); + } + void Process(DNS::Request* req) override { if ((unloading) || (req->creator->dying)) throw Exception("Module is being unloaded"); + if (!HasFd()) + { + Query rr(req->question); + rr.error = ERROR_DISABLED; + req->OnError(&rr); + return; + } + ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Processing request to lookup " + req->question.name + " of type " + ConvToStr(req->question.type) + " to " + this->myserver.addr()); /* Create an id */ @@ -531,6 +553,8 @@ class MyManager : public Manager, public Timer, public EventHandler case ERROR_DOMAIN_NOT_FOUND: case ERROR_NO_RECORDS: return "Domain not found"; + case ERROR_DISABLED: + return "DNS lookups are disabled"; case ERROR_NONE: case ERROR_UNKNOWN: default: @@ -701,23 +725,15 @@ class MyManager : public Manager, public Timer, public EventHandler void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport) { - if (this->HasFd()) - { - SocketEngine::Shutdown(this, 2); - SocketEngine::Close(this); - - // Remove all entries from the cache. - cache.clear(); - } - irc::sockets::aptosa(dnsserver, DNS::PORT, myserver); /* Initialize mastersocket */ + Close(); int s = socket(myserver.family(), SOCK_DGRAM, 0); this->SetFd(s); /* Have we got a socket? */ - if (this->GetFd() != -1) + if (this->HasFd()) { SocketEngine::SetReuse(s); SocketEngine::NonBlocking(s); @@ -831,13 +847,25 @@ class ModuleDNS : public Module void ReadConfig(ConfigStatus& status) override { - std::string oldserver = DNSServer; - const std::string oldip = SourceIP; - const unsigned int oldport = SourcePort; - auto tag = ServerInstance->Config->ConfValue("dns"); + if (!tag->getBool("enabled", true)) + { + // Clear these so they get reset if DNS is enabled again. + DNSServer.clear(); + SourceIP.clear(); + SourcePort = 0; + + this->manager.Close(); + return; + } + + const std::string oldserver = DNSServer; DNSServer = tag->getString("server"); + + const std::string oldip = SourceIP; SourceIP = tag->getString("sourceip"); + + const unsigned int oldport = SourcePort; SourcePort = tag->getUInt("sourceport", 0, 0, UINT16_MAX); if (DNSServer.empty()) diff --git a/src/coremods/core_reloadmodule.cpp b/src/coremods/core_reloadmodule.cpp index 1800f9cd9..d67969510 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->Users.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 CmdResult::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 CmdResult::FAILURE; } } diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp index 70b66a786..bba54811a 100644 --- a/src/modules/m_connectban.cpp +++ b/src/modules/m_connectban.cpp @@ -61,6 +61,16 @@ class ModuleConnectBan return 0; } + static bool IsExempt(LocalUser* user) + { + // E-lined and already banned users shouldn't be hit. + if (user->exempt || user->quitting) + return true; + + // Users in an exempt class shouldn't be hit. + return user->GetClass() && !user->GetClass()->config->getBool("useconnectban", true); + } + public: ModuleConnectBan() : Module(VF_VENDOR, "Z-lines IP addresses which make excessive connections to the server.") @@ -87,7 +97,7 @@ class ModuleConnectBan void OnWebIRCAuth(LocalUser* user, const WebIRC::FlagMap* flags) override { - if (user->exempt) + if (IsExempt(user)) return; // HACK: Lower the connection attempts for the gateway IP address. The user @@ -101,7 +111,7 @@ class ModuleConnectBan void OnSetUserIP(LocalUser* u) override { - if (u->exempt || u->quitting) + if (IsExempt(u)) return; irc::sockets::cidr_mask mask(u->client_sa, GetRange(u)); diff --git a/src/modules/m_globalload.cpp b/src/modules/m_globalload.cpp index 7828411d7..03b83654d 100644 --- a/src/modules/m_globalload.cpp +++ b/src/modules/m_globalload.cpp @@ -26,14 +26,14 @@ #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) { access_needed = CmdAccess::OPERATOR; + allow_empty_last_param = false; syntax = { "<modulename> [<servermask>]" }; } @@ -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,14 +65,14 @@ class CommandGloadmodule : public Command } }; -/** Handle /GUNLOADMODULE - */ -class CommandGunloadmodule : public Command +class CommandGUnloadModule : public Command { public: - CommandGunloadmodule(Module* Creator) : Command(Creator,"GUNLOADMODULE", 1) + CommandGUnloadModule(Module* Creator) + : Command(Creator,"GUNLOADMODULE", 1) { access_needed = CmdAccess::OPERATOR; + allow_empty_last_param = false; syntax = { "<modulename> [<servermask>]" }; } @@ -80,7 +80,7 @@ class CommandGunloadmodule : public Command { if (InspIRCd::Match(parameters[0], "core_*" DLL_EXTENSION, 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 CmdResult::FAILURE; } @@ -98,7 +98,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 @@ -116,14 +116,14 @@ 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) { access_needed = CmdAccess::OPERATOR; + allow_empty_last_param = false; syntax = { "<modulename> [<servermask>]" }; } @@ -141,7 +141,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 CmdResult::FAILURE; } } @@ -160,16 +160,16 @@ class CommandGreloadmodule : public Command class ModuleGlobalLoad : public Module { private: - CommandGloadmodule cmd1; - CommandGunloadmodule cmd2; - CommandGreloadmodule cmd3; + CommandGLoadModule cmdgloadmodule; + CommandGUnloadModule cmdgunloadmodule; + CommandGReloadModule cmdgreloadmodule; public: ModuleGlobalLoad() : Module(VF_VENDOR | VF_COMMON, "Adds the /GLOADMODULE, /GRELOADMODULE, and /GUNLOADMODULE commands which allows server operators to load, reload, and unload modules on remote servers.") - , cmd1(this) - , cmd2(this) - , cmd3(this) + , cmdgloadmodule(this) + , cmdgunloadmodule(this) + , cmdgreloadmodule(this) { } }; diff --git a/src/socket.cpp b/src/socket.cpp index 87bde3a4c..6a2d6f743 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -102,7 +102,7 @@ size_t InspIRCd::BindPorts(FailedPortList& failed_ports) if (!path.empty()) { // Expand the path relative to the config directory. - const std::string fullpath = ServerInstance->Config->Paths.PrependData(path); + const std::string fullpath = ServerInstance->Config->Paths.PrependRuntime(path); // UNIX socket paths are length limited to less than PATH_MAX. irc::sockets::sockaddrs bindspec; |
