From af651e15f3495c6f2702752dcc80995b0d7eeee9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 29 Jan 2007 05:02:44 +0000 Subject: [PATCH] finished implementing admin interface --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40411 --- core/AdminCache.cpp | 69 ++++++++++++++++++++++++++++++++------------- core/AdminCache.h | 5 ++-- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/core/AdminCache.cpp b/core/AdminCache.cpp index 0f05e49f..2555f552 100644 --- a/core/AdminCache.cpp +++ b/core/AdminCache.cpp @@ -30,6 +30,7 @@ AdminCache::AdminCache() m_pGroups = sm_trie_create(); m_pCacheFwd = NULL; m_FirstGroup = -1; + m_pAuthTables = sm_trie_create(); } AdminCache::~AdminCache() @@ -44,13 +45,23 @@ AdminCache::~AdminCache() sm_trie_destroy(m_pCmdOverrides); } - InvalidateGroupCache(); + DumpAdminCache(0xFFFFFFFF, false); if (m_pGroups) { sm_trie_destroy(m_pGroups); } + List::iterator iter; + for (iter=m_AuthMethods.begin(); + iter!=m_AuthMethods.end(); + iter++) + { + sm_trie_destroy((*iter).table); + } + + sm_trie_destroy(m_pAuthTables); + delete m_pStrings; } @@ -220,16 +231,15 @@ AdminId AdminCache::CreateAdmin(const char *name) id = m_pMemory->CreateMem(sizeof(AdminUser), (void **)&pUser); pUser->grp_size = 0; pUser->grp_table = -1; - pUser->auth_size = 0; - pUser->auth_table = -1; } memset(pUser->flags, 0, sizeof(pUser->flags)); memset(pUser->eflags, 0, sizeof(pUser->flags)); pUser->grp_count = 0; - pUser->auth_count = 0; pUser->password = -1; pUser->magic = USR_MAGIC_SET; + pUser->auth.identidx = -1; + pUser->auth.index = 0; if (m_FirstUser == INVALID_ADMIN_ID) { @@ -599,25 +609,18 @@ bool AdminCache::InvalidateAdmin(AdminId id) } /* Unlink from auth tables */ - if (pUser->auth_count > 0) + if (pUser->auth.identidx != -1) { - UserAuth *pAuth = (UserAuth *)m_pMemory->GetAddress(pUser->auth_table); - Trie *pTrie; - for (unsigned int i=0; iauth_count; i++) + Trie *pTrie = GetMethodByIndex(pUser->auth.index); + if (pTrie) { - pTrie = GetMethodByIndex(pAuth[i].index); - if (!pTrie) - { - continue; - } - sm_trie_delete(pTrie, m_pStrings->GetString(pAuth->identidx)); + sm_trie_delete(pTrie, m_pStrings->GetString(pUser->auth.identidx)); } } /* Clear table counts */ pUser->grp_count = 0; - pUser->auth_count = 0; - + /* Link into free list */ pUser->magic = USR_MAGIC_UNSET; pUser->next_user = m_FreeUserList; @@ -791,9 +794,16 @@ void AdminCache::InvalidateAdminCache(bool unlink_admins) sm_trie_clear((*iter).table); } - while (m_FirstUser != INVALID_ADMIN_ID) + if (unlink_admins) { - InvalidateAdmin(m_FirstUser); + while (m_FirstUser != INVALID_ADMIN_ID) + { + InvalidateAdmin(m_FirstUser); + } + } else { + m_FirstUser = -1; + m_LastUser = -1; + m_FreeUserList = -1; } } @@ -844,6 +854,24 @@ const char *AdminCache::GetAdminName(AdminId id) return m_pStrings->GetString(pUser->nameidx); } +bool AdminCache::GetMethodIndex(const char *name, unsigned int *_index) +{ + List::iterator iter; + unsigned int index = 0; + for (iter=m_AuthMethods.begin(); + iter!=m_AuthMethods.end(); + iter++,index++) + { + if ((*iter).name.compare(name) == 0) + { + *_index = index; + return true; + } + } + + return false; +} + bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ident) { AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); @@ -863,6 +891,9 @@ bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ide return false; } + pUser->auth.identidx = m_pStrings->AddString(ident); + GetMethodIndex(auth, &pUser->auth.index); + return sm_trie_insert(pTable, ident, (void **)id); } @@ -958,7 +989,7 @@ bool AdminCache::AdminInheritGroup(AdminId id, GroupId gid) } AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(gid); - if (!pGroup || pGroup->magic != USR_MAGIC_SET) + if (!pGroup || pGroup->magic != GRP_MAGIC_SET) { return false; } diff --git a/core/AdminCache.h b/core/AdminCache.h index 07681a14..704250b5 100644 --- a/core/AdminCache.h +++ b/core/AdminCache.h @@ -71,9 +71,7 @@ struct AdminUser int grp_table; /* Group table itself */ int next_user; /* Next user in ze list */ int prev_user; /* Prev user in the list */ - unsigned int auth_count; /* Number of auth methods */ - unsigned int auth_size; /* Size of auth table */ - int auth_table; /* Auth table itself */ + UserAuth auth; /* Auth method for this user */ }; class AdminCache : @@ -135,6 +133,7 @@ private: void InvalidateAdminCache(bool unlink_admins); void DumpCommandOverrideCache(OverrideType type); Trie *GetMethodByIndex(unsigned int index); + bool GetMethodIndex(const char *name, unsigned int *_index); public: BaseStringTable *m_pStrings; BaseMemTable *m_pMemory;