mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fix key slot indices after removing a key
This commit is contained in:
parent
8c79f28802
commit
c1e826e853
|
@ -24,11 +24,11 @@ void CAuthManager::Init()
|
|||
}
|
||||
|
||||
if(g_Config.m_SvRconPassword[0])
|
||||
AddAdminKey(g_Config.m_SvRconPassword);
|
||||
AddDefaultKey(AUTHED_ADMIN, g_Config.m_SvRconPassword);
|
||||
if(g_Config.m_SvRconModPassword[0])
|
||||
AddModKey(g_Config.m_SvRconModPassword);
|
||||
AddDefaultKey(AUTHED_MOD, g_Config.m_SvRconModPassword);
|
||||
if (g_Config.m_SvRconHelperPassword[0])
|
||||
AddHelperKey(g_Config.m_SvRconHelperPassword);
|
||||
AddDefaultKey(AUTHED_HELPER, g_Config.m_SvRconHelperPassword);
|
||||
}
|
||||
|
||||
int CAuthManager::AddKeyHash(const char *pIdent, const unsigned char *pHash, const unsigned char *pSalt, int AuthLevel)
|
||||
|
@ -63,9 +63,10 @@ int CAuthManager::AddKey(const char *pIdent, const char *pPw, int AuthLevel)
|
|||
return AddKeyHash(pIdent, aHash, aSalt, AuthLevel);
|
||||
}
|
||||
|
||||
void CAuthManager::RemoveKey(int Slot)
|
||||
int CAuthManager::RemoveKey(int Slot)
|
||||
{
|
||||
m_aKeys.remove_index_fast(Slot);
|
||||
return m_aKeys.size();
|
||||
}
|
||||
|
||||
int CAuthManager::FindKey(const char *pIdent)
|
||||
|
@ -147,22 +148,15 @@ void CAuthManager::ListKeys(FListCallback pfnListCallback, void *pUser)
|
|||
pfnListCallback(m_aKeys[i].m_aIdent, m_aKeys[i].m_Level, pUser);
|
||||
}
|
||||
|
||||
void CAuthManager::AddAdminKey(const char *pPw)
|
||||
void CAuthManager::AddDefaultKey(int Level, const char *pPw)
|
||||
{
|
||||
m_aDefault[0] = AddKey(ADMIN_IDENT, pPw, AUTHED_ADMIN);
|
||||
}
|
||||
|
||||
void CAuthManager::AddModKey(const char *pPw)
|
||||
{
|
||||
m_aDefault[1] = AddKey(MOD_IDENT, pPw, AUTHED_MOD);
|
||||
}
|
||||
|
||||
void CAuthManager::AddHelperKey(const char *pPw)
|
||||
{
|
||||
m_aDefault[2] = AddKey(HELPER_IDENT, pPw, AUTHED_HELPER);
|
||||
dbg_assert(AUTHED_HELPER <= Level && Level <= AUTHED_ADMIN, "level out of range");
|
||||
static const char IDENTS[3][sizeof(HELPER_IDENT)] = {ADMIN_IDENT, MOD_IDENT, HELPER_IDENT};
|
||||
int Index = AUTHED_ADMIN - Level;
|
||||
m_aDefault[Index] = AddKey(IDENTS[Index], pPw, Level);
|
||||
}
|
||||
|
||||
bool CAuthManager::IsGenerated()
|
||||
{
|
||||
return m_Generated;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
void Init();
|
||||
int AddKeyHash(const char *pIdent, const unsigned char *pHash, const unsigned char *pSalt, int AuthLevel);
|
||||
int AddKey(const char *pIdent, const char *pPw, int AuthLevel);
|
||||
void RemoveKey(int Slot);
|
||||
int RemoveKey(int Slot); // Returns the old key slot that is now in the named one.
|
||||
int FindKey(const char *pIdent);
|
||||
bool CheckKey(int Slot, const char *pPw);
|
||||
int DefaultKey(int AuthLevel);
|
||||
|
@ -43,9 +43,7 @@ public:
|
|||
void UpdateKeyHash(int Slot, const unsigned char *pHash, const unsigned char *pSalt, int AuthLevel);
|
||||
void UpdateKey(int Slot, const char *pPw, int AuthLevel);
|
||||
void ListKeys(FListCallback pfnListCallbac, void *pUser);
|
||||
void AddAdminKey(const char *pPw);
|
||||
void AddModKey(const char *pPw);
|
||||
void AddHelperKey(const char *pPw);
|
||||
void AddDefaultKey(int Level, const char *pPw);
|
||||
bool IsGenerated();
|
||||
};
|
||||
|
||||
|
|
|
@ -1969,6 +1969,21 @@ static int GetAuthLevel(const char *pLevel)
|
|||
return Level;
|
||||
}
|
||||
|
||||
void CServer::AuthRemoveKey(int KeySlot)
|
||||
{
|
||||
int NewKeySlot = KeySlot;
|
||||
int OldKeySlot = m_AuthManager.RemoveKey(KeySlot);
|
||||
LogoutKey(KeySlot, "key removal");
|
||||
|
||||
// Update indices.
|
||||
if(OldKeySlot != NewKeySlot)
|
||||
{
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
if(m_aClients[i].m_AuthKey == OldKeySlot)
|
||||
m_aClients[i].m_AuthKey = NewKeySlot;
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::ConAuthAdd(IConsole::IResult *pResult, void *pUser)
|
||||
{
|
||||
CServer *pThis = (CServer *)pUser;
|
||||
|
@ -2111,8 +2126,7 @@ void CServer::ConAuthRemove(IConsole::IResult *pResult, void *pUser)
|
|||
return;
|
||||
}
|
||||
|
||||
pManager->RemoveKey(KeySlot);
|
||||
pThis->LogoutKey(KeySlot, "key removal");
|
||||
pThis->AuthRemoveKey(KeySlot);
|
||||
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "key removed, all users logged out");
|
||||
}
|
||||
|
||||
|
@ -2411,72 +2425,47 @@ void CServer::LogoutKey(int Key, const char *pReason)
|
|||
LogoutClient(i, pReason);
|
||||
}
|
||||
|
||||
void CServer::ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
void CServer::ConchainRconPasswordChangeGeneric(int Level, IConsole::IResult *pResult)
|
||||
{
|
||||
pfnCallback(pResult, pCallbackUserData);
|
||||
if(pResult->NumArguments() == 1)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUserData;
|
||||
CAuthManager *pManager = &pServer->m_AuthManager;
|
||||
|
||||
int KeySlot = pManager->DefaultKey(AUTHED_ADMIN);
|
||||
int KeySlot = m_AuthManager.DefaultKey(Level);
|
||||
if(KeySlot == -1 && pResult->GetString(0)[0])
|
||||
{
|
||||
pManager->AddAdminKey(pResult->GetString(0));
|
||||
m_AuthManager.AddDefaultKey(Level, pResult->GetString(0));
|
||||
}
|
||||
else if(KeySlot > 0)
|
||||
{
|
||||
if(!pResult->GetString(0)[0])
|
||||
pManager->RemoveKey(KeySlot);
|
||||
{
|
||||
AuthRemoveKey(KeySlot);
|
||||
// Already logs users out.
|
||||
}
|
||||
else
|
||||
pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_ADMIN);
|
||||
pServer->LogoutKey(KeySlot, "key update");
|
||||
{
|
||||
m_AuthManager.UpdateKey(KeySlot, pResult->GetString(0), Level);
|
||||
LogoutKey(KeySlot, "key update");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
{
|
||||
pfnCallback(pResult, pCallbackUserData);
|
||||
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_ADMIN, pResult);
|
||||
}
|
||||
|
||||
void CServer::ConchainRconModPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
{
|
||||
pfnCallback(pResult, pCallbackUserData);
|
||||
if(pResult->NumArguments() == 1)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUserData;
|
||||
CAuthManager *pManager = &pServer->m_AuthManager;
|
||||
|
||||
int KeySlot = pManager->DefaultKey(AUTHED_MOD);
|
||||
if(KeySlot == -1 && pResult->GetString(0)[0])
|
||||
pManager->AddModKey(pResult->GetString(0));
|
||||
else if(KeySlot > 0)
|
||||
{
|
||||
if(!pResult->GetString(0)[0])
|
||||
pManager->RemoveKey(KeySlot);
|
||||
else
|
||||
pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_MOD);
|
||||
pServer->LogoutKey(KeySlot, "key update");
|
||||
}
|
||||
}
|
||||
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_MOD, pResult);
|
||||
}
|
||||
|
||||
void CServer::ConchainRconHelperPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
{
|
||||
pfnCallback(pResult, pCallbackUserData);
|
||||
if(pResult->NumArguments() == 1)
|
||||
{
|
||||
CServer *pServer = (CServer *)pUserData;
|
||||
CAuthManager *pManager = &pServer->m_AuthManager;
|
||||
|
||||
int KeySlot = pManager->DefaultKey(AUTHED_HELPER);
|
||||
if(KeySlot == -1 && pResult->GetString(0)[0])
|
||||
pManager->AddHelperKey(pResult->GetString(0));
|
||||
else if(KeySlot > 0)
|
||||
{
|
||||
if(!pResult->GetString(0)[0])
|
||||
pManager->RemoveKey(KeySlot);
|
||||
else
|
||||
pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_HELPER);
|
||||
pServer->LogoutKey(KeySlot, "key update");
|
||||
}
|
||||
}
|
||||
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_HELPER, pResult);
|
||||
}
|
||||
|
||||
void CServer::RegisterCommands()
|
||||
|
|
|
@ -319,6 +319,7 @@ public:
|
|||
void LogoutClient(int ClientID, const char *pReason);
|
||||
void LogoutKey(int Key, const char *pReason);
|
||||
|
||||
void ConchainRconPasswordChangeGeneric(int Level, IConsole::IResult *pResult);
|
||||
static void ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||
static void ConchainRconModPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||
static void ConchainRconHelperPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||
|
@ -347,6 +348,8 @@ public:
|
|||
return m_aClients[ClientID].m_DnsblState == CClient::DNSBL_STATE_NONE ||
|
||||
m_aClients[ClientID].m_DnsblState == CClient::DNSBL_STATE_WHITELISTED;
|
||||
}
|
||||
|
||||
void AuthRemoveKey(int KeySlot);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue