mirror of
https://github.com/anope/anope.git
synced 2026-06-29 08:56:39 +02:00
Deduplicate some SASL logic.
This commit is contained in:
+23
-10
@@ -52,6 +52,17 @@ namespace SASL
|
||||
Reference<Mechanism> mech;
|
||||
|
||||
Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { }
|
||||
|
||||
inline Anope::string GetUserInfo()
|
||||
{
|
||||
auto *u = User::Find(uid);
|
||||
if (u)
|
||||
return u->GetMask();
|
||||
if (!hostname.empty() && !ip.empty())
|
||||
return Anope::printf("%s (%s)", hostname.c_str(), ip.c_str());
|
||||
return "A user";
|
||||
};
|
||||
|
||||
virtual ~Session()
|
||||
{
|
||||
if (sasl)
|
||||
@@ -83,6 +94,16 @@ namespace SASL
|
||||
Anope::string uid;
|
||||
Anope::string hostname;
|
||||
|
||||
inline Anope::string GetUserInfo()
|
||||
{
|
||||
auto *u = User::Find(uid);
|
||||
if (u)
|
||||
return u->GetMask();
|
||||
if (!hostname.empty() && !GetAddress().empty())
|
||||
return Anope::printf("%s (%s)", hostname.c_str(), GetAddress().c_str());
|
||||
return "A user";
|
||||
};
|
||||
|
||||
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, i)
|
||||
@@ -107,11 +128,7 @@ namespace SASL
|
||||
Session *s = sasl->GetSession(uid);
|
||||
if (s)
|
||||
{
|
||||
Anope::string user = "A user";
|
||||
if (!hostname.empty() && !GetAddress().empty())
|
||||
user = hostname + " (" + GetAddress() + ")";
|
||||
|
||||
Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << user << " identified to account " << this->GetAccount() << " using SASL";
|
||||
Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << GetUserInfo() << " identified to account " << this->GetAccount() << " using SASL";
|
||||
sasl->Succeed(s, na->nc);
|
||||
delete s;
|
||||
}
|
||||
@@ -138,11 +155,7 @@ namespace SASL
|
||||
else if (na->nc->HasExt("UNCONFIRMED"))
|
||||
accountstatus = "unconfirmed ";
|
||||
|
||||
Anope::string user = "A user";
|
||||
if (!hostname.empty() && !GetAddress().empty())
|
||||
user = hostname + " (" + GetAddress() + ")";
|
||||
|
||||
Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << user << " failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL";
|
||||
Log(this->GetOwner(), "sasl", Config->GetClient("NickServ")) << GetUserInfo() << " failed to identify for " << accountstatus << "account " << this->GetAccount() << " using SASL";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+3
-12
@@ -98,13 +98,6 @@ public:
|
||||
if (!certs || mysess->certs.empty())
|
||||
return false;
|
||||
|
||||
Anope::string user = "A user";
|
||||
auto *u = User::Find(sess->uid);
|
||||
if (u)
|
||||
user = u->GetMask();
|
||||
else if (!mysess->hostname.empty() && !mysess->ip.empty())
|
||||
user = mysess->hostname + " (" + mysess->ip + ")";
|
||||
|
||||
for (auto it = mysess->certs.begin(); it != mysess->certs.end(); ++it)
|
||||
{
|
||||
auto *nc = certs->FindAccountFromCert(*it);
|
||||
@@ -118,14 +111,14 @@ public:
|
||||
cl->ReplaceCert(*it, mysess->certs[0]);
|
||||
}
|
||||
|
||||
Log(this->owner, "sasl", Config->GetClient("NickServ")) << user << " identified to account " << nc->display << " using SASL EXTERNAL";
|
||||
Log(this->owner, "sasl", Config->GetClient("NickServ")) << sess->GetUserInfo() << " identified to account " << nc->display << " using SASL EXTERNAL";
|
||||
sasl->Succeed(sess, nc);
|
||||
delete sess;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Log(this->owner, "sasl", Config->GetClient("NickServ")) << user << " failed to identify using certificate " << mysess->certs.front() << " using SASL EXTERNAL";
|
||||
Log(this->owner, "sasl", Config->GetClient("NickServ")) << sess->GetUserInfo() << " failed to identify using certificate " << mysess->certs.front() << " using SASL EXTERNAL";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -149,9 +142,7 @@ public:
|
||||
Anope::string decoded;
|
||||
Anope::B64Decode(m.data[0], decoded);
|
||||
|
||||
Anope::string user = "A user";
|
||||
if (!sess->hostname.empty() && !sess->ip.empty())
|
||||
user = sess->hostname + " (" + sess->ip + ")";
|
||||
auto user = sess->GetUserInfo();
|
||||
if (!decoded.empty())
|
||||
user += " [" + decoded + "]";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user