summaryrefslogtreecommitdiff
path: root/modules/m_sasl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/m_sasl.cpp')
-rw-r--r--modules/m_sasl.cpp92
1 files changed, 66 insertions, 26 deletions
diff --git a/modules/m_sasl.cpp b/modules/m_sasl.cpp
index 70ea2feaf..a64aa7440 100644
--- a/modules/m_sasl.cpp
+++ b/modules/m_sasl.cpp
@@ -17,7 +17,7 @@ class Plain : public Mechanism
public:
Plain(Module *o) : Mechanism(o, "PLAIN") { }
- void ProcessMessage(Session *sess, const SASL::Message &m) anope_override
+ void ProcessMessage(Session *sess, const SASL::Message &m) override
{
if (m.type == "S")
{
@@ -90,12 +90,12 @@ class External : public Mechanism
throw ModuleException("No CertFP");
}
- Session* CreateSession(const Anope::string &uid) anope_override
+ Session* CreateSession(const Anope::string &uid) override
{
return new Session(this, uid);
}
- void ProcessMessage(SASL::Session *sess, const SASL::Message &m) anope_override
+ void ProcessMessage(SASL::Session *sess, const SASL::Message &m) override
{
Session *mysess = anope_dynamic_static_cast<Session *>(sess);
@@ -134,6 +134,42 @@ class External : public Mechanism
}
};
+class Anonymous : public Mechanism
+{
+ public:
+ Anonymous(Module *o) : Mechanism(o, "ANONYMOUS") { }
+
+ void ProcessMessage(Session *sess, const SASL::Message &m) override
+ {
+ if (!IRCD->CanSVSLogout && !User::Find(sess->uid))
+ {
+ // This IRCd can't log users out yet.
+ sasl->Fail(sess);
+ delete sess;
+ return;
+ }
+
+ if (m.type == "S")
+ {
+ sasl->SendMessage(sess, "C", "+");
+ }
+ else if (m.type == "C")
+ {
+ Anope::string decoded;
+ Anope::B64Decode(m.data, decoded);
+
+ Anope::string user = "A user";
+ if (!sess->hostname.empty() && !sess->ip.empty())
+ user = sess->hostname + " (" + sess->ip + ")";
+ if (!decoded.empty())
+ user += " [" + decoded + "]";
+
+ Log(this->owner, "sasl", Config->GetClient("NickServ")) << user << " unidentified using SASL ANONYMOUS";
+ sasl->Succeed(sess, nullptr);
+ }
+ }
+};
+
class SASLService : public SASL::Service, public Timer
{
std::map<Anope::string, SASL::Session *> sessions;
@@ -141,13 +177,13 @@ class SASLService : public SASL::Service, public Timer
public:
SASLService(Module *o) : SASL::Service(o), Timer(o, 60, Anope::CurTime, true) { }
- ~SASLService()
+ ~SASLService() override
{
- for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end(); it++)
- delete it->second;
+ for (const auto &[_, session] : sessions)
+ delete session;
}
- void ProcessMessage(const SASL::Message &m) anope_override
+ void ProcessMessage(const SASL::Message &m) override
{
if (m.target != "*")
{
@@ -212,7 +248,7 @@ class SASLService : public SASL::Service, public Timer
session->mech->ProcessMessage(session, m);
}
- Anope::string GetAgent() anope_override
+ Anope::string GetAgent() override
{
Anope::string agent = Config->GetModule(Service::owner)->Get<Anope::string>("agent", "NickServ");
BotInfo *bi = Config->GetClient(agent);
@@ -221,7 +257,7 @@ class SASLService : public SASL::Service, public Timer
return agent;
}
- Session* GetSession(const Anope::string &uid) anope_override
+ Session* GetSession(const Anope::string &uid) override
{
std::map<Anope::string, Session *>::iterator it = sessions.find(uid);
if (it != sessions.end())
@@ -229,12 +265,12 @@ class SASLService : public SASL::Service, public Timer
return NULL;
}
- void RemoveSession(Session *sess) anope_override
+ void RemoveSession(Session *sess) override
{
sessions.erase(sess->uid);
}
- void DeleteSessions(Mechanism *mech, bool da) anope_override
+ void DeleteSessions(Mechanism *mech, bool da) override
{
for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end();)
{
@@ -248,7 +284,7 @@ class SASLService : public SASL::Service, public Timer
}
}
- void SendMessage(Session *session, const Anope::string &mtype, const Anope::string &data) anope_override
+ void SendMessage(Session *session, const Anope::string &mtype, const Anope::string &data) override
{
SASL::Message msg;
msg.source = this->GetAgent();
@@ -259,7 +295,7 @@ class SASLService : public SASL::Service, public Timer
IRCD->SendSASLMessage(msg);
}
- void Succeed(Session *session, NickCore *nc) anope_override
+ void Succeed(Session *session, NickCore *nc) override
{
// If the user is already introduced then we log them in now.
// Otherwise, we send an SVSLOGIN to log them in later.
@@ -267,31 +303,34 @@ class SASLService : public SASL::Service, public Timer
NickAlias *na = NickAlias::Find(nc->display);
if (user)
{
- user->Identify(na);
+ if (na)
+ user->Identify(na);
+ else
+ user->Logout();
}
else
{
- IRCD->SendSVSLogin(session->uid, nc->display, na->GetVhostIdent(), na->GetVhostHost());
+ IRCD->SendSVSLogin(session->uid, na);
}
this->SendMessage(session, "D", "S");
}
- void Fail(Session *session) anope_override
+ void Fail(Session *session) override
{
this->SendMessage(session, "D", "F");
}
- void SendMechs(Session *session) anope_override
+ void SendMechs(Session *session) override
{
std::vector<Anope::string> mechs = Service::GetServiceKeys("SASL::Mechanism");
Anope::string buf;
- for (unsigned j = 0; j < mechs.size(); ++j)
- buf += "," + mechs[j];
+ for (const auto &mech : mechs)
+ buf += "," + mech;
this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1));
}
- void Tick(time_t) anope_override
+ void Tick(time_t) override
{
for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end();)
{
@@ -312,8 +351,9 @@ class ModuleSASL : public Module
{
SASLService sasl;
+ Anonymous anonymous;
Plain plain;
- External *external;
+ External *external = nullptr;
std::vector<Anope::string> mechs;
@@ -332,7 +372,7 @@ class ModuleSASL : public Module
public:
ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- sasl(this), plain(this), external(NULL)
+ sasl(this), anonymous(this), plain(this)
{
try
{
@@ -342,22 +382,22 @@ class ModuleSASL : public Module
catch (ModuleException &) { }
}
- ~ModuleSASL()
+ ~ModuleSASL() override
{
delete external;
}
- void OnModuleLoad(User *, Module *) anope_override
+ void OnModuleLoad(User *, Module *) override
{
CheckMechs();
}
- void OnModuleUnload(User *, Module *) anope_override
+ void OnModuleUnload(User *, Module *) override
{
CheckMechs();
}
- void OnPreUplinkSync(Server *) anope_override
+ void OnPreUplinkSync(Server *) override
{
// We have not yet sent a mechanism list so always do it here.
IRCD->SendSASLMechanisms(mechs);