VOID VMCAFreeStringW( RP_PWSTR pszString ) { VMCAFreeMemory(pszString); }
DWORD VMCAAllocateMemory( DWORD dwSize, PVOID * ppMemory ) { DWORD dwError = 0; void* pMemory = NULL; if (!ppMemory || !dwSize) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_ERROR(dwError); } pMemory = calloc(1, dwSize); if (!pMemory) { dwError = -2; //ERROR_NO_MEMORY; BAIL_ON_ERROR(dwError); } cleanup: *ppMemory = pMemory; return dwError; error: VMCAFreeMemory(pMemory); pMemory = NULL; goto cleanup; }
VOID VMCAFreeStringA( RP_PSTR pszString ) { VMCAFreeMemory(pszString); }
static VOID VMCASrvFreeDirSyncParams( PVMCA_DIR_SYNC_PARAMS pSyncInfo ) { if (pSyncInfo->pMutex) { pthread_mutex_destroy(&pSyncInfo->mutex); pSyncInfo->pMutex = NULL; } VMCAFreeMemory(pSyncInfo); }
VOID VMCALdapClose( PVMCA_LDAP_CONTEXT pContext ) { if (pContext != NULL) { if (pContext->pConnection != NULL) { ldap_unbind_ext(pContext->pConnection, NULL, NULL); } VMCAFreeMemory(pContext); } }
DWORD ConvertAnsitoUnicodeString( PCSTR pszSrc, PWSTR* ppwszDst ) { DWORD dwError = 0; #ifdef _WIN32 PSTR pszNewString = NULL; #endif if (!pszSrc || !ppwszDst) { dwError = ERROR_INVALID_PARAMETER; } else { #ifdef _WIN32 // allocate space for new string then pass addr to output // double the original PSTR size for WPSTR ULONG srcLen = (ULONG)strlen(pszSrc)+1; ULONG destLen = (srcLen+1)*2; dwError = VMCAAllocateMemory((DWORD) destLen, (PVOID*)&pszNewString); BAIL_ON_ERROR(dwError); if (0 == MultiByteToWideChar(CP_ACP, 0, pszSrc, -1, (LPWSTR)pszNewString, destLen)) { dwError = GetLastError(); BAIL_ON_ERROR(dwError); } *ppwszDst = (LPWSTR)pszNewString; cleanup: return dwError; error: VMCAFreeMemory(pszNewString); goto cleanup; #else dwError = LwNtStatusToWin32Error( LwRtlWC16StringAllocateFromCString(ppwszDst, pszSrc)); #endif } return dwError; }
DWORD ConvertUnicodetoAnsiString( PCWSTR pwszSrc, PSTR* ppszDst ) { DWORD dwError = 0; #ifdef _WIN32 PSTR pszNewString = NULL; #endif if (!pwszSrc || !ppszDst) { dwError = ERROR_INVALID_PARAMETER; } else { #ifdef _WIN32 ULONG srcLen = (ULONG)wcslen(pwszSrc)+1; ULONG destLen = srcLen*2; dwError = VMCAAllocateMemory((DWORD) destLen, (PVOID*)&pszNewString); BAIL_ON_ERROR(dwError); if (0 == WideCharToMultiByte(CP_ACP, 0, pwszSrc, -1, pszNewString, destLen, NULL, NULL )) { dwError = GetLastError(); BAIL_ON_ERROR(dwError); } *ppszDst = pszNewString; cleanup: return dwError; error: VMCAFreeMemory(pszNewString); goto cleanup; #else dwError = LwNtStatusToWin32Error( LwRtlCStringAllocateFromWC16String(ppszDst, pwszSrc)); #endif } return dwError; }
VOID VMCAFreeStringArrayA( PSTR* ppszStrings, DWORD dwCount ) { if (ppszStrings) { DWORD dwCnt = 0; for (dwCnt = 0; dwCnt < dwCount; dwCnt++) { if (ppszStrings[dwCnt]) { VMCAFreeStringA(ppszStrings[dwCnt]); } } VMCAFreeMemory(ppszStrings); } }
DWORD VMCAFreeDBEntryFields( PVMCA_DB_CERTIFICATE_ENTRY pDBEntry ) { DWORD dwError = 0; if(pDBEntry == NULL) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMCA_ERROR(dwError); } if( pDBEntry->pwszCommonName) { VMCAFreeMemory(pDBEntry->pwszCommonName); } if( pDBEntry->pwszAltNames) { VMCAFreeMemory(pDBEntry->pwszAltNames); } if( pDBEntry->pwszOrgName) { VMCAFreeMemory(pDBEntry->pwszOrgName); } if( pDBEntry->pwszOrgUnitName) { VMCAFreeMemory(pDBEntry->pwszOrgUnitName); } if( pDBEntry->pwszIssuerName) { VMCAFreeMemory(pDBEntry->pwszIssuerName); } if(pDBEntry->pwszCountryName) { VMCAFreeMemory(pDBEntry->pwszCountryName); } if( pDBEntry->pwszSerial) { VMCAFreeMemory(pDBEntry->pwszSerial); } if ( pDBEntry->pwszTimeValidFrom){ VMCAFreeMemory(pDBEntry->pwszTimeValidFrom); } if ( pDBEntry->pwszTimeValidTo){ VMCAFreeMemory(pDBEntry->pwszTimeValidTo); } if(pDBEntry->pCertBlob) { VMCAFreeMemory(pDBEntry->pCertBlob); } VMCAFreeMemory(pDBEntry); pDBEntry = NULL; error: return dwError; }
VOID VmcaDbFreeContext( PVMCA_DB_CONTEXT pDbContext ) { while (pDbContext) { PVMCA_DB_CONTEXT pContext = pDbContext; pDbContext = pDbContext->pNext; if (pContext->pAddCertQuery) { sqlite3_finalize(pContext->pAddCertQuery); } if (pContext->pQueryAllCertificates) { sqlite3_finalize(pContext->pQueryAllCertificates); } if (pContext->pQueryCertificatesPaged) { sqlite3_finalize(pContext->pQueryCertificatesPaged); } if (pContext->pQueryRevokedCertificates) { sqlite3_finalize(pContext->pQueryRevokedCertificates); } if (pContext->pTotalCertCountQuery) { sqlite3_finalize(pContext->pTotalCertCountQuery); } if (pContext->pDelCertQuery) { sqlite3_finalize(pContext->pDelCertQuery); } if (pContext->pUpdateCertQuery) { sqlite3_finalize(pContext->pUpdateCertQuery); } if (pContext->pVerifyCertQuery) { sqlite3_finalize(pContext->pVerifyCertQuery); } if (pContext->pGetCertID) { sqlite3_finalize(pContext->pGetCertID); } if (pContext->pRevokeCert) { sqlite3_finalize(pContext->pRevokeCert); } if (pContext->pRevokedCertCount) { sqlite3_finalize(pContext->pRevokedCertCount); } if (pContext->pGetCrlNumber) { sqlite3_finalize(pContext->pGetCrlNumber); } if (pContext->pSetCrlNumber) { sqlite3_finalize(pContext->pSetCrlNumber); } if (pContext->pDb) { VmcaDbDatabaseClose(pContext->pDb); } VMCAFreeMemory(pContext); } }