X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_sasl.cpp;h=e202bae45181f8538153c6bc2417d59823548240;hb=e2b0f3dc9ef4d56c71d7abda13e6139ca092e387;hp=54bb8a44a7a1243cc7a2dfcafca1c4d89ddb4126;hpb=e57d1b19ff4823b7885eb7f4d3b37c84d2edca0e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 54bb8a44a..e202bae45 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -1,8 +1,15 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2016 Adam + * Copyright (C) 2014 Mantas Mikulėnas + * Copyright (C) 2013-2016, 2018 Attila Molnar + * Copyright (C) 2013, 2017-2020 Sadie Powell + * Copyright (C) 2013 Daniel Vassdal + * Copyright (C) 2012, 2019 Robby * Copyright (C) 2009-2010 Daniel De Graaf - * Copyright (C) 2008 Craig Edwards + * Copyright (C) 2008, 2010 Craig Edwards + * Copyright (C) 2008 Thomas Stagner * * 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 @@ -37,8 +44,12 @@ enum static std::string sasl_target; -class ServerTracker : public ServerEventListener +class ServerTracker + : public ServerProtocol::LinkEventListener { + // Stop GCC warnings about the deprecated OnServerSplit event. + using ServerProtocol::LinkEventListener::OnServerSplit; + bool online; void Update(const Server* server, bool linked) @@ -58,14 +69,14 @@ class ServerTracker : public ServerEventListener Update(server, true); } - void OnServerSplit(const Server* server) CXX11_OVERRIDE + void OnServerSplit(const Server* server, bool error) CXX11_OVERRIDE { Update(server, false); } public: ServerTracker(Module* mod) - : ServerEventListener(mod) + : ServerProtocol::LinkEventListener(mod) { Reset(); } @@ -98,21 +109,28 @@ class ServerTracker : public ServerEventListener class SASLCap : public Cap::Capability { + private: std::string mechlist; const ServerTracker& servertracker; + UserCertificateAPI sslapi; bool OnRequest(LocalUser* user, bool adding) CXX11_OVERRIDE { - // Requesting this cap is allowed anytime - if (adding) - return true; + if (requiressl && sslapi && !sslapi->GetCertificate(user)) + return false; - // But removing it can only be done when unregistered - return (user->registered != REG_ALL); + // Servers MUST NAK any sasl capability request if the authentication layer + // is unavailable. + return servertracker.IsOnline(); } bool OnList(LocalUser* user) CXX11_OVERRIDE { + if (requiressl && sslapi && !sslapi->GetCertificate(user)) + return false; + + // Servers MUST NOT advertise the sasl capability if the authentication layer + // is unavailable. return servertracker.IsOnline(); } @@ -122,9 +140,11 @@ class SASLCap : public Cap::Capability } public: + bool requiressl; SASLCap(Module* mod, const ServerTracker& tracker) : Cap::Capability(mod, "sasl") , servertracker(tracker) + , sslapi(mod) { } @@ -193,7 +213,7 @@ class SaslAuthenticator params.push_back(method); const std::string fp = sslapi ? sslapi->GetFingerprint(user) : ""; - if (fp.size()) + if (!fp.empty()) params.push_back(fp); SendSASL(user, "*", 'S', params); @@ -284,7 +304,7 @@ class SaslAuthenticator case SASL_OK: this->user->WriteNumeric(RPL_SASLSUCCESS, "SASL authentication successful"); break; - case SASL_ABORT: + case SASL_ABORT: this->user->WriteNumeric(ERR_SASLABORTED, "SASL authentication aborted"); break; case SASL_FAIL: @@ -416,10 +436,13 @@ class ModuleSASL : public Module void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { - std::string target = ServerInstance->Config->ConfValue("sasl")->getString("target"); + ConfigTag* tag = ServerInstance->Config->ConfValue("sasl"); + + const std::string target = tag->getString("target"); if (target.empty()) throw ModuleException(" must be set to the name of your services server!"); + cap.requiressl = tag->getBool("requiressl"); sasl_target = target; servertracker.Reset(); } @@ -432,7 +455,7 @@ class ModuleSASL : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Provides support for IRC Authentication Layer (aka: SASL) via AUTHENTICATE", VF_VENDOR); + return Version("Provides the IRCv3 sasl client capability.", VF_VENDOR); } };