diff --git a/src/engine/server/authmanager.cpp b/src/engine/server/authmanager.cpp index fbabc0cae..d4a5186bc 100644 --- a/src/engine/server/authmanager.cpp +++ b/src/engine/server/authmanager.cpp @@ -12,10 +12,18 @@ CAuthManager::CAuthManager() m_aDefault[0] = -1; m_aDefault[1] = -1; m_aDefault[2] = -1; + m_Generated = false; } void CAuthManager::Init() { + if(m_aKeys.size() == 0 && !g_Config.m_SvRconPassword[0]) + { + secure_random_password(g_Config.m_SvRconPassword, sizeof(g_Config.m_SvRconPassword), 6); + m_Generated = true; + } + + if(g_Config.m_SvRconPassword[0]) AddAdminKey(g_Config.m_SvRconPassword); if(g_Config.m_SvRconModPassword[0]) @@ -69,8 +77,7 @@ int CAuthManager::FindKey(const char *pIdent) bool CAuthManager::CheckKey(int Slot, const char *pPw) { - if(Slot < 0 || Slot > m_aKeys.size()) - return false; + dbg_assert(Slot < 0 || Slot > m_aKeys.size(), "indice out of bounds"); md5_state_t ctx; unsigned char aHash[MD5_BYTES]; @@ -86,32 +93,25 @@ bool CAuthManager::CheckKey(int Slot, const char *pPw) int CAuthManager::DefaultKey(int AuthLevel) { - if(AuthLevel < 0 || AuthLevel > AUTHED_ADMIN) - return -1; - + dbg_assert(AuthLevel < 0 || AuthLevel > AUTHED_ADMIN, "auth level invalid"); return m_aDefault[AUTHED_ADMIN - AuthLevel]; } int CAuthManager::KeyLevel(int Slot) { - if(Slot < 0 || Slot > m_aKeys.size()) - return AUTHED_NO; - + dbg_assert(Slot < 0 || Slot > m_aKeys.size(), "indice out of bounds"); return m_aKeys[Slot].m_Level; } const char *CAuthManager::KeyIdent(int Slot) { - if(Slot < 0 || Slot > m_aKeys.size()) - return 0; - + dbg_assert(Slot < 0 || Slot > m_aKeys.size(), "indice out of bounds"); return m_aKeys[Slot].m_aIdent; } void CAuthManager::UpdateKeyHash(int Slot, const unsigned char *pHash, const unsigned char *pSalt, int AuthLevel) { - if(Slot < 0 || Slot > m_aKeys.size()) - return; + dbg_assert(Slot < 0 || Slot > m_aKeys.size(), "indice out of bounds"); CKey *pKey = &m_aKeys[Slot]; mem_copy(pKey->m_aPw, pHash, MD5_BYTES); @@ -121,8 +121,7 @@ void CAuthManager::UpdateKeyHash(int Slot, const unsigned char *pHash, const uns void CAuthManager::UpdateKey(int Slot, const char *pPw, int AuthLevel) { - if(Slot < 0 || Slot > m_aKeys.size()) - return; + dbg_assert(Slot < 0 || Slot > m_aKeys.size(), "indice out of bounds"); md5_state_t ctx; unsigned char aHash[MD5_BYTES]; @@ -159,4 +158,9 @@ void CAuthManager::AddModKey(const char *pPw) void CAuthManager::AddHelperKey(const char *pPw) { m_aDefault[2] = AddKey(HELPER_IDENT, pPw, AUTHED_HELPER); +} + +bool CAuthManager::IsGenerated() +{ + return m_Generated; } \ No newline at end of file diff --git a/src/engine/server/authmanager.h b/src/engine/server/authmanager.h index 5460956fb..70f0d6b46 100644 --- a/src/engine/server/authmanager.h +++ b/src/engine/server/authmanager.h @@ -25,6 +25,7 @@ private: array m_aKeys; int m_aDefault[3]; + bool m_Generated; public: typedef void (*FListCallback)(const char *pIdent, int Level, void *pUser); @@ -45,6 +46,7 @@ public: void AddAdminKey(const char *pPw); void AddModKey(const char *pPw); void AddHelperKey(const char *pPw); + bool IsGenerated(); }; #endif //ENGINE_SERVER_AUTH_MANAGER_H diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 32f441fd4..e7f4d1846 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -554,17 +554,6 @@ int CServer::MaxClients() const return m_NetServer.MaxClients(); } -void CServer::InitRconPasswordIfEmpty() -{ - if(g_Config.m_SvRconPassword[0]) - { - return; - } - - secure_random_password(g_Config.m_SvRconPassword, sizeof(g_Config.m_SvRconPassword), 6); - m_GeneratedRconPassword = 1; -} - int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) { return SendMsgEx(pMsg, Flags, ClientID, false); @@ -1195,7 +1184,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) { const char *pName = Unpacker.GetString(CUnpacker::SANITIZE_CC); // login name, now used const char *pPw = Unpacker.GetString(CUnpacker::SANITIZE_CC); - if(!str_utf8_check(pPw)) + if(!str_utf8_check(pPw) || !str_utf8_check(pName)) { return; } @@ -2423,11 +2412,14 @@ void CServer::ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUser int KeySlot = pManager->DefaultKey(AUTHED_ADMIN); if(KeySlot == -1) { - pManager->AddAdminKey(pResult->GetString(0));//Shouldn't happen + pManager->AddAdminKey(pResult->GetString(0));//Shouldn't happen except for the first launch } else { - pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_ADMIN); + if(!pResult->GetString(0)[0]) + pManager->RemoveKey(KeySlot); + else + pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_ADMIN); pServer->LogoutKey(KeySlot, "key update"); } } @@ -2446,7 +2438,10 @@ void CServer::ConchainRconModPasswordChange(IConsole::IResult *pResult, void *pU pManager->AddModKey(pResult->GetString(0)); else { - pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_MOD); + if(!pResult->GetString(0)[0]) + pManager->RemoveKey(KeySlot); + else + pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_MOD); pServer->LogoutKey(KeySlot, "key update"); } } @@ -2465,7 +2460,10 @@ void CServer::ConchainRconHelperPasswordChange(IConsole::IResult *pResult, void pManager->AddHelperKey(pResult->GetString(0)); else { - pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_HELPER); + if(!pResult->GetString(0)[0]) + pManager->RemoveKey(KeySlot); + else + pManager->UpdateKey(KeySlot, pResult->GetString(0), AUTHED_HELPER); pServer->LogoutKey(KeySlot, "key update"); } } @@ -2629,7 +2627,6 @@ int main(int argc, const char **argv) // ignore_convention pConsole->Register("sv_rescue", "", CFGFLAG_SERVER, CServer::ConRescue, pConsole, "Allow /rescue command so players can teleport themselves out of freeze"); pEngine->InitLogfile(); - pServer->InitRconPasswordIfEmpty(); // run the server dbg_msg("server", "starting...");