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 VmAfdModifyPermissions ( PVECS_SERV_STORE pStore, PCWSTR pszServiceName, DWORD accessMask, VMAFD_ACE_TYPE aceType, PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptor, VMW_IPC_MODIFY_PERMISSIONS modifyType ) { DWORD dwError = 0; PVM_AFD_SECURITY_CONTEXT pSecurityContext = NULL; PVMAFD_ACL pAcl = NULL; PVMAFD_ACE_LIST pAceList = NULL; PVMAFD_ACE_LIST pAceListCursor = NULL; PVMAFD_ACE_LIST pAceListNew = NULL; WCHAR wszEveryone[] = GROUP_EVERYONE_W; if (IsNullOrEmptyString (pszServiceName) || !pSecurityDescriptor || !modifyType || !pStore || !accessMask ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } if (VmAfdStringIsEqualW( pszServiceName, wszEveryone, FALSE ) ) { dwError = VmAfdCreateWellKnownContext ( VM_AFD_CONTEXT_TYPE_EVERYONE, &pSecurityContext ); } else { dwError = VmAfdAllocateContextFromName ( pszServiceName, &pSecurityContext ); } BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdCheckOwnerShip ( pStore, pSecurityContext ); if (dwError == 0) { goto cleanup; } dwError = 0; if ( !pSecurityDescriptor->pAcl && modifyType != VMW_IPC_MODIFY_PERMISSIONS_REVOKE ) { dwError = VmAfdAllocateMemory( sizeof (VMAFD_ACL), (PVOID *) &pAcl ); BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdAllocateMemory ( sizeof (VMAFD_ACE_LIST), (PVOID *) pAceList ); BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdCopySecurityContext( pSecurityContext, &(pAceList->Ace.pSecurityContext ) ); BAIL_ON_VMAFD_ERROR (dwError); pAceList->Ace.accessMask = accessMask; pAceList->Ace.changeStatus = VMAFD_UPDATE_STATUS_NEW; pAceList->Ace.type = aceType; pAcl->pAceList = pAceList; pAcl->dwAceCount ++; pSecurityDescriptor->pAcl = pAcl; } else if (pSecurityDescriptor->pAcl) { pAceListCursor = pSecurityDescriptor->pAcl->pAceList; while (pAceListCursor) { if ( VmAfdEqualsSecurityContext( pSecurityContext, pAceListCursor->Ace.pSecurityContext ) && pAceListCursor->Ace.type == aceType ) { break; } pAceListCursor = pAceListCursor->pNext; } if ( !pAceListCursor && modifyType != VMW_IPC_MODIFY_PERMISSIONS_REVOKE ) { dwError = VmAfdAllocateMemory ( sizeof (VMAFD_ACE_LIST), (PVOID *) &pAceListNew ); BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdCopySecurityContext ( pSecurityContext, &(pAceListNew->Ace.pSecurityContext) ); BAIL_ON_VMAFD_ERROR (dwError); pAceListNew->pNext = pSecurityDescriptor->pAcl->pAceList; pAceListNew->Ace.accessMask = accessMask; pAceListNew->Ace.changeStatus = VMAFD_UPDATE_STATUS_NEW; pAceListNew->Ace.type = aceType; pSecurityDescriptor->pAcl->pAceList = pAceListNew; pSecurityDescriptor->pAcl->dwAceCount ++; } else if (pAceListCursor) { switch (modifyType) { case VMW_IPC_MODIFY_PERMISSIONS_SET: pAceListCursor->Ace.accessMask = accessMask; break; case VMW_IPC_MODIFY_PERMISSIONS_ADD: pAceListCursor->Ace.accessMask = pAceListCursor->Ace.accessMask | accessMask; break; case VMW_IPC_MODIFY_PERMISSIONS_REVOKE: pAceListCursor->Ace.accessMask = pAceListCursor->Ace.accessMask & ~accessMask; break; default: dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } pAceListCursor->Ace.changeStatus = VMAFD_UPDATE_STATUS_MODIFIED; } } if (pSecurityDescriptor->changeStatus == VMAFD_UPDATE_STATUS_UNCHANGED) { pSecurityDescriptor->changeStatus = VMAFD_UPDATE_STATUS_MODIFIED; } cleanup: if (pSecurityContext) { VmAfdFreeSecurityContext (pSecurityContext); } return dwError; error: if (pAcl) { VmAfdFreeAcl (pAcl); } if (pAceList) { VmAfdFreeAceList (pAceList); } if (pAceListNew) { VmAfdFreeAceList (pAceListNew); } goto cleanup; }
static DWORD CdcRefreshCache( BOOL bPurgeRefresh, PCDC_DB_ENTRY_W pCdcEntry, DWORD dwCount ) { //TODO: Or simply always purge and repopulate? DWORD dwError = 0; PWSTR *ppszDomainControllers = NULL; DWORD dwDBDCCount = 0; DWORD dwDbIndex = 0; DWORD dwIndex = 0; PWSTR pwszDomainName = NULL; if (!pCdcEntry) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfSrvGetDomainName(&pwszDomainName); BAIL_ON_VMAFD_ERROR(dwError); if (bPurgeRefresh) { dwError = CdcDbEnumDCEntries(&ppszDomainControllers, &dwDBDCCount); BAIL_ON_VMAFD_ERROR(dwError); for (; dwDbIndex<dwDBDCCount; ++dwDbIndex) { BOOL bFoundDC = FALSE; for (dwIndex = 0;dwIndex < dwCount; ++dwIndex) { if (VmAfdStringIsEqualW( ppszDomainControllers[dwDbIndex], pCdcEntry[dwIndex].pszDCName, FALSE ) ) { pCdcEntry[dwIndex].cdcEntryStatus = CDC_DB_ENTRY_STATUS_UPDATE; bFoundDC = TRUE; break; } } if (!bFoundDC) { CdcDbDeleteDCEntry(ppszDomainControllers[dwDbIndex]); } } } for (dwIndex = 0; dwIndex < dwCount; ++dwIndex) { dwError = VmAfdAllocateStringW( pwszDomainName, &pCdcEntry[dwIndex].pszDomainName ); BAIL_ON_VMAFD_ERROR(dwError); switch (pCdcEntry[dwIndex].cdcEntryStatus) { case CDC_DB_ENTRY_STATUS_NEW: dwError = CdcDbAddDCEntry(&pCdcEntry[dwIndex]); break; case CDC_DB_ENTRY_STATUS_UPDATE: dwError = CdcDbUpdateDCEntry(&pCdcEntry[dwIndex]); break; default: dwError = ERROR_INVALID_PARAMETER; break; } BAIL_ON_VMAFD_ERROR(dwError); } cleanup: if (ppszDomainControllers) { VmAfdFreeStringArrayW(ppszDomainControllers, dwDBDCCount); } VMAFD_SAFE_FREE_MEMORY(pwszDomainName); return dwError; error: goto cleanup; }
DWORD CdcSrvGetDCName( PCWSTR pszDomainName, PCDC_DC_INFO_W *ppAffinitizedDC ) { DWORD dwError = 0; PCDC_DC_INFO_W pAffinitizedDC = NULL; DWORD dwAffinitizedSince = 0; BOOL bHAState = FALSE; PWSTR pszDomainToUse = NULL; if (!ppAffinitizedDC) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfSrvGetDomainName(&pszDomainToUse); BAIL_ON_VMAFD_ERROR(dwError); if (!IsNullOrEmptyString(pszDomainName)) { if (!VmAfdStringIsEqualW( pszDomainName, pszDomainToUse, FALSE ) ) { dwError = ERROR_INVALID_DOMAINNAME; BAIL_ON_VMAFD_ERROR(dwError); } } dwError = CdcRegDbGetHAMode(&bHAState); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcDbGetAffinitizedDC( pszDomainToUse, &dwAffinitizedSince, &pAffinitizedDC ); if (!bHAState || dwError) { dwError = VmAfdAllocateMemory( sizeof(CDC_DC_INFO_W), (PVOID *)&pAffinitizedDC ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfSrvGetDCName(&pAffinitizedDC->pszDCName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfSrvGetDomainName(&pAffinitizedDC->pszDomainName); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcGetClientSiteName(&pAffinitizedDC->pszDcSiteName); BAIL_ON_VMAFD_ERROR(dwError); } *ppAffinitizedDC = pAffinitizedDC; cleanup: VMAFD_SAFE_FREE_MEMORY(pszDomainToUse); return dwError; error: if (ppAffinitizedDC) { *ppAffinitizedDC = NULL; } if (pAffinitizedDC) { VmAfdFreeDomainControllerInfoW(pAffinitizedDC); } goto cleanup; }
DWORD CdcSrvGetDCName( PCWSTR pszDomainName, PCDC_DC_INFO_W *ppAffinitizedDC ) { DWORD dwError = 0; PCDC_DC_INFO_W pAffinitizedDC = NULL; PCDC_DC_INFO_W pAffinitizedDCToFree = NULL; DWORD dwAffinitizedSince = 0; CDC_DB_ENUM_HA_MODE cdcHAMode = CDC_DB_ENUM_HA_MODE_UNDEFINED; PWSTR pszDomainToUse = NULL; UINT64 iStart = 0; UINT64 iEnd = 0; if (!ppAffinitizedDC) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } iStart = VmAfdGetTimeInMilliSec(); dwError = VmAfSrvGetDomainName(&pszDomainToUse); BAIL_ON_VMAFD_ERROR(dwError); if (!IsNullOrEmptyString(pszDomainName)) { if (!VmAfdStringIsEqualW( pszDomainName, pszDomainToUse, FALSE ) ) { dwError = ERROR_INVALID_DOMAINNAME; BAIL_ON_VMAFD_ERROR(dwError); } } dwError = CdcRegDbGetHAMode(&cdcHAMode); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcDbGetAffinitizedDC( pszDomainToUse, &dwAffinitizedSince, &pAffinitizedDC ); if (cdcHAMode == CDC_DB_ENUM_HA_MODE_LEGACY || dwError) { pAffinitizedDCToFree = pAffinitizedDC; dwError = VmAfdAllocateMemory( sizeof(CDC_DC_INFO_W), (PVOID *)&pAffinitizedDC ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfSrvGetDCName(&pAffinitizedDC->pszDCName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdTrimFQDNTrailingDot(pAffinitizedDC->pszDCName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfSrvGetDomainName(&pAffinitizedDC->pszDomainName); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcRegDbGetSiteName(&pAffinitizedDC->pszDcSiteName); BAIL_ON_VMAFD_ERROR(dwError); } iEnd = VmAfdGetTimeInMilliSec(); *ppAffinitizedDC = pAffinitizedDC; cleanup: VMAFD_SAFE_FREE_MEMORY(pszDomainToUse); if (pAffinitizedDCToFree) { VmAfdFreeDomainControllerInfoW(pAffinitizedDCToFree); } return dwError; error: (DWORD)VmAfdAddDCSuperLogEntry( gVmafdGlobals.pLogger, iStart, iEnd, pAffinitizedDC, dwError); if (ppAffinitizedDC) { *ppAffinitizedDC = NULL; } if (pAffinitizedDC) { VmAfdFreeDomainControllerInfoW(pAffinitizedDC); } goto cleanup; }