/*
* InspIRCd -- Internet Relay Chat Daemon
*
+ * Copyright (C) 2016 Adam <Adam@anope.org>
+ * Copyright (C) 2014 Mantas Mikulėnas <grawity@gmail.com>
+ * Copyright (C) 2013-2016, 2018 Attila Molnar <attilamolnar@hush.com>
+ * Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
+ * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
- * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
+ * Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
+ * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.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
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)
Update(server, true);
}
- void OnServerSplit(const Server* server) CXX11_OVERRIDE
+ void OnServerSplit(const Server* server, bool error) CXX11_OVERRIDE
{
Update(server, false);
}
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();
}
}
public:
+ bool requiressl;
SASLCap(Module* mod, const ServerTracker& tracker)
: Cap::Capability(mod, "sasl")
, servertracker(tracker)
+ , sslapi(mod)
{
}
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:
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("<sasl:target> must be set to the name of your services server!");
+ cap.requiressl = tag->getBool("requiressl");
sasl_target = target;
servertracker.Reset();
}