1.1 --- a/core/AdminCache.cpp Mon Jan 29 04:19:14 2007 +0000
1.2 +++ b/core/AdminCache.cpp Mon Jan 29 05:02:44 2007 +0000
1.3 @@ -30,6 +30,7 @@
1.4 m_pGroups = sm_trie_create();
1.5 m_pCacheFwd = NULL;
1.6 m_FirstGroup = -1;
1.7 + m_pAuthTables = sm_trie_create();
1.8 }
1.9
1.10 AdminCache::~AdminCache()
1.11 @@ -44,13 +45,23 @@
1.12 sm_trie_destroy(m_pCmdOverrides);
1.13 }
1.14
1.15 - InvalidateGroupCache();
1.16 + DumpAdminCache(0xFFFFFFFF, false);
1.17
1.18 if (m_pGroups)
1.19 {
1.20 sm_trie_destroy(m_pGroups);
1.21 }
1.22
1.23 + List<AuthMethod>::iterator iter;
1.24 + for (iter=m_AuthMethods.begin();
1.25 + iter!=m_AuthMethods.end();
1.26 + iter++)
1.27 + {
1.28 + sm_trie_destroy((*iter).table);
1.29 + }
1.30 +
1.31 + sm_trie_destroy(m_pAuthTables);
1.32 +
1.33 delete m_pStrings;
1.34 }
1.35
1.36 @@ -220,16 +231,15 @@
1.37 id = m_pMemory->CreateMem(sizeof(AdminUser), (void **)&pUser);
1.38 pUser->grp_size = 0;
1.39 pUser->grp_table = -1;
1.40 - pUser->auth_size = 0;
1.41 - pUser->auth_table = -1;
1.42 }
1.43
1.44 memset(pUser->flags, 0, sizeof(pUser->flags));
1.45 memset(pUser->eflags, 0, sizeof(pUser->flags));
1.46 pUser->grp_count = 0;
1.47 - pUser->auth_count = 0;
1.48 pUser->password = -1;
1.49 pUser->magic = USR_MAGIC_SET;
1.50 + pUser->auth.identidx = -1;
1.51 + pUser->auth.index = 0;
1.52
1.53 if (m_FirstUser == INVALID_ADMIN_ID)
1.54 {
1.55 @@ -599,25 +609,18 @@
1.56 }
1.57
1.58 /* Unlink from auth tables */
1.59 - if (pUser->auth_count > 0)
1.60 + if (pUser->auth.identidx != -1)
1.61 {
1.62 - UserAuth *pAuth = (UserAuth *)m_pMemory->GetAddress(pUser->auth_table);
1.63 - Trie *pTrie;
1.64 - for (unsigned int i=0; i<pUser->auth_count; i++)
1.65 + Trie *pTrie = GetMethodByIndex(pUser->auth.index);
1.66 + if (pTrie)
1.67 {
1.68 - pTrie = GetMethodByIndex(pAuth[i].index);
1.69 - if (!pTrie)
1.70 - {
1.71 - continue;
1.72 - }
1.73 - sm_trie_delete(pTrie, m_pStrings->GetString(pAuth->identidx));
1.74 + sm_trie_delete(pTrie, m_pStrings->GetString(pUser->auth.identidx));
1.75 }
1.76 }
1.77
1.78 /* Clear table counts */
1.79 pUser->grp_count = 0;
1.80 - pUser->auth_count = 0;
1.81 -
1.82 +
1.83 /* Link into free list */
1.84 pUser->magic = USR_MAGIC_UNSET;
1.85 pUser->next_user = m_FreeUserList;
1.86 @@ -791,9 +794,16 @@
1.87 sm_trie_clear((*iter).table);
1.88 }
1.89
1.90 - while (m_FirstUser != INVALID_ADMIN_ID)
1.91 + if (unlink_admins)
1.92 {
1.93 - InvalidateAdmin(m_FirstUser);
1.94 + while (m_FirstUser != INVALID_ADMIN_ID)
1.95 + {
1.96 + InvalidateAdmin(m_FirstUser);
1.97 + }
1.98 + } else {
1.99 + m_FirstUser = -1;
1.100 + m_LastUser = -1;
1.101 + m_FreeUserList = -1;
1.102 }
1.103 }
1.104
1.105 @@ -844,6 +854,24 @@
1.106 return m_pStrings->GetString(pUser->nameidx);
1.107 }
1.108
1.109 +bool AdminCache::GetMethodIndex(const char *name, unsigned int *_index)
1.110 +{
1.111 + List<AuthMethod>::iterator iter;
1.112 + unsigned int index = 0;
1.113 + for (iter=m_AuthMethods.begin();
1.114 + iter!=m_AuthMethods.end();
1.115 + iter++,index++)
1.116 + {
1.117 + if ((*iter).name.compare(name) == 0)
1.118 + {
1.119 + *_index = index;
1.120 + return true;
1.121 + }
1.122 + }
1.123 +
1.124 + return false;
1.125 +}
1.126 +
1.127 bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ident)
1.128 {
1.129 AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id);
1.130 @@ -863,6 +891,9 @@
1.131 return false;
1.132 }
1.133
1.134 + pUser->auth.identidx = m_pStrings->AddString(ident);
1.135 + GetMethodIndex(auth, &pUser->auth.index);
1.136 +
1.137 return sm_trie_insert(pTable, ident, (void **)id);
1.138 }
1.139
1.140 @@ -958,7 +989,7 @@
1.141 }
1.142
1.143 AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(gid);
1.144 - if (!pGroup || pGroup->magic != USR_MAGIC_SET)
1.145 + if (!pGroup || pGroup->magic != GRP_MAGIC_SET)
1.146 {
1.147 return false;
1.148 }