diff --git a/include/znc/Client.h b/include/znc/Client.h index b7aed570..d64b768f 100644 --- a/include/znc/Client.h +++ b/include/znc/Client.h @@ -19,8 +19,8 @@ #include #include -#include #include +#include // Forward Declarations class CZNC; @@ -169,7 +169,7 @@ protected: CString m_sPass; CString m_sUser; CString m_sNetwork; - CSmartPtr m_spAuth; + std::shared_ptr m_spAuth; SCString m_ssAcceptedCaps; }; diff --git a/include/znc/Modules.h b/include/znc/Modules.h index 159f0046..51283748 100644 --- a/include/znc/Modules.h +++ b/include/znc/Modules.h @@ -1013,7 +1013,7 @@ public: * @param Auth The necessary authentication info for this login attempt. * @return See CModule::EModRet. */ - virtual EModRet OnLoginAttempt(CSmartPtr Auth); + virtual EModRet OnLoginAttempt(std::shared_ptr Auth); /** Called after a client login was rejected. * @param sUsername The username that tried to log in. * @param sRemoteIP The IP address from which the client tried to login. @@ -1223,7 +1223,7 @@ public: bool OnAddUser(CUser& User, CString& sErrorRet); bool OnDeleteUser(CUser& User); bool OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort); - bool OnLoginAttempt(CSmartPtr Auth); + bool OnLoginAttempt(std::shared_ptr Auth); bool OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); bool OnUnknownUserRaw(CClient* pClient, CString& sLine); bool OnClientCapLs(CClient* pClient, SCString& ssCaps); diff --git a/include/znc/WebModules.h b/include/znc/WebModules.h index aa0a7310..f4d01c14 100644 --- a/include/znc/WebModules.h +++ b/include/znc/WebModules.h @@ -158,7 +158,7 @@ private: bool m_bPathsSet; CTemplate m_Template; - CSmartPtr m_spAuth; + std::shared_ptr m_spAuth; CString m_sModName; CString m_sPath; CString m_sPage; diff --git a/include/znc/znc.h b/include/znc/znc.h index b4f3e8de..92a4ca37 100644 --- a/include/znc/znc.h +++ b/include/znc/znc.h @@ -88,8 +88,7 @@ public: // Authenticate a user. // The result is passed back via callbacks to CAuthBase. - // CSmartPtr handles freeing this pointer! - void AuthUser(CSmartPtr AuthClass); + void AuthUser(std::shared_ptr AuthClass); // Setters void SetConfigState(enum ConfigState e) { m_eConfigState = e; } diff --git a/modules/blockuser.cpp b/modules/blockuser.cpp index 1e2c261c..9a618a11 100644 --- a/modules/blockuser.cpp +++ b/modules/blockuser.cpp @@ -51,7 +51,7 @@ public: return true; } - virtual EModRet OnLoginAttempt(CSmartPtr Auth) { + virtual EModRet OnLoginAttempt(std::shared_ptr Auth) { if (IsBlocked(Auth->GetUsername())) { Auth->RefuseLogin(MESSAGE); return HALT; diff --git a/modules/certauth.cpp b/modules/certauth.cpp index 61e56870..10008934 100644 --- a/modules/certauth.cpp +++ b/modules/certauth.cpp @@ -101,7 +101,7 @@ public: return pair.second; } - virtual EModRet OnLoginAttempt(CSmartPtr Auth) { + virtual EModRet OnLoginAttempt(std::shared_ptr Auth) { const CString sUser = Auth->GetUsername(); Csock *pSock = Auth->GetSocket(); CUser *pUser = CZNC::Get().FindUser(sUser); diff --git a/modules/cyrusauth.cpp b/modules/cyrusauth.cpp index 515c6012..e1afd868 100644 --- a/modules/cyrusauth.cpp +++ b/modules/cyrusauth.cpp @@ -87,7 +87,7 @@ public: return true; } - virtual EModRet OnLoginAttempt(CSmartPtr Auth) { + virtual EModRet OnLoginAttempt(std::shared_ptr Auth) { const CString& sUsername = Auth->GetUsername(); const CString& sPassword = Auth->GetPassword(); CUser *pUser(CZNC::Get().FindUser(sUsername)); diff --git a/modules/fail2ban.cpp b/modules/fail2ban.cpp index 36e66de5..29ba8299 100644 --- a/modules/fail2ban.cpp +++ b/modules/fail2ban.cpp @@ -81,7 +81,7 @@ public: Add(sRemoteIP, 1); } - virtual EModRet OnLoginAttempt(CSmartPtr Auth) { + virtual EModRet OnLoginAttempt(std::shared_ptr Auth) { // e.g. webadmin ends up here const CString& sRemoteIP = Auth->GetRemoteIP(); diff --git a/modules/imapauth.cpp b/modules/imapauth.cpp index 368ae268..3773f926 100644 --- a/modules/imapauth.cpp +++ b/modules/imapauth.cpp @@ -22,7 +22,7 @@ class CIMAPAuthMod; class CIMAPSock : public CSocket { public: - CIMAPSock(CIMAPAuthMod* pModule, CSmartPtr Auth) + CIMAPSock(CIMAPAuthMod* pModule, std::shared_ptr Auth) : CSocket((CModule*) pModule), m_spAuth(Auth) { m_pIMAPMod = pModule; m_bSentReply = false; @@ -39,10 +39,10 @@ public: virtual void ReadLine(const CString& sLine); private: protected: - CIMAPAuthMod* m_pIMAPMod; - bool m_bSentLogin; - bool m_bSentReply; - CSmartPtr m_spAuth; + CIMAPAuthMod* m_pIMAPMod; + bool m_bSentLogin; + bool m_bSentReply; + std::shared_ptr m_spAuth; }; @@ -84,7 +84,7 @@ public: return true; } - virtual EModRet OnLoginAttempt(CSmartPtr Auth) { + virtual EModRet OnLoginAttempt(std::shared_ptr Auth) { CUser* pUser = CZNC::Get().FindUser(Auth->GetUsername()); if (!pUser) { // @todo Will want to do some sort of && !m_bAllowCreate in the future diff --git a/src/Client.cpp b/src/Client.cpp index cf9d8e4b..28d5e5aa 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -67,7 +67,7 @@ using std::vector; } CClient::~CClient() { - if (!m_spAuth.IsNull()) { + if (m_spAuth) { CClientAuth* pAuth = (CClientAuth*) &(*m_spAuth); pAuth->Invalidate(); } @@ -618,7 +618,7 @@ void CClient::AuthUser() { if (!m_bGotNick || !m_bGotUser || !m_bGotPass || m_bInCap || IsAttached()) return; - m_spAuth = new CClientAuth(this, m_sUser, m_sPass); + m_spAuth = std::make_shared(this, m_sUser, m_sPass); CZNC::Get().AuthUser(m_spAuth); } diff --git a/src/Modules.cpp b/src/Modules.cpp index 5420368a..08d29b5e 100644 --- a/src/Modules.cpp +++ b/src/Modules.cpp @@ -751,7 +751,7 @@ bool CModule::PutModNotice(const CString& sLine) { CModule::EModRet CModule::OnAddUser(CUser& User, CString& sErrorRet) { return CONTINUE; } CModule::EModRet CModule::OnDeleteUser(CUser& User) { return CONTINUE; } void CModule::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) {} -CModule::EModRet CModule::OnLoginAttempt(CSmartPtr Auth) { return CONTINUE; } +CModule::EModRet CModule::OnLoginAttempt(std::shared_ptr Auth) { return CONTINUE; } void CModule::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) {} CModule::EModRet CModule::OnUnknownUserRaw(CClient* pClient, CString& sLine) { return CONTINUE; } void CModule::OnClientCapLs(CClient* pClient, SCString& ssCaps) {} @@ -915,7 +915,7 @@ bool CModules::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned return false; } -bool CModules::OnLoginAttempt(CSmartPtr Auth) { +bool CModules::OnLoginAttempt(std::shared_ptr Auth) { MODHALTCHK(OnLoginAttempt(Auth)); } diff --git a/src/WebModules.cpp b/src/WebModules.cpp index b359748c..7014f3b3 100644 --- a/src/WebModules.cpp +++ b/src/WebModules.cpp @@ -870,7 +870,7 @@ CString CWebSock::GetCSRFCheck() { bool CWebSock::OnLogin(const CString& sUser, const CString& sPass) { DEBUG("=================== CWebSock::OnLogin()"); - m_spAuth = new CWebAuth(this, sUser, sPass); + m_spAuth = std::make_shared(this, sUser, sPass); // Some authentication module could need some time, block this socket // until then. CWebAuth will UnPauseRead(). diff --git a/src/znc.cpp b/src/znc.cpp index 913e0af8..dfc0604d 100644 --- a/src/znc.cpp +++ b/src/znc.cpp @@ -1783,7 +1783,7 @@ CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users, return ret; } -void CZNC::AuthUser(CSmartPtr AuthClass) { +void CZNC::AuthUser(std::shared_ptr AuthClass) { // TODO unless the auth module calls it, CUser::IsHostAllowed() is not honoured bool bReturn = false; GLOBALMODULECALL(OnLoginAttempt(AuthClass), &bReturn);