Merge pull request #663 from heinrich5991/pr_ddnet_fix_default_pws

Fix handling of default passwords
This commit is contained in:
Dennis Felsing 2017-03-10 12:45:01 +01:00 committed by GitHub
commit 1d67e29c74
2 changed files with 27 additions and 15 deletions

View file

@ -3297,7 +3297,7 @@ void CClient::RegisterCommands()
m_pConsole->Register("screenshot", "", CFGFLAG_CLIENT, Con_Screenshot, this, "Take a screenshot");
m_pConsole->Register("rcon", "r[rcon-command]", CFGFLAG_CLIENT, Con_Rcon, this, "Send specified command to rcon");
m_pConsole->Register("rcon_auth", "s[password]", CFGFLAG_CLIENT, Con_RconAuth, this, "Authenticate to rcon");
m_pConsole->Register("rcon_login", "s[username] s[password]", CFGFLAG_CLIENT, Con_RconLogin, this, "Authenticate to rcon with a username");
m_pConsole->Register("rcon_login", "s[username] r[password]", CFGFLAG_CLIENT, Con_RconLogin, this, "Authenticate to rcon with a username");
m_pConsole->Register("play", "r[file]", CFGFLAG_CLIENT|CFGFLAG_STORE, Con_Play, this, "Play the file specified");
m_pConsole->Register("record", "?s[file]", CFGFLAG_CLIENT, Con_Record, this, "Record to the file");
m_pConsole->Register("stoprecord", "", CFGFLAG_CLIENT, Con_StopRecord, this, "Stop recording");

View file

@ -17,23 +17,23 @@ CAuthManager::CAuthManager()
void CAuthManager::Init()
{
if(m_aKeys.size() == 0 && !g_Config.m_SvRconPassword[0])
int NumDefaultKeys = 0;
if(g_Config.m_SvRconPassword[0])
NumDefaultKeys++;
if(g_Config.m_SvRconModPassword[0])
NumDefaultKeys++;
if(g_Config.m_SvRconHelperPassword[0])
NumDefaultKeys++;
if(m_aKeys.size() == NumDefaultKeys && !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])
AddDefaultKey(AUTHED_ADMIN, g_Config.m_SvRconPassword);
if(g_Config.m_SvRconModPassword[0])
AddDefaultKey(AUTHED_MOD, g_Config.m_SvRconModPassword);
if (g_Config.m_SvRconHelperPassword[0])
AddDefaultKey(AUTHED_HELPER, g_Config.m_SvRconHelperPassword);
}
int CAuthManager::AddKeyHash(const char *pIdent, const unsigned char *pHash, const unsigned char *pSalt, int AuthLevel)
{
if(FindKey(pIdent) > 0)
if(FindKey(pIdent) >= 0)
return -1;
CKey Key;
@ -66,6 +66,17 @@ int CAuthManager::AddKey(const char *pIdent, const char *pPw, int AuthLevel)
int CAuthManager::RemoveKey(int Slot)
{
m_aKeys.remove_index_fast(Slot);
for(int i = 0; i < (int)(sizeof(m_aDefault) / sizeof(m_aDefault[0])); i++)
{
if(m_aDefault[i] == Slot)
{
m_aDefault[i] = -1;
}
else if(m_aDefault[i] == m_aKeys.size())
{
m_aDefault[i] = Slot;
}
}
return m_aKeys.size();
}
@ -80,7 +91,7 @@ int CAuthManager::FindKey(const char *pIdent)
bool CAuthManager::CheckKey(int Slot, const char *pPw)
{
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "indice out of bounds");
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "index out of bounds");
md5_state_t ctx;
unsigned char aHash[MD5_BYTES];
@ -102,19 +113,19 @@ int CAuthManager::DefaultKey(int AuthLevel)
int CAuthManager::KeyLevel(int Slot)
{
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "indice out of bounds");
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "index out of bounds");
return m_aKeys[Slot].m_Level;
}
const char *CAuthManager::KeyIdent(int Slot)
{
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "indice out of bounds");
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "index out of bounds");
return m_aKeys[Slot].m_aIdent;
}
void CAuthManager::UpdateKeyHash(int Slot, const unsigned char *pHash, const unsigned char *pSalt, int AuthLevel)
{
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "indice out of bounds");
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "index out of bounds");
CKey *pKey = &m_aKeys[Slot];
mem_copy(pKey->m_aPw, pHash, MD5_BYTES);
@ -124,7 +135,7 @@ void CAuthManager::UpdateKeyHash(int Slot, const unsigned char *pHash, const uns
void CAuthManager::UpdateKey(int Slot, const char *pPw, int AuthLevel)
{
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "indice out of bounds");
dbg_assert(Slot >= 0 || Slot < m_aKeys.size(), "index out of bounds");
md5_state_t ctx;
unsigned char aHash[MD5_BYTES];
@ -153,6 +164,7 @@ void CAuthManager::AddDefaultKey(int Level, const char *pPw)
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;
dbg_assert(m_aDefault[Index] == -1, "trying to add an already existing default key");
m_aDefault[Index] = AddKey(IDENTS[Index], pPw, Level);
}