DWORD VmAfdWakeupRootFlushThr( PVMAFD_CERT_THR_DATA pCertThrData ) { DWORD dwError = 0; if (pCertThrData == NULL) { VmAfdLog(VMAFD_DEBUG_ANY, "No Thread Data to Wakeup the Thread."); goto cleanup; } dwError = pthread_cond_signal(pCertThrData->pCond); if (dwError != 0) { VmAfdLog(VMAFD_DEBUG_ANY, "Condition Signaling Failed. Error [%d]", dwError); } BAIL_ON_VMAFD_ERROR(dwError); cleanup: return dwError; error: goto cleanup; }
DWORD VmAfdLocalTriggerRootCertsRefresh( VOID ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_TRIGGER_ROOT_CERTS_REFRESH; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC output_spec[] = RESPONSE_PARAMS; noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalTriggerRootCertsRefresh failed. Error(%u)", dwError); goto cleanup; }
static VOID _VmAfdSuperLoggingReadRegistry( PDWORD pdwCapacity, PBOOLEAN pbEnabled ) { DWORD dwEnabled = 0; DWORD dwCapacity = 0; DWORD dwError = 0; dwError = _VmAfdConfigGetInteger( VMAFD_REG_KEY_SUPER_LOGGING_ENABLE, &dwEnabled); if(dwError != ERROR_SUCCESS) { dwEnabled = 0; } VmAfdLog(VMAFD_DEBUG_ANY, "Registry key value for Super Logging: %d", dwEnabled); dwError = _VmAfdConfigGetInteger( VMAFD_REG_KEY_SUPER_LOGGING_CAPACITY, &dwCapacity); if(dwError != ERROR_SUCCESS) { dwCapacity = VMAFD_SUPERLOGGING_DEFAULT_CAPACITY; } *pdwCapacity = dwCapacity; *pbEnabled = dwEnabled; }
DWORD CdcSrvWakeupStateMachine( PCDC_CONTEXT pCdcContext ) { DWORD dwError = 0; if (!pCdcContext) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = CdcWakeupStateMachine(pCdcContext->pCdcStateMachineContext); if (dwError) { VmAfdLog( VMAFD_DEBUG_ANY, "Failed to wake up state machine: [%d]", dwError); } BAIL_ON_VMAFD_ERROR(dwError); cleanup: return dwError; error: goto cleanup; }
DWORD CdcWakeupDCCachingThread( PVMAFD_THREAD pDCCachingThread, BOOLEAN bPurgeRefresh ) { DWORD dwError = 0; PVMAFD_CERT_THR_DATA pThrData = NULL; if (!pDCCachingThread) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } pThrData = &pDCCachingThread->thrData; pThrData->forceFlush = bPurgeRefresh; dwError = pthread_cond_signal(pThrData->pCond); if (dwError != 0) { VmAfdLog(VMAFD_DEBUG_ANY, "Condition Signaling Failed. Error [%d]", dwError); } BAIL_ON_VMAFD_ERROR(dwError); cleanup: return dwError; error: goto cleanup; }
VOID CdcShutdownThread( PCDC_THREAD_CONTEXT pThrContext, PSTR pszThreadName ) { DWORD dwError = 0; if (pThrContext && pThrContext->pThread) { CdcSetShutdownFlagThread(pThrContext); dwError = pthread_cond_signal(&pThrContext->thr_cond); if (dwError) { VmAfdLog( VMAFD_DEBUG_ANY, "Condition Signalling %s failed. Error [%d]", IsNullOrEmptyString(pszThreadName)?"":pszThreadName, dwError ); dwError = 0; } pthread_cond_destroy(&pThrContext->thr_cond); pthread_mutex_destroy(&pThrContext->thr_mutex); } VMAFD_SAFE_FREE_MEMORY(pThrContext); }
VOID VmAfdShutdownRootFlushThread( PVMAFD_THREAD pThread ) { DWORD dwError = 0; if (pThread && pThread->pThread && pThread->thrData.pCond) { VmAfdSetShutdownFlagRootFlushThr(&pThread->thrData); dwError = pthread_cond_signal(pThread->thrData.pCond); if (dwError != 0) { VmAfdLog(VMAFD_DEBUG_ANY, "Condition Signaling Failed. Error [%d]", dwError); } dwError = pthread_join(*pThread->pThread, NULL); if (dwError != 0) { VmAfdLog(VMAFD_DEBUG_ANY, "Thread join Failed. Error [%d]", dwError); } if (pThread->thrData.pCond) { pthread_cond_destroy(pThread->thrData.pCond); pThread->thrData.pCond = NULL; } if (pThread->thrData.pMutex) { pthread_mutex_destroy(pThread->thrData.pMutex); pThread->thrData.pMutex = NULL; } } VmAfdFreeMemory(pThread); }
DWORD VmAfdLocalGetMachineID( PWSTR* ppwszMachineID ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_GET_MACHINE_ID; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; PWSTR pwszMachineID = NULL; VMW_TYPE_SPEC output_spec[] = GET_MACHINE_ID_OUTPUT_PARAMS; noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); if (IsNullOrEmptyString(output_spec[1].data.pWString)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateStringW( output_spec[1].data.pWString, &pwszMachineID ); BAIL_ON_VMAFD_ERROR (dwError); *ppwszMachineID = pwszMachineID; cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalGetMachineID failed. Error(%u)", dwError); goto cleanup; }
DWORD VmAfdLocalGetDomainName( PWSTR* ppwszDomain ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_GET_DOMAIN_NAME; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; PWSTR pwszDomain = NULL; VMW_TYPE_SPEC output_spec[] = GET_DOMAIN_NAME_OUTPUT_PARAMS; noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); if (IsNullOrEmptyString(output_spec[1].data.pWString)) { dwError = ERROR_NO_DATA; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateStringW( output_spec[1].data.pWString, &pwszDomain ); BAIL_ON_VMAFD_ERROR (dwError); *ppwszDomain = pwszDomain; cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalGetDomainName failed. Error(%u)", dwError); goto cleanup; }
DWORD VmAfdLocalJoinVmDir( PCWSTR pwszServerName, PCWSTR pwszUserName, PCWSTR pwszPassword, PCWSTR pwszMachineName, PCWSTR pwszDomainName, PCWSTR pwszOrgUnit ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_JOIN_VMDIR; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC input_spec[] = JOIN_VMDIR_INPUT_PARAMS; VMW_TYPE_SPEC output_spec[] = RESPONSE_PARAMS; noOfArgsIn = sizeof (input_spec) / sizeof (input_spec[0]); noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); input_spec[0].data.pWString = (PWSTR) pwszServerName; input_spec[1].data.pWString = (PWSTR) pwszUserName; input_spec[2].data.pWString = (PWSTR) pwszPassword; input_spec[3].data.pWString = (PWSTR) pwszMachineName; input_spec[4].data.pWString = (PWSTR) pwszDomainName; input_spec[5].data.pWString = (PWSTR) pwszOrgUnit; dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, input_spec, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalJoinVmDir failed. Error(%u)", dwError); goto cleanup; }
static DWORD VmAfdNotifyLikewiseServiceManager() { DWORD dwError = ERROR_SUCCESS; PCSTR pszSmNotify = NULL; int ret = 0; int notifyFd = -1; char notifyCode = 0; // interact with likewise service manager (start/stop control) if ((pszSmNotify = getenv("LIKEWISE_SM_NOTIFY")) != NULL) { notifyFd = atoi(pszSmNotify); do { ret = write(notifyFd, ¬ifyCode, sizeof(notifyCode)); } while (ret != sizeof(notifyCode) && errno == EINTR); if (ret < 0) { #define BUFFER_SIZE 1024 char buffer[BUFFER_SIZE]= {0}; int errorNumber = errno; VmAfdStringErrorA( buffer, BUFFER_SIZE, errorNumber ); VmAfdLog( VMAFD_DEBUG_TRACE, "Could not notify service manager: %s (%i)", buffer, errorNumber); dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMAFD_ERROR(dwError); #undef BUFFER_SIZE } } error: if(notifyFd != -1) { close(notifyFd); } return dwError; }
DWORD CdcEnableClientAffinity( VOID ) { DWORD dwError = 0; BOOL bIsLocked = 0; BOOL bEnabledHA = FALSE; dwError = CdcRegDbGetHAMode(&bEnabledHA); BAIL_ON_VMAFD_ERROR(dwError); if (!bEnabledHA) { VMAFD_LOCK_MUTEX(bIsLocked,&mutexStateChange); dwError = CdcDbSetHAClientState(CDC_DC_STATE_NO_DC_LIST); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcRegDbSetHAMode(TRUE); BAIL_ON_VMAFD_ERROR(dwError); VMAFD_UNLOCK_MUTEX(bIsLocked,&mutexStateChange); } dwError = CdcWakeupDCCachingThread( gVmafdGlobals.pDCCacheThr, TRUE ); if (dwError) { VmAfdLog (VMAFD_DEBUG_ANY, "Failed to wake up DC Caching thread: %d", dwError ); dwError = 0; } cleanup: VMAFD_UNLOCK_MUTEX(bIsLocked,&mutexStateChange); return dwError; error: goto cleanup; }
DWORD VmAfdSuperLoggingInit( PVMSUPERLOGGING *ppLogger ) { PVMSUPERLOGGING pLogger = NULL; DWORD dwError = 0; DWORD dwCapacity = 0; dwError = VmAfdAllocateMemory(sizeof(*pLogger), (PVOID)&pLogger); BAIL_ON_VMAFD_ERROR(dwError); _VmAfdSuperLoggingReadRegistry( &dwCapacity, &pLogger->bEnabled); dwError = VmAfdCircularBufferCreate( dwCapacity, sizeof(VMAFD_SUPERLOG_ENTRY), &pLogger->pCircularBuffer); BAIL_ON_VMAFD_ERROR(dwError); // Note: Keep event log publisher disabled until we have a run-time on/off switch if (0) { dwError = _VmAfdInitEventLogPublisherThread(pLogger->pCircularBuffer); BAIL_ON_VMAFD_ERROR(dwError); } *ppLogger = pLogger; VmAfdLog(VMAFD_DEBUG_ANY, "Super Logger object is created."); cleanup: return dwError; error: if (pLogger != NULL) { VmAfdCircularBufferFree(pLogger->pCircularBuffer); VmAfdFreeMemory(pLogger); pLogger = NULL; } goto cleanup; }
DWORD VmAfdLocalSetMachineID( PCWSTR pwszMachineID ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_SET_MACHINE_ID; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC input_spec[] = SET_MACHINE_ID_INPUT_PARAMS; VMW_TYPE_SPEC output_spec[] = RESPONSE_PARAMS; if (IsNullOrEmptyString(pwszMachineID)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } noOfArgsIn = sizeof (input_spec) / sizeof (input_spec[0]); noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); input_spec[0].data.pWString = (PWSTR) pwszMachineID; dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, input_spec, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VmAfdFreeTypeSpecContent (output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalSetMachineID failed. Error(%u)", dwError); goto cleanup; }
DWORD VmAfdLocalSetDCPort( DWORD dwPort ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_SET_DC_PORT; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC input_spec[] = SET_DC_PORT_INPUT_PARAMS; VMW_TYPE_SPEC output_spec[] = RESPONSE_PARAMS; if (dwPort < 0 || dwPort > 65535) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } noOfArgsIn = sizeof (input_spec) / sizeof (input_spec[0]); noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); input_spec[0].data.pUint32 = &dwPort; dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, input_spec, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VmAfdFreeTypeSpecContent (output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalSetDCPort failed. Error(%u)", dwError); goto cleanup; }
static PVOID VmAfdFlushTrustedRoots( PVOID pData ) { DWORD dwError = 0; PVMAFD_CERT_THR_DATA pThrArgs = (PVMAFD_CERT_THR_DATA)pData; while (TRUE) { DWORD dwSleepSecs = VmAfdGetRootFlushSleepInterval() ; BOOLEAN bShutdown = FALSE; bShutdown = VmAfdToShutdownRootFlushThr(pThrArgs); if (bShutdown) { break; } dwError = VmAfdFlushRoots(); if (dwError) { VmAfdLog( VMAFD_DEBUG_ANY, "Failed to flush trusted roots. Error [%u]", dwError); } dwError = VmAfdRootFlushThrSleep(pThrArgs, dwSleepSecs); if (dwError == ETIMEDOUT) { dwError = 0; } BAIL_ON_VMAFD_ERROR(dwError); } cleanup: return NULL; error: goto cleanup; }
DWORD VmAfdLocalGetStatus( PVMAFD_STATUS pStatus ) { DWORD dwError = 0; UINT32 status = 0; UINT32 apiType = VMAFD_IPC_GET_STATUS; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC output_spec[] = GET_STATUS_OUTPUT_PARAMS; noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); status = *(output_spec[1].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); *pStatus = (VMAFD_STATUS) status; cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalGetStatus failed. Error(%u)", dwError); goto cleanup; }
DWORD VmAfdLocalLeaveAD( PCWSTR pwszUserName, PCWSTR pwszPassword ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_LEAVE_AD; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC input_spec[] = LEAVE_AD_INPUT_PARAMS; VMW_TYPE_SPEC output_spec[] = RESPONSE_PARAMS; noOfArgsIn = sizeof (input_spec) / sizeof (input_spec[0]); noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); input_spec[0].data.pWString = (PWSTR) pwszUserName; input_spec[1].data.pWString = (PWSTR) pwszPassword; dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, input_spec, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalLeaveAD failed. Error(%u)", dwError); goto cleanup; }
DWORD VmAfdLocalForceReplication( PCWSTR pwszServerName ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_FORCE_REPLICATION; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; VMW_TYPE_SPEC input_spec[] = FORCE_REPLICATION_INPUT_PARAMS; VMW_TYPE_SPEC output_spec[] = RESPONSE_PARAMS; noOfArgsIn = sizeof (input_spec) / sizeof (input_spec[0]); noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); input_spec[0].data.pWString = (PWSTR) pwszServerName; dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalForceReplication failed. Error(%u)", dwError); goto cleanup; }
DWORD CdcSrvEnableLegacyModeHA( PCDC_CONTEXT pCdcContext ) { DWORD dwError = 0; BOOL bIsLocked = FALSE; if (!pCdcContext) { dwError = ERROR_INVALID_PARAMETER; VmAfdLog( VMAFD_DEBUG_ERROR, "Invalid state machine context received" ); BAIL_ON_VMAFD_ERROR(dwError); } VMAFD_LOCK_MUTEX(bIsLocked, &pCdcContext->context_mutex); dwError = CdcRegDbSetHAMode(CDC_DB_ENUM_HA_MODE_LEGACY); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcSrvShutdownDefaultHAMode(pCdcContext); BAIL_ON_VMAFD_ERROR(dwError); VMAFD_UNLOCK_MUTEX(bIsLocked, &pCdcContext->context_mutex); cleanup: if (pCdcContext) { VMAFD_UNLOCK_MUTEX(bIsLocked,&pCdcContext->context_mutex); } return dwError; error: goto cleanup; }
DWORD VmAfdInitRootFlushThread( PVMAFD_THREAD* ppThread ) { DWORD dwError = 0; PVMAFD_THREAD pThread = NULL; VmAfdLog(VMAFD_DEBUG_ANY, "Starting Roots Flush Thread, %s", __FUNCTION__); dwError = VmAfdAllocateMemory( sizeof(VMAFD_THREAD), (PVOID*)&pThread); BAIL_ON_VMAFD_ERROR(dwError); dwError = pthread_mutex_init(&pThread->thrData.mutex, NULL); if (dwError) { #ifndef _WIN32 dwError = LwErrnoToWin32Error(dwError); #endif BAIL_ON_VMAFD_ERROR(dwError); } pThread->thrData.pMutex = &pThread->thrData.mutex; dwError = pthread_cond_init(&pThread->thrData.cond, NULL); if (dwError) { #ifndef _WIN32 dwError = LwErrnoToWin32Error(dwError); #endif BAIL_ON_VMAFD_ERROR(dwError); } pThread->thrData.pCond = &pThread->thrData.cond; dwError = pthread_create( &pThread->thread, NULL, &VmAfdFlushTrustedRoots, (PVOID)&pThread->thrData); if (dwError) { #ifndef _WIN32 dwError = LwErrnoToWin32Error(dwError); #endif BAIL_ON_VMAFD_ERROR(dwError); } pThread->pThread = &pThread->thread; *ppThread = pThread; VmAfdLog(VMAFD_DEBUG_ANY, "Started Roots Flush Thread successfully, %s", __FUNCTION__); cleanup: return dwError; error: *ppThread = NULL; if (pThread) { VmAfdShutdownRootFlushThread(pThread); } goto cleanup; }
static PVOID CdcHandleDCCaching( PVOID pData ) { DWORD dwError = 0; DWORD dwRefreshInterval = 0; DWORD dwHeartBeat = 0; BOOL bHAState = FALSE; PVMAFD_CERT_THR_DATA pThrArgs = (PVMAFD_CERT_THR_DATA)pData; pThrArgs->forceFlush = TRUE; while (TRUE) { BOOLEAN bShutdown = FALSE; dwError = CdcRegDbGetRefreshInterval(&dwRefreshInterval); if (dwError) { dwRefreshInterval = DCCA_DEFAULT_SYNC_INTERVAL; } dwError = CdcRegDbGetHeartBeatInterval(&dwHeartBeat); if (dwError) { dwHeartBeat = DCCA_DEFAULT_HEARTBEAT; } bShutdown = CdcToShutdownDCCacheThread(pThrArgs); if (bShutdown) { break; } dwError = CdcRegDbGetHAMode(&bHAState); if (dwError) { bHAState = FALSE; dwError = 0; } if (bHAState) { dwError = CdcRunStateMachine(pThrArgs->forceFlush); if (dwError) { VmAfdLog( VMAFD_DEBUG_ANY, "Failed to populate the DC Cache. Error [%u]", dwError); } } dwError = CdcDCCacheThreadSleep( pThrArgs, dwRefreshInterval, dwHeartBeat ); if (dwError == ETIMEDOUT) { dwError = 0; } BAIL_ON_VMAFD_ERROR(dwError); } cleanup: return NULL; error: goto cleanup; }
static DWORD CdcVmafdHeartbeatPing( PWSTR pwszDCName, PWSTR pwszAccount, PWSTR pwszPassword, PWSTR pwszDomainName, PBOOL pbIsAlive ) { DWORD dwError = 0; PSTR pszUPN = NULL; PSTR pszAccount = NULL; PSTR pszDomainName = NULL; PWSTR pwszUPN = NULL; BOOL bIsAlive = FALSE; PVMAFD_SERVER pServer = NULL; PVMAFD_HB_STATUS_W pHeartbeatStatus = NULL; if (IsNullOrEmptyString(pwszDCName) || IsNullOrEmptyString(pwszAccount) || IsNullOrEmptyString(pwszPassword) || IsNullOrEmptyString(pwszDomainName) || !pbIsAlive ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateStringAFromW( pwszAccount, &pszAccount ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringAFromW( pwszDomainName, &pszDomainName ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringPrintf( &pszUPN, "%s@%s", pszAccount, pszDomainName ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringWFromA( pszUPN, &pwszUPN ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdOpenServerW( pwszDCName, pwszUPN, pwszPassword, &pServer ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdGetHeartbeatStatusW( pServer, &pHeartbeatStatus ); BAIL_ON_VMAFD_ERROR(dwError); bIsAlive = pHeartbeatStatus->bIsAlive? TRUE: FALSE; *pbIsAlive = bIsAlive; cleanup: if (pServer) { VmAfdCloseServer(pServer); } if (pHeartbeatStatus) { VmAfdFreeHeartbeatStatusW(pHeartbeatStatus); } VMAFD_SAFE_FREE_MEMORY(pszUPN); VMAFD_SAFE_FREE_MEMORY(pwszUPN); VMAFD_SAFE_FREE_MEMORY(pszAccount); VMAFD_SAFE_FREE_MEMORY(pszDomainName); return dwError; error: if (pbIsAlive) { *pbIsAlive = FALSE; } VmAfdLog(VMAFD_DEBUG_ANY, "Failed to get heartbeat Status due to Error: %d", dwError ); goto cleanup; }
static PVOID VmLinuxWaitOnEventWorker( PVOID pData ) { DWORD dwError = 0; int iError = 0; DWORD len = 0; char buffer[VMDDNS_BUFFER_SIZE] = {0}; nl_addr *bindAddr = NULL; struct nlmsghdr *nh = NULL; PVMNETEVENT_DATA pEventData = NULL; if (!pData) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } pEventData = (PVMNETEVENT_DATA)pData; if (pEventData->eventFd.dwNetlinkFD < 0) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMNETEVENT_ERROR(dwError); } dwError = VmAfdAllocateMemory( sizeof(nl_addr), (PVOID *)&bindAddr ); BAIL_ON_VMAFD_ERROR(dwError); bindAddr->nl_family = AF_NETLINK; bindAddr->nl_pad = 0; bindAddr->nl_pid = getpid(); bindAddr->nl_groups = RTMGRP_IPV6_IFADDR | RTMGRP_IPV4_IFADDR; //bind to the IFADDR API iError = bind( pEventData->eventFd.dwNetlinkFD, (struct sockaddr*)bindAddr, sizeof(nl_addr) ); if (iError < 0) { dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMAFD_ERROR(dwError); } nh = (struct nlmsghdr *)buffer; while(1) { len = recv(pEventData->eventFd.dwNetlinkFD, nh, 4096, 0); if(len < 0) { dwError = LwErrnoToWin32Error(errno); VmAfdLog(VMAFD_DEBUG_ANY, "Recieve failed. Error[%d]", dwError); continue; } else if (len == 0) { break; } for(; (NLMSG_OK (nh, len)) && (nh->nlmsg_type != NLMSG_DONE); nh = NLMSG_NEXT(nh, len)) { if (nh->nlmsg_type != RTM_NEWADDR) { continue; /* some other kind of message */ } if (pEventData->pfnCallBack) { dwError = pEventData->pfnCallBack(); if (dwError) { VmAfdLog(VMAFD_DEBUG_ANY, "Callback failed"); } } memset(buffer, 0, VMDDNS_BUFFER_SIZE); } } cleanup: VMAFD_SAFE_FREE_MEMORY(pEventData); VMAFD_SAFE_FREE_MEMORY(bindAddr); VmAfdLog(VMAFD_DEBUG_ANY, "VmLinuxWaitOnEventWorker exiting. Error[%d]", dwError); return NULL; error: goto cleanup; }
DWORD VecsSrvRevokePermission ( PVECS_SRV_STORE_HANDLE pStore, PCWSTR pszUserName, UINT32 accessMask, VMAFD_ACE_TYPE aceType, PVM_AFD_CONNECTION_CONTEXT pConnectionContext ) { DWORD dwError = 0; PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptor = NULL; PVECS_SERV_STORE pStoreInstance = NULL; BOOL bIsHoldingLock = FALSE; PWSTR pwszAccountName = NULL; DWORD dwLogError = 0; dwError = VmAfdCheckOwnerShipWithHandle ( pStore, pConnectionContext ); BAIL_ON_VMAFD_ERROR (dwError); pthread_mutex_lock (&gVmafdGlobals.mutexStoreState); bIsHoldingLock = TRUE; dwError = VmAfdGetSecurityDescriptorFromHandle ( pStore, &pSecurityDescriptor ); BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdGetStoreFromHandle ( pStore, pConnectionContext->pSecurityContext, &pStoreInstance ); BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdModifyPermissions ( pStoreInstance, pszUserName, accessMask, aceType, pSecurityDescriptor, VMW_IPC_MODIFY_PERMISSIONS_REVOKE ); BAIL_ON_VMAFD_ERROR (dwError); dwError = VmAfdSetSecurityDescriptorForHandle ( pStore, pSecurityDescriptor ); BAIL_ON_VMAFD_ERROR (dwError); pthread_mutex_unlock (&gVmafdGlobals.mutexStoreState); bIsHoldingLock = FALSE; dwLogError = VmAfdAllocateNameFromContext ( pConnectionContext->pSecurityContext, &pwszAccountName ); if (!IsNullOrEmptyString(pwszAccountName)) { PSTR pszAccountName = NULL; PSTR paszUserName = NULL; dwLogError = VmAfdAllocateStringAFromW( pwszAccountName, &pszAccountName ); dwLogError = VmAfdAllocateStringAFromW ( pszUserName, &paszUserName ); if (pszAccountName) { VmAfdLog (VMAFD_DEBUG_ANY, "User %s changed permission of Store with ID: %d \n " "Permission %s %s was revoked from user %s", pszAccountName, pStoreInstance->dwStoreId, accessMask & READ_STORE ? "read" : "", accessMask & WRITE_STORE ? "write": "", !IsNullOrEmptyString(paszUserName)? paszUserName: "" ); } VMAFD_SAFE_FREE_MEMORY (pszAccountName); VMAFD_SAFE_FREE_MEMORY (paszUserName); } cleanup: if (pSecurityDescriptor) { VmAfdFreeSecurityDescriptor (pSecurityDescriptor); } if (bIsHoldingLock) { pthread_mutex_unlock(&gVmafdGlobals.mutexStoreState); } VMAFD_SAFE_FREE_MEMORY (pStoreInstance); VMAFD_SAFE_FREE_MEMORY (pwszAccountName); return dwError; error: goto cleanup; }
DWORD VmAfdHandleSignals( VOID ) { DWORD dwError = 0; struct sigaction action; sigset_t catch_signal_mask; int which_signal = 0; int sysRet = 0; // After starting up threads, we now want to handle SIGINT async // instead of using sigwait() on it. The reason for this is so // that a debugger (such as gdb) can break in properly. // See http://sourceware.org/ml/gdb/2007-03/msg00145.html and // http://bugzilla.kernel.org/show_bug.cgi?id=9039. memset(&action, 0, sizeof(action)); action.sa_handler = VmAfdInterruptHandler; sysRet = sigaction(SIGINT, &action, NULL); dwError = (sysRet != 0) ? errno : 0; BAIL_ON_VMAFD_ERROR(dwError); // Unblock SIGINT sigemptyset(&catch_signal_mask); sigaddset(&catch_signal_mask, SIGINT); dwError = pthread_sigmask(SIG_UNBLOCK, &catch_signal_mask, NULL); BAIL_ON_VMAFD_ERROR(dwError); // These should already be blocked... sigemptyset(&catch_signal_mask); sigaddset(&catch_signal_mask, SIGTERM); sigaddset(&catch_signal_mask, SIGQUIT); sigaddset(&catch_signal_mask, SIGHUP); sigaddset(&catch_signal_mask, SIGPIPE); while (1) { /* Wait for a signal to arrive */ sigwait(&catch_signal_mask, &which_signal); switch (which_signal) { case SIGINT: case SIGQUIT: case SIGTERM: { VmAfdLog(VMAFD_DEBUG_ANY, "Handled SIG[%d]", which_signal); goto error; } case SIGPIPE: { VmAfdLog(VMAFD_DEBUG_ANY, "Handled SIGPIPE"); break; } case SIGHUP: { break; } default: break; } } error: return dwError; }
int main(int argc, char* argv[]) { DWORD dwError = 0; int retCode = 0; PSTR pszDomain = NULL; PSTR pszDomainName = NULL; PSTR pszUserName = NULL; PSTR pszPassword = NULL; PSTR pszPwdFile = NULL; PSTR pszSiteName = NULL; PSTR pszPartnerHostName = NULL; PSTR pszLotusServerName = NULL; PSTR pszPasswordBuf = NULL; FILE * fpPwdFile = NULL; PSTR pszPath = NULL; PSTR pszLogPathName = NULL; size_t dPwdLen = 0; BOOL bLogInitialized = FALSE; PCSTR pszErrorMsg = NULL; PSTR pszErrorDesc = NULL; PCSTR pszLocalhost = "localhost"; PSTR pszPnid = NULL; DNS_INIT_FLAG dnsInitFlag = DNS_NONE; #ifdef _WIN32 WSADATA wsaData = { 0 }; BOOLEAN bWsaStartup = FALSE; #endif #ifndef _WIN32 setlocale(LC_ALL, ""); #else dwError = WSAStartup(MAKEWORD(2, 2), &wsaData); BAIL_ON_VMAFD_ERROR(dwError); bWsaStartup = TRUE; #endif dwError = VmAfCfgInit(); BAIL_ON_VMAFD_ERROR(dwError); #ifndef _WIN32 dwError = VmAfdAllocateStringA(VMAFD_LOG_PATH, &pszLogPathName ); BAIL_ON_VMAFD_ERROR(dwError); #else dwError = VmAfdConfigGetString(VMAFD_SOFTWARE_KEY_PATH, VMAFD_LOGPATH_KEY_VALUE, &pszLogPathName); BAIL_ON_VMAFD_ERROR(dwError); #endif dwError = VmAfdAllocateStringAVsnprintf( &pszPath, "%s%s", pszLogPathName, "vdcpromo.log" ); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdLogInitialize(pszPath, 0, 0); BAIL_ON_VMAFD_ERROR(dwError); bLogInitialized = TRUE; dwError = VmAfdParseArgs(argc, argv, &pszDomain, &pszUserName, &pszPassword, &pszSiteName, &pszPartnerHostName, &pszLotusServerName, &pszPwdFile, &dnsInitFlag); if (dwError) { ShowUsage(); BAIL_ON_VMAFD_ERROR(dwError); } if (IsNullOrEmptyString(pszUserName)) { VmAfdLog(VMAFD_DEBUG_ANY, "Username parameter is not valid"); } else { VmAfdLog(VMAFD_DEBUG_ANY, "Username: \"%s\"", pszUserName); } if (!pszPwdFile && IsNullOrEmptyString(pszPassword)) { VmAfdLog(VMAFD_DEBUG_ANY, "Password parameter is not valid"); } if (IsNullOrEmptyString(pszDomain)) { VmAfdLog(VMAFD_DEBUG_ANY, "Domain parameter is not valid"); } else { VmAfdLog(VMAFD_DEBUG_ANY, "Domain: \"%s\"", pszDomain); } dwError = VmAfdAllocateMemory(VMAFD_MAX_PWD_LEN+1, (PVOID *)&pszPasswordBuf); BAIL_ON_VMAFD_ERROR(dwError); if (pszPassword == NULL && pszPwdFile != NULL) { dwError = VmAfdOpenFilePath(pszPwdFile, "rb", &fpPwdFile); if (dwError != ERROR_SUCCESS) { printf("vdcpromo: cannot open password file %s (%u)\n", pszPwdFile, dwError); dwError = ERROR_LOCAL_PASSWORDFILE_CANNOT_OPEN; BAIL_ON_VMAFD_ERROR(dwError); } if ( (dPwdLen = fread(pszPasswordBuf, 1, VMAFD_MAX_PWD_LEN, fpPwdFile)) == 0) { dwError = ERROR_LOCAL_PASSWORDFILE_CANNOT_READ; printf("vdcpromo: Could not read password file\n"); BAIL_ON_VMAFD_ERROR(dwError); } if (*pszPasswordBuf == '\0') { VmAfdLog(VMAFD_DEBUG_ANY, "password is empty"); dwError = ERROR_LOCAL_PASSWORD_EMPTY; BAIL_ON_VMAFD_ERROR(dwError); } } else if (pszPassword != NULL && pszPwdFile == NULL) { dwError = VmAfdStringCpyA(pszPasswordBuf, VMAFD_MAX_PWD_LEN, pszPassword); BAIL_ON_VMAFD_ERROR(dwError); } else //no password nor password-file, read password from stdin { VmAfdReadString("password: "******"Warning: failed to initialize DNS. Error [%d]\n", dwError); } else { fprintf(stdout, "Successfully initialized DNS.\n"); } BAIL_ON_VMAFD_ERROR(dwError); goto cleanup; } printf("Initializing Directory server instance ... \n"); fflush(stdout); dwError = VmAfdPromoteVmDirA( pszLotusServerName ? pszLotusServerName : pszLocalhost, pszDomain, pszUserName, pszPasswordBuf, pszSiteName, pszPartnerHostName); BAIL_ON_VMAFD_ERROR(dwError); printf("Directory host instance created successfully\n"); cleanup: VmAfCfgShutdown(); if (bLogInitialized) { VmAfdLogTerminate(); } #ifdef _WIN32 if (bWsaStartup != FALSE) { WSACleanup(); } #endif VMAFD_SAFE_FREE_MEMORY(pszPnid); VMAFD_SAFE_FREE_MEMORY(pszPasswordBuf); VMAFD_SAFE_FREE_MEMORY(pszPath); VMAFD_SAFE_FREE_MEMORY(pszLogPathName); VMAFD_SAFE_FREE_MEMORY(pszErrorDesc); VMAFD_SAFE_FREE_MEMORY(pszDomainName); return retCode; error: switch (dwError) { case ERROR_LOCAL_OPTION_UNKNOWN: retCode = 2; pszErrorMsg = "An unknown option was present on the command line."; break; case ERROR_LOCAL_OPTION_INVALID: retCode = 3; pszErrorMsg = "The options present on the command line are not valid."; break; case ERROR_LOCAL_PASSWORDFILE_CANNOT_OPEN: retCode = 4; pszErrorMsg = "Could not open password file.\nVerify the path is correct."; break; case ERROR_LOCAL_PASSWORDFILE_CANNOT_READ: retCode = 5; pszErrorMsg = "Problem reading password file.\nVerify contents of password file."; break; case ERROR_LOCAL_PASSWORD_EMPTY: retCode = 6; pszErrorMsg = "Invalid password; password cannot be empty."; break; case ERROR_CANNOT_CONNECT_VMAFD: retCode = 20; pszErrorMsg = "Could not connect to the local service VMware AFD.\nVerify VMware AFD is running."; break; case VMDIR_ERROR_CANNOT_CONNECT_VMDIR: retCode = 21; pszErrorMsg = "Could not connect to the local service VMware Directory Service.\nVerify VMware Directory Service is running."; break; case ERROR_INVALID_CONFIGURATION: retCode = 22; pszErrorMsg = "Configuration is not correct.\nFirst boot scripts need to be executed."; break; case VMDIR_ERROR_SERVER_DOWN: retCode = 23; pszErrorMsg = "Could not connect to VMware Directory Service via LDAP.\nVerify VMware Directory Service is running on the appropriate system and is reachable from this host."; break; case VMDIR_ERROR_USER_INVALID_CREDENTIAL: retCode = 24; pszErrorMsg = "Authentication to VMware Directory Service failed.\nVerify the username and password."; break; case ERROR_ACCESS_DENIED: retCode = 25; pszErrorMsg = "Authorization failed.\nVerify account has proper administrative privileges."; break; case VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE: retCode = 26; pszErrorMsg = "Could not join to the remote service VMWare Directory Service.\nThe remote schema is incompatible with the local schema."; break; default: retCode = 1; } if (bLogInitialized) { if (pszErrorMsg == NULL) { VmAfdLog(VMAFD_DEBUG_ANY, "Vdcpromo failed. Error[%d]", dwError); } else { VmAfdLog(VMAFD_DEBUG_ANY, "Vdcpromo failed. Error[%d]\n%s", dwError, pszErrorMsg); } } if (pszErrorMsg == NULL) { if (!VmAfdGetErrorString(dwError, &pszErrorDesc)) { printf("Vdcpromo failed. Error %d: %s\n", dwError, pszErrorDesc); } else { printf("Vdcpromo failed. Error %d.\n", dwError); } } else { printf("Vdcpromo failed. Error[%d]\n%s\n", dwError, pszErrorMsg); } goto cleanup; }
DWORD VmAfdAccessCheckWithHandle ( PVECS_SRV_STORE_HANDLE pStore, PVM_AFD_CONNECTION_CONTEXT pConnectionContext, DWORD dwDesiredAccess ) { DWORD dwError = 0; DWORD dwLogError = 0; PVECS_SERV_STORE pStoreInfo = NULL; PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptor = NULL; PWSTR pszAccountName = NULL; if (!pStore || !pConnectionContext || !pConnectionContext->pSecurityContext ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } if ((dwDesiredAccess | VECS_MAXIMUM_ALLOWED_MASK) != VECS_MAXIMUM_ALLOWED_MASK ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } /* * We don't care about dwLogError errors because they are * used solely for logging purpose. Even if some call fails, * the function should not fail */ dwLogError = VmAfdAllocateNameFromContext ( pConnectionContext->pSecurityContext, &pszAccountName ); dwLogError = VmAfdGetStoreFromHandle ( pStore, pConnectionContext->pSecurityContext, &pStoreInfo ); if ( !IsNullOrEmptyString(pszAccountName) && pStoreInfo ) { PSTR paszAccountName = NULL; dwLogError = VmAfdAllocateStringAFromW( pszAccountName, &paszAccountName ); if (paszAccountName) { switch (dwDesiredAccess) { case READ_STORE: VmAfdLog (VMAFD_DEBUG_DEBUG, "User %s requested READ operation on Store with ID: %d", paszAccountName, pStoreInfo->dwStoreId ); break; case WRITE_STORE: VmAfdLog (VMAFD_DEBUG_DEBUG, "User %s requested WRITE operation on Store with ID:%d", paszAccountName, pStoreInfo->dwStoreId ); break; default: break; } } else { VmAfdLog(VMAFD_DEBUG_ANY, "%s log failed. error(%u)", __FUNCTION__, dwLogError); } VMAFD_SAFE_FREE_MEMORY (paszAccountName); } dwError = VmAfdGetSecurityDescriptorFromHandle ( pStore, &pSecurityDescriptor ); BAIL_ON_VMAFD_ERROR (dwError); if (!(VmAfdIsRootSecurityContext (pConnectionContext))) { if (!(VmAfdEqualsSecurityContext( pConnectionContext->pSecurityContext, pSecurityDescriptor->pOwnerSecurityContext ) )) { dwError = VmAfdCheckAcl ( pSecurityDescriptor, pConnectionContext->pSecurityContext, dwDesiredAccess ); BAIL_ON_VMAFD_ERROR (dwError); } } cleanup: VMAFD_SAFE_FREE_MEMORY (pszAccountName); VMAFD_SAFE_FREE_MEMORY (pStoreInfo); if (pSecurityDescriptor) { VmAfdFreeSecurityDescriptor (pSecurityDescriptor); } return dwError; error: goto cleanup; }
DWORD VmAfdLocalQueryAD( PWSTR *ppwszComputer, PWSTR *ppwszDomain, PWSTR *ppwszDistinguishedName, PWSTR *ppwszNetbiosName ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_QUERY_AD; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; PWSTR pwszComputer = NULL; PWSTR pwszDomain = NULL; PWSTR pwszDistinguishedName = NULL; PWSTR pwszNetbiosName = NULL; VMW_TYPE_SPEC output_spec[] = QUERY_AD_OUTPUT_PARAMS; noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); if (IsNullOrEmptyString(output_spec[1].data.pWString)) { dwError = ERROR_NO_DATA; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateStringW( output_spec[1].data.pWString, &pwszComputer ); BAIL_ON_VMAFD_ERROR (dwError); if (IsNullOrEmptyString(output_spec[2].data.pWString)) { dwError = ERROR_NO_DATA; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateStringW( output_spec[2].data.pWString, &pwszDomain ); BAIL_ON_VMAFD_ERROR (dwError); if (ppwszDistinguishedName && !IsNullOrEmptyString(output_spec[3].data.pWString)) { dwError = VmAfdAllocateStringW( output_spec[3].data.pWString, &pwszDistinguishedName ); BAIL_ON_VMAFD_ERROR (dwError); } if (ppwszNetbiosName && !IsNullOrEmptyString(output_spec[4].data.pWString)) { dwError = VmAfdAllocateStringW( output_spec[4].data.pWString, &pwszNetbiosName ); BAIL_ON_VMAFD_ERROR (dwError); } *ppwszComputer = pwszComputer; *ppwszDomain = pwszDomain; if (ppwszDistinguishedName) { *ppwszDistinguishedName = pwszDistinguishedName; } if (ppwszNetbiosName) { *ppwszNetbiosName = pwszNetbiosName; } cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalQueryAD failed. Error(%u)", dwError); goto cleanup; }
DWORD VmAfdLocalGetMachineAccountInfo( PWSTR* ppwszAccount, PWSTR* ppwszPassword ) { DWORD dwError = 0; UINT32 apiType = VMAFD_IPC_GET_MACHINE_ACCOUNT_INFO; DWORD noOfArgsIn = 0; DWORD noOfArgsOut = 0; PWSTR pwszAccount= NULL; PWSTR pwszPassword = NULL; VMW_TYPE_SPEC output_spec[] = GET_MACHINE_ACCOUNT_INFO_OUTPUT_PARAMS; noOfArgsOut = sizeof (output_spec) / sizeof (output_spec[0]); dwError = VecsLocalIPCRequest( apiType, noOfArgsIn, noOfArgsOut, NULL, output_spec); BAIL_ON_VMAFD_ERROR(dwError); dwError = *(output_spec[0].data.pUint32); BAIL_ON_VMAFD_ERROR(dwError); if (IsNullOrEmptyString(output_spec[1].data.pWString)) { dwError = ERROR_NO_DATA; BAIL_ON_VMAFD_ERROR (dwError); } dwError = VmAfdAllocateStringW( output_spec[1].data.pWString, &pwszAccount ); BAIL_ON_VMAFD_ERROR (dwError); if (!output_spec[2].data.pWString) { dwError = ERROR_NO_DATA; BAIL_ON_VMAFD_ERROR (dwError); } dwError = VmAfdAllocateStringW( output_spec[2].data.pWString, &pwszPassword ); BAIL_ON_VMAFD_ERROR (dwError); *ppwszAccount = pwszAccount; *ppwszPassword = pwszPassword; cleanup: VmAfdFreeTypeSpecContent(output_spec, noOfArgsOut); return dwError; error: VmAfdLog(VMAFD_DEBUG_ANY, "VmAfdLocalGetMachineAccountInfo failed. Error(%u)", dwError); goto cleanup; }