diff options
-rw-r--r-- | include/modules/sasl.h | 33 | ||||
-rw-r--r-- | modules/sasl.cpp | 15 |
2 files changed, 26 insertions, 22 deletions
diff --git a/include/modules/sasl.h b/include/modules/sasl.h index f088ec1f1..d051e2e61 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -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"; } }; } diff --git a/modules/sasl.cpp b/modules/sasl.cpp index 5b1ea94ec..63b90fc8c 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -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 + "]"; |