summaryrefslogtreecommitdiff
path: root/modules/protocol
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-02-12 14:39:41 -0500
committerAdam <Adam@anope.org>2014-02-12 14:39:41 -0500
commit269c2786e96c3c8d2711be912d8fa40d99b090d4 (patch)
treec49e5ce41b25a07f5e9b593948e6a2ca3f5d6b1d /modules/protocol
parent96fc940af7f20001b290cc65a76d0afb88a6160c (diff)
Add SASL EXTERNAL support. Thanks to ShutterQuick for fixing and testing.
Diffstat (limited to 'modules/protocol')
-rw-r--r--modules/protocol/charybdis.cpp104
-rw-r--r--modules/protocol/inspircd12.cpp124
-rw-r--r--modules/protocol/inspircd20.cpp2
-rw-r--r--modules/protocol/unreal.cpp100
4 files changed, 87 insertions, 243 deletions
diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp
index b1d2e6614..e9ea89673 100644
--- a/modules/protocol/charybdis.cpp
+++ b/modules/protocol/charybdis.cpp
@@ -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;
-
- 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::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] : "";
+
+ 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
diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp
index 328049c64..e64079dca 100644
--- a/modules/protocol/inspircd12.cpp
+++ b/modules/protocol/inspircd12.cpp
@@ -10,6 +10,7 @@
*/
#include "module.h"
+#include "modules/sasl.h"
struct SASLUser
{
@@ -18,7 +19,6 @@ struct SASLUser
time_t created;
};
-static bool sasl = true;
static std::list<SASLUser> saslusers;
static Anope::string rsquit_server, rsquit_id;
@@ -398,6 +398,33 @@ class InspIRCd12Proto : public IRCDProto
{
}
+ void SendSASLMessage(const SASL::Message &message) anope_override
+ {
+ UplinkSocket::Message(Me) << "ENCAP " << 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
+ {
+ UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc;
+
+ SASLUser su;
+ su.uid = uid;
+ su.acc = acc;
+ su.created = Anope::CurTime;
+
+ for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
+ {
+ SASLUser &u = *it;
+
+ if (u.created + 30 < Anope::CurTime || u.uid == uid)
+ it = saslusers.erase(it);
+ else
+ ++it;
+ }
+
+ saslusers.push_back(su);
+ }
+
bool IsExtbanValid(const Anope::string &mask) anope_override
{
return mask.length() >= 3 && mask[1] == ':';
@@ -846,88 +873,16 @@ struct IRCDMessageEncap : IRCDMessage
if (Anope::Match(Me->GetSID(), params[0]) == false)
return;
- if (sasl && params[1] == "SASL" && params.size() == 6)
+ if (sasl && params[1] == "SASL" && params.size() >= 6)
{
- class InspIRCDSASLIdentifyRequest : public IdentifyRequest
- {
- Anope::string uid;
-
- public:
- InspIRCDSASLIdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), uid(id) { }
-
- void OnSuccess() anope_override
- {
- Anope::string accountname = GetAccount();
- NickAlias *na = NickAlias::Find(accountname);
- if (na)
- accountname = na->nc->display;
-
- UplinkSocket::Message(Me) << "METADATA " << this->uid << " accountname :" << accountname;
- UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " D S";
-
- SASLUser su;
- su.uid = this->uid;
- su.acc = this->GetAccount();
- su.created = Anope::CurTime;
-
- for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
- {
- SASLUser &u = *it;
-
- if (u.created + 30 < Anope::CurTime || u.uid == this->uid)
- it = saslusers.erase(it);
- else
- ++it;
- }
-
- saslusers.push_back(su);
- }
-
- void OnFail() anope_override
- {
- UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " " << " D F";
-
- Log(Config->GetClient("NickServ")) << "A user failed to identify for account " << this->GetAccount() << " using SASL";
- }
- };
-
- /*
- Received: :869 ENCAP * SASL 869AAAAAH * S PLAIN
- Sent: :00B ENCAP 869 SASL 00B 869AAAAAH C +
- Received: :869 ENCAP * SASL 869AAAAAH 00B C QWRhbQBBZGFtAG1vbw==
- base64(account\0account\0pass)
- */
- if (params[4] == "S")
- {
- if (params[5] == "PLAIN")
- UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << params[2] << " C +";
- else
- UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << 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 InspIRCDSASLIdentifyRequest(this->owner, params[2], acc, pass);
- FOREACH_MOD(OnCheckAuthentication, (NULL, req));
- req->Dispatch();
- }
+ 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] : "";
+
+ sasl->ProcessMessage(m);
}
}
};
@@ -1407,11 +1362,6 @@ class ProtoInspIRCd12 : public Module
Servers::Capab.insert("NOQUIT");
}
- void OnReload(Configuration::Conf *conf) anope_override
- {
- sasl = conf->GetModule(this)->Get<bool>("sasl") || conf->GetModule("inspircd20")->Get<bool>("sasl");
- }
-
void OnUserNickChange(User *u, const Anope::string &) anope_override
{
/* InspIRCd 1.2 doesn't set -r on nick change, remove -r here. Note that if we have to set +r later
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index 6ee000f68..4e88d01a8 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -71,6 +71,8 @@ class InspIRCd20Proto : public IRCDProto
void SendLogin(User *u, NickAlias *na) anope_override { insp12->SendLogin(u, na); }
void SendLogout(User *u) anope_override { insp12->SendLogout(u); }
void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); }
+ void SendSASLMessage(const SASL::Message &message) anope_override { insp12->SendSASLMessage(message); }
+ void SendSVSLogin(const Anope::string &uid, const Anope::string &acc) anope_override { insp12->SendSVSLogin(uid, acc); }
bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); }
bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); }
};
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
index 00f7cc586..e0f051aa6 100644
--- a/modules/protocol/unreal.cpp
+++ b/modules/protocol/unreal.cpp
@@ -11,8 +11,7 @@
#include "module.h"
#include "modules/cs_mode.h"
-
-static bool sasl = true;
+#include "modules/sasl.h"
class UnrealIRCdProto : public IRCDProto
{
@@ -377,6 +376,23 @@ class UnrealIRCdProto : public IRCDProto
}
}
+ void SendSASLMessage(const SASL::Message &message) anope_override
+ {
+ size_t p = message.target.find('!');
+ if (p == Anope::string::npos)
+ return;
+
+ UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << message.target.substr(0, p) << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext);
+ }
+
+ void SendSVSLogin(const Anope::string &uid, const Anope::string &acc) anope_override
+ {
+ size_t p = uid.find('!');
+ if (p == Anope::string::npos)
+ return;
+ UplinkSocket::Message(Me) << "SVSLOGIN " << uid.substr(0, p) << " " << uid << " " << acc;
+ }
+
bool IsIdentValid(const Anope::string &ident) anope_override
{
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
@@ -868,85 +884,22 @@ struct IRCDMessagePong : IRCDMessage
struct IRCDMessageSASL : IRCDMessage
{
- class UnrealSASLIdentifyRequest : public IdentifyRequest
- {
- Anope::string uid;
-
- public:
- UnrealSASLIdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), uid(id) { }
-
- void OnSuccess() anope_override
- {
- size_t p = this->uid.find('!');
- if (p == Anope::string::npos)
- return;
-
- Anope::string accountname = GetAccount();
- NickAlias *na = NickAlias::Find(accountname);
- if (na)
- accountname = na->nc->display;
-
- UplinkSocket::Message(Me) << "SVSLOGIN " << this->uid.substr(0, p) << " " << this->uid << " " << accountname;
- UplinkSocket::Message() << "SASL " << this->uid.substr(0, p) << " " << this->uid << " D S";
- }
+ IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
- void OnFail() anope_override
- {
- size_t p = this->uid.find('!');
- if (p == Anope::string::npos)
- return;
-
- UplinkSocket::Message() << "SASL " << this->uid.substr(0, p) << " " << this->uid << " D F";
-
- Log(Config->GetClient("NickServ")) << "A user failed to identify for account " << this->GetAccount() << " using SASL";
- }
- };
-
- IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
-
- /* Received: :irc.foonet.com SASL services.localhost.net irc.foonet.com!1.57290 S PLAIN
- * uid
- *
- * Received: :irc.foonet.com SASL services.localhost.net irc.foonet.com!3.56270 C QWRhbQBBZGFtAHF3ZXJ0eQ==
- * uid base64(account\0account\0pass)
- */
void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
{
size_t p = params[1].find('!');
if (!sasl || p == Anope::string::npos)
return;
- if (params[2] == "S")
- {
- if (params[3] == "PLAIN")
- UplinkSocket::Message() << "SASL " << params[1].substr(0, p) << " " << params[1] << " C +";
- else
- UplinkSocket::Message() << "SASL " << params[1].substr(0, p) << " " << params[1] << " D F";
- }
- else if (params[2] == "C")
- {
- Anope::string decoded;
- Anope::B64Decode(params[3], decoded);
-
- 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;
+ SASL::Message m;
+ m.source = params[1];
+ m.target = params[0];
+ m.type = params[2];
+ m.data = params[3];
+ m.ext = params.size() > 4 ? params[4] : "";
- Anope::string acc = decoded.substr(0, p),
- pass = decoded.substr(p + 1);
-
- if (acc.empty() || pass.empty())
- return;
-
- IdentifyRequest *req = new UnrealSASLIdentifyRequest(this->owner, params[1], acc, pass);
- FOREACH_MOD(OnCheckAuthentication, (NULL, req));
- req->Dispatch();
- }
+ sasl->ProcessMessage(m);
}
};
@@ -1241,7 +1194,6 @@ class ProtoUnreal : 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 OnUserNickChange(User *u, const Anope::string &) anope_override