BOOL VmAfdCanDeleteStore ( PVECS_SRV_STORE_HANDLE pStoreHandle ) { BOOL bResult = 0; if (pStoreHandle) { BOOLEAN bIsHoldingLock = FALSE; VMAFD_LOCK_MUTEX_SHARED (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); if (gVecsGlobalStoreMap[pStoreHandle->dwStoreHandle].pStore && gVecsGlobalStoreMap[pStoreHandle->dwStoreHandle].pStore->refCount ==1 ) { bResult = 1; } VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); } return bResult; }
DWORD VmAfSrvGetHeartbeatStatus( PVMAFD_HB_STATUS_W* ppHeartbeatStatus ) { DWORD dwError = 0; PVMAFD_HB_STATUS_W pHeartbeatStatus = NULL; BOOL bIsHoldingLock = FALSE; DWORD dwEntriesCount = 0; if (!ppHeartbeatStatus) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateMemory( sizeof(VMAFD_HB_STATUS_W), (PVOID *)&pHeartbeatStatus ); BAIL_ON_VMAFD_ERROR(dwError); pHeartbeatStatus->bIsAlive = TRUE; VMAFD_LOCK_MUTEX_SHARED(&rwlockHeartbeatTable, bIsHoldingLock); dwError = VmAfdGetHeartbeatInfo( &pHeartbeatStatus->pHeartbeatInfoArr, &dwEntriesCount, &pHeartbeatStatus->bIsAlive ); BAIL_ON_VMAFD_ERROR(dwError); VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock); pHeartbeatStatus->dwCount = dwEntriesCount; *ppHeartbeatStatus = pHeartbeatStatus; cleanup: return dwError; error: if (ppHeartbeatStatus) { *ppHeartbeatStatus = NULL; } if (pHeartbeatStatus) { VmAfdFreeHbStatusW(pHeartbeatStatus); } goto cleanup; }
DWORD VmAfdGetSecurityDescriptorFromHandle ( PVECS_SRV_STORE_HANDLE pStore, PVMAFD_SECURITY_DESCRIPTOR *ppSecurityDescriptor ) { DWORD dwError = 0; PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptor = NULL; BOOL bIsHoldingLock = FALSE; VECS_SRV_STORE_MAP storeMapEntry = {0}; if (!pStore || !ppSecurityDescriptor ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } VMAFD_LOCK_MUTEX_SHARED (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); storeMapEntry = gVecsGlobalStoreMap[pStore->dwStoreHandle]; if (storeMapEntry.status != STORE_MAP_ENTRY_STATUS_OPEN) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } dwError = VmAfdCopySecurityDescriptor ( storeMapEntry.pSecurityDescriptor, &pSecurityDescriptor ); BAIL_ON_VMAFD_ERROR (dwError); *ppSecurityDescriptor = pSecurityDescriptor; cleanup: VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); return dwError; error: if (ppSecurityDescriptor) { *ppSecurityDescriptor = NULL; } if (pSecurityDescriptor) { VmAfdFreeSecurityDescriptor (pSecurityDescriptor); } goto cleanup; }
DWORD VmAfdGetStoreStatus( PVECS_SRV_STORE_HANDLE pStore, STORE_MAP_ENTRY_STATUS *pStoreStatus ) { DWORD dwError = 0; STORE_MAP_ENTRY_STATUS storeStatus = STORE_MAP_ENTRY_STATUS_EMPTY; BOOLEAN bIsHoldingLock = FALSE; if ( !pStore || !pStoreStatus ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } VMAFD_LOCK_MUTEX_SHARED (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); /*TODO: Do we really need to validate handle before * returning the store status?. Also where is this call * used at all */ /*if (!VmAfdIsValidStoreHandle( pStore, pSecurityContext ) ) { dwError = ERROR_INVALID_HANDLE; BAIL_ON_VMAFD_ERROR (dwError); }*/ storeStatus = gVecsGlobalStoreMap[pStore->dwStoreHandle].status; *pStoreStatus = storeStatus; cleanup: VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); return dwError; error: if (pStoreStatus) { *pStoreStatus = STORE_MAP_ENTRY_STATUS_EMPTY; } goto cleanup; }
static DWORD VmAfdFindNode( PCWSTR pwszServiceName, DWORD dwPort, PVMAFD_HB_NODE *ppNode ) { DWORD dwError = 0; DWORD dwIndex = 0; PVMAFD_HB_NODE pNode = NULL; BOOL bIsHoldingLock = FALSE; VMAFD_LOCK_MUTEX_SHARED(&rwlockHeartbeatTable, bIsHoldingLock); for (;dwIndex<VMAFD_HEARTBEAT_TABLE_COUNT; ++dwIndex) { if (gHeartbeatTable.pEntries[dwIndex] && VmAfdStringIsEqualW( pwszServiceName, gHeartbeatTable.pEntries[dwIndex]->pszServiceName, FALSE ) && gHeartbeatTable.pEntries[dwIndex]->dwPort == dwPort ) { pNode = gHeartbeatTable.pEntries[dwIndex]; break; } } VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock); if (!pNode) { dwError = ERROR_OBJECT_NOT_FOUND; BAIL_ON_VMAFD_ERROR(dwError); } *ppNode = pNode; cleanup: VMAFD_LOCK_MUTEX_UNLOCK(&rwlockHeartbeatTable, bIsHoldingLock); return dwError; error: if (ppNode) { *ppNode = NULL; } goto cleanup; }
DWORD VmAfdGetStoreFromHandle ( PVECS_SRV_STORE_HANDLE pStoreHandle, PVM_AFD_SECURITY_CONTEXT pSecurityContext, PVECS_SERV_STORE *ppStore ) { DWORD dwError = 0; PVECS_SERV_STORE pStore = NULL; VECS_SRV_STORE_MAP storeMapEntry = {0}; BOOL bIsHoldingLock = FALSE; if ( !pStoreHandle || !ppStore ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } if (!VmAfdIsValidStoreHandle ( pStoreHandle, pSecurityContext ) ) { dwError = ERROR_INVALID_HANDLE; BAIL_ON_VMAFD_ERROR (dwError); } VMAFD_LOCK_MUTEX_SHARED (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); storeMapEntry = gVecsGlobalStoreMap[pStoreHandle->dwStoreHandle]; if ( storeMapEntry.status != STORE_MAP_ENTRY_STATUS_OPEN || !storeMapEntry.pStore ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } dwError = VmAfdAllocateMemory ( sizeof (VECS_SERV_STORE), (PVOID *) &pStore ); BAIL_ON_VMAFD_ERROR (dwError); pStore->dwStoreId = storeMapEntry.pStore->dwStoreId; pStore->refCount = storeMapEntry.pStore->refCount; *ppStore = pStore; cleanup: VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); return dwError; error: if (ppStore) { *ppStore = NULL; } VMAFD_SAFE_FREE_MEMORY (pStore); goto cleanup; }
BOOL VmAfdIsValidStoreHandle ( PVECS_SRV_STORE_HANDLE pStore, PVM_AFD_SECURITY_CONTEXT pSecurityContext ) { VECS_SRV_STORE_MAP storeMapEntry = {0}; PVECS_STORE_CONTEXT_LIST pContextListCursor = NULL; BOOL bResult = 0; BOOL bIsHoldingLock = FALSE; if (!pStore || !pSecurityContext ) { goto error; } VMAFD_LOCK_MUTEX_SHARED (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); storeMapEntry = gVecsGlobalStoreMap[pStore->dwStoreHandle]; if (storeMapEntry.status != STORE_MAP_ENTRY_STATUS_OPEN) { goto error; } if (!storeMapEntry.pStore) { goto error; } if (pStore->dwStoreSessionID != storeMapEntry.dwStoreSessionID) { goto error; } if (!VmAfdIsValidClientInstance(pStore->dwClientInstance)) { goto error; //Client Instance should have only 1 bit set. } pContextListCursor = storeMapEntry.pStoreContextList; while (pContextListCursor) { if (VmAfdEqualsSecurityContext( pContextListCursor->pSecurityContext, pSecurityContext ) ) { if (pStore->dwClientInstance & pContextListCursor->dwClientInstances) { bResult = 1; break; } } pContextListCursor = pContextListCursor->pNext; } error: VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); return bResult; }