From f2e3fd5952b23209b084bde4f464e6643c8a00ff Mon Sep 17 00:00:00 2001 From: Matt Schatz Date: Tue, 8 Jan 2019 03:03:53 -0700 Subject: Improve X-line text consistency. - Change any "-Line", ":Line", or "*line" to "-line" throughout the X-line code, comments, and documentation. - Add periods to the end of some notices. - Correct a typo in the Q-line code comments. - Update the filter module documentation (shun addition). Co-authored-by: Robby --- src/modules/m_cban.cpp | 4 ++-- src/modules/m_clearchan.cpp | 2 +- src/modules/m_connectban.cpp | 4 ++-- src/modules/m_dnsbl.cpp | 6 +++--- src/modules/m_filter.cpp | 10 +++++----- src/modules/m_rline.cpp | 18 +++++++++--------- src/modules/m_shun.cpp | 4 ++-- src/modules/m_spanningtree/treesocket.h | 2 +- src/modules/m_svshold.cpp | 6 +++--- 9 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp index e0768aa88..3cdbbbdfb 100644 --- a/src/modules/m_cban.cpp +++ b/src/modules/m_cban.cpp @@ -114,7 +114,7 @@ class CommandCBan : public Command unsigned long duration; if (!InspIRCd::Duration(parameters[1], duration)) { - user->WriteNotice("*** Invalid duration for CBan"); + user->WriteNotice("*** Invalid duration for CBan."); return CMD_FAILURE; } const char *reason = (parameters.size() > 2) ? parameters[2].c_str() : "No reason supplied"; @@ -202,7 +202,7 @@ class ModuleCBan : public Module, public Stats::EventListener Version GetVersion() CXX11_OVERRIDE { - return Version("Gives /cban, aka C:lines. Think Q:lines, for channels.", VF_COMMON | VF_VENDOR); + return Version("Gives /cban, aka C-lines. Think Q-lines, for channels.", VF_COMMON | VF_VENDOR); } }; diff --git a/src/modules/m_clearchan.cpp b/src/modules/m_clearchan.cpp index 016d28737..dec49866c 100644 --- a/src/modules/m_clearchan.cpp +++ b/src/modules/m_clearchan.cpp @@ -211,7 +211,7 @@ class ModuleClearChan : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Adds /CLEARCHAN that allows opers to masskick, masskill or mass-G/ZLine users on a channel", VF_VENDOR|VF_OPTCOMMON); + return Version("Adds /CLEARCHAN that allows opers to masskick, masskill or mass G/Z-line users on a channel.", VF_VENDOR|VF_OPTCOMMON); } }; diff --git a/src/modules/m_connectban.cpp b/src/modules/m_connectban.cpp index d57ffca02..20121f5f9 100644 --- a/src/modules/m_connectban.cpp +++ b/src/modules/m_connectban.cpp @@ -73,7 +73,7 @@ class ModuleConnectBan : public Module if (i->second >= threshold) { - // Create zline for set duration. + // Create Z-line for set duration. ZLine* zl = new ZLine(ServerInstance->Time(), banduration, ServerInstance->Config->ServerName, banmessage, mask.str()); if (!ServerInstance->XLines->AddLine(zl, NULL)) { @@ -83,7 +83,7 @@ class ModuleConnectBan : public Module ServerInstance->XLines->ApplyLines(); std::string maskstr = mask.str(); std::string timestr = InspIRCd::TimeString(zl->expiry); - ServerInstance->SNO->WriteGlobalSno('x',"Module m_connectban added Z:line on *@%s to expire on %s: Connect flooding", + ServerInstance->SNO->WriteGlobalSno('x',"Module m_connectban added Z-line on %s to expire on %s: Connect flooding", maskstr.c_str(), timestr.c_str()); ServerInstance->SNO->WriteGlobalSno('a', "Connect flooding from IP range %s (%d)", maskstr.c_str(), threshold); connects.erase(i); diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index d1ca800b3..a645e2cd1 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -148,7 +148,7 @@ class DNSBLResolver : public DNS::Request if (ServerInstance->XLines->AddLine(kl,NULL)) { std::string timestr = InspIRCd::TimeString(kl->expiry); - ServerInstance->SNO->WriteGlobalSno('x',"K:line added due to DNSBL match on *@%s to expire on %s: %s", + ServerInstance->SNO->WriteGlobalSno('x', "K-line added due to DNSBL match on *@%s to expire on %s: %s", them->GetIPString().c_str(), timestr.c_str(), reason.c_str()); ServerInstance->XLines->ApplyLines(); } @@ -166,7 +166,7 @@ class DNSBLResolver : public DNS::Request if (ServerInstance->XLines->AddLine(gl,NULL)) { std::string timestr = InspIRCd::TimeString(gl->expiry); - ServerInstance->SNO->WriteGlobalSno('x',"G:line added due to DNSBL match on *@%s to expire on %s: %s", + ServerInstance->SNO->WriteGlobalSno('x', "G-line added due to DNSBL match on *@%s to expire on %s: %s", them->GetIPString().c_str(), timestr.c_str(), reason.c_str()); ServerInstance->XLines->ApplyLines(); } @@ -184,7 +184,7 @@ class DNSBLResolver : public DNS::Request if (ServerInstance->XLines->AddLine(zl,NULL)) { std::string timestr = InspIRCd::TimeString(zl->expiry); - ServerInstance->SNO->WriteGlobalSno('x',"Z:line added due to DNSBL match on %s to expire on %s: %s", + ServerInstance->SNO->WriteGlobalSno('x', "Z-line added due to DNSBL match on %s to expire on %s: %s", them->GetIPString().c_str(), timestr.c_str(), reason.c_str()); ServerInstance->XLines->ApplyLines(); } diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 0c8b81e4b..849f99086 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -421,7 +421,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar else if (f->action == FA_GLINE) { GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was glined because their message to %s matched %s (%s)", + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was G-lined because their message to %s matched %s (%s)", user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(gl,NULL)) { @@ -433,7 +433,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar else if (f->action == FA_ZLINE) { ZLine* zl = new ZLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was zlined because their message to %s matched %s (%s)", + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was Z-lined because their message to %s matched %s (%s)", user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(zl,NULL)) { @@ -506,9 +506,9 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params& } if (f->action == FA_GLINE) { - /* Note: We gline *@IP so that if their host doesnt resolve the gline still applies. */ + /* Note: We G-line *@IP so that if their host doesn't resolve the G-line still applies. */ GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was glined because their %s message matched %s (%s)", + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was G-lined because their %s message matched %s (%s)", user->nick.c_str(), command.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(gl,NULL)) @@ -521,7 +521,7 @@ ModResult ModuleFilter::OnPreCommand(std::string& command, CommandBase::Params& if (f->action == FA_ZLINE) { ZLine* zl = new ZLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString()); - ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was zlined because their %s message matched %s (%s)", + ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s was Z-lined because their %s message matched %s (%s)", user->nick.c_str(), command.c_str(), f->freeform.c_str(), f->reason.c_str())); if (ServerInstance->XLines->AddLine(zl,NULL)) diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index 77b3bc3aa..1247e81d3 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -32,7 +32,7 @@ class RLine : public XLine { public: - /** Create a R-Line. + /** Create a R-line. * @param s_time The set time * @param d The duration of the xline * @param src The sender of the xline @@ -81,7 +81,7 @@ class RLine : public XLine if (ServerInstance->XLines->AddLine(zl, NULL)) { std::string timestr = InspIRCd::TimeString(zl->expiry); - ServerInstance->SNO->WriteToSnoMask('x', "Z-line added due to R-line match on *@%s%s%s: %s", + ServerInstance->SNO->WriteToSnoMask('x', "Z-line added due to R-line match on %s%s%s: %s", zl->ipaddr.c_str(), zl->duration ? " to expire on " : "", zl->duration ? timestr.c_str() : "", zl->reason.c_str()); added_zline = true; } @@ -150,7 +150,7 @@ class CommandRLine : public Command unsigned long duration; if (!InspIRCd::Duration(parameters[1], duration)) { - user->WriteNotice("*** Invalid duration for R-line"); + user->WriteNotice("*** Invalid duration for R-line."); return CMD_FAILURE; } XLine *r = NULL; @@ -184,7 +184,7 @@ class CommandRLine : public Command else { delete r; - user->WriteNotice("*** R-Line for " + parameters[0] + " already exists"); + user->WriteNotice("*** R-line for " + parameters[0] + " already exists."); } } } @@ -196,7 +196,7 @@ class CommandRLine : public Command } else { - user->WriteNotice("*** R-Line " + parameters[0] + " not found in list, try /stats R."); + user->WriteNotice("*** R-line " + parameters[0] + " not found in list, try /stats R."); } } @@ -279,15 +279,15 @@ class ModuleRLine : public Module, public Stats::EventListener if (!rxfactory) { if (newrxengine.empty()) - ServerInstance->SNO->WriteToSnoMask('a', "WARNING: No regex engine loaded - R-Line functionality disabled until this is corrected."); + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: No regex engine loaded - R-line functionality disabled until this is corrected."); else - ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", newrxengine.c_str()); + ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-line functionality disabled until this is corrected.", newrxengine.c_str()); ServerInstance->XLines->DelAll(f.GetType()); } else if ((!initing) && (rxfactory.operator->() != factory)) { - ServerInstance->SNO->WriteToSnoMask('a', "Regex engine has changed, removing all R-Lines"); + ServerInstance->SNO->WriteToSnoMask('a', "Regex engine has changed, removing all R-lines."); ServerInstance->XLines->DelAll(f.GetType()); } @@ -331,7 +331,7 @@ class ModuleRLine : public Module, public Stats::EventListener void OnUnloadModule(Module* mod) CXX11_OVERRIDE { - // If the regex engine became unavailable or has changed, remove all rlines + // If the regex engine became unavailable or has changed, remove all R-lines. if (!rxfactory) { ServerInstance->XLines->DelAll(f.GetType()); diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp index e4fb2c11d..6453ace81 100644 --- a/src/modules/m_shun.cpp +++ b/src/modules/m_shun.cpp @@ -92,7 +92,7 @@ class CommandShun : public Command { if (!InspIRCd::Duration(parameters[1], duration)) { - user->WriteNotice("*** Invalid duration for SHUN"); + user->WriteNotice("*** Invalid duration for SHUN."); return CMD_FAILURE; } expr = parameters[2]; @@ -122,7 +122,7 @@ class CommandShun : public Command else { delete r; - user->WriteNotice("*** Shun for " + target + " already exists"); + user->WriteNotice("*** Shun for " + target + " already exists."); return CMD_FAILURE; } } diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h index 878b34ad7..6206448c1 100644 --- a/src/modules/m_spanningtree/treesocket.h +++ b/src/modules/m_spanningtree/treesocket.h @@ -259,7 +259,7 @@ class TreeSocket : public BufferedSocket */ void SendFJoins(Channel* c); - /** Send G, Q, Z and E lines */ + /** Send G-, Q-, Z- and E-lines */ void SendXLines(); /** Send all known information about a channel */ diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp index 52c250fef..0aaf113f0 100644 --- a/src/modules/m_svshold.cpp +++ b/src/modules/m_svshold.cpp @@ -76,7 +76,7 @@ class SVSHoldFactory : public XLineFactory public: SVSHoldFactory() : XLineFactory("SVSHOLD") { } - /** Generate a shun + /** Generate an SVSHOLD */ XLine* Generate(time_t set_time, unsigned long duration, const std::string& source, const std::string& reason, const std::string& xline_specific_mask) CXX11_OVERRIDE { @@ -130,7 +130,7 @@ class CommandSvshold : public Command unsigned long duration; if (!InspIRCd::Duration(parameters[1], duration)) { - user->WriteNotice("*** Invalid duration for SVSHOLD"); + user->WriteNotice("*** Invalid duration for SVSHOLD."); return CMD_FAILURE; } SVSHold* r = new SVSHold(ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str()); @@ -221,7 +221,7 @@ class ModuleSVSHold : public Module, public Stats::EventListener Version GetVersion() CXX11_OVERRIDE { - return Version("Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services.", VF_COMMON | VF_VENDOR); + return Version("Implements SVSHOLD. Like Q-lines, but can only be added/removed by Services.", VF_COMMON | VF_VENDOR); } }; -- cgit v1.3.1-10-gc9f91 From aea67c2520b9abbd3be702914b025e1b2a37e046 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Wed, 9 Jan 2019 15:55:03 +0000 Subject: Fix m_alias not initialising 'active' before use. --- src/modules/m_alias.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules') diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 4d1dd65c9..3e00db765 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -107,6 +107,7 @@ class ModuleAlias : public Module ModuleAlias() : botmode(this, "bot") + , active(false) { } -- cgit v1.3.1-10-gc9f91 From 21ae8e31440c40c5168f8451558a308b1317a2f7 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 10 Jan 2019 11:45:06 +0000 Subject: m_ircv3_echomessage: only echo the tags which were actually used. --- src/modules/m_ircv3_echomessage.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_ircv3_echomessage.cpp b/src/modules/m_ircv3_echomessage.cpp index f6eae5a00..b407aece4 100644 --- a/src/modules/m_ircv3_echomessage.cpp +++ b/src/modules/m_ircv3_echomessage.cpp @@ -40,25 +40,26 @@ class ModuleIRCv3EchoMessage : public Module LocalUser* const localuser = static_cast(user); const std::string& text = details.echo_original ? details.original_text : details.text; + const ClientProtocol::TagMap& tags = details.echo_original ? details.tags_in : details.tags_out; if (target.type == MessageTarget::TYPE_USER) { User* destuser = target.Get(); ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type); - privmsg.AddTags(details.tags_in); + privmsg.AddTags(tags); localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg); } else if (target.type == MessageTarget::TYPE_CHANNEL) { Channel* chan = target.Get(); ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status); - privmsg.AddTags(details.tags_in); + privmsg.AddTags(tags); localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg); } else { const std::string* servername = target.Get(); ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type); - privmsg.AddTags(details.tags_in); + privmsg.AddTags(tags); localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg); } } -- cgit v1.3.1-10-gc9f91 From 100c6c419c319663c43796d5d69f738df8d0f583 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 10 Jan 2019 19:09:02 +0000 Subject: Fix copying too much data into the remote endpoint field. This is a buffer overrun but its harmless as the things it will overwrite are no longer necessary. --- src/modules/m_haproxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/m_haproxy.cpp b/src/modules/m_haproxy.cpp index e92c45686..c5b7dddd8 100644 --- a/src/modules/m_haproxy.cpp +++ b/src/modules/m_haproxy.cpp @@ -240,7 +240,7 @@ class HAProxyHook : public IOHookMiddle { case AF_INET: memcpy(&client.in4.sin_addr.s_addr, &recvq[0], 4); - memcpy(&server.in4.sin_addr.s_addr, &recvq[4], 8); + memcpy(&server.in4.sin_addr.s_addr, &recvq[4], 4); memcpy(&client.in4.sin_port, &recvq[8], 2); memcpy(&server.in4.sin_port, &recvq[10], 2); tlv_index = 12; -- cgit v1.3.1-10-gc9f91 From 98e90d6d682c9795ab486d730d636d5c6ec1c817 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 10 Jan 2019 19:14:17 +0000 Subject: Fix reading the server path for UNIX sockets. --- src/modules/m_haproxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/m_haproxy.cpp b/src/modules/m_haproxy.cpp index c5b7dddd8..f61a39fdd 100644 --- a/src/modules/m_haproxy.cpp +++ b/src/modules/m_haproxy.cpp @@ -256,7 +256,7 @@ class HAProxyHook : public IOHookMiddle case AF_UNIX: memcpy(client.un.sun_path, &recvq[0], 108); - memcpy(client.un.sun_path, &recvq[108], 108); + memcpy(server.un.sun_path, &recvq[108], 108); tlv_index = 216; break; } -- cgit v1.3.1-10-gc9f91 From 0a7d2456d9e8b5a506e4619c40caef4606864502 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Fri, 11 Jan 2019 09:44:51 -0600 Subject: Allow wildcards in This makes it consistent with other class parameters like `webirc` --- src/modules/m_dnsbl.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp index a645e2cd1..eade39bd7 100644 --- a/src/modules/m_dnsbl.cpp +++ b/src/modules/m_dnsbl.cpp @@ -420,10 +420,14 @@ class ModuleDNSBL : public Module, public Stats::EventListener std::string dnsbl; if (!myclass->config->readString("dnsbl", dnsbl)) return MOD_RES_PASSTHRU; + std::string* match = nameExt.get(user); - std::string myname = match ? *match : ""; - if (dnsbl == myname) + if (!match) + return MOD_RES_PASSTHRU; + + if (InspIRCd::Match(*match, dnsbl)) return MOD_RES_PASSTHRU; + return MOD_RES_DENY; } -- cgit v1.3.1-10-gc9f91 From f400d5f394a258dee58fb56420acd65e22503761 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Mon, 14 Jan 2019 05:48:45 -0600 Subject: Redo OnSetEndPoint logic to fix duplicate clones (#1549). --- include/inspsocket.h | 3 ++- include/users.h | 10 +++++----- src/coremods/core_xline/core_xline.cpp | 9 +++++++++ src/inspsocket.cpp | 5 +++++ src/modules/m_cgiirc.cpp | 27 ++----------------------- src/modules/m_haproxy.cpp | 3 ++- src/users.cpp | 36 +++++++++++++++++++++------------- 7 files changed, 47 insertions(+), 46 deletions(-) (limited to 'src/modules') diff --git a/include/inspsocket.h b/include/inspsocket.h index e432f9c16..69fdaac8b 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -312,8 +312,9 @@ class CoreExport StreamSocket : public EventHandler /** Called when the endpoint addresses are changed. * @param local The new local endpoint. * @param remote The new remote endpoint. + * @return true if the connection is still open, false if it has been closed */ - virtual void OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote) { } + virtual bool OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote); /** Send the given data out the socket, either now or when writes unblock */ diff --git a/include/users.h b/include/users.h index 469c17124..eaf400c67 100644 --- a/include/users.h +++ b/include/users.h @@ -380,9 +380,9 @@ class CoreExport User : public Extensible /** Sets the client IP for this user * @return true if the conversion was successful */ - virtual bool SetClientIP(const std::string& address, bool recheck_eline = true); + virtual bool SetClientIP(const std::string& address); - virtual void SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline = true); + virtual void SetClientIP(const irc::sockets::sockaddrs& sa); /** Constructor * @throw CoreException if the UID allocated to the user already exists @@ -689,7 +689,7 @@ class CoreExport UserIOHandler : public StreamSocket { } void OnDataReady() CXX11_OVERRIDE; - void OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote) CXX11_OVERRIDE; + bool OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote) CXX11_OVERRIDE; void OnError(BufferedSocketError error) CXX11_OVERRIDE; /** Adds to the user's write buffer. @@ -820,9 +820,9 @@ class CoreExport LocalUser : public User, public insp::intrusive_list_nodequitting) + return; + + user->exempt = (ServerInstance->XLines->MatchesLine("E", user) != NULL); + user->CheckLines(true); + } + ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE { // Check Q-lines (for local nick changes only, remote servers have our Q-lines to enforce themselves) diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 69c427212..ebbff448e 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -358,6 +358,11 @@ void StreamSocket::FlushSendQ(SendQueue& sq) } } +bool StreamSocket::OnSetEndPoint(const irc::sockets::sockaddrs& local, const irc::sockets::sockaddrs& remote) +{ + return false; +} + void StreamSocket::WriteData(const std::string &data) { if (fd < 0) diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 4a5a4fb03..df8201bde 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -34,29 +34,6 @@ enum RPL_WHOISGATEWAY = 350 }; -// We need this method up here so that it can be accessed from anywhere -static void ChangeIP(LocalUser* user, const irc::sockets::sockaddrs& sa) -{ - // Set the users IP address and make sure they are in the right clone pool. - ServerInstance->Users->RemoveCloneCounts(user); - user->SetClientIP(sa); - ServerInstance->Users->AddClone(user); - if (user->quitting) - return; - - // Recheck the connect class. - user->MyClass = NULL; - user->SetClass(); - user->CheckClass(); - if (user->quitting) - return; - - // Check if this user matches any XLines. - user->CheckLines(true); - if (user->quitting) - return; -} - // Encapsulates information about an ident host. class IdentHost { @@ -215,7 +192,7 @@ class CommandWebIRC : public SplitCommand // Set the IP address sent via WEBIRC. We ignore the hostname and lookup // instead do our own DNS lookups because of unreliable gateways. - ChangeIP(user, ipaddr); + user->SetClientIP(ipaddr); return CMD_SUCCESS; } @@ -391,7 +368,7 @@ class ModuleCgiIRC user->uuid.c_str(), user->GetIPString().c_str(), address.addr().c_str(), user->ident.c_str(), newident.c_str()); user->ChangeIdent(newident); - ChangeIP(user, address); + user->SetClientIP(address); break; } return MOD_RES_PASSTHRU; diff --git a/src/modules/m_haproxy.cpp b/src/modules/m_haproxy.cpp index f61a39fdd..ee9079cbf 100644 --- a/src/modules/m_haproxy.cpp +++ b/src/modules/m_haproxy.cpp @@ -261,7 +261,8 @@ class HAProxyHook : public IOHookMiddle break; } - sock->OnSetEndPoint(server, client); + if (!sock->OnSetEndPoint(server, client)) + return -1; // Parse any available TLVs. while (tlv_index < address_length) diff --git a/src/users.cpp b/src/users.cpp index f11a7a380..a0b9c9d03 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -318,10 +318,11 @@ void UserIOHandler::AddWriteBuf(const std::string &data) WriteData(data); } -void UserIOHandler::OnSetEndPoint(const irc::sockets::sockaddrs& server, const irc::sockets::sockaddrs& client) +bool UserIOHandler::OnSetEndPoint(const irc::sockets::sockaddrs& server, const irc::sockets::sockaddrs& client) { memcpy(&user->server_sa, &server, sizeof(irc::sockets::sockaddrs)); user->SetClientIP(client); + return !user->quitting; } void UserIOHandler::OnError(BufferedSocketError) @@ -723,17 +724,17 @@ irc::sockets::cidr_mask User::GetCIDRMask() return irc::sockets::cidr_mask(client_sa, range); } -bool User::SetClientIP(const std::string& address, bool recheck_eline) +bool User::SetClientIP(const std::string& address) { irc::sockets::sockaddrs sa; if (!irc::sockets::aptosa(address, client_sa.port(), sa)) return false; - User::SetClientIP(sa, recheck_eline); + User::SetClientIP(sa); return true; } -void User::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline) +void User::SetClientIP(const irc::sockets::sockaddrs& sa) { const std::string oldip(GetIPString()); memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs)); @@ -746,26 +747,33 @@ void User::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline) ChangeDisplayedHost(GetIPString()); } -bool LocalUser::SetClientIP(const std::string& address, bool recheck_eline) +bool LocalUser::SetClientIP(const std::string& address) { irc::sockets::sockaddrs sa; if (!irc::sockets::aptosa(address, client_sa.port(), sa)) return false; - LocalUser::SetClientIP(sa, recheck_eline); + LocalUser::SetClientIP(sa); return true; } -void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa, bool recheck_eline) +void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa) { - if (sa != client_sa) - { - User::SetClientIP(sa); - if (recheck_eline) - this->exempt = (ServerInstance->XLines->MatchesLine("E", this) != NULL); + if (sa == client_sa) + return; - FOREACH_MOD(OnSetUserIP, (this)); - } + ServerInstance->Users->RemoveCloneCounts(this); + + User::SetClientIP(sa); + + FOREACH_MOD(OnSetUserIP, (this)); + + ServerInstance->Users->AddClone(this); + + // Recheck the connect class. + this->MyClass = NULL; + this->SetClass(); + this->CheckClass(); } void LocalUser::Write(const ClientProtocol::SerializedMessage& text) -- cgit v1.3.1-10-gc9f91 From 11cc922584b050b3242e1f50b6821e973d42b3f5 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 14 Jan 2019 21:33:51 +0000 Subject: Fix the hostchange set action swapping the host/value fields. --- src/modules/m_hostchange.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 201c4b59b..4c9b24140 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -47,7 +47,7 @@ class HostRule std::string suffix; public: - HostRule(const std::string& Host, const std::string& Mask, const insp::flat_set& Ports) + HostRule(const std::string& Mask, const std::string& Host, const insp::flat_set& Ports) : action(HCA_SET) , host(Host) , mask(Mask) -- cgit v1.3.1-10-gc9f91 From 0527f858cecb05a79b6405b6d353a460a4946f7f Mon Sep 17 00:00:00 2001 From: Robby Date: Thu, 17 Jan 2019 12:20:26 +0100 Subject: m_check: Fix showing oper permissions (privileges). (#1556) --- src/modules/m_check.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index f820f2bd0..1d030acc6 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -200,7 +200,7 @@ class CommandCheck : public Command opcmdlist.Add(oper->AllowedOperCommands.ToString()); opcmdlist.Flush(); CheckContext::List privlist(context, "permissions"); - opcmdlist.Add(oper->AllowedPrivs.ToString()); + privlist.Add(oper->AllowedPrivs.ToString()); privlist.Flush(); } } -- cgit v1.3.1-10-gc9f91 From 25b3686f43d2a0dcc40157d7119a80b783a07f8f Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 19 Jan 2019 12:55:31 +0000 Subject: Fix sending the entire VERSION output as a single parameter. Closes #1560. --- src/coremods/core_info/cmd_version.cpp | 8 ++++++-- src/modules/m_spanningtree/main.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/coremods/core_info/cmd_version.cpp b/src/coremods/core_info/cmd_version.cpp index 29d96169e..57f9b05cf 100644 --- a/src/coremods/core_info/cmd_version.cpp +++ b/src/coremods/core_info/cmd_version.cpp @@ -29,8 +29,12 @@ CommandVersion::CommandVersion(Module* parent) CmdResult CommandVersion::Handle(User* user, const Params& parameters) { - std::string version = ServerInstance->GetVersionString((user->IsOper())); - user->WriteNumeric(RPL_VERSION, version); + Numeric::Numeric numeric(RPL_VERSION); + irc::tokenstream tokens(ServerInstance->GetVersionString(user->IsOper())); + for (std::string token; tokens.GetTrailing(token); ) + numeric.push(token); + user->WriteNumeric(numeric); + LocalUser *lu = IS_LOCAL(user); if (lu != NULL) { diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 985762872..de1e8eb19 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -324,8 +324,12 @@ ModResult ModuleSpanningTree::HandleVersion(const CommandBase::Params& parameter // If it's empty it might be that the server is still syncing (full version hasn't arrived yet) // or the server is a 2.0 server and does not send a full version. bool showfull = ((user->IsOper()) && (!found->GetFullVersion().empty())); - const std::string& Version = (showfull ? found->GetFullVersion() : found->GetVersion()); - user->WriteNumeric(RPL_VERSION, Version); + + Numeric::Numeric numeric(RPL_VERSION); + irc::tokenstream tokens(showfull ? found->GetFullVersion() : found->GetVersion()); + for (std::string token; tokens.GetTrailing(token); ) + numeric.push(token); + user->WriteNumeric(numeric); } else { -- cgit v1.3.1-10-gc9f91 From 0a9c72335a3d3dea286382ad3e7635a05713d7cc Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 20 Jan 2019 09:51:12 +0000 Subject: Move ident lookups to the OnSetUserIP hook. --- src/modules/m_ident.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index ca12a9ba3..803c19846 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -275,12 +275,24 @@ class ModuleIdent : public Module NoLookupPrefix = tag->getBool("nolookupprefix", false); } - void OnUserInit(LocalUser *user) CXX11_OVERRIDE + void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE { + IdentRequestSocket* isock = ext.get(user); + if (isock) + { + // If an ident lookup request was in progress then cancel it. + isock->Close(); + ext.unset(user); + } + // The ident protocol requires that clients are connecting over a protocol with ports. if (user->client_sa.family() != AF_INET && user->client_sa.family() != AF_INET6) return; + // We don't want to look this up once the user has connected. + if (user->registered == REG_ALL) + return; + ConfigTag* tag = user->MyClass->config; if (!tag->getBool("useident", true)) return; @@ -289,7 +301,7 @@ class ModuleIdent : public Module try { - IdentRequestSocket *isock = new IdentRequestSocket(user); + isock = new IdentRequestSocket(user); ext.set(user, isock); } catch (ModuleException &e) -- cgit v1.3.1-10-gc9f91 From 965c81baee0fb6f46aa788f45742d558f50c8b15 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Tue, 22 Jan 2019 11:59:44 +0000 Subject: Rename OnClientProtocolProcessTag to OnProcessTag. --- include/clientprotocol.h | 2 +- src/clientprotocol.cpp | 2 +- src/modules/m_spanningtree/treesocket2.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/include/clientprotocol.h b/include/clientprotocol.h index 10b70e80b..ec033e166 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -549,7 +549,7 @@ class ClientProtocol::MessageTagProvider : public Events::ModuleEventListener * MOD_RES_PASSTHRU to make no decision. If no hooks accept a tag, the tag is rejected. * The default implementation returns MOD_RES_PASSTHRU. */ - virtual ModResult OnClientProtocolProcessTag(User* user, const std::string& tagname, std::string& tagvalue) + virtual ModResult OnProcessTag(User* user, const std::string& tagname, std::string& tagvalue) { return MOD_RES_PASSTHRU; } diff --git a/src/clientprotocol.cpp b/src/clientprotocol.cpp index a732855a5..212d65d6b 100644 --- a/src/clientprotocol.cpp +++ b/src/clientprotocol.cpp @@ -35,7 +35,7 @@ bool ClientProtocol::Serializer::HandleTag(LocalUser* user, const std::string& t for (::Events::ModuleEventProvider::SubscriberList::const_iterator i = list.begin(); i != list.end(); ++i) { MessageTagProvider* const tagprov = static_cast(*i); - const ModResult res = tagprov->OnClientProtocolProcessTag(user, tagname, tagvalue); + const ModResult res = tagprov->OnProcessTag(user, tagname, tagvalue); if (res == MOD_RES_ALLOW) return tags.insert(std::make_pair(tagname, MessageTagData(tagprov, tagvalue))).second; else if (res == MOD_RES_DENY) diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index dc24802fb..45f8a380f 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -292,7 +292,7 @@ void TreeSocket::ProcessTag(User* source, const std::string& tag, ClientProtocol for (Events::ModuleEventProvider::SubscriberList::const_iterator i = list.begin(); i != list.end(); ++i) { ClientProtocol::MessageTagProvider* const tagprov = static_cast(*i); - const ModResult res = tagprov->OnClientProtocolProcessTag(source, tagkey, tagval); + const ModResult res = tagprov->OnProcessTag(source, tagkey, tagval); if (res == MOD_RES_ALLOW) tags.insert(std::make_pair(tagkey, ClientProtocol::MessageTagData(tagprov, tagval))); else if (res == MOD_RES_DENY) -- cgit v1.3.1-10-gc9f91 From 5394adf41ff609f7f97af529774fcb616fe072b2 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Wed, 23 Jan 2019 02:40:25 -0600 Subject: Fix away broadcast logic (#1561) --- src/modules/m_spanningtree/away.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/away.cpp b/src/modules/m_spanningtree/away.cpp index 13972589b..62300580f 100644 --- a/src/modules/m_spanningtree/away.cpp +++ b/src/modules/m_spanningtree/away.cpp @@ -47,6 +47,6 @@ CmdResult CommandAway::HandleRemote(::RemoteUser* u, Params& params) CommandAway::Builder::Builder(User* user) : CmdBuilder(user, "AWAY") { - if (user->awaymsg.empty()) + if (!user->awaymsg.empty()) push_int(user->awaytime).push_last(user->awaymsg); } -- cgit v1.3.1-10-gc9f91 From 806e4006199a057e0e7f82420a491e8fe6dd15cb Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Wed, 23 Jan 2019 14:46:20 +0000 Subject: Fix a crash in m_sslinfo when a socket is SSL but a gateway is not. --- src/modules/m_sslinfo.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp index 54aeb9755..30dfd9a76 100644 --- a/src/modules/m_sslinfo.cpp +++ b/src/modules/m_sslinfo.cpp @@ -54,8 +54,7 @@ class SSLCertExt : public ExtensionItem void unset(Extensible* container) { - void* old = unset_raw(container); - delete static_cast(old); + free(container, unset_raw(container)); } std::string serialize(SerializeFormat format, const Extensible* container, void* item) const CXX11_OVERRIDE -- cgit v1.3.1-10-gc9f91 From a7fac86ccda9e75c6f426b07faa85081f5857d33 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 24 Jan 2019 07:34:54 -0600 Subject: Avoid forwarding passwords to nickserv when using SASL (#1562) --- src/modules/m_passforward.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/modules') diff --git a/src/modules/m_passforward.cpp b/src/modules/m_passforward.cpp index 08d3533cd..37efec02b 100644 --- a/src/modules/m_passforward.cpp +++ b/src/modules/m_passforward.cpp @@ -18,6 +18,7 @@ #include "inspircd.h" +#include "modules/account.h" class ModulePassForward : public Module { @@ -82,6 +83,13 @@ class ModulePassForward : public Module if (!user->MyClass->config->getString("password").empty()) return; + AccountExtItem* actext = GetAccountExtItem(); + if (actext && actext->get(user)) + { + // User is logged in already (probably via SASL) don't forward the password + return; + } + if (!nickrequired.empty()) { /* Check if nick exists and its server is ulined */ -- cgit v1.3.1-10-gc9f91 From 4047a143fc1d16350db70c94b9ea77d79de05714 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 24 Jan 2019 15:10:02 +0000 Subject: Move the tag out of the core to a new module. --- docs/conf/inspircd.conf.example | 19 ---- docs/conf/modules.conf.example | 37 ++++++++ include/configreader.h | 15 ---- include/ctables.h | 21 ----- src/command_parse.cpp | 19 ---- src/configreader.cpp | 46 ---------- src/inspircd.cpp | 1 - src/mode.cpp | 11 --- src/modules/m_conn_umodes.cpp | 6 -- src/modules/m_disable.cpp | 189 ++++++++++++++++++++++++++++++++++++++++ src/modules/m_samode.cpp | 3 + 11 files changed, 229 insertions(+), 138 deletions(-) create mode 100644 src/modules/m_disable.cpp (limited to 'src/modules') diff --git a/docs/conf/inspircd.conf.example b/docs/conf/inspircd.conf.example index f2db74500..890c9cc4c 100644 --- a/docs/conf/inspircd.conf.example +++ b/docs/conf/inspircd.conf.example @@ -520,25 +520,6 @@ # up to 100 entries. -#-#-#-#-#-#-#-#-#-#-#- DISABLED FEATURES -#-#-#-#-#-#-#-#-#-#-#-#-#-# -# # -# This tag is optional, and specifies one or more features which are # -# not available to non-operators. # -# # -# For example you may wish to disable NICK and prevent non-opers from # -# changing their nicknames. # -# Note that any disabled commands take effect only after the user has # -# 'registered' (e.g. after the initial USER/NICK/PASS on connection) # -# so for example disabling NICK will not cripple your network. # -# # -# You can also define if you want to disable any channelmodes # -# or usermodes from your users. # -# # -# `fakenonexistant' will make the ircd pretend that nonexistant # -# commands simply don't exist to non-opers ("no such command"). # -# # -# - #-#-#-#-#-#-#-#-#-#-#-#-#- SERVER OPTIONS -#-#-#-#-#-#-#-#-#-#-#-#-# # # # Settings to define which features are usable on your server. # diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index 0647f77c0..980d0d6a5 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -764,6 +764,43 @@ # # # Glob masks are accepted here also. # +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# +# Disable module: Provides support for disabling commands and modes. # +# +# +#-#-#-#-#-#-#-#-#-#-#-#- DISABLE CONFIGURATION -#-#-#-#-#-#-#-#-#-#-#-# +# # +# If you have the disable module loaded then you need to specify the # +# commands and modes that you want disabled. Users who have not fully # +# connected yet are exempt from this module so you can e.g. disable # +# the NICK command but still allow users to connect to the server. # +# # +# commands - A space-delimited list of commands that can not be used # +# by users. You can exempt server operators from this with # +# the servers/use-disabled-commands privilege. # +# # +# chanmodes - One or more channel modes that can not be added/removed # +# by users. You can exempt server operators from this # +# with the servers/use-disabled-commands privilege. # +# # +# usermodes - One or more user modes that can not be added/removed by # +# users. You can exempt server operators from this with # +# the servers/use-disabled-commands privilege. # +# # +# fakenonexistent - Whether to pretend that a disabled command/mode # +# does not exist when executed/changed by a user. # +# Defaults to no. # +# # +# notifyopers - Whether to send a notice to snomask `a` when a user # +# is prevented from using a disabled command/mode. # +# Defaults to no. # +# # +# # + #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # DNS blacklist module: Provides support for looking up IPs on one or # # more blacklists. # diff --git a/include/configreader.h b/include/configreader.h index fd9401c0f..511bedbee 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -332,18 +332,6 @@ class CoreExport ServerConfig */ std::string ServerDesc; - /** Pretend disabled commands don't exist. - */ - bool DisabledDontExist; - - /** This variable identifies which usermodes have been diabled. - */ - std::bitset<64> DisabledUModes; - - /** This variable identifies which chanmodes have been disabled. - */ - std::bitset<64> DisabledCModes; - /** How to treat a user in a channel who is banned. */ BannedUserTreatment RestrictBannedUsers; @@ -466,9 +454,6 @@ class CoreExport ServerConfig void Fill(); - /** Disables the commands specified in . */ - bool ApplyDisabledCommands(); - /** Escapes a value for storage in a configuration key. * @param str The string to escape. * @param xml Are we using the XML config format? diff --git a/include/ctables.h b/include/ctables.h index 8be40cc54..1c7d5b4bd 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -163,10 +163,6 @@ class CoreExport CommandBase : public ServiceProvider */ unsigned long use_count; - /** True if the command is disabled to non-opers - */ - bool disabled; - /** True if the command can be issued before registering */ bool works_before_reg; @@ -212,23 +208,6 @@ class CoreExport CommandBase : public ServiceProvider */ virtual void EncodeParameter(std::string& parameter, unsigned int index); - /** Disable or enable this command. - * @param setting True to disable the command. - */ - void Disable(bool setting) - { - disabled = setting; - } - - /** Obtain this command's disable state. - * @return true if the command is currently disabled - * (disabled commands can be used only by operators) - */ - bool IsDisabled() - { - return disabled; - } - /** @return true if the command works before registration. */ bool WorksBeforeReg() diff --git a/src/command_parse.cpp b/src/command_parse.cpp index c2ae39d49..7a732f8b5 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -266,24 +266,6 @@ void CommandParser::ProcessCommand(LocalUser* user, std::string& command, Comman } } - if ((user->registered == REG_ALL) && (!user->IsOper()) && (handler->IsDisabled())) - { - /* command is disabled! */ - user->CommandFloodPenalty += failpenalty; - if (ServerInstance->Config->DisabledDontExist) - { - user->WriteNumeric(ERR_UNKNOWNCOMMAND, command, "Unknown command"); - } - else - { - user->WriteNumeric(ERR_UNKNOWNCOMMAND, command, "This command has been disabled."); - } - - ServerInstance->SNO->WriteToSnoMask('a', "%s denied for %s (%s@%s)", - command.c_str(), user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str()); - return; - } - if ((!command_p.empty()) && (command_p.back().empty()) && (!handler->allow_empty_last_param)) command_p.pop_back(); @@ -333,7 +315,6 @@ CommandBase::CommandBase(Module* mod, const std::string& cmd, unsigned int minpa , min_params(minpara) , max_params(maxpara) , use_count(0) - , disabled(false) , works_before_reg(false) , allow_empty_last_param(true) , Penalty(1) diff --git a/src/configreader.cpp b/src/configreader.cpp index ce03f1d9e..5a0ceff06 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -72,31 +72,6 @@ ServerConfig::~ServerConfig() delete EmptyTag; } -bool ServerConfig::ApplyDisabledCommands() -{ - // Enable everything first. - const CommandParser::CommandMap& commands = ServerInstance->Parser.GetCommands(); - for (CommandParser::CommandMap::const_iterator x = commands.begin(); x != commands.end(); ++x) - x->second->Disable(false); - - // Now disable the commands specified in the config. - std::string command; - irc::spacesepstream commandlist(ConfValue("disabled")->getString("commands")); - while (commandlist.GetToken(command)) - { - Command* handler = ServerInstance->Parser.GetHandler(command); - if (!handler) - { - ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "Unable to disable the %s command as it does not exist!", command.c_str()); - continue; - } - - ServerInstance->Logs->Log("CONFIG", LOG_DEBUG, "The %s command has been disabled", command.c_str()); - handler->Disable(true); - } - return true; -} - static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::string& key, XLineFactory* make) { ConfigTagList tags = conf->ConfTags(tag); @@ -378,7 +353,6 @@ void ServerConfig::Fill() ServerDesc = server->getString("description", "Configure Me"); Network = server->getString("network", "Network"); NetBufferSize = ConfValue("performance")->getInt("netbuffersize", 10240, 1024, 65534); - DisabledDontExist = ConfValue("disabled")->getBool("fakenonexistant"); CustomVersion = security->getString("customversion"); HideBans = security->getBool("hidebans"); HideServer = security->getString("hideserver", security->getString("hidewhois")); @@ -429,25 +403,6 @@ void ServerConfig::Fill() RestrictBannedUsers = ServerConfig::BUT_RESTRICT_NOTIFY; else throw CoreException(restrictbannedusers + " is an invalid value, at " + options->getTagLocation()); - - DisabledUModes.reset(); - std::string modes = ConfValue("disabled")->getString("usermodes"); - for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p) - { - // Complain when the character is not a valid mode character. - if (!ModeParser::IsModeChar(*p)) - throw CoreException("Invalid usermode " + std::string(1, *p) + " was found."); - DisabledUModes.set(*p - 'A'); - } - - DisabledCModes.reset(); - modes = ConfValue("disabled")->getString("chanmodes"); - for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p) - { - if (!ModeParser::IsModeChar(*p)) - throw CoreException("Invalid chanmode " + std::string(1, *p) + " was found."); - DisabledCModes.set(*p - 'A'); - } } // WARNING: it is not safe to use most of the codebase in this function, as it @@ -723,7 +678,6 @@ void ConfigReaderThread::Finish() ServerInstance->Users.RehashCloneCounts(); ServerInstance->XLines->CheckELines(); ServerInstance->XLines->ApplyLines(); - Config->ApplyDisabledCommands(); User* user = ServerInstance->FindNick(TheUserUID); ConfigStatus status(user); diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 7e299700b..09e48ea1f 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -442,7 +442,6 @@ InspIRCd::InspIRCd(int argc, char** argv) : // Build ISupport as ModuleManager::LoadAll() does not do it this->ISupport.Build(); - Config->ApplyDisabledCommands(); if (!pl.empty()) { diff --git a/src/mode.cpp b/src/mode.cpp index 5793b4e66..459eb21c8 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -312,17 +312,6 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode } } - if (IS_LOCAL(user) && !user->IsOper()) - { - const std::bitset<64>& disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes; - if (disabled.test(modechar - 'A')) - { - user->WriteNumeric(ERR_NOPRIVILEGES, InspIRCd::Format("Permission Denied - %s mode %c has been locked by the administrator", - type == MODETYPE_CHANNEL ? "channel" : "user", modechar)); - return MODEACTION_DENY; - } - } - if ((adding) && (IS_LOCAL(user)) && (mh->NeedsOper()) && (!user->HasModePermission(mh))) { /* It's an oper only mode, and they don't have access to it. */ diff --git a/src/modules/m_conn_umodes.cpp b/src/modules/m_conn_umodes.cpp index 1f2fe7455..3132aed40 100644 --- a/src/modules/m_conn_umodes.cpp +++ b/src/modules/m_conn_umodes.cpp @@ -38,10 +38,6 @@ class ModuleModesOnConnect : public Module void OnUserConnect(LocalUser* user) CXX11_OVERRIDE { - // Backup and zero out the disabled usermodes, so that we can override them here. - const std::bitset<64> save = ServerInstance->Config->DisabledUModes; - ServerInstance->Config->DisabledUModes.reset(); - ConfigTag* tag = user->MyClass->config; std::string ThisModes = tag->getString("modes"); if (!ThisModes.empty()) @@ -58,8 +54,6 @@ class ModuleModesOnConnect : public Module ServerInstance->Parser.CallHandler("MODE", modes, user); } - - ServerInstance->Config->DisabledUModes = save; } }; diff --git a/src/modules/m_disable.cpp b/src/modules/m_disable.cpp new file mode 100644 index 000000000..203f9ee64 --- /dev/null +++ b/src/modules/m_disable.cpp @@ -0,0 +1,189 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2019 Peter Powell + * + * 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 . + */ + + +#include "inspircd.h" + +enum +{ + // From ircu. + ERR_DISABLED = 517 +}; + +// Holds a list of disabled commands. +typedef std::vector CommandList; + +// Holds whether modes are disabled or not. +typedef std::bitset<64> ModeStatus; + +class ModuleDisable : public Module +{ + private: + CommandList commands; + ModeStatus chanmodes; + bool fakenonexistent; + bool notifyopers; + ModeStatus usermodes; + + void ReadModes(ConfigTag* tag, const std::string& field, ModeType type, ModeStatus& status) + { + const std::string modes = tag->getString(field); + for (std::string::const_iterator iter = modes.begin(); iter != modes.end(); ++iter) + { + const char& chr = *iter; + + // Check that the character is a valid mode letter. + if (!ModeParser::IsModeChar(chr)) + throw ModuleException(InspIRCd::Format("Invalid mode '%c' was specified in at %s", + chr, field.c_str(), tag->getTagLocation().c_str())); + + // Check that the mode actually exists. + ModeHandler* mh = ServerInstance->Modes->FindMode(chr, type); + if (!chr) + throw ModuleException(InspIRCd::Format("Non-existent mode '%c' was specified in at %s", + chr, field.c_str(), tag->getTagLocation().c_str())); + + // Disable the mode. + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "The %c (%s) %s mode has been disabled", + mh->GetModeChar(), mh->name.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user"); + status.set(chr - 'A'); + } + } + + void WriteLog(const char* message, ...) CUSTOM_PRINTF(2, 3) + { + std::string buffer; + VAFORMAT(buffer, message, message); + + if (notifyopers) + ServerInstance->SNO->WriteToSnoMask('a', buffer); + else + ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, buffer); + } + + public: + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE + { + ConfigTag* tag = ServerInstance->Config->ConfValue("disabled"); + + // Parse the disabled commands. + CommandList newcommands; + irc::spacesepstream commandlist(tag->getString("commands")); + for (std::string command; commandlist.GetToken(command); ) + { + // Check that the command actually exists. + Command* handler = ServerInstance->Parser.GetHandler(command); + if (!handler) + throw ModuleException(InspIRCd::Format("Non-existent command '%s' was specified in at %s", + command.c_str(), tag->getTagLocation().c_str())); + + // Prevent admins from disabling COMMANDS and MODULES for transparency reasons. + if (handler->name == "COMMANDS" || handler->name == "MODULES") + continue; + + // Disable the command. + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "The %s command has been disabled", handler->name.c_str()); + newcommands.push_back(handler->name); + } + + // Parse the disabled channel modes. + ModeStatus newchanmodes; + ReadModes(tag, "chanmodes", MODETYPE_CHANNEL, newchanmodes); + + // Parse the disabled user modes. + ModeStatus newusermodes; + ReadModes(tag, "usermodes", MODETYPE_USER, newusermodes); + + // The server config was valid so we can use these now. + chanmodes = newchanmodes; + usermodes = newusermodes; + commands.swap(newcommands); + + // Whether we should fake the non-existence of disabled things. + fakenonexistent = tag->getBool("fakenonexistent", tag->getBool("fakenonexistant")); + + // Whether to notify server operators via snomask `a` about the attempted use of disabled commands/modes. + notifyopers = tag->getBool("notifyopers"); + } + + ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE + { + // If a command is unvalidated or the source is not registered we do nothing. + if (!validated || user->registered != REG_ALL) + return MOD_RES_PASSTHRU; + + // If the command is not disabled or the user has the servers/use-disabled-commands priv we do nothing. + if (!stdalgo::isin(commands, command) || user->HasPrivPermission("servers/use-disabled-commands")) + return MOD_RES_PASSTHRU; + + // The user has tried to execute a disabled command! + user->CommandFloodPenalty += 2000; + WriteLog("%s was blocked from executing the disabled %s command", user->GetFullRealHost().c_str(), command.c_str()); + + if (fakenonexistent) + { + // The server administrator has specified that disabled commands should be + // treated as if they do not exist. + user->WriteNumeric(ERR_UNKNOWNCOMMAND, command, "Unknown command"); + ServerInstance->stats.Unknown++; + return MOD_RES_DENY; + } + + // Inform the user that the command they executed has been disabled. + user->WriteNumeric(ERR_DISABLED, command, "Command disabled"); + return MOD_RES_DENY; + } + + ModResult OnRawMode(User* user, Channel* chan, ModeHandler* mh, const std::string& param, bool adding) CXX11_OVERRIDE + { + // If a mode change is remote or the source is not registered we do nothing. + if (!IS_LOCAL(user) || user->registered != REG_ALL) + return MOD_RES_PASSTHRU; + + // If the mode is not disabled or the user has the servers/use-disabled-modes priv we do nothing. + const std::bitset<64>& disabled = (mh->GetModeType() == MODETYPE_CHANNEL) ? chanmodes : usermodes; + if (!disabled.test(mh->GetModeChar() - 'A') || user->HasPrivPermission("servers/use-disabled-modes")) + return MOD_RES_PASSTHRU; + + // The user has tried to change a disabled mode! + const char* what = mh->GetModeType() == MODETYPE_CHANNEL ? "channel" : "user"; + WriteLog("%s was blocked from executing the disabled %s mode %c (%s)", + user->GetFullRealHost().c_str(), what, mh->GetModeChar(), mh->name.c_str()); + + if (fakenonexistent) + { + // The server administrator has specified that disabled modes should be + // treated as if they do not exist. + user->WriteNumeric(mh->GetModeType() == MODETYPE_CHANNEL ? ERR_UNKNOWNMODE : ERR_UNKNOWNSNOMASK, + mh->GetModeChar(), "is unknown mode char to me"); + return MOD_RES_DENY; + } + + // Inform the user that the mode they changed has been disabled. + user->WriteNumeric(ERR_NOPRIVILEGES, InspIRCd::Format("Permission Denied - %s mode %c (%s) is disabled", + what, mh->GetModeChar(), mh->name.c_str())); + return MOD_RES_DENY; + } + + Version GetVersion() CXX11_OVERRIDE + { + return Version("Provides support for disabling commands and modes", VF_VENDOR); + } +}; + +MODULE_INIT(ModuleDisable) diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp index 8f28a7e9c..db3345b98 100644 --- a/src/modules/m_samode.cpp +++ b/src/modules/m_samode.cpp @@ -124,6 +124,9 @@ class ModuleSaMode : public Module void Prioritize() CXX11_OVERRIDE { + Module* disabled = ServerInstance->Modules->Find("m_disabled.so"); + ServerInstance->Modules->SetPriority(this, I_OnRawMode, PRIORITY_BEFORE, disabled); + Module *override = ServerInstance->Modules->Find("m_override.so"); ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_BEFORE, override); } -- cgit v1.3.1-10-gc9f91 From 2f35b78fbaadb8d9a6c47ffc198bd97f91af3306 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 24 Jan 2019 09:52:59 -0600 Subject: Add translation for casemapping between 2.0/3.0 (#1544) If the casemapping is set to ascii, advertise the m_ascii module to 2.0 to allow use of the m_ascii extras module for 2.0--- src/modules/m_spanningtree/capab.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index c29330516..ea11a917e 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -76,6 +76,15 @@ std::string TreeSocket::MyModules(int filter) capabilities.append(v.link_data); } } + + // If we are linked in a 2.0 server and have an ascii casemapping + // advertise it as m_ascii.so from inspircd-extras + if ((filter & VF_COMMON) && ServerInstance->Config->CaseMapping == "ascii" && proto_version == 1202) + { + if (!capabilities.empty()) + capabilities += "m_ascii.so"; + } + return capabilities; } -- cgit v1.3.1-10-gc9f91