VOID VmAfdFreeAbsoluteSecurityDescriptor( PSECURITY_DESCRIPTOR_ABSOLUTE *ppSecDesc ) { PSID pOwner = NULL; PSID pGroup = NULL; PACL pDacl = NULL; PACL pSacl = NULL; BOOLEAN bDefaulted = FALSE; BOOLEAN bPresent = FALSE; PSECURITY_DESCRIPTOR_ABSOLUTE pSecDesc = NULL; if (ppSecDesc == NULL || *ppSecDesc == NULL) { return; } pSecDesc = *ppSecDesc; VmAfdGetOwnerSecurityDescriptor(pSecDesc, &pOwner, &bDefaulted); VmAfdGetGroupSecurityDescriptor(pSecDesc, &pGroup, &bDefaulted); VmAfdGetDaclSecurityDescriptor(pSecDesc, &bPresent, &pDacl, &bDefaulted); VmAfdGetSaclSecurityDescriptor(pSecDesc, &bPresent, &pSacl, &bDefaulted); VMAFD_SAFE_FREE_MEMORY(pSecDesc); VMAFD_SAFE_FREE_MEMORY(pOwner); VMAFD_SAFE_FREE_MEMORY(pGroup); VMAFD_SAFE_FREE_MEMORY(pDacl); VMAFD_SAFE_FREE_MEMORY(pSacl); *ppSecDesc = NULL; }
static DWORD VmAfdCheckCertOnDisk( PCSTR pszAlias, PCSTR pszCAPath, PCSTR pszFilename, LONG maxIndex, PBOOLEAN pbCertOnDisk ) { DWORD dwError = 0; LONG index = 0; BOOLEAN bCertOnDisk = FALSE; PSTR pszPath = NULL; PSTR pszAliasOther = NULL; // Note : maxIndex starts from 0 for (; !bCertOnDisk && (index <= maxIndex); index++) { VMAFD_SAFE_FREE_MEMORY(pszPath); dwError = VmAfdAllocateStringPrintf( &pszPath, "%s%s%s.%ld", pszCAPath, VMAFD_PATH_SEPARATOR_STR, pszFilename, index); BAIL_ON_VMAFD_ERROR(dwError); VMAFD_SAFE_FREE_MEMORY(pszAliasOther); dwError = VecsComputeCertAliasFile(pszPath, &pszAliasOther); BAIL_ON_VMAFD_ERROR(dwError); if (!VmAfdStringCompareA(pszAlias, pszAliasOther, FALSE)) { bCertOnDisk = TRUE; } } *pbCertOnDisk = bCertOnDisk; cleanup: VMAFD_SAFE_FREE_MEMORY(pszPath); VMAFD_SAFE_FREE_MEMORY(pszAliasOther); return dwError; error: *pbCertOnDisk = FALSE; goto cleanup; }
VOID VmAfdFreeSuperLogEntryArray( PVMAFD_SUPERLOG_ENTRY_ARRAY pEntries ) { if (pEntries) { VMAFD_SAFE_FREE_MEMORY(pEntries->entries); VMAFD_SAFE_FREE_MEMORY(pEntries); } }
VOID VmAfdFreeHbNode( PVMAFD_HB_NODE pNode ) { if (pNode) { VMAFD_SAFE_FREE_MEMORY(pNode->pszServiceName); VMAFD_SAFE_FREE_MEMORY(pNode); } }
VOID VecsDbFreeCertEntryContents( PVECS_DB_CERTIFICATE_ENTRY pCertEntry ) { VMAFD_SAFE_FREE_MEMORY(pCertEntry->pwszAlias); VMAFD_SAFE_FREE_MEMORY(pCertEntry->pwszSerial); VMAFD_SAFE_FREE_MEMORY(pCertEntry->pCertBlob); VMAFD_SAFE_FREE_MEMORY(pCertEntry->pwszPassword); VMAFD_SAFE_FREE_MEMORY(pCertEntry->pPrivateKey); }
VOID DirCliFreeCert( PDIR_CLI_CERT pCert ) { VMAFD_SAFE_FREE_MEMORY(pCert->pszSubjectName); VMAFD_SAFE_FREE_MEMORY(pCert->pszFingerPrint); if (pCert->pX509Cert) { X509_free(pCert->pX509Cert); } VmAfdFreeMemory(pCert); }
static DWORD VmAfdCliGetDCList( PVM_AFD_CLI_CONTEXT pContext ) { DWORD dwError = 0; DWORD dwServerCount = 0; DWORD dwIndex = 0; PSTR pszHostname = NULL; PSTR pszAddress = NULL; PVMAFD_DC_INFO_W pVmAfdDCInfoList = NULL; if (!pContext) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdGetDCList( pContext->pszServerName, pContext->pszDomainName, &dwServerCount, &pVmAfdDCInfoList ); BAIL_ON_VMAFD_ERROR(dwError); printf("Number of Server in the Domain = %d\n",dwServerCount); for (; dwIndex < dwServerCount ; dwIndex++) { PVMAFD_DC_INFO_W pDCInfo = &pVmAfdDCInfoList[dwIndex]; dwError = VmAfdAllocateStringAFromW(pDCInfo->pwszHostName,&pszHostname); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringAFromW(pDCInfo->pwszAddress,&pszAddress); BAIL_ON_VMAFD_ERROR(dwError); printf("Hostname = %s, Address = %s\n",pszHostname,pszAddress); VMAFD_SAFE_FREE_MEMORY(pszHostname); VMAFD_SAFE_FREE_MEMORY(pszAddress); } cleanup: VMAFD_SAFE_FREE_MEMORY(pVmAfdDCInfoList); return dwError; error: goto cleanup; }
DWORD VmAfSrvConfigureDNSW( PCWSTR pwszServerName, PCWSTR pwszDomainName, PCWSTR pwszUserName, PCWSTR pwszPassword ) { DWORD dwError = 0; PSTR pszServerName = NULL; PSTR pszDomainName = NULL; PSTR pszUserName = NULL; PSTR pszPassword = NULL; dwError = VmAfdAllocateStringAFromW( pwszServerName, &pszServerName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringAFromW( pwszDomainName, &pszDomainName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringAFromW( pwszUserName, &pszUserName); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdAllocateStringAFromW( pwszPassword, &pszPassword); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfSrvConfigureDNSA( pszServerName, pszDomainName, pszUserName, pszPassword); BAIL_ON_VMAFD_ERROR(dwError); error: VMAFD_SAFE_FREE_MEMORY(pszServerName); VMAFD_SAFE_FREE_MEMORY(pszDomainName); VMAFD_SAFE_FREE_MEMORY(pszUserName); VMAFD_SAFE_FREE_MEMORY(pszPassword); return dwError; }
VOID VmAfdFreeRegArgs( PVMAFD_REG_ARG pArgs ) { if ( pArgs ) { VMAFD_SAFE_FREE_MEMORY(pArgs->pszAccount); VMAFD_SAFE_FREE_MEMORY(pArgs->pszAccountDN); VMAFD_SAFE_FREE_MEMORY(pArgs->pszPassword); VMAFD_SAFE_FREE_MEMORY(pArgs->pszDomain); VMAFD_SAFE_FREE_MEMORY(pArgs->pszAccountUPN); VmAfdFreeMemory(pArgs); } }
VOID VmAfdTearDownStoreHashMap ( VOID ) { DWORD dwIndex = 0; BOOLEAN bIsHoldingLock = FALSE; VMAFD_LOCK_MUTEX_EXCLUSIVE (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); for (; dwIndex < VECS_STOREHASH_MAP_SIZE; dwIndex++) { VECS_SRV_STORE_MAP storeMapEntry = gVecsGlobalStoreMap[dwIndex]; VMAFD_SAFE_FREE_MEMORY (storeMapEntry.pStore); if (storeMapEntry.pSecurityDescriptor) { VmAfdFreeSecurityDescriptor (storeMapEntry.pSecurityDescriptor); } if (storeMapEntry.pStoreContextList) { VmAfdFreeContextList(storeMapEntry.pStoreContextList); } gVecsGlobalStoreMap[dwIndex].status = STORE_MAP_ENTRY_STATUS_EMPTY; } VMAFD_LOCK_MUTEX_UNLOCK (&gVmafdGlobals.rwlockStoreMap, bIsHoldingLock); }
static DWORD CdcUpdateAffinitizedDC( PWSTR pszNewDCName ) { DWORD dwError = 0; PWSTR pszDomainName = NULL; dwError = VmAfSrvGetDomainName(&pszDomainName); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcDbAddAffinitizedDC( pszNewDCName, pszDomainName ); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VMAFD_SAFE_FREE_MEMORY(pszDomainName); return dwError; error: goto cleanup; }
static DWORD CdcHandleNoDCsAlive( VOID ) { DWORD dwError = 0; PWSTR pszNextDCName = NULL; CDC_DC_STATE cdcNextState = CDC_DC_STATE_NO_DCS_ALIVE; dwError = CdcGetNewDC(&pszNextDCName, &cdcNextState); BAIL_ON_VMAFD_ERROR(dwError); if (cdcNextState != CDC_DC_STATE_NO_DCS_ALIVE) { dwError = CdcUpdateAffinitizedDC( pszNextDCName ); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcStateTransition(cdcNextState); BAIL_ON_VMAFD_ERROR(dwError); } cleanup: VMAFD_SAFE_FREE_MEMORY(pszNextDCName); return dwError; error: goto cleanup; }
static DWORD CdcGetClientSiteName( PWSTR* ppszSiteName ) { DWORD dwError = 0; PWSTR pszSiteName = NULL; if (!ppszSiteName) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = CdcRegDbGetSiteName(&pszSiteName); BAIL_ON_VMAFD_ERROR(dwError); *ppszSiteName = pszSiteName; cleanup: return dwError; error: if (ppszSiteName) { *ppszSiteName = NULL; } VMAFD_SAFE_FREE_MEMORY(pszSiteName); 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); }
static DWORD _VmAfdWriteSuperlogEntryToEventLog( PVMAFD_SUPERLOG_ENTRY superlogEntry ) { DWORD dwError = 0; PCSTR pszDelimiter = "||"; PSTR pszMarshalledEntry = NULL; dwError = VmAfdAllocateStringPrintf( &pszMarshalledEntry, "%u%s%u%s%u%s%lu%s", superlogEntry->dwErrorCode, pszDelimiter, superlogEntry->dwCDCLastPing, pszDelimiter, superlogEntry->iStartTime, pszDelimiter, superlogEntry->iEndTime, pszDelimiter ); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VMAFD_SAFE_FREE_MEMORY(pszMarshalledEntry); return dwError; error: goto cleanup; }
static DWORD VmAfdSrvFlushRoot_SHA_1( PCSTR pszCertificate, PCSTR pszCAPath ) { DWORD dwError = 0; PSTR pszHash = NULL; dwError = VecsComputeCertHash_SHA_1((PSTR)pszCertificate, &pszHash); BAIL_ON_VMAFD_ERROR(dwError); dwError = VmAfdSrvWriteRootToDisk(pszCertificate, pszCAPath, pszHash); BAIL_ON_VMAFD_ERROR(dwError); cleanup: VMAFD_SAFE_FREE_MEMORY(pszHash); return dwError; error: goto cleanup; }
static DWORD ProcessInfo( int argc, char* argv[] ) { DWORD dwError = 0; PSTR pszDomain = NULL; BOOLEAN bIsDC = FALSE; dwError = VmAfdGetJoinStatus(&pszDomain, &bIsDC); if (dwError == ERROR_NOT_JOINED) { dwError = ERROR_SUCCESS; } BAIL_ON_VMAFD_ERROR(dwError); printf("Domain : %s\n", VMAFD_SAFE_STRING(pszDomain)); if (bIsDC) { printf("Domain controller : TRUE\n"); } cleanup: VMAFD_SAFE_FREE_MEMORY(pszDomain); return dwError; error: goto cleanup; }
std::string client::GetCertByAlias( opaque Store, std::string Alias) { DWORD dwError = 0; PSTR pszAlias = NULL; PSTR pszCertificate = NULL; PVECS_STORE pStore = NULL; std::string result; if (Alias.length() <= 0) { dwError = VECS_NO_CERT_FOUND; BAIL_ON_ERROR(dwError); } pStore = (PVECS_STORE)Store; dwError = VecsGetCertificateByAliasA( pStore, (PSTR)Alias.c_str(), &pszCertificate); BAIL_ON_ERROR(dwError); result.assign(pszCertificate); cleanup: VMAFD_SAFE_FREE_MEMORY(pszCertificate); return result; error: THROW_IF_NEEDED(dwError); goto cleanup; }
static DWORD VmAfdCliGetMachineID( PVM_AFD_CLI_CONTEXT pContext ) { DWORD dwError = 0; PSTR pszMachineID = NULL; if (!pContext) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdGetMachineIDA( pContext->pszServerName, &pszMachineID); BAIL_ON_VMAFD_ERROR(dwError); printf("%s\n", pszMachineID); cleanup: VMAFD_SAFE_FREE_MEMORY(pszMachineID); return dwError; error: goto cleanup; }
VOID VmAfdFreeSecurityContextImpl( PVM_AFD_SECURITY_CONTEXT pSecurityContext ) { VMAFD_SAFE_FREE_MEMORY (pSecurityContext); }
static DWORD _VmAfdInitEventLogPublisherThread( PVMAFD_CIRCULAR_BUFFER pCircularBuffer ) { DWORD dwError = 0; PVMSUPERLOG_THREAD_INFO pThrInfo = NULL; dwError = VmAfdAllocateMemory( sizeof(*pThrInfo), (PVOID)&pThrInfo); BAIL_ON_VMAFD_ERROR(dwError); dwError = _VmAfdSrvThrInit(pThrInfo, NULL, NULL, TRUE); BAIL_ON_VMAFD_ERROR(dwError); dwError = _VmAfdCreateThread(&pThrInfo->tid, FALSE, _VmAfdEventLogPublisherThrFun, (PVOID)pCircularBuffer); BAIL_ON_VMAFD_ERROR(dwError); _VmAfdSrvThrAdd(pThrInfo); cleanup: return dwError; error: if (pThrInfo) { VMAFD_SAFE_FREE_MEMORY(pThrInfo); } goto cleanup; }
VOID VecsDbFreeCertEntry( PVECS_DB_CERTIFICATE_ENTRY pCertEntry ) { VecsDbFreeCertEntryContents(pCertEntry); VMAFD_SAFE_FREE_MEMORY(pCertEntry); }
static DWORD GetPassword( PSTR *ppszPassword ) { CHAR pszPasswordBuff[100] = {0}; PSTR pszPassword = NULL; DWORD dwError = 0; struct termios tp, save; fflush(stdout); tcgetattr(0, &tp) ; memcpy (&save, &tp, sizeof (struct termios)); save.c_lflag &= ~ECHO; /* ECHO off, other bits unchanged */ tcsetattr(0, TCSANOW, &save); if (!fgets(pszPasswordBuff, 100, stdin) && ferror(stdin)) { dwError = LwErrnoToWin32Error(ferror(stdin)); BAIL_ON_VMAFD_ERROR (dwError); } if (pszPasswordBuff[strlen(pszPasswordBuff)-1] == '\n') { pszPasswordBuff[strlen(pszPasswordBuff)-1] = '\0'; } dwError = VmAfdAllocateStringPrintf( &pszPassword, "%s", pszPasswordBuff ); BAIL_ON_VMAFD_ERROR (dwError); *ppszPassword = pszPassword; cleanup: tcsetattr(0, TCSANOW, &tp); fflush (stdin); return dwError; error: if (ppszPassword) { *ppszPassword = NULL; } VMAFD_SAFE_FREE_MEMORY (pszPassword); goto cleanup; }
VOID VmAfdFreeConnectionImpl( PVM_AFD_CONNECTION pConnection ) { if (pConnection->fd >= 0){ close(pConnection->fd); } VMAFD_SAFE_FREE_MEMORY (pConnection); }
static VOID VecsDbFreeStmtArray( PVECS_DB_STMT_ARRAY pStmtArray ) { DWORD dwIndx = 0; if (pStmtArray) { for (; dwIndx < pStmtArray->dwCount; dwIndx++) { sqlite3_stmt* pStmtCursor = pStmtArray->pStmtToExecute[dwIndx]; sqlite3_finalize(pStmtCursor); } VMAFD_SAFE_FREE_MEMORY (pStmtArray->pStmtToExecute); } VMAFD_SAFE_FREE_MEMORY (pStmtArray); }
static PVOID ThreadFunction( PVOID pArgs ) { DWORD dwError = ERROR_SUCCESS; PVMAFD_START_ROUTINE pThreadStart = NULL; PVOID pThreadArgs = NULL; union { DWORD dwError; PVOID pvRet; } retVal; memset(&retVal, 0, sizeof(retVal)); if( pArgs == NULL) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } pThreadStart = ((PVMAFD_THREAD_START_INFO)pArgs)->pStartRoutine; pThreadArgs = ((PVMAFD_THREAD_START_INFO)pArgs)->pArgs; if( pThreadStart == NULL ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } VMAFD_SAFE_FREE_MEMORY( pArgs ); dwError = pThreadStart( pThreadArgs ); BAIL_ON_VMAFD_ERROR(dwError); error: VMAFD_SAFE_FREE_MEMORY( pArgs ); retVal.dwError = dwError; return retVal.pvRet; }
static DWORD CdcHandleOffSite( VOID ) { DWORD dwError = 0; PCDC_DC_INFO_W pCdcDCName = NULL; PWSTR pszNextDCName = NULL; BOOL bIsAlive = FALSE; CDC_DC_STATE cdcNextState = CDC_DC_STATE_UNDEFINED; dwError = CdcSrvGetDCName(NULL,&pCdcDCName); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcDbIsDCAlive(pCdcDCName, &bIsAlive); BAIL_ON_VMAFD_ERROR(dwError); dwError = CdcGetNewDC(&pszNextDCName, &cdcNextState); BAIL_ON_VMAFD_ERROR(dwError); switch (cdcNextState) { case CDC_DC_STATE_OFF_SITE: if (bIsAlive) { break; } case CDC_DC_STATE_SITE_AFFINITIZED: dwError = CdcUpdateAffinitizedDC(pszNextDCName); BAIL_ON_VMAFD_ERROR(dwError); break; case CDC_DC_STATE_NO_DCS_ALIVE: break; default: dwError = ERROR_INVALID_STATE; BAIL_ON_VMAFD_ERROR(dwError); } dwError = CdcStateTransition(cdcNextState); BAIL_ON_VMAFD_ERROR(dwError); cleanup: if (pCdcDCName) { VmAfdFreeDomainControllerInfoW(pCdcDCName); } VMAFD_SAFE_FREE_MEMORY(pszNextDCName); return dwError; error: goto cleanup; }
static DWORD VmAfdCopyQueryResultAttributeString( LDAP* pLotus, LDAPMessage* pCAResult, PCSTR pszAttribute, BOOL bOptional, PSTR* ppszOut ) { DWORD dwError = 0; struct berval** ppValues = NULL; PSTR pszOut = NULL; ppValues = ldap_get_values_len( pLotus, pCAResult, pszAttribute); if (ppValues && ppValues[0]) { dwError = VmAfdAllocateMemory( sizeof(CHAR) * ppValues[0]->bv_len + 1, (PVOID)&pszOut); BAIL_ON_VMAFD_ERROR(dwError); memcpy( (PVOID) pszOut, (PVOID) ppValues[0]->bv_val, (size_t) ppValues[0]->bv_len); } else if (!bOptional) { dwError = ERROR_INVALID_DATA; BAIL_ON_VMAFD_ERROR(dwError); } *ppszOut = pszOut; cleanup: if (ppValues) { ldap_value_free_len(ppValues); ppValues = NULL; } return dwError; error: VMAFD_SAFE_FREE_MEMORY(pszOut); if (ppszOut) { *ppszOut = NULL; } goto cleanup; }
DWORD VmAfdOpenServerConnectionImpl( PVM_AFD_CONNECTION *ppConnection ) { DWORD dwError = 0; int socket_fd = -1, on = 1; struct sockaddr_un address = {0}; PVM_AFD_CONNECTION pConnection = NULL; socket_fd = socket(PF_UNIX,SOCK_STREAM, 0); if (socket_fd < 0){ dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMAFD_ERROR(dwError); } if( setsockopt( socket_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) ) < 0){ dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMAFD_ERROR(dwError); } unlink (SOCKET_FILE_PATH); address.sun_family = AF_UNIX; snprintf (address.sun_path, sizeof(SOCKET_FILE_PATH), SOCKET_FILE_PATH); if (bind (socket_fd, (struct sockaddr *)&address, sizeof(struct sockaddr_un)) < 0){ dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMAFD_ERROR(dwError); } if (listen (socket_fd, 5) < 0){ dwError = LwErrnoToWin32Error(errno); BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateMemory(sizeof(VM_AFD_CONNECTION), (PVOID *)&pConnection); BAIL_ON_VMAFD_ERROR(dwError); pConnection->fd = socket_fd; *ppConnection = pConnection; cleanup: return dwError; error: if (ppConnection != NULL){ *ppConnection = NULL; } if (socket_fd >=0 ){ close (socket_fd); } VMAFD_SAFE_FREE_MEMORY (pConnection); goto cleanup; }
void client::SetMachineCert( std::string CertificateFile, std::string PrivateKeyFile) { DWORD dwError = 0; PSTR pszCertificate = NULL; PSTR pszPrivateKey = NULL; if (CertificateFile.length() <= 0) { dwError = VECS_NO_CERT_FOUND; BAIL_ON_ERROR(dwError); } if(PrivateKeyFile.length() <= 0) { dwError = VECS_GENERIC_FILE_IO; BAIL_ON_ERROR(dwError); } dwError = ReadFileContentsToString(CertificateFile.c_str(),&pszCertificate); BAIL_ON_ERROR(dwError); dwError = ReadFileContentsToString(PrivateKeyFile.c_str(), &pszPrivateKey); BAIL_ON_ERROR(dwError); dwError = VmAfdSetSSLCertificate( ServerName.c_str(), pszCertificate, pszPrivateKey); BAIL_ON_ERROR(dwError); cleanup: VMAFD_SAFE_FREE_MEMORY(pszPrivateKey); VMAFD_SAFE_FREE_MEMORY(pszCertificate); return; error: THROW_IF_NEEDED(dwError); goto cleanup; }