From 3c8009b4950a670618c3ee476f21f67a9468fdb2 Mon Sep 17 00:00:00 2001 From: Daniel Vassdal Date: Thu, 13 Feb 2014 09:29:39 -0800 Subject: sasl.h, m_sasl.cpp: Add RemoveSession(), DeleteSessions(), and have active sessions closed when a Mechanism is unloaded --- include/modules/sasl.h | 56 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/modules/sasl.h b/include/modules/sasl.h index 836c26d19..f997ead76 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -18,6 +18,29 @@ namespace SASL }; class Mechanism; + struct Session; + + class Service : public ::Service + { + public: + Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { } + + virtual void ProcessMessage(const Message &) = 0; + + virtual Anope::string GetAgent() = 0; + + virtual Session* GetSession(const Anope::string &uid) = 0; + + virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) = 0; + + virtual void Succeed(Session *, NickCore *) = 0; + virtual void Fail(Session *) = 0; + virtual void SendMechs(Session *) = 0; + virtual void DeleteSessions(Mechanism *, bool = false) = 0; + virtual void RemoveSession(Session *) = 0; + }; + + static ServiceReference sasl("SASL::Service", "sasl"); struct Session { @@ -26,11 +49,15 @@ namespace SASL Reference mech; Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { } - virtual ~Session() { } + virtual ~Session() + { + if (sasl) + sasl->RemoveSession(this); + } }; /* PLAIN, EXTERNAL, etc */ - class Mechanism : public Service + class Mechanism : public ::Service { public: Mechanism(Module *o, const Anope::string &sname) : Service(o, "SASL::Mechanism", sname) { } @@ -38,26 +65,11 @@ namespace SASL virtual Session* CreateSession(const Anope::string &uid) { return new Session(this, uid); } virtual void ProcessMessage(Session *session, const Message &) = 0; - }; - - class Service : public ::Service - { - public: - Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { } - - virtual void ProcessMessage(const Message &) = 0; - - virtual Anope::string GetAgent() = 0; - virtual Session* GetSession(const Anope::string &uid) = 0; - - virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) = 0; - - virtual void Succeed(Session *, NickCore *) = 0; - virtual void Fail(Session *) = 0; - virtual void SendMechs(Session *) = 0; + virtual ~Mechanism() + { + if (sasl) + sasl->DeleteSessions(this, true); + } }; } - -static ServiceReference sasl("SASL::Service", "sasl"); - -- cgit From a4ecfa5bc0151f2a65774cb5b1e9092c8de5e107 Mon Sep 17 00:00:00 2001 From: Daniel Vassdal Date: Thu, 13 Feb 2014 16:57:02 -0800 Subject: Anope::string: Add .data() --- include/anope.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/anope.h b/include/anope.h index 28bc50512..638661440 100644 --- a/include/anope.h +++ b/include/anope.h @@ -115,6 +115,7 @@ namespace Anope * The following functions return the various types of strings. */ inline const char *c_str() const { return this->_string.c_str(); } + inline const char *data() const { return this->_string.data(); } inline std::string &str() { return this->_string; } inline const std::string &str() const { return this->_string; } inline ci::string ci_str() const { return ci::string(this->_string.c_str()); } -- cgit From b13bded620b391ecd613d3f4a1b759959ce6ae87 Mon Sep 17 00:00:00 2001 From: Daniel Vassdal Date: Fri, 14 Feb 2014 15:03:42 -0800 Subject: sasl.h, m_sasl.cpp: Move IdentifyRequest to the header --- include/modules/sasl.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'include') diff --git a/include/modules/sasl.h b/include/modules/sasl.h index f997ead76..a7c440110 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -72,4 +72,44 @@ namespace SASL sasl->DeleteSessions(this, true); } }; + + class IdentifyRequest : public ::IdentifyRequest + { + Anope::string uid; + + public: + IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : ::IdentifyRequest(m, acc, pass), uid(id) { } + + void OnSuccess() anope_override + { + if (!sasl) + return; + + NickAlias *na = NickAlias::Find(GetAccount()); + if (!na) + return OnFail(); + + Session *s = sasl->GetSession(uid); + if (s) + { + sasl->Succeed(s, na->nc); + delete s; + } + } + + void OnFail() anope_override + { + if (!sasl) + return; + + Session *s = sasl->GetSession(uid); + if (s) + { + sasl->Fail(s); + delete s; + } + + Log(Config->GetClient("NickServ")) << "A user failed to identify for account " << this->GetAccount() << " using SASL"; + } + }; } -- cgit