diff options
Diffstat (limited to 'include/modules/sasl.h')
-rw-r--r-- | include/modules/sasl.h | 128 |
1 files changed, 48 insertions, 80 deletions
diff --git a/include/modules/sasl.h b/include/modules/sasl.h index 249a4c3b0..980a5da2e 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -1,9 +1,20 @@ /* + * Anope IRC Services * - * (C) 2014-2017 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2014-2017 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ namespace SASL @@ -23,117 +34,74 @@ namespace SASL class Service : public ::Service { public: - Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { } + static constexpr const char *NAME = "sasl"; + + Service(Module *o) : ::Service(o, NAME) { } - virtual void ProcessMessage(const Message &) = 0; + virtual void ProcessMessage(const Message &) anope_abstract; - virtual Anope::string GetAgent() = 0; + virtual Anope::string GetAgent() anope_abstract; - virtual Session* GetSession(const Anope::string &uid) = 0; + virtual Session* GetSession(const Anope::string &uid) anope_abstract; - virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) = 0; + virtual void SendMessage(SASL::Session *session, const Anope::string &type, const Anope::string &data) anope_abstract; - 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; + virtual void Succeed(Session *, NickServ::Account *) anope_abstract; + virtual void Fail(Session *) anope_abstract; + virtual void SendMechs(Session *) anope_abstract; + virtual void DeleteSessions(Mechanism *, bool = false) anope_abstract; + virtual void RemoveSession(Session *) anope_abstract; }; - static ServiceReference<SASL::Service> sasl("SASL::Service", "sasl"); - - struct Session + class Session { + SASL::Service *service; + + public: time_t created; Anope::string uid; - Anope::string hostname, ip; Reference<Mechanism> mech; - Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { } + Session(SASL::Service *s, Mechanism *m, const Anope::string &u) : service(s), created(Anope::CurTime), uid(u), mech(m) { } + virtual ~Session() { - if (sasl) - sasl->RemoveSession(this); + service->RemoveSession(this); } }; /* PLAIN, EXTERNAL, etc */ class Mechanism : public ::Service { + SASL::Service *service; + public: - Mechanism(Module *o, const Anope::string &sname) : Service(o, "SASL::Mechanism", sname) { } + static constexpr const char *NAME = "sasl/mechanism"; + + Mechanism(SASL::Service *s, Module *o, const Anope::string &sname) : Service(o, NAME, sname), service(s) { } + + SASL::Service *GetService() const { return service; } - virtual Session* CreateSession(const Anope::string &uid) { return new Session(this, uid); } + virtual Session* CreateSession(const Anope::string &uid) { return new Session(service, this, uid); } - virtual void ProcessMessage(Session *session, const Message &) = 0; + virtual void ProcessMessage(Session *session, const Message &) anope_abstract; virtual ~Mechanism() { - if (sasl) - sasl->DeleteSessions(this, true); + service->DeleteSessions(this, true); } }; - class IdentifyRequest : public ::IdentifyRequest + class IdentifyRequestListener : public NickServ::IdentifyRequestListener { + SASL::Service *service = nullptr; Anope::string uid; - Anope::string hostname, ip; public: - IdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass, const Anope::string &h, const Anope::string &i) : ::IdentifyRequest(m, acc, pass), uid(id), hostname(h), ip(i) { } + IdentifyRequestListener(SASL::Service *s, const Anope::string &id) : service(s), uid(id) { } - void OnSuccess() anope_override - { - if (!sasl) - return; - - NickAlias *na = NickAlias::Find(GetAccount()); - if (!na || na->nc->HasExt("NS_SUSPENDED") || na->nc->HasExt("UNCONFIRMED")) - return OnFail(); - - unsigned int maxlogins = Config->GetModule("ns_identify")->Get<unsigned int>("maxlogins"); - if (maxlogins && na->nc->users.size() >= maxlogins) - return OnFail(); - - Session *s = sasl->GetSession(uid); - if (s) - { - Anope::string user = "A user"; - if (!hostname.empty() && !ip.empty()) - user = hostname + " (" + ip + ")"; - - Log(Config->GetClient("NickServ"), "sasl") << user << " identified to account " << this->GetAccount() << " using SASL"; - sasl->Succeed(s, na->nc); - delete s; - } - } + void OnSuccess(NickServ::IdentifyRequest *req) override; - void OnFail() anope_override - { - if (!sasl) - return; - - Session *s = sasl->GetSession(uid); - if (s) - { - sasl->Fail(s); - delete s; - } - - Anope::string accountstatus; - NickAlias *na = NickAlias::Find(GetAccount()); - if (!na) - accountstatus = "nonexistent "; - else if (na->nc->HasExt("NS_SUSPENDED")) - accountstatus = "suspended "; - else if (na->nc->HasExt("UNCONFIRMED")) - accountstatus = "unconfirmed "; - - Anope::string user = "A user"; - if (!hostname.empty() && !ip.empty()) - user = hostname + " (" + ip + ")"; - - Log(Config->GetClient("NickServ"), "sasl") << user << " failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL"; - } + void OnFail(NickServ::IdentifyRequest *req) override; }; } |