extern "C" HRESULT DAPI LocLoadFromResource( __in HMODULE hModule, __in_z LPCSTR szResource, __out WIX_LOCALIZATION** ppWixLoc ) { HRESULT hr = S_OK; LPVOID pvResource = NULL; DWORD cbResource = 0; LPWSTR sczXml = NULL; IXMLDOMDocument* pixd = NULL; hr = ResReadData(hModule, szResource, &pvResource, &cbResource); ExitOnFailure(hr, "Failed to read theme from resource."); hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), 0, CP_UTF8); ExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string."); hr = XmlLoadDocument(sczXml, &pixd); ExitOnFailure(hr, "Failed to load theme resource as XML document."); hr = ParseWxl(pixd, ppWixLoc); ExitOnFailure(hr, "Failed to parse WXL."); LExit: ReleaseObject(pixd); ReleaseStr(sczXml); return hr; }
static void CheckLoggingPolicy( __out DWORD *pdwAttributes ) { HRESULT hr = S_OK; HKEY hk = NULL; LPWSTR sczLoggingPolicy = NULL; hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\Installer", KEY_READ, &hk); if (SUCCEEDED(hr)) { hr = RegReadString(hk, L"Logging", &sczLoggingPolicy); if (SUCCEEDED(hr)) { LPCWSTR wz = sczLoggingPolicy; while (*wz) { if (L'v' == *wz || L'V' == *wz) { *pdwAttributes |= BURN_LOGGING_ATTRIBUTE_VERBOSE; } else if (L'x' == *wz || L'X' == *wz) { *pdwAttributes |= BURN_LOGGING_ATTRIBUTE_EXTRADEBUG; } ++wz; } } } ReleaseStr(sczLoggingPolicy); ReleaseRegKey(hk); }
extern "C" UINT __stdcall WixShellExec( __in MSIHANDLE hInstall ) { Assert(hInstall); HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; LPWSTR pwzTarget = NULL; hr = WcaInitialize(hInstall, "WixShellExec"); ExitOnFailure(hr, "failed to initialize"); hr = WcaGetFormattedProperty(L"WixShellExecTarget", &pwzTarget); ExitOnFailure(hr, "failed to get WixShellExecTarget"); WcaLog(LOGMSG_VERBOSE, "WixShellExecTarget is %ls", pwzTarget); if (!pwzTarget || !*pwzTarget) { hr = E_INVALIDARG; ExitOnFailure(hr, "failed to get WixShellExecTarget"); } hr = ShellExec(pwzTarget, FALSE); ExitOnFailure(hr, "failed to launch target"); LExit: ReleaseStr(pwzTarget); if (FAILED(hr)) { er = ERROR_INSTALL_FAILURE; } return WcaFinalize(er); }
static __callback INT_PTR FAR DIAMONDAPI CabExtractOpen(__in_z PSTR pszFile, __in int oflag, __in int pmode) { HRESULT hr = S_OK; INT_PTR pFile = -1; LPWSTR sczCabFile = NULL; // if FDI asks for some unusual mode (in low memory situation it could ask for a scratch file) fail if ((oflag != (/*_O_BINARY*/ 0x8000 | /*_O_RDONLY*/ 0x0000)) || (pmode != (_S_IREAD | _S_IWRITE))) { hr = E_OUTOFMEMORY; ExitOnFailure(hr, "FDI asked for a scratch file to be created, which is unsupported"); } hr = StrAllocStringAnsi(&sczCabFile, pszFile, 0, CP_UTF8); ExitOnFailure(hr, "Failed to convert UTF8 cab file name to wide character string"); pFile = reinterpret_cast<INT_PTR>(::CreateFileW(sczCabFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); if (INVALID_HANDLE_VALUE == reinterpret_cast<HANDLE>(pFile)) { ExitWithLastError1(hr, "failed to open file: %ls", sczCabFile); } if (vdw64EmbeddedOffset) { hr = CabExtractSeek(pFile, 0, 0); ExitOnFailure1(hr, "Failed to seek to embedded offset %I64d", vdw64EmbeddedOffset); } LExit: ReleaseStr(sczCabFile); return FAILED(hr) ? -1 : pFile; }
HRESULT CpiPartitionRolesRead( CPI_PARTITION_LIST* pPartList, CPI_PARTITION_ROLE_LIST* pPartRoleList ) { HRESULT hr = S_OK; PMSIHANDLE hView, hRec; CPI_PARTITION_ROLE* pItm = NULL; LPWSTR pwzData = NULL; // loop through all application roles hr = WcaOpenExecuteView(vcsPartitionRoleQuery, &hView); ExitOnFailure(hr, "Failed to execute view on ComPlusPartitionRole table"); while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) { // create entry pItm = (CPI_PARTITION_ROLE*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_PARTITION_ROLE)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // get key hr = WcaGetRecordString(hRec, prqPartitionRole, &pwzData); ExitOnFailure(hr, "Failed to get key"); StringCchCopyW(pItm->wzKey, countof(pItm->wzKey), pwzData); // get partition hr = WcaGetRecordString(hRec, prqPartition, &pwzData); ExitOnFailure(hr, "Failed to get application"); hr = CpiPartitionFindByKey(pPartList, pwzData, &pItm->pPartition); if (S_FALSE == hr) hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); ExitOnFailure1(hr, "Failed to find partition, key: %S", pwzData); // get name hr = WcaGetRecordFormattedString(hRec, prqName, &pwzData); ExitOnFailure(hr, "Failed to get name"); StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzData); // add entry if (pPartRoleList->pFirst) pItm->pNext = pPartRoleList->pFirst; pPartRoleList->pFirst = pItm; pItm = NULL; } if (E_NOMOREITEMS == hr) hr = S_OK; LExit: // clean up if (pItm) FreePartitionRole(pItm); ReleaseStr(pwzData); return hr; }
static HRESULT RunRunOnce( __in_z_opt LPCWSTR wzCommandLine, __in int nCmdShow ) { HRESULT hr = S_OK; LPWSTR sczNewCommandLine = NULL; LPWSTR sczBurnPath = NULL; HANDLE hProcess = NULL; int argc = 0; LPWSTR* argv = NULL; // rebuild the command line without the runonce switch if (wzCommandLine && *wzCommandLine) { argv = ::CommandLineToArgvW(wzCommandLine, &argc); ExitOnNullWithLastError(argv, hr, "Failed to get command line."); for (int i = 0; i < argc; ++i) { if (!((argv[i][0] == L'-' || argv[i][0] == L'/') && CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, BURN_COMMANDLINE_SWITCH_RUNONCE, -1))) { PathCommandLineAppend(&sczNewCommandLine, argv[i]); } } } // and re-launch hr = PathForCurrentProcess(&sczBurnPath, NULL); ExitOnFailure(hr, "Failed to get current process path."); hr = ProcExec(sczBurnPath, 0 < sczNewCommandLine ? sczNewCommandLine : L"", nCmdShow, &hProcess); ExitOnFailure1(hr, "Failed to re-launch bundle process after RunOnce: %ls", sczBurnPath); LExit: if (argv) { ::LocalFree(argv); } ReleaseHandle(hProcess); ReleaseStr(sczNewCommandLine); ReleaseStr(sczBurnPath); return hr; }
static void FreeUserInApplicationRole( CPI_USER_IN_APPLICATION_ROLE* pItm ) { ReleaseStr(pItm->pwzAccount); ::HeapFree(::GetProcessHeap(), 0, pItm); }
extern "C" void ApprovedExesUninitialize( __in BURN_APPROVED_EXES* pApprovedExes ) { if (pApprovedExes->rgApprovedExes) { for (DWORD i = 0; i < pApprovedExes->cApprovedExes; ++i) { BURN_APPROVED_EXE* pApprovedExe = &pApprovedExes->rgApprovedExes[i]; ReleaseStr(pApprovedExe->sczId); ReleaseStr(pApprovedExe->sczKey); ReleaseStr(pApprovedExe->sczValueName); } MemFree(pApprovedExes->rgApprovedExes); } }
DAPI_(void) BalInfoUninitialize( __in BAL_INFO_BUNDLE* pBundle ) { for (DWORD i = 0; i < pBundle->packages.cPackages; ++i) { ReleaseStr(pBundle->packages.rgPackages[i].sczDisplayName); ReleaseStr(pBundle->packages.rgPackages[i].sczDescription); ReleaseStr(pBundle->packages.rgPackages[i].sczId); } ReleaseMem(pBundle->packages.rgPackages); ReleaseStr(pBundle->sczName); ReleaseStr(pBundle->sczLogVariable); memset(pBundle, 0, sizeof(BAL_INFO_BUNDLE)); }
static void FreePartitionUser( CPI_PARTITION_USER* pItm ) { ReleaseStr(pItm->pwzAccount); ::HeapFree(::GetProcessHeap(), 0, pItm); }
static void FreeUserInPartitionRole( CPI_USER_IN_PARTITION_ROLE* pItm ) { ReleaseStr(pItm->pwzAccount); ::HeapFree(::GetProcessHeap(), 0, pItm); }
/******************************************************************** StrAnsiAllocFormattedArgs - allocates or reuses dynamic ANSI string memory and formats it with the passed in args NOTE: caller is responsible for freeing ppsz even if function fails ********************************************************************/ extern "C" HRESULT DAPI StrAnsiAllocFormattedArgs( __inout LPSTR* ppsz, __in LPCSTR szFormat, __in va_list args ) { Assert(ppsz && szFormat && *szFormat); HRESULT hr = S_OK; DWORD_PTR cch = *ppsz ? MemSize(*ppsz) / sizeof(CHAR) : 0; LPSTR pszOriginal = NULL; DWORD cchOriginal = 0; if (*ppsz) { cch = MemSize(*ppsz); // get the count in bytes so we can check if it failed (returns -1) if (-1 == cch) ExitOnFailure(hr = E_INVALIDARG, "failed to get size of destination string"); cch /= sizeof(CHAR); //convert the count in bytes to count in characters cchOriginal = lstrlenA(*ppsz); } if (0 == cch) // if there is no space in the string buffer { cch = 256; hr = StrAnsiAlloc(ppsz, cch); ExitOnFailure1(hr, "failed to allocate string to format: %s", szFormat); } // format the message (grow until it fits or there is a failure) do { hr = StringCchVPrintfA(*ppsz, cch, szFormat, args); if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) { if (!pszOriginal) { // this allows you to pass the original string as a formatting argument and not crash // save the original string and free it after the printf is complete pszOriginal = *ppsz; *ppsz = NULL; // StringCchVPrintfW starts writing to the string... // NOTE: this hack only works with sprintf(&pwz, "%s ...", pwz, ...); pszOriginal[cchOriginal] = 0; } cch *= 2; hr = StrAnsiAlloc(ppsz, cch); ExitOnFailure1(hr, "failed to allocate string to format: %S", szFormat); hr = S_FALSE; } } while (S_FALSE == hr); ExitOnFailure(hr, "failed to format string"); LExit: ReleaseStr((void*) pszOriginal); return hr; }
HRESULT ScaVirtualDirsUninstall7( __in SCA_VDIR7* psvdList ) { HRESULT hr = S_OK; SCA_VDIR7* psvd = psvdList; LPWSTR wzPath = NULL; while (psvd) { if (WcaIsUninstalling(psvd->isInstalled, psvd->isAction)) { //init path hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); ExitOnFailure(hr, "Failed to create vdir path"); if (psvd->fHasApplication) { //delete Application hr = ScaWriteConfigID(IIS_APPLICATION); ExitOnFailure(hr, "Failed to write app ID "); hr = ScaWriteConfigID(IIS_DELETE); ExitOnFailure(hr, "Failed to write delete app ID "); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzWebName); //site name key ExitOnFailure(hr, "Failed to write App site Name"); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(wzPath); // App Path ExitOnFailure(hr, "Failed to write app path root "); hr = ScaWriteConfigString(L"NOP"); // App pool ExitOnFailure(hr, "Failed to write app path app pool "); } else { //delete VDir hr = ScaWriteConfigID(IIS_VDIR); ExitOnFailure(hr, "Failed to write vDir ID "); hr = ScaWriteConfigID(IIS_DELETE); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzWebName); //site name key ExitOnFailure(hr, "Failed to write App site Name"); hr = ScaWriteConfigString(wzPath); // Vdir Path ExitOnFailure(hr, "Failed to write app vdir "); hr = ScaWriteConfigString(L"NOP"); // Phy Path ExitOnFailure(hr, "Failed to write vdir path"); } ExitOnFailure(hr, "Failed to remove VirtualDir '%ls' from config", psvd->wzKey); } psvd = psvd->psvdNext; } LExit: ReleaseStr(wzPath); return hr; }
/****************************************************************** WixRollbackInternetShortcuts - entry point for Internet shortcuts custom action (rollback) *******************************************************************/ extern "C" UINT __stdcall WixRollbackInternetShortcuts( __in MSIHANDLE hInstall ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; LPWSTR pwz = NULL; LPWSTR pwzCustomActionData = NULL; LPWSTR pwzShortcutPath = NULL; int iAttr = 0; // initialize hr = WcaInitialize(hInstall, "WixRemoveInternetShortcuts"); ExitOnFailure(hr, "failed to initialize WixRemoveInternetShortcuts"); hr = WcaGetProperty(L"CustomActionData", &pwzCustomActionData); ExitOnFailure(hr, "failed to get CustomActionData"); // loop through all the custom action data pwz = pwzCustomActionData; while (pwz && *pwz) { // extract the custom action data we're interested in hr = WcaReadStringFromCaData(&pwz, &pwzShortcutPath); ExitOnFailure(hr, "failed to read shortcut path from custom action data for rollback"); // delete file hr = FileEnsureDelete(pwzShortcutPath); ExitOnFailure1(hr, "failed to delete file '%ls'", pwzShortcutPath); // skip over the shortcut target and attributes hr = WcaReadStringFromCaData(&pwz, &pwzShortcutPath); ExitOnFailure(hr, "failed to skip shortcut target from custom action data for rollback"); hr = WcaReadIntegerFromCaData(&pwz, &iAttr); ExitOnFailure(hr, "failed to read shortcut attributes from custom action data"); } LExit: ReleaseStr(pwzCustomActionData); ReleaseStr(pwzShortcutPath); er = FAILED(hr) ? ERROR_INSTALL_FAILURE : er; return WcaFinalize(er); }
extern "C" void PayloadsUninitialize( __in BURN_PAYLOADS* pPayloads ) { if (pPayloads->rgPayloads) { for (DWORD i = 0; i < pPayloads->cPayloads; ++i) { BURN_PAYLOAD* pPayload = &pPayloads->rgPayloads[i]; ReleaseStr(pPayload->sczKey); ReleaseStr(pPayload->sczFilePath); ReleaseMem(pPayload->pbHash); ReleaseMem(pPayload->pbCertificateRootThumbprint); ReleaseMem(pPayload->pbCertificateRootPublicKeyIdentifier); ReleaseStr(pPayload->sczSourcePath); ReleaseStr(pPayload->sczLocalFilePath); ReleaseStr(pPayload->downloadSource.sczUrl); ReleaseStr(pPayload->downloadSource.sczUser); ReleaseStr(pPayload->downloadSource.sczPassword); } MemFree(pPayloads->rgPayloads); } // clear struct memset(pPayloads, 0, sizeof(BURN_PAYLOADS)); }
DAPI_(void) JsonUninitializeReader( __in JSON_READER* pReader ) { ReleaseStr(pReader->sczJson); ::DeleteCriticalSection(&pReader->cs); memset(pReader, 0, sizeof(JSON_READER)); }
static HRESULT AuthenticationRequired( __in BURN_USER_EXPERIENCE* pUX, __in_z LPCWSTR wzPackageOrContainerId, __in_z LPCWSTR /*wzPayloadId*/, __in HINTERNET hUrl, __in long lHttpCode, __out BOOL* pfRetrySend, __out BOOL* pfRetry ) { Assert(401 == lHttpCode || 407 == lHttpCode); HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; BOOTSTRAPPER_ERROR_TYPE errorType = (401 == lHttpCode) ? BOOTSTRAPPER_ERROR_TYPE_HTTP_AUTH_SERVER : BOOTSTRAPPER_ERROR_TYPE_HTTP_AUTH_PROXY; LPWSTR sczError = NULL; *pfRetrySend = FALSE; *pfRetry = FALSE; hr = StrAllocFromError(&sczError, HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), NULL); ExitOnFailure(hr, "Failed to allocation error string."); int nResult = pUX->pUserExperience->OnError(errorType, wzPackageOrContainerId, ERROR_ACCESS_DENIED, sczError, MB_RETRYTRYAGAIN, 0, NULL, IDNOACTION); nResult = UserExperienceCheckExecuteResult(pUX, FALSE, MB_RETRYTRYAGAIN, nResult); if (IDTRYAGAIN == nResult && pUX->hwndApply) { er = ::InternetErrorDlg(pUX->hwndApply, hUrl, ERROR_INTERNET_INCORRECT_PASSWORD, FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA, NULL); if (ERROR_SUCCESS == er || ERROR_CANCELLED == er) { hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT); } else if (ERROR_INTERNET_FORCE_RETRY == er) { *pfRetrySend = TRUE; hr = S_OK; } else { hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); } } else if (IDRETRY == nResult) { *pfRetry = TRUE; hr = S_OK; } else { hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); } LExit: ReleaseStr(sczError); return hr; }
extern "C" HRESULT CatalogsParseFromXml( __in BURN_CATALOGS* pCatalogs, __in IXMLDOMNode* pixnBundle ) { HRESULT hr = S_OK; IXMLDOMNodeList* pixnNodes = NULL; IXMLDOMNode* pixnNode = NULL; DWORD cNodes = 0; LPWSTR scz = NULL; // select catalog nodes hr = XmlSelectNodes(pixnBundle, L"Catalog", &pixnNodes); ExitOnFailure(hr, "Failed to select catalog nodes."); // get catalog node count hr = pixnNodes->get_length((long*)&cNodes); ExitOnFailure(hr, "Failed to get payload node count."); if (!cNodes) { ExitFunction(); } // allocate memory for catalogs pCatalogs->rgCatalogs = (BURN_CATALOG*)MemAlloc(sizeof(BURN_CATALOG) * cNodes, TRUE); ExitOnNull(pCatalogs->rgCatalogs, hr, E_OUTOFMEMORY, "Failed to allocate memory for payload structs."); pCatalogs->cCatalogs = cNodes; // parse catalog elements for (DWORD i = 0; i < cNodes; ++i) { BURN_CATALOG* pCatalog = &pCatalogs->rgCatalogs[i]; pCatalog->hFile = INVALID_HANDLE_VALUE; hr = XmlNextElement(pixnNodes, &pixnNode, NULL); ExitOnFailure(hr, "Failed to get next node."); // @Id hr = XmlGetAttributeEx(pixnNode, L"Id", &pCatalog->sczKey); ExitOnFailure(hr, "Failed to get @Id."); // @Payload hr = XmlGetAttributeEx(pixnNode, L"Payload", &pCatalog->sczPayload); ExitOnFailure(hr, "Failed to get @Payload."); // prepare next iteration ReleaseNullObject(pixnNode); } LExit: ReleaseObject(pixnNodes); ReleaseObject(pixnNode); ReleaseStr(scz); return hr; }
extern "C" void UpdateUninitialize( __in BURN_UPDATE* pUpdate ) { PackageUninitialize(&pUpdate->package); ReleaseStr(pUpdate->sczUpdateSource); memset(pUpdate, 0, sizeof(BURN_UPDATE)); }
static HRESULT BeginChangeFile( __in LPCWSTR pwzFile, __in int iCompAttributes, __inout LPWSTR* ppwzCustomActionData ) { Assert(pwzFile && *pwzFile && ppwzCustomActionData); HRESULT hr = S_OK; BOOL fIs64Bit = iCompAttributes & msidbComponentAttributes64bit; LPBYTE pbData = NULL; DWORD cbData = 0; LPWSTR pwzRollbackCustomActionData = NULL; if (fIs64Bit) { hr = WcaWriteIntegerToCaData((int)xaOpenFilex64, ppwzCustomActionData); ExitOnFailure(hr, "failed to write 64-bit file indicator to custom action data"); } else { hr = WcaWriteIntegerToCaData((int)xaOpenFile, ppwzCustomActionData); ExitOnFailure(hr, "failed to write file indicator to custom action data"); } hr = WcaWriteStringToCaData(pwzFile, ppwzCustomActionData); ExitOnFailure1(hr, "failed to write file to custom action data: %ls", pwzFile); // If the file already exits, then we have to put it back the way it was on failure if (FileExistsEx(pwzFile, NULL)) { hr = FileRead(&pbData, &cbData, pwzFile); ExitOnFailure1(hr, "failed to read file: %ls", pwzFile); // Set up the rollback for this file hr = WcaWriteIntegerToCaData((int)fIs64Bit, &pwzRollbackCustomActionData); ExitOnFailure(hr, "failed to write component bitness to rollback custom action data"); hr = WcaWriteStringToCaData(pwzFile, &pwzRollbackCustomActionData); ExitOnFailure1(hr, "failed to write file name to rollback custom action data: %ls", pwzFile); hr = WcaWriteStreamToCaData(pbData, cbData, &pwzRollbackCustomActionData); ExitOnFailure(hr, "failed to write file contents to rollback custom action data."); hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"ExecXmlConfigRollback"), pwzRollbackCustomActionData, COST_XMLFILE); ExitOnFailure1(hr, "failed to schedule ExecXmlConfigRollback for file: %ls", pwzFile); ReleaseStr(pwzRollbackCustomActionData); } LExit: ReleaseMem(pbData); return hr; }
CMyString& CMyString::MyStrCpy(const CMyString& obj) { ReleaseStr(); m_szBuf = obj.m_szBuf; m_nSize = obj.m_nSize; m_nStrLen = obj.m_nStrLen; m_pCount = obj.m_pCount; (*m_pCount)++; return *this; }
/******************************************************************** SqlSessionCreateDatabase - creates a database on the server NOTE: pidbSession must be connected to the master database ********************************************************************/ extern "C" HRESULT DAPI SqlSessionCreateDatabase( __in IDBCreateSession* pidbSession, __in_z LPCWSTR wzDatabase, __in_opt const SQL_FILESPEC* psfDatabase, __in_opt const SQL_FILESPEC* psfLog, __out_opt BSTR* pbstrErrorDescription ) { HRESULT hr = S_OK; LPWSTR pwzDbFile = NULL; LPWSTR pwzLogFile = NULL; LPWSTR pwzQuery = NULL; LPWSTR pwzDatabaseEscaped = NULL; if (psfDatabase) { hr = FileSpecToString(psfDatabase, &pwzDbFile); ExitOnFailure(hr, "failed to convert db filespec to string"); } if (psfLog) { hr = FileSpecToString(psfLog, &pwzLogFile); ExitOnFailure(hr, "failed to convert log filespec to string"); } hr = EscapeSqlIdentifier(wzDatabase, &pwzDatabaseEscaped); ExitOnFailure(hr, "failed to escape database string"); hr = StrAllocFormatted(&pwzQuery, L"CREATE DATABASE %s %s%s %s%s", pwzDatabaseEscaped, pwzDbFile ? L"ON " : L"", pwzDbFile ? pwzDbFile : L"", pwzLogFile ? L"LOG ON " : L"", pwzLogFile ? pwzLogFile : L""); ExitOnFailure1(hr, "failed to allocate query to create database: %ls", pwzDatabaseEscaped); hr = SqlSessionExecuteQuery(pidbSession, pwzQuery, NULL, NULL, pbstrErrorDescription); ExitOnFailure2(hr, "failed to create database: %ls, Query: %ls", pwzDatabaseEscaped, pwzQuery); LExit: ReleaseStr(pwzQuery); ReleaseStr(pwzLogFile); ReleaseStr(pwzDbFile); ReleaseStr(pwzDatabaseEscaped); return hr; }
DAPI_(void) JsonUninitializeWriter( __in JSON_WRITER* pWriter ) { ReleaseMem(pWriter->rgTokenStack); ReleaseStr(pWriter->sczJson); ::DeleteCriticalSection(&pWriter->cs); memset(pWriter, 0, sizeof(JSON_WRITER)); }
extern "C" HRESULT WINAPI UpdateThreadCheck( __in LPCWSTR wzAppId, __in BOOL fTryExecuteUpdate ) { HRESULT hr = S_OK; BOOL fLocked = FALSE; BACKGROUND_UPDATE_THREAD_CONTEXT* pContext = NULL; ::EnterCriticalSection(&vUpdateThreadLock); fLocked = TRUE; if (vhUpdateThread) { DWORD er = ::WaitForSingleObject(vhUpdateThread, 0); if (WAIT_OBJECT_0 == er) { ::CloseHandle(vhUpdateThread); vhUpdateThread = NULL; } else { hr = S_FALSE; ExitFunction(); } } pContext = static_cast<BACKGROUND_UPDATE_THREAD_CONTEXT*>(MemAlloc(sizeof(BACKGROUND_UPDATE_THREAD_CONTEXT), TRUE)); ExitOnNull(pContext, hr, E_OUTOFMEMORY, "Failed to allocate memory for context."); hr= StrAllocString(&pContext->pwzApplicationId, wzAppId, 0); ExitOnFailure(hr, "Failed to copy app id into context."); pContext->fExecuteUpdate = fTryExecuteUpdate; vhUpdateThread = ::CreateThread(NULL, 0, BackgroundUpdateThread, reinterpret_cast<LPVOID>(pContext), 0, NULL); ExitOnNullWithLastError(vhUpdateThread, hr, "Failed to create background update thread."); pContext = NULL; LExit: if (pContext) { ReleaseStr(pContext->pwzApplicationId); MemFree(pContext); } if (fLocked) { ::LeaveCriticalSection(&vUpdateThreadLock); } return hr; }
HRESULT CpiReadPropertyList( LPWSTR* ppwzData, CPI_PROPERTY** ppPropList ) { HRESULT hr = S_OK; CPI_PROPERTY* pItm = NULL; LPWSTR pwzName = NULL; // clear list if it already contains items if (*ppPropList) CpiFreePropertyList(*ppPropList); *ppPropList = NULL; // read property count int iPropCnt = 0; hr = WcaReadIntegerFromCaData(ppwzData, &iPropCnt); ExitOnFailure(hr, "Failed to read property count"); for (int i = 0; i < iPropCnt; i++) { // allocate new element pItm = (CPI_PROPERTY*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_PROPERTY)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // Name hr = WcaReadStringFromCaData(ppwzData, &pwzName); ExitOnFailure(hr, "Failed to read name"); StringCchCopyW(pItm->wzName, countof(pItm->wzName), pwzName); // Value hr = WcaReadStringFromCaData(ppwzData, &pItm->pwzValue); ExitOnFailure(hr, "Failed to read property value"); // add to list if (*ppPropList) pItm->pNext = *ppPropList; *ppPropList = pItm; pItm = NULL; } hr = S_OK; LExit: // clean up ReleaseStr(pwzName); if (pItm) CpiFreePropertyList(pItm); return hr; }
extern "C" void CatalogUninitialize( __in BURN_CATALOGS* pCatalogs ) { if (pCatalogs->rgCatalogs) { for (DWORD i = 0; i < pCatalogs->cCatalogs; ++i) { BURN_CATALOG* pCatalog = &pCatalogs->rgCatalogs[i]; ReleaseHandle(pCatalog->hFile); ReleaseStr(pCatalog->sczKey); ReleaseStr(pCatalog->sczLocalFilePath); ReleaseStr(pCatalog->sczPayload); } MemFree(pCatalogs->rgCatalogs); } // clear struct memset(pCatalogs, 0, sizeof(BURN_CATALOGS)); }
void CpiPropertiesFreeList( CPI_PROPERTY* pList ) { while (pList) { ReleaseStr(pList->pwzValue); CPI_PROPERTY* pDelete = pList; pList = pList->pNext; ::HeapFree(::GetProcessHeap(), 0, pDelete); } }
HRESULT MqiMessageQueueVerify( MQI_MESSAGE_QUEUE_LIST* pList ) { HRESULT hr = S_OK; LPWSTR pwzFormatName = NULL; DWORD dwCount = 128; for (MQI_MESSAGE_QUEUE* pItm = pList->pFirst; pItm; pItm = pItm->pNext) { // queues that are being installed only if (!WcaIsInstalling(pItm->isInstalled, pItm->isAction)) continue; // get format name hr = StrAlloc(&pwzFormatName, dwCount); ExitOnFailure(hr, "Failed to allocate format name string"); do { hr = gpfnMQPathNameToFormatName(pItm->wzPathName, pwzFormatName, &dwCount); switch (hr) { case MQ_ERROR_QUEUE_NOT_FOUND: break; // break case MQ_ERROR_FORMATNAME_BUFFER_TOO_SMALL: hr = StrAlloc(&pwzFormatName, dwCount); ExitOnFailure(hr, "Failed to reallocate format name string"); hr = S_FALSE; // retry break; default: ExitOnFailure(hr, "Failed to get format name"); hr = S_OK; } } while (S_FALSE == hr); if (MQ_ERROR_QUEUE_NOT_FOUND == hr) { continue; } pItm->fExists = TRUE; pList->iInstallCount--; // clean up ReleaseNullStr(pwzFormatName); } hr = S_OK; LExit: ReleaseStr(pwzFormatName); return hr; }
void CfgTest::RedirectDatabases() { HRESULT hr = S_OK; LPWSTR sczPathUser = NULL; LPWSTR sczPathLegacy = NULL; LPWSTR sczPathAdmin = NULL; // Override user DB directory hr = PathExpand(&sczPathUser, L"%TEMP%\\TestUserDb\\", PATH_EXPAND_ENVIRONMENT); ExitOnFailure(hr, "Failed to expand path"); hr = DirEnsureDelete(sczPathUser, TRUE, TRUE); if (E_PATHNOTFOUND == hr) { hr = S_OK; } ExitOnFailure1(hr, "Failed to ensure directory %ls is deleted", sczPathUser); TestHookOverrideUserDatabasePath(L"%TEMP%\\TestUserDb\\"); // Override legacy DB directory hr = PathExpand(&sczPathAdmin, L"%TEMP%\\TestAdminDb\\", PATH_EXPAND_ENVIRONMENT); ExitOnFailure(hr, "Failed to expand path"); hr = DirEnsureDelete(sczPathAdmin, TRUE, TRUE); if (E_PATHNOTFOUND == hr) { hr = S_OK; } ExitOnFailure1(hr, "Failed to ensure directory %ls is deleted", sczPathAdmin); TestHookOverrideAdminDatabasePath(L"%TEMP%\\TestAdminDb\\"); LExit: ReleaseStr(sczPathUser); ReleaseStr(sczPathLegacy); ReleaseStr(sczPathAdmin); }
static HRESULT OpenRequest( __in HINTERNET hConnect, __in_z_opt LPCWSTR wzMethod, __in INTERNET_SCHEME scheme, __in_z LPCWSTR wzResource, __in_z_opt LPCWSTR wzQueryString, __in_z_opt LPCWSTR wzHeader, __out HINTERNET* phUrl ) { HRESULT hr = S_OK; DWORD dwRequestFlags = INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_RELOAD; LPWSTR sczResource = NULL; HINTERNET hUrl = NULL; if (INTERNET_SCHEME_HTTPS == scheme) { dwRequestFlags |= INTERNET_FLAG_SECURE; } // Allocate the resource name. hr = StrAllocString(&sczResource, wzResource, 0); ExitOnFailure(hr, "Failed to allocate string for resource URI."); if (wzQueryString && *wzQueryString) { hr = StrAllocConcat(&sczResource, wzQueryString, 0); ExitOnFailure(hr, "Failed to append query strong to resource from URI."); } // Open the request and add the header if provided. hUrl = ::HttpOpenRequestW(hConnect, wzMethod, sczResource, NULL, NULL, BURN_DOWNLOAD_ENGINE_ACCEPT_TYPES, dwRequestFlags, NULL); ExitOnNullWithLastError(hUrl, hr, "Failed to open internet request."); if (wzHeader && *wzHeader) { if (!::HttpAddRequestHeadersW(hUrl, wzHeader, static_cast<DWORD>(-1), HTTP_ADDREQ_FLAG_COALESCE)) { ExitWithLastError(hr, "Failed to add header to HTTP request."); } } *phUrl = hUrl; hUrl = NULL; LExit: ReleaseInternet(hUrl); ReleaseStr(sczResource); return hr; }