1
0
mirror of https://github.com/anope/anope.git synced 2026-07-08 16:43:13 +02:00

Add SASL EXTERNAL support. Thanks to ShutterQuick for fixing and testing.

This commit is contained in:
Adam
2014-02-12 14:39:41 -05:00
parent 96fc940af7
commit 269c2786e9
10 changed files with 446 additions and 248 deletions
+21 -81
View File
@@ -11,8 +11,8 @@
#include "module.h"
#include "modules/cs_mode.h"
#include "modules/sasl.h"
static bool sasl = true;
static Anope::string UplinkSID;
static ServiceReference<IRCDProto> ratbox("IRCDProto", "ratbox");
@@ -140,6 +140,18 @@ class CharybdisProto : public IRCDProto
{
this->SendVhost(u, "", u->host);
}
void SendSASLMessage(const SASL::Message &message) anope_override
{
Server *s = Server::Find(message.target.substr(0, 3));
UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : message.target.substr(0, 3)) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext));
}
void SendSVSLogin(const Anope::string &uid, const Anope::string &acc) anope_override
{
Server *s = Server::Find(uid.substr(0, 3));
UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : uid.substr(0, 3)) << " SVSLOGIN " << uid << " * * * " << acc;
}
};
@@ -176,87 +188,16 @@ struct IRCDMessageEncap : IRCDMessage
*
* Charybdis only accepts messages from SASL agents; these must have umode +S
*/
if (params[1] == "SASL" && sasl && params.size() == 6)
if (params[1] == "SASL" && sasl && params.size() >= 6)
{
class CharybdisSASLIdentifyRequest : public IdentifyRequest
{
Anope::string uid;
MessageSource msource;
SASL::Message m;
m.source = params[2];
m.target = params[3];
m.type = params[4];
m.data = params[5];
m.ext = params.size() > 6 ? params[6] : "";
public:
CharybdisSASLIdentifyRequest(Module *m, MessageSource &source_, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), uid(id), msource(source_) { }
void OnSuccess() anope_override
{
BotInfo *NickServ = Config->GetClient("NickServ");
if (!NickServ)
return;
Anope::string accountname = GetAccount();
NickAlias *na = NickAlias::Find(accountname);
if (na)
accountname = na->nc->display;
/* SVSLOGIN
* parameters: target, new nick, new username, new visible hostname, new login name
* Sent after successful SASL authentication.
* The target is a UID, typically an unregistered one.
* Any of the "new" parameters can be '*' to leave the corresponding field
* unchanged. The new login name can be '0' to log the user out.
* If the UID is registered on the network, a SIGNON with the changes will be
* broadcast, otherwise the changes will be stored, to be used when registration
* completes.
*/
UplinkSocket::Message(Me) << "ENCAP " << msource.GetName() << " SVSLOGIN " << this->uid << " * * * " << accountname;
UplinkSocket::Message(Me) << "ENCAP " << msource.GetName() << " SASL " << NickServ->GetUID() << " " << this->uid << " D S";
}
void OnFail() anope_override
{
BotInfo *NickServ = Config->GetClient("NickServ");
if (!NickServ)
return;
UplinkSocket::Message(Me) << "ENCAP " << msource.GetName() << " SASL " << NickServ->GetUID() << " " << this->uid << " " << " D F";
Log(NickServ) << "A user failed to identify for account " << this->GetAccount() << " using SASL";
}
};
if (params[4] == "S")
{
BotInfo *NickServ = Config->GetClient("NickServ");
if (!NickServ)
return;
if (params[5] == "PLAIN")
UplinkSocket::Message(Me) << "ENCAP " << source.GetName() << " SASL " << NickServ->GetUID() << " " << params[2] << " C +";
else
UplinkSocket::Message(Me) << "ENCAP " << source.GetName() << " SASL " << NickServ->GetUID() << " " << params[2] << " D F";
}
else if (params[4] == "C")
{
Anope::string decoded;
Anope::B64Decode(params[5], decoded);
size_t p = decoded.find('\0');
if (p == Anope::string::npos)
return;
decoded = decoded.substr(p + 1);
p = decoded.find('\0');
if (p == Anope::string::npos)
return;
Anope::string acc = decoded.substr(0, p),
pass = decoded.substr(p + 1);
if (acc.empty() || pass.empty())
return;
IdentifyRequest *req = new CharybdisSASLIdentifyRequest(this->owner, source, params[2], acc, pass);
FOREACH_MOD(OnCheckAuthentication, (NULL, req));
req->Dispatch();
}
sasl->ProcessMessage(m);
}
}
};
@@ -422,7 +363,6 @@ class ProtoCharybdis : public Module
void OnReload(Configuration::Conf *conf) anope_override
{
use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock");
sasl = conf->GetModule(this)->Get<bool>("sasl");
}
void OnChannelSync(Channel *c) anope_override