DWORD ADLdap_MoveHashKeysToArray( IN OUT PLW_HASH_TABLE pHash, OUT PDWORD pCount, OUT PVOID** pppValues ) { LW_HASH_ITERATOR hashIterator = {0}; DWORD count = (DWORD) LwHashGetKeyCount(pHash); DWORD index = 0; DWORD dwError = 0; PVOID* ppValues = NULL; LW_HASH_ENTRY* pHashEntry = NULL; if (count) { dwError = LwAllocateMemory( sizeof(ppValues[0]) * count, OUT_PPVOID(&ppValues)); BAIL_ON_LSA_ERROR(dwError); dwError = LwHashGetIterator(pHash, &hashIterator); BAIL_ON_LSA_ERROR(dwError); for (index = 0; (pHashEntry = LwHashNext(&hashIterator)) != NULL; index++) { ppValues[index] = pHashEntry->pKey; } } *pCount = count; *pppValues = ppValues; cleanup: return dwError; error: *pCount = 0; *pppValues = NULL; LW_SAFE_FREE_MEMORY(ppValues); goto cleanup; }
DWORD LocalDirQueryMemberOf( IN HANDLE hProvider, IN LSA_FIND_FLAGS FindFlags, IN DWORD dwSidCount, IN PSTR* ppszSids, OUT PDWORD pdwGroupSidCount, OUT PSTR** pppszGroupSids ) { DWORD dwError = 0; DWORD dwIndex = 0; PLW_HASH_TABLE pGroupHash = NULL; LW_HASH_ITERATOR hashIterator = {0}; LW_HASH_ENTRY* pHashEntry = NULL; DWORD dwGroupSidCount = 0; PSTR* ppszGroupSids = NULL; dwError = LwHashCreate( 13, LwHashCaselessStringCompare, LwHashCaselessStringHash, NULL, NULL, &pGroupHash); BAIL_ON_LSA_ERROR(dwError); for (dwIndex = 0; dwIndex < dwSidCount; dwIndex++) { dwError = LocalDirQueryMemberOfInternal( hProvider, FindFlags, ppszSids[dwIndex], pGroupHash); BAIL_ON_LSA_ERROR(dwError); } dwGroupSidCount = (DWORD) LwHashGetKeyCount(pGroupHash); if (dwGroupSidCount) { dwError = LwAllocateMemory( sizeof(*ppszGroupSids) * dwGroupSidCount, OUT_PPVOID(&ppszGroupSids)); BAIL_ON_LSA_ERROR(dwError); dwError = LwHashGetIterator(pGroupHash, &hashIterator); BAIL_ON_LSA_ERROR(dwError); for(dwIndex = 0; (pHashEntry = LwHashNext(&hashIterator)) != NULL; dwIndex++) { ppszGroupSids[dwIndex] = (PSTR) pHashEntry->pValue; pHashEntry->pValue = NULL; } } *pdwGroupSidCount = dwGroupSidCount; *pppszGroupSids = ppszGroupSids; cleanup: if (pGroupHash) { if (LwHashGetIterator(pGroupHash, &hashIterator) == 0) { while ((pHashEntry = LwHashNext(&hashIterator))) { LW_SAFE_FREE_MEMORY(pHashEntry->pValue); } } LwHashSafeFree(&pGroupHash); } return dwError; error: *pdwGroupSidCount = 0; *pppszGroupSids = NULL; if (ppszGroupSids) { LwFreeStringArray(ppszGroupSids, dwGroupSidCount); } goto cleanup; }