DAPI_(HRESULT) PathDirectoryContainsPath( __in_z LPCWSTR wzDirectory, __in_z LPCWSTR wzPath ) { HRESULT hr = S_OK; LPWSTR sczPath = NULL; LPWSTR sczDirectory = NULL; LPWSTR sczOriginalPath = NULL; LPWSTR sczOriginalDirectory = NULL; hr = PathCanonicalizePath(wzPath, &sczOriginalPath); ExitOnFailure(hr, "Failed to canonicalize the path."); hr = PathCanonicalizePath(wzDirectory, &sczOriginalDirectory); ExitOnFailure(hr, "Failed to canonicalize the directory."); if (!sczOriginalPath || !*sczOriginalPath) { ExitFunction1(hr = S_FALSE); } if (!sczOriginalDirectory || !*sczOriginalDirectory) { ExitFunction1(hr = S_FALSE); } sczPath = sczOriginalPath; sczDirectory = sczOriginalDirectory; for (; *sczDirectory;) { if (!*sczPath) { ExitFunction1(hr = S_FALSE); } if (CSTR_EQUAL != ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, sczDirectory, 1, sczPath, 1)) { ExitFunction1(hr = S_FALSE); } ++sczDirectory; ++sczPath; } --sczDirectory; if (('\\' == *sczDirectory && *sczPath) || '\\' == *sczPath) { hr = S_OK; } else { hr = S_FALSE; } LExit: ReleaseStr(sczOriginalPath); ReleaseStr(sczOriginalDirectory); return hr; }
static HRESULT ReadFileAll( HANDLE hFile, PBYTE pbBuffer, DWORD dwBufferLength ) { HRESULT hr = S_OK; DWORD dwBytesRead; while (dwBufferLength) { if (!::ReadFile(hFile, pbBuffer, dwBufferLength, &dwBytesRead, NULL)) ExitFunction1(hr = HRESULT_FROM_WIN32(::GetLastError())); if (0 == dwBytesRead) ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_HANDLE_EOF)); dwBufferLength -= dwBytesRead; pbBuffer += dwBytesRead; } hr = S_OK; LExit: return hr; }
extern "C" HRESULT DAPI PolcReadNumber( __in_z LPCWSTR wzPolicyPath, __in_z LPCWSTR wzPolicyName, __in DWORD dwDefault, __out DWORD* pdw ) { HRESULT hr = S_OK; HKEY hk = NULL; hr = OpenPolicyKey(wzPolicyPath, &hk); if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { ExitFunction1(hr = S_FALSE); } ExitOnFailure1(hr, "Failed to open policy key: %ls", wzPolicyPath); hr = RegReadNumber(hk, wzPolicyName, pdw); if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { ExitFunction1(hr = S_FALSE); } ExitOnFailure2(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); LExit: ReleaseRegKey(hk); if (S_FALSE == hr || FAILED(hr)) { *pdw = dwDefault; } return hr; }
/****************************************************************** GetCurrentFirewallProfile - get the active firewall profile as an INetFwProfile, which owns the lists of exceptions we're updating. ********************************************************************/ static HRESULT GetCurrentFirewallProfile( __in BOOL fIgnoreFailures, __out INetFwProfile** ppfwProfile ) { HRESULT hr = S_OK; INetFwMgr* pfwMgr = NULL; INetFwPolicy* pfwPolicy = NULL; INetFwProfile* pfwProfile = NULL; *ppfwProfile = NULL; do { ReleaseNullObject(pfwPolicy); ReleaseNullObject(pfwMgr); ReleaseNullObject(pfwProfile); if (SUCCEEDED(hr = ::CoCreateInstance(__uuidof(NetFwMgr), NULL, CLSCTX_INPROC_SERVER, __uuidof(INetFwMgr), (void**)&pfwMgr)) && SUCCEEDED(hr = pfwMgr->get_LocalPolicy(&pfwPolicy)) && SUCCEEDED(hr = pfwPolicy->get_CurrentProfile(&pfwProfile))) { break; } else if (fIgnoreFailures) { ExitFunction1(hr = S_FALSE); } else { WcaLog(LOGMSG_STANDARD, "Failed to connect to Windows Firewall"); UINT er = WcaErrorMessage(msierrFirewallCannotConnect, hr, INSTALLMESSAGE_ERROR | MB_ABORTRETRYIGNORE, 0); switch (er) { case IDABORT: // exit with the current HRESULT ExitFunction(); case IDRETRY: // clean up and retry the loop hr = S_FALSE; break; case IDIGNORE: // pass S_FALSE back to the caller, who knows how to ignore the failure ExitFunction1(hr = S_FALSE); default: // No UI, so default is to fail. ExitFunction(); } } } while (S_FALSE == hr); *ppfwProfile = pfwProfile; pfwProfile = NULL; LExit: ReleaseObject(pfwPolicy); ReleaseObject(pfwMgr); ReleaseObject(pfwProfile); return hr; }
HRESULT CpiReadRollbackDataList( HANDLE hFile, CPI_ROLLBACK_DATA** pprdList ) { HRESULT hr = S_OK; int iCount; CPI_ROLLBACK_DATA* pItm = NULL; // read count hr = ReadFileAll(hFile, (PBYTE)&iCount, sizeof(int)); if (HRESULT_FROM_WIN32(ERROR_HANDLE_EOF) == hr) ExitFunction1(hr = S_OK); // EOF reached, nothing left to read ExitOnFailure(hr, "Failed to read count"); for (int i = 0; i < iCount; i++) { // allocate new element pItm = (CPI_ROLLBACK_DATA*)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CPI_ROLLBACK_DATA)); if (!pItm) ExitFunction1(hr = E_OUTOFMEMORY); // read from file hr = ReadFileAll(hFile, (PBYTE)pItm->wzKey, MAX_DARWIN_KEY * sizeof(WCHAR)); if (HRESULT_FROM_WIN32(ERROR_HANDLE_EOF) == hr) break; // EOF reached, nothing left to read ExitOnFailure(hr, "Failed to read key"); hr = ReadFileAll(hFile, (PBYTE)&pItm->iStatus, sizeof(int)); if (HRESULT_FROM_WIN32(ERROR_HANDLE_EOF) == hr) pItm->iStatus = 0; // EOF reached, the operation was interupted; set status to zero else ExitOnFailure(hr, "Failed to read status"); // add to list if (*pprdList) pItm->pNext = *pprdList; *pprdList = pItm; pItm = NULL; } hr = S_OK; LExit: // clean up if (pItm) CpiFreeRollbackDataList(pItm); return hr; }
static HRESULT RemoveApplicationRole( CPI_APPLICATION_ROLE_ATTRIBUTES* pAttrs ) { HRESULT hr = S_OK; ICatalogCollection* piRolesColl = NULL; long lChanges = 0; // log WcaLog(LOGMSG_VERBOSE, "Removing application role, key: %S", pAttrs->pwzKey); // get roles collection hr = CpiGetRolesCollection(pAttrs->pwzPartID, pAttrs->pwzAppID, &piRolesColl); ExitOnFailure(hr, "Failed to get roles collection"); if (S_FALSE == hr) { // roles collection not found WcaLog(LOGMSG_VERBOSE, "Unable to retrieve roles collection, nothing to delete, key: %S", pAttrs->pwzKey); ExitFunction1(hr = S_OK); } // remove hr = CpiRemoveCollectionObject(piRolesColl, NULL, pAttrs->pwzName, FALSE); ExitOnFailure(hr, "Failed to remove role"); if (S_FALSE == hr) { // role not found WcaLog(LOGMSG_VERBOSE, "Role not found, nothing to delete, key: %S", pAttrs->pwzKey); ExitFunction1(hr = S_OK); } // save changes hr = piRolesColl->SaveChanges(&lChanges); if (COMADMIN_E_OBJECTERRORS == hr) CpiLogCatalogErrorInfo(); ExitOnFailure(hr, "Failed to save changes"); // log WcaLog(LOGMSG_VERBOSE, "%d changes saved to catalog, key: %S", lChanges, pAttrs->pwzKey); hr = S_OK; LExit: // clean up ReleaseObject(piRolesColl); return hr; }
DAPI_(HRESULT) SrpCreateRestorePoint( __in_z LPCWSTR wzApplicationName, __in SRP_ACTION action ) { HRESULT hr = S_OK; RESTOREPOINTINFOW restorePoint = { }; STATEMGRSTATUS status = { }; if (!vpfnSRSetRestorePointW) { ExitFunction1(hr = E_NOTIMPL); } restorePoint.dwEventType = BEGIN_SYSTEM_CHANGE; restorePoint.dwRestorePtType = (SRP_ACTION_INSTALL == action) ? APPLICATION_INSTALL : (SRP_ACTION_UNINSTALL == action) ? APPLICATION_UNINSTALL : MODIFY_SETTINGS; ::StringCbCopyW(restorePoint.szDescription, sizeof(restorePoint.szDescription), wzApplicationName); if (!vpfnSRSetRestorePointW(&restorePoint, &status)) { ExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point."); } LExit: return hr; }
extern "C" HRESULT ApprovedExesFindById( __in BURN_APPROVED_EXES* pApprovedExes, __in_z LPCWSTR wzId, __out BURN_APPROVED_EXE** ppApprovedExe ) { HRESULT hr = S_OK; BURN_APPROVED_EXE* pApprovedExe = NULL; for (DWORD i = 0; i < pApprovedExes->cApprovedExes; ++i) { pApprovedExe = &pApprovedExes->rgApprovedExes[i]; if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pApprovedExe->sczId, -1, wzId, -1)) { *ppApprovedExe = pApprovedExe; ExitFunction1(hr = S_OK); } } hr = E_NOTFOUND; LExit: return hr; }
/******************************************************************** StrMaxLength - returns maximum number of characters that can be stored in dynamic string p NOTE: assumes Unicode string ********************************************************************/ extern "C" HRESULT DAPI StrMaxLength( __in LPVOID p, __out DWORD_PTR* pcch ) { Assert(pcch); HRESULT hr = S_OK; if (p) { *pcch = MemSize(p); // get size of entire buffer if (-1 == *pcch) { ExitFunction1(hr = E_FAIL); } *pcch /= sizeof(WCHAR); // reduce to count of characters } else { *pcch = 0; } Assert(S_OK == hr); LExit: return hr; }
/******************************************************************** ConfigureSmb - CUSTOM ACTION ENTRY POINT for installing fileshare settings ********************************************************************/ extern "C" UINT __stdcall ConfigureSmbUninstall( __in MSIHANDLE hInstall ) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; SCA_SMB* pssList = NULL; // initialize hr = WcaInitialize(hInstall, "ConfigureSmbUninstall"); ExitOnFailure(hr, "Failed to initialize"); // check to see if necessary tables are specified if (WcaTableExists(L"FileShare") != S_OK) { WcaLog(LOGMSG_VERBOSE, "Skipping SMB CustomAction, no FileShare table"); ExitFunction1(hr = S_FALSE); } hr = ScaSmbRead(&pssList); ExitOnFailure(hr, "failed to read FileShare table"); hr = ScaSmbUninstall(pssList); ExitOnFailure(hr, "failed to uninstall FileShares"); LExit: if (pssList) ScaSmbFreeList(pssList); er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
static HRESULT FindEmbeddedBySourcePath( __in BURN_PAYLOADS* pPayloads, __in_opt BURN_CONTAINER* pContainer, __in_z LPCWSTR wzStreamName, __out BURN_PAYLOAD** ppPayload ) { HRESULT hr = S_OK; for (DWORD i = 0; i < pPayloads->cPayloads; ++i) { BURN_PAYLOAD* pPayload = &pPayloads->rgPayloads[i]; if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging && (!pContainer || pPayload->pContainer == pContainer)) { if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pPayload->sczSourcePath, -1, wzStreamName, -1)) { *ppPayload = pPayload; ExitFunction1(hr = S_OK); } } } hr = E_NOTFOUND; LExit: return hr; }
extern "C" HRESULT PayloadFindEmbeddedBySourcePath( __in BURN_PAYLOADS* pPayloads, __in_z LPCWSTR wzStreamName, __out BURN_PAYLOAD** ppPayload ) { HRESULT hr = S_OK; BURN_PAYLOAD* pPayload = NULL; for (DWORD i = 0; i < pPayloads->cPayloads; ++i) { pPayload = &pPayloads->rgPayloads[i]; if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging) { if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pPayload->sczSourcePath, -1, wzStreamName, -1)) { *ppPayload = pPayload; ExitFunction1(hr = S_OK); } } } hr = E_NOTFOUND; LExit: return hr; }
extern "C" HRESULT PayloadFindById( __in BURN_PAYLOADS* pPayloads, __in_z LPCWSTR wzId, __out BURN_PAYLOAD** ppPayload ) { HRESULT hr = S_OK; BURN_PAYLOAD* pPayload = NULL; for (DWORD i = 0; i < pPayloads->cPayloads; ++i) { pPayload = &pPayloads->rgPayloads[i]; if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pPayload->sczKey, -1, wzId, -1)) { *ppPayload = pPayload; ExitFunction1(hr = S_OK); } } hr = E_NOTFOUND; LExit: return hr; }
/******************************************************************** DetectWDDMDriver Set a property if the driver on the machine is a WDDM driver. One reliable way to detect the presence of a WDDM driver is to try and use the Direct3DCreate9Ex() function. This method attempts that then sets the property appropriately. ********************************************************************/ static HRESULT DetectWDDMDriver() { HRESULT hr = S_OK; HMODULE hModule = NULL; // Manually load the d3d9.dll library. If the library couldn't be loaded then we obviously won't be able // to try calling the function so just return. hr = LoadSystemLibrary(L"d3d9.dll", &hModule); if (E_MODNOTFOUND == hr) { TraceError(hr, "Unable to load DirectX APIs, skipping WDDM driver check."); ExitFunction1(hr = S_OK); } ExitOnFailure(hr, "Failed to the load the existing DirectX APIs."); // Obtain the address of the Direct3DCreate9Ex function. If this fails we know it isn't a WDDM // driver so just exit. const void* Direct3DCreate9ExPtr = ::GetProcAddress(hModule, "Direct3DCreate9Ex"); ExitOnNull(Direct3DCreate9ExPtr, hr, S_OK, "Unable to load Direct3DCreateEx function, so the driver is not a WDDM driver."); // At this point we know it's a WDDM driver so set the property. hr = WcaSetIntProperty(L"WIX_WDDM_DRIVER_PRESENT", 1); ExitOnFailure(hr, "Failed write property"); LExit: if (NULL != hModule) { FreeLibrary(hModule); } return hr; }
extern "C" HRESULT DAPI LocGetControl( __in const WIX_LOCALIZATION* pWixLoc, __in_z LPCWSTR wzId, __out LOC_CONTROL** ppLocControl ) { HRESULT hr = S_OK; LOC_CONTROL* pLocControl = NULL; for (DWORD i = 0; i < pWixLoc->cLocControls; ++i) { pLocControl = &pWixLoc->rgLocControls[i]; if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pLocControl->wzControl, -1, wzId, -1)) { *ppLocControl = pLocControl; ExitFunction1(hr = S_OK); } } hr = E_NOTFOUND; LExit: return hr; }
virtual STDMETHODIMP QueryInterface( __in const IID& riid, __out void** ppvObject ) { HRESULT hr = S_OK; ExitOnNull(ppvObject, hr, E_INVALIDARG, "Invalid argument ppvObject"); *ppvObject = NULL; if (::IsEqualIID(__uuidof(IBackgroundCopyCallback), riid)) { *ppvObject = static_cast<IBackgroundCopyCallback*>(this); } else if (::IsEqualIID(IID_IUnknown, riid)) { *ppvObject = reinterpret_cast<IUnknown*>(this); } else // no interface for requested iid { ExitFunction1(hr = E_NOINTERFACE); } AddRef(); LExit: return hr; }
DAPI_(HRESULT) SrpInitialize( __in BOOL fInitializeComSecurity ) { HRESULT hr = S_OK; hr = LoadSystemLibrary(L"srclient.dll", &vhSrClientDll); if (FAILED(hr)) { ExitFunction1(hr = E_NOTIMPL); } vpfnSRSetRestorePointW = reinterpret_cast<PFN_SETRESTOREPTW>(::GetProcAddress(vhSrClientDll, "SRSetRestorePointW")); ExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address."); // If allowed, initialize COM security to enable NetworkService, // LocalService and System to make callbacks to the process // calling System Restore. This is required for any process // that calls SRSetRestorePoint. if (fInitializeComSecurity) { hr = InitializeComSecurity(); ExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore."); } LExit: if (FAILED(hr) && vhSrClientDll) { SrpUninitialize(); } return hr; }
/******************************************************************** ScaDropSmb - delete this file share from this computer ********************************************************************/ HRESULT ScaDropSmb(SCA_SMBP* pssp) { HRESULT hr = S_OK; NET_API_STATUS s; hr = DoesShareExist(pssp->wzKey); if (E_FILENOTFOUND == hr) { WcaLog(LOGMSG_VERBOSE, "Share doesn't exist, share removal skipped. (%ls)", pssp->wzKey); ExitFunction1(hr = S_OK); } ExitOnFailure1(hr, "Unable to detect share. (%ls)", pssp->wzKey); s = ::NetShareDel(NULL, pssp->wzKey, 0); if (NERR_Success != s) { hr = E_FAIL; ExitOnFailure1(hr, "Failed to remove file share: Err: %d", s); } LExit: return hr; }
/******************************************************************** RegValueEnum - enumerates a registry value. *********************************************************************/ HRESULT DAPI RegValueEnum( __in HKEY hk, __in DWORD dwIndex, __deref_out_z LPWSTR* psczName, __out_opt DWORD *pdwType ) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; DWORD cbValueName = 0; er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbValueName, NULL, NULL, NULL); ExitOnWin32Error(er, hr, "Failed to get max size of value name under registry key."); // Add one for null terminator ++cbValueName; hr = StrAlloc(psczName, cbValueName); ExitOnFailure(hr, "Failed to allocate array for registry value name"); er = vpfnRegEnumValueW(hk, dwIndex, *psczName, &cbValueName, NULL, pdwType, NULL, NULL); if (ERROR_NO_MORE_ITEMS == er) { ExitFunction1(hr = E_NOMOREITEMS); } ExitOnWin32Error(er, hr, "Failed to enumerate registry value"); LExit: return hr; }
extern "C" HRESULT CatalogFindById( __in BURN_CATALOGS* pCatalogs, __in_z LPCWSTR wzId, __out BURN_CATALOG** ppCatalog ) { HRESULT hr = S_OK; BURN_CATALOG* pCatalog = NULL; for (DWORD i = 0; i < pCatalogs->cCatalogs; ++i) { pCatalog = &pCatalogs->rgCatalogs[i]; if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pCatalog->sczKey, -1, wzId, -1)) { *ppCatalog = pCatalog; ExitFunction1(hr = S_OK); } } hr = E_NOTFOUND; LExit: return hr; }
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; }
HRESULT HandleEnsureSummaryDataTable( __in CFGDB_STRUCT *pcdb ) { HRESULT hr = S_OK; BOOL fInSceTransaction = FALSE; BOOL fEmpty = FALSE; SCE_ROW_HANDLE sceRow = NULL; hr = SceGetFirstRow(pcdb->psceDb, SUMMARY_DATA_TABLE, &sceRow); if (E_NOTFOUND == hr) { fEmpty = TRUE; hr = S_OK; } ExitOnFailure(hr, "Failed to get first row of summary data table"); if (fEmpty) { hr = GuidCreate(&pcdb->sczGuid); ExitOnRootFailure(hr, "Failed to generate guid string"); hr = SceBeginTransaction(pcdb->psceDb); ExitOnFailure(hr, "Failed to begin transaction"); fInSceTransaction = TRUE; hr = ScePrepareInsert(pcdb->psceDb, SUMMARY_DATA_TABLE, &sceRow); ExitOnFailure(hr, "Failed to prepare for insert"); hr = SceSetColumnString(sceRow, SUMMARY_GUID, pcdb->sczGuid); ExitOnFailure(hr, "Failed to set column string of summary data table guid"); hr = SceFinishUpdate(sceRow); ExitOnFailure(hr, "Failed to finish insert into summary data table"); hr = SceCommitTransaction(pcdb->psceDb); ExitOnFailure(hr, "Failed to commit transaction"); fInSceTransaction = FALSE; ExitFunction1(hr = S_OK); } ExitOnFailure(hr, "Failed to move to first row in SummaryData table"); hr = SceGetColumnString(sceRow, SUMMARY_GUID, &pcdb->sczGuid); ExitOnFailure(hr, "Failed to get GUID from summary data table"); LExit: ReleaseSceRow(sceRow); if (fInSceTransaction) { SceRollbackTransaction(pcdb->psceDb); } if (FAILED(hr)) { ReleaseNullStr(pcdb->sczGuid); } return hr; }
HRESULT ScaWebAppExtensionsWrite7( __in_z LPCWSTR wzWebName, __in_z LPCWSTR wzRootOfWeb, __in SCA_WEB_APPLICATION_EXTENSION* pswappextList ) { HRESULT hr = S_OK; SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL; if (!pswappextList) { ExitFunction1(hr = S_OK); } //create the Extension for this vdir application //all go to same web/root location tag hr = ScaWriteConfigID(IIS_APPEXT_BEGIN); ExitOnFailure(hr, "Failed to write webappext begin id"); hr = ScaWriteConfigString(wzWebName); //site name key ExitOnFailure(hr, "Failed to write app web key"); hr = ScaWriteConfigString(wzRootOfWeb); //app path key ExitOnFailure(hr, "Failed to write app web key"); pswappext = pswappextList; while (pswappext) { //create the Extension for this vdir application hr = ScaWriteConfigID(IIS_APPEXT); ExitOnFailure(hr, "Failed to write webappext begin id"); if (*pswappext->wzExtension) { hr = ScaWriteConfigString(pswappext->wzExtension); } else // blank means "*" (all) { hr = ScaWriteConfigString(L"*"); } ExitOnFailure(hr, "Failed to write extension"); hr = ScaWriteConfigString(pswappext->wzExecutable); ExitOnFailure(hr, "Failed to write extension executable"); hr = ScaWriteConfigString(pswappext->wzVerbs); ExitOnFailure(hr, "Failed to write extension verbs"); pswappext = pswappext->pswappextNext; } hr = ScaWriteConfigID(IIS_APPEXT_END); ExitOnFailure(hr, "Failed to write webappext begin id"); LExit: return hr; }
DAPI_(HRESULT) BalInfoAddRelatedBundleAsPackage( __in BAL_INFO_PACKAGES* pPackages, __in LPCWSTR wzId, __in BOOTSTRAPPER_RELATION_TYPE relationType, __in BOOL /*fPerMachine*/ ) { HRESULT hr = S_OK; BAL_INFO_PACKAGE_TYPE type = BAL_INFO_PACKAGE_TYPE_UNKNOWN; BAL_INFO_PACKAGE* pPackage = NULL; // Ensure we have a supported relation type. switch (relationType) { case BOOTSTRAPPER_RELATION_ADDON: type = BAL_INFO_PACKAGE_TYPE_BUNDLE_ADDON; break; case BOOTSTRAPPER_RELATION_PATCH: type = BAL_INFO_PACKAGE_TYPE_BUNDLE_PATCH; break; case BOOTSTRAPPER_RELATION_UPGRADE: type = BAL_INFO_PACKAGE_TYPE_BUNDLE_UPGRADE; break; default: ExitOnFailure1(hr = E_INVALIDARG, "Unknown related bundle type: %u", relationType); } // Check to see if the bundle is already in the list of packages. for (DWORD i = 0; i < pPackages->cPackages; ++i) { if (CSTR_EQUAL == ::CompareStringW(LOCALE_NEUTRAL, 0, wzId, -1, pPackages->rgPackages[i].sczId, -1)) { ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)); } } // Add the related bundle as a package. hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pPackages->rgPackages), pPackages->cPackages + 1, sizeof(BAL_INFO_PACKAGE), 2); ExitOnFailure(hr, "Failed to allocate memory for related bundle package information."); pPackage = pPackages->rgPackages + pPackages->cPackages; ++pPackages->cPackages; hr = StrAllocString(&pPackage->sczId, wzId, 0); ExitOnFailure(hr, "Failed to copy related bundle package id."); pPackage->type = type; // TODO: try to look up the DisplayName and Description in Add/Remove Programs with the wzId. LExit: return hr; }
static HRESULT ConfigureSqlData( __in SCA_ACTION saAction ) { //AssertSz(FALSE, "debug ConfigureSqlData()"); HRESULT hr = S_OK; SCA_DB* psdList = NULL; SCA_SQLSTR* psssList = NULL; // check for the prerequsite tables if (S_OK != WcaTableExists(L"SqlDatabase")) { WcaLog(LOGMSG_VERBOSE, "skipping SQL CustomAction, no SqlDatabase table"); ExitFunction1(hr = S_FALSE); } // read tables hr = ScaDbsRead(&psdList, saAction); ExitOnFailure(hr, "failed to read SqlDatabase table"); hr = ScaSqlStrsRead(&psssList, saAction); ExitOnFailure(hr, "failed to read SqlStrings table"); hr = ScaSqlStrsReadScripts(&psssList, saAction); ExitOnFailure(hr, "failed to read SqlScripts table"); if (SCA_ACTION_UNINSTALL == saAction) { // do uninstall actions (order is important!) hr = ScaSqlStrsUninstall(psdList, psssList); ExitOnFailure(hr, "failed to execute uninstall SQL strings"); hr = ScaDbsUninstall(psdList); ExitOnFailure(hr, "failed to uninstall databases"); } else { // do install actions (order is important!) hr = ScaDbsInstall(psdList); ExitOnFailure(hr, "failed to install databases"); hr = ScaSqlStrsInstall(psdList, psssList); ExitOnFailure(hr, "failed to execute install SQL strings, length may be too long, try add GO to break up"); } LExit: if (psssList) ScaSqlStrsFreeList(psssList); if (psdList) ScaDbsFreeList(psdList); 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" HRESULT DAPI PolcReadString( __in_z LPCWSTR wzPolicyPath, __in_z LPCWSTR wzPolicyName, __in_z_opt LPCWSTR wzDefault, __deref_out_z LPWSTR* pscz ) { HRESULT hr = S_OK; HKEY hk = NULL; hr = OpenPolicyKey(wzPolicyPath, &hk); if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { ExitFunction1(hr = S_FALSE); } ExitOnFailure1(hr, "Failed to open policy key: %ls", wzPolicyPath); hr = RegReadString(hk, wzPolicyName, pscz); if (E_FILENOTFOUND == hr || E_PATHNOTFOUND == hr) { ExitFunction1(hr = S_FALSE); } ExitOnFailure2(hr, "Failed to open policy key: %ls, name: %ls", wzPolicyPath, wzPolicyName); LExit: ReleaseRegKey(hk); if (S_FALSE == hr || FAILED(hr)) { if (NULL == wzDefault) { ReleaseNullStr(*pscz); } else { hr = StrAllocString(pscz, wzDefault, 0); } } return hr; }
/******************************************************************** RegKeyEnum - enumerates a registry key. *********************************************************************/ extern "C" HRESULT DAPI RegKeyEnum( __in HKEY hk, __in DWORD dwIndex, __deref_out_z LPWSTR* psczKey ) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; DWORD cch = 0; if (psczKey && *psczKey) { hr = StrMaxLength(*psczKey, reinterpret_cast<DWORD_PTR*>(&cch)); ExitOnFailure(hr, "Failed to determine length of string."); } if (2 > cch) { cch = 2; hr = StrAlloc(psczKey, cch); ExitOnFailure(hr, "Failed to allocate string to minimum size."); } er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL); if (ERROR_MORE_DATA == er) { er = vpfnRegQueryInfoKeyW(hk, NULL, NULL, NULL, NULL, &cch, NULL, NULL, NULL, NULL, NULL, NULL); ExitOnWin32Error(er, hr, "Failed to get max size of subkey name under registry key."); ++cch; // add one because RegQueryInfoKeyW() returns the length of the subkeys without the null terminator. hr = StrAlloc(psczKey, cch); ExitOnFailure(hr, "Failed to allocate string bigger for enum registry key."); er = vpfnRegEnumKeyExW(hk, dwIndex, *psczKey, &cch, NULL, NULL, NULL, NULL); } else if (ERROR_NO_MORE_ITEMS == er) { ExitFunction1(hr = E_NOMOREITEMS); } ExitOnWin32Error(er, hr, "Failed to enum registry key."); // Always ensure the registry key name is null terminated. #pragma prefast(push) #pragma prefast(disable:26018) (*psczKey)[cch] = L'\0'; // note that cch will always be one less than the size of the buffer because that's how RegEnumKeyExW() works. #pragma prefast(pop) LExit: return hr; }
HRESULT CpiGetApplicationsCollForPartition( CPI_PARTITION* pPart, ICatalogCollection** ppiAppColl ) { HRESULT hr = S_OK; ICatalogCollection* piPartColl = NULL; ICatalogObject* piPartObj = NULL; // if a previous attempt to locate the collection object failed if (pPart->fObjectNotFound) ExitFunction1(hr = S_FALSE); // get applications collection if (!pPart->piApplicationsColl) { // get partitions collection from catalog hr = CpiGetPartitionsCollection(&piPartColl); ExitOnFailure(hr, "Failed to get partitions collection"); // find application object hr = CpiFindCollectionObject(piPartColl, pPart->wzID, *pPart->wzID ? NULL : pPart->wzName, &piPartObj); ExitOnFailure(hr, "Failed to find partition object"); if (S_FALSE == hr) { pPart->fObjectNotFound = TRUE; ExitFunction(); // exit with hr = S_FALSE } // get roles collection hr = CpiGetCatalogCollection(piPartColl, piPartObj, L"Applications", &pPart->piApplicationsColl); ExitOnFailure(hr, "Failed to get applications collection"); } // return value *ppiAppColl = pPart->piApplicationsColl; (*ppiAppColl)->AddRef(); hr = S_OK; LExit: // clean up ReleaseObject(piPartColl); ReleaseObject(piPartObj); return hr; }
/******************************************************************* DirEnsureExists *******************************************************************/ extern "C" HRESULT DAPI DirEnsureExists( __in LPCWSTR wzPath, __in_opt LPSECURITY_ATTRIBUTES psa ) { HRESULT hr = S_OK; UINT er; // try to create this directory if (!::CreateDirectoryW(wzPath, psa)) { // if the directory already exists, bail er = ::GetLastError(); if (ERROR_ALREADY_EXISTS == er) ExitFunction1(hr = S_OK); // get the parent path and try to create it LPWSTR pwzLastSlash = NULL; for (LPWSTR pwz = const_cast<LPWSTR>(wzPath); *pwz; pwz++) if (*pwz == L'\\') pwzLastSlash = pwz; // if there is no parent directory fail ExitOnNullDebugTrace(pwzLastSlash, hr, HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "cannot find parent path"); *pwzLastSlash = L'\0'; // null terminate the parent path hr = DirEnsureExists(wzPath, psa); // recurse! *pwzLastSlash = L'\\'; // put the slash back ExitOnFailureDebugTrace1(hr, "failed to create path: %S", wzPath); // try to create the directory now that all parents are created if (!::CreateDirectoryW(wzPath, psa)) { // if the directory already exists for some reason no error er = ::GetLastError(); if (ERROR_ALREADY_EXISTS == er) hr = S_FALSE; else hr = HRESULT_FROM_WIN32(er); } else hr = S_OK; } LExit: return hr; }