mirror of
https://github.com/znc/znc.git
synced 2026-08-11 11:23:18 +02:00
client auth: Switch from CSmartPtr to std::shared_ptr
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
|
||||
#include <znc/zncconfig.h>
|
||||
#include <znc/Socket.h>
|
||||
#include <znc/Utils.h>
|
||||
#include <znc/main.h>
|
||||
#include <memory>
|
||||
|
||||
// Forward Declarations
|
||||
class CZNC;
|
||||
@@ -169,7 +169,7 @@ protected:
|
||||
CString m_sPass;
|
||||
CString m_sUser;
|
||||
CString m_sNetwork;
|
||||
CSmartPtr<CAuthBase> m_spAuth;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
SCString m_ssAcceptedCaps;
|
||||
};
|
||||
|
||||
|
||||
@@ -1013,7 +1013,7 @@ public:
|
||||
* @param Auth The necessary authentication info for this login attempt.
|
||||
* @return See CModule::EModRet.
|
||||
*/
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth);
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> 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<CAuthBase> Auth);
|
||||
bool OnLoginAttempt(std::shared_ptr<CAuthBase> Auth);
|
||||
bool OnFailedLogin(const CString& sUsername, const CString& sRemoteIP);
|
||||
bool OnUnknownUserRaw(CClient* pClient, CString& sLine);
|
||||
bool OnClientCapLs(CClient* pClient, SCString& ssCaps);
|
||||
|
||||
@@ -158,7 +158,7 @@ private:
|
||||
|
||||
bool m_bPathsSet;
|
||||
CTemplate m_Template;
|
||||
CSmartPtr<CAuthBase> m_spAuth;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
CString m_sModName;
|
||||
CString m_sPath;
|
||||
CString m_sPage;
|
||||
|
||||
+1
-2
@@ -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<CAuthBase> AuthClass);
|
||||
void AuthUser(std::shared_ptr<CAuthBase> AuthClass);
|
||||
|
||||
// Setters
|
||||
void SetConfigState(enum ConfigState e) { m_eConfigState = e; }
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
if (IsBlocked(Auth->GetUsername())) {
|
||||
Auth->RefuseLogin(MESSAGE);
|
||||
return HALT;
|
||||
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
return pair.second;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
const CString sUser = Auth->GetUsername();
|
||||
Csock *pSock = Auth->GetSocket();
|
||||
CUser *pUser = CZNC::Get().FindUser(sUser);
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
const CString& sUsername = Auth->GetUsername();
|
||||
const CString& sPassword = Auth->GetPassword();
|
||||
CUser *pUser(CZNC::Get().FindUser(sUsername));
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
Add(sRemoteIP, 1);
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
// e.g. webadmin ends up here
|
||||
const CString& sRemoteIP = Auth->GetRemoteIP();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class CIMAPAuthMod;
|
||||
|
||||
class CIMAPSock : public CSocket {
|
||||
public:
|
||||
CIMAPSock(CIMAPAuthMod* pModule, CSmartPtr<CAuthBase> Auth)
|
||||
CIMAPSock(CIMAPAuthMod* pModule, std::shared_ptr<CAuthBase> 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<CAuthBase> m_spAuth;
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
CUser* pUser = CZNC::Get().FindUser(Auth->GetUsername());
|
||||
|
||||
if (!pUser) { // @todo Will want to do some sort of && !m_bAllowCreate in the future
|
||||
|
||||
+2
-2
@@ -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<CClientAuth>(this, m_sUser, m_sPass);
|
||||
|
||||
CZNC::Get().AuthUser(m_spAuth);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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<CAuthBase> Auth) { return CONTINUE; }
|
||||
CModule::EModRet CModule::OnLoginAttempt(std::shared_ptr<CAuthBase> 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<CAuthBase> Auth) {
|
||||
bool CModules::OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
MODHALTCHK(OnLoginAttempt(Auth));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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<CWebAuth>(this, sUser, sPass);
|
||||
|
||||
// Some authentication module could need some time, block this socket
|
||||
// until then. CWebAuth will UnPauseRead().
|
||||
|
||||
+1
-1
@@ -1783,7 +1783,7 @@ CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CZNC::AuthUser(CSmartPtr<CAuthBase> AuthClass) {
|
||||
void CZNC::AuthUser(std::shared_ptr<CAuthBase> AuthClass) {
|
||||
// TODO unless the auth module calls it, CUser::IsHostAllowed() is not honoured
|
||||
bool bReturn = false;
|
||||
GLOBALMODULECALL(OnLoginAttempt(AuthClass), &bReturn);
|
||||
|
||||
Reference in New Issue
Block a user