diff --git a/include/znc/Client.h b/include/znc/Client.h index 6d8208d0..c56961ab 100644 --- a/include/znc/Client.h +++ b/include/znc/Client.h @@ -41,12 +41,6 @@ class CAuthBase : private CCoreTranslationMixin { CZNCSock* pSock) : m_sUsername(sUsername), m_sPassword(sPassword), m_pSock(pSock) {} - // If a module tries to do std::make_shared, the vtable of the mutex inside - // shared_ptr will point to the code in the module, and will crash when the - // module is unloaded, e.g. shutdown. This function forces the creation of - // shared_ptr in the 'znc' binary instead of in the module. - static std::shared_ptr WrapPointer(CAuthBase*); - virtual ~CAuthBase() {} CAuthBase(const CAuthBase&) = delete; @@ -102,17 +96,6 @@ class CClientAuth : public CAuthBase { CClient* m_pClient; }; -// Workaround SWIG bug, TODO report it -#ifndef SWIG -/** Username+password auth, which reports success/failure to client via SASL. */ -class CClientSASLAuth : public CClientAuth { - public: - using CClientAuth::CClientAuth; - void AcceptedLogin(CUser& User) override; - void RefusedLogin(const CString& sReason) override; -}; -#endif - class CClient : public CIRCSocket { public: CClient(); @@ -273,9 +256,10 @@ class CClient : public CIRCSocket { void SendSASLChallenge(CString sMessage); void RefuseSASLLogin(const CString& sReason); void AcceptSASLLogin(CUser& User); - // Like CZNC::AuthUser() but also stores the pointer, and calls Invalidate() - // if the client is destroyed. - void StartPasswordCheck(std::shared_ptr spAuth); + /** Start potentially asynchronous process of checking the credentials. + * When finished, will send the success/failure SASL numerics to the + * client. This is mostly useful for SASL PLAIN. */ + void StartSASLPasswordCheck(const CString& sUser, const CString& sPassword); private: void HandleCap(const CMessage& Message); diff --git a/modules/saslplainauth.cpp b/modules/saslplainauth.cpp index bca40346..b0231d6c 100644 --- a/modules/saslplainauth.cpp +++ b/modules/saslplainauth.cpp @@ -42,8 +42,7 @@ class CSASLMechanismPlain : public CModule { return HALTMODS; } - auto spAuth = CAuthBase::WrapPointer(new CClientSASLAuth(GetClient(), sAuthcId, sPassword)); - GetClient()->StartPasswordCheck(spAuth); + GetClient()->StartSASLPasswordCheck(sAuthcId, sPassword); return HALTMODS; } }; diff --git a/src/Client.cpp b/src/Client.cpp index 724630b0..7796bd7c 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -366,8 +366,8 @@ void CClient::AuthUser() { return; if (m_sSASLUser.empty()) { - StartPasswordCheck( - std::make_shared(this, m_sUser, m_sPass)); + m_spAuth = std::make_shared(this, m_sUser, m_sPass); + CZNC::Get().AuthUser(m_spAuth); } else { // Already logged in, but the user could have been deleted meanwhile. CUser* pUser = CZNC::Get().FindUser(m_sSASLUser); @@ -379,8 +379,16 @@ void CClient::AuthUser() { } } -void CClient::StartPasswordCheck(std::shared_ptr spAuth) { - m_spAuth = spAuth; +/** Username+password auth, which reports success/failure to client via SASL. */ +class CClientSASLAuth : public CClientAuth { + public: + using CClientAuth::CClientAuth; + void AcceptedLogin(CUser& User) override; + void RefusedLogin(const CString& sReason) override; +}; + +void CClient::StartSASLPasswordCheck(const CString& sUser, const CString& sPassword) { + m_spAuth = std::make_shared(this, sUser, sPassword); CZNC::Get().AuthUser(m_spAuth); } @@ -415,10 +423,6 @@ void CAuthBase::AcceptLogin(CUser& User) { Invalidate(); } -std::shared_ptr CAuthBase::WrapPointer(CAuthBase* p) { - return std::shared_ptr(p); -} - void CAuthBase::RefuseLogin(const CString& sReason) { if (!m_pSock) return;