/****************************************************************** AddPortException ********************************************************************/ static HRESULT AddPortException( __in LPCWSTR wzName, __in int iProfile, __in_opt LPCWSTR wzRemoteAddresses, __in BOOL fIgnoreFailures, __in LPCWSTR wzPort, __in int iProtocol, __in LPCWSTR wzDescription ) { HRESULT hr = S_OK; BSTR bstrName = NULL; INetFwRules* pNetFwRules = NULL; INetFwRule* pNetFwRule = NULL; // convert to BSTRs to make COM happy bstrName = ::SysAllocString(wzName); ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString for name"); // get the collection of firewall rules hr = GetFirewallRules(fIgnoreFailures, &pNetFwRules); ExitOnFailure(hr, "failed to get firewall rules object"); if (S_FALSE == hr) // user or package author chose to ignore missing firewall { ExitFunction(); } // try to find it (i.e., support reinstall) hr = pNetFwRules->Item(bstrName, &pNetFwRule); if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) { hr = CreateFwRuleObject(bstrName, iProfile, wzRemoteAddresses, wzPort, iProtocol, wzDescription, &pNetFwRule); ExitOnFailure(hr, "failed to create FwRule object"); // enable it hr = pNetFwRule->put_Enabled(VARIANT_TRUE); ExitOnFailure(hr, "failed to to enable port exception"); // add it to the list of authorized ports hr = pNetFwRules->Add(pNetFwRule); ExitOnFailure(hr, "failed to add app to the authorized ports list"); } else { // we found an existing port exception (if we succeeded, that is) ExitOnFailure(hr, "failed trying to find existing port rule"); // enable it (just in case it was disabled) pNetFwRule->put_Enabled(VARIANT_TRUE); } LExit: ReleaseBSTR(bstrName); ReleaseObject(pNetFwRules); ReleaseObject(pNetFwRule); return fIgnoreFailures ? S_OK : hr; }
BOOL CompareBinding( __in IAppHostElement* pBinding, __in LPVOID pContext ) { BOOL fFound = FALSE; HRESULT hr = S_OK; LPWSTR pwzBindingInfo = NULL; SCA_WEB7* psw = (SCA_WEB7*)pContext; hr = Iis7GetPropertyString(pBinding, IIS_CONFIG_BINDINGINFO, &pwzBindingInfo); ExitOnFailure(hr, "Failed to get bindinginfo for binding element"); LPWSTR pwzExists = pwzBindingInfo; // Break down the address into its constituent parts (IP:Port:Header). // Taken from IIS6 CA code for compatibility while (S_OK == hr && *pwzExists) { LPCWSTR pwzIPExists = pwzExists; pwzExists = const_cast<LPWSTR>(wcsstr(pwzIPExists, L":")); if (NULL == pwzExists) { ExitFunction(); } *pwzExists = L'\0'; LPCWSTR pwzPortExists = pwzExists + 1; pwzExists = const_cast<LPWSTR>(wcsstr(pwzPortExists, L":")); if (NULL == pwzExists) { ExitFunction(); } *pwzExists = L'\0'; int iPortExists = wcstol(pwzPortExists, NULL, 10); LPCWSTR pwzHeaderExists = pwzExists + 1; BOOL fIpMatches = (0 == lstrcmpW(psw->swaBinding.wzIP, pwzIPExists)); // Explicit IP match fIpMatches |= (0 == lstrcmpW(psw->swaBinding.wzIP, L"*")); // Authored * matches any IP fIpMatches |= ('\0' != psw->swaBinding.wzIP) && // Unauthored IP (0 == lstrcmpW(pwzIPExists, L"*")); // matches the All Unassigned IP : '*' // compare the passed in address with the address listed for this web if (fIpMatches && psw->swaBinding.iPort == iPortExists && 0 == lstrcmpW(psw->swaBinding.wzHeader, pwzHeaderExists)) { fFound = TRUE; break; } // move to the next block of data, this may move beyond the available // data and exit the while loop above. pwzExists = const_cast<LPWSTR>(pwzHeaderExists + lstrlenW(pwzHeaderExists)); } LExit: WcaLog(LOGMSG_VERBOSE, "Site with binding %ls %s a match", pwzBindingInfo, fFound ? "is" : "is not"); ReleaseNullStr(pwzBindingInfo); return fFound; }
/****************************************************************** 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; }
static HRESULT DAPI RedirectLoggingOverPipe( __in_z LPCSTR szString, __in_opt LPVOID pvContext ) { static BOOL s_fCurrentlyLoggingToPipe = FALSE; HRESULT hr = S_OK; BURN_ENGINE_STATE* pEngineState = static_cast<BURN_ENGINE_STATE*>(pvContext); BOOL fStartedLogging = FALSE; HANDLE hPipe = INVALID_HANDLE_VALUE; BYTE* pbData = NULL; SIZE_T cbData = 0; DWORD dwResult = 0; // Prevent this function from being called recursively. if (s_fCurrentlyLoggingToPipe) { ExitFunction(); } s_fCurrentlyLoggingToPipe = TRUE; fStartedLogging = TRUE; // Make sure the current thread set the pipe in TLS. hPipe = ::TlsGetValue(pEngineState->dwElevatedLoggingTlsId); if (!hPipe || INVALID_HANDLE_VALUE == hPipe) { hr = HRESULT_FROM_WIN32(ERROR_PIPE_NOT_CONNECTED); ExitFunction(); } // Do not log or use ExitOnFailure() macro here because they will be discarded // by the recursive block at the top of this function. hr = BuffWriteStringAnsi(&pbData, &cbData, szString); if (SUCCEEDED(hr)) { hr = PipeSendMessage(hPipe, static_cast<DWORD>(BURN_PIPE_MESSAGE_TYPE_LOG), pbData, cbData, NULL, NULL, &dwResult); if (SUCCEEDED(hr)) { hr = (HRESULT)dwResult; } } LExit: ReleaseBuffer(pbData); // We started logging so remember to say we are no longer logging. if (fStartedLogging) { s_fCurrentlyLoggingToPipe = FALSE; } return hr; }
extern "C" HRESULT ApprovedExesVerifySecureLocation( __in BURN_VARIABLES* pVariables, __in BURN_LAUNCH_APPROVED_EXE* pLaunchApprovedExe ) { HRESULT hr = S_OK; LPWSTR scz = NULL; const LPCWSTR vrgSecureFolderVariables[] = { L"ProgramFiles64Folder", L"ProgramFilesFolder", }; for (DWORD i = 0; i < countof(vrgSecureFolderVariables); ++i) { LPCWSTR wzSecureFolderVariable = vrgSecureFolderVariables[i]; hr = VariableGetString(pVariables, wzSecureFolderVariable, &scz); if (SUCCEEDED(hr)) { hr = PathDirectoryContainsPath(scz, pLaunchApprovedExe->sczExecutablePath); if (S_OK == hr) { ExitFunction(); } } else if (E_NOTFOUND != hr) { ExitOnFailure1(hr, "Failed to get the variable: %ls", wzSecureFolderVariable); } } // The problem with using a Variable for the root package cache folder is that it might not have been secured yet. // Getting it through CacheGetRootCompletedPath makes sure it has been secured. hr = CacheGetRootCompletedPath(TRUE, TRUE, &scz); ExitOnFailure(hr, "Failed to get the root package cache folder."); hr = PathDirectoryContainsPath(scz, pLaunchApprovedExe->sczExecutablePath); if (S_OK == hr) { ExitFunction(); } hr = S_FALSE; LExit: ReleaseStr(scz); return hr; }
HRESULT DatabaseListFind( __in CFGDB_STRUCT *pcdb, __in LPCWSTR wzFriendlyName, __out SCE_ROW_HANDLE *pSceRow ) { HRESULT hr = S_OK; SCE_QUERY_HANDLE sqhHandle = NULL; hr = SceBeginQuery(pcdb->psceDb, DATABASE_INDEX_TABLE, 1, &sqhHandle); ExitOnFailure(hr, "Failed to begin query into database index table"); hr = SceSetQueryColumnString(sqhHandle, wzFriendlyName); ExitOnFailure(hr, "Failed to set query column name string to: %ls", wzFriendlyName); hr = SceRunQueryExact(&sqhHandle, pSceRow); if (E_NOTFOUND == hr) { // Don't pollute our log with unnecessary messages ExitFunction(); } ExitOnFailure(hr, "Failed to query for database '%ls' in database list", wzFriendlyName); LExit: ReleaseSceQuery(sqhHandle); return hr; }
extern "C" HRESULT DatabaseListDelete( __in CFGDB_STRUCT *pcdb, __in LPCWSTR wzFriendlyName ) { HRESULT hr = S_OK; SCE_QUERY_HANDLE sqhHandle = NULL; SCE_ROW_HANDLE sceRow = NULL; hr = DatabaseListFind(pcdb, wzFriendlyName, &sceRow); if (E_NOTFOUND == hr) { ExitFunction(); } ExitOnFailure(hr, "Failed to search for database '%ls' in database list", wzFriendlyName); hr = SceDeleteRow(&sceRow); ExitOnFailure(hr, "Failed to delete database '%ls' from database list", wzFriendlyName); LExit: ReleaseSceRow(sceRow); ReleaseSceQuery(sqhHandle); return hr; }
DAPI_(HRESULT) JsonReadNext( __in JSON_READER* pReader, __out JSON_TOKEN* pToken, __out JSON_VALUE* pValue ) { HRESULT hr = S_OK; //WCHAR wz; //JSON_TOKEN token = JSON_TOKEN_NONE; ::EnterCriticalSection(&pReader->cs); hr = NextToken(pReader, pToken); if (E_NOMOREITEMS == hr) { ExitFunction(); } ExitOnFailure(hr, "Failed to get next token."); if (JSON_TOKEN_VALUE == *pToken) { hr = JsonReadValue(pReader, pValue); } else { ++pReader->pwz; } LExit: ::LeaveCriticalSection(&pReader->cs); return hr; }
static HRESULT FindObjectForSubscription( CPI_SUBSCRIPTION* pItm, BOOL fFindId, BOOL fFindName, ICatalogObject** ppiSubsObj ) { HRESULT hr = S_OK; ICatalogCollection* piSubsColl = NULL; // get applications collection hr = CpiGetSubscriptionsCollForComponent(pItm->pAssembly, pItm->pComponent, &piSubsColl); ExitOnFailure(hr, "Failed to get collection"); if (S_FALSE == hr) ExitFunction(); // exit with hr = S_FALSE // find application object hr = CpiFindCollectionObject(piSubsColl, fFindId ? pItm->wzID : NULL, fFindName ? pItm->wzName : NULL, ppiSubsObj); ExitOnFailure(hr, "Failed to find object"); // exit with hr from CpiFindCollectionObject() LExit: // clean up ReleaseObject(piSubsColl); return hr; }
/****************************************************************** RemoveException - Removes the exception rule with the given name. ********************************************************************/ static HRESULT RemoveException( __in LPCWSTR wzName, __in BOOL fIgnoreFailures ) { HRESULT hr = S_OK;; INetFwRules* pNetFwRules = NULL; // convert to BSTRs to make COM happy BSTR bstrName = ::SysAllocString(wzName); ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString for path"); // get the collection of firewall rules hr = GetFirewallRules(fIgnoreFailures, &pNetFwRules); ExitOnFailure(hr, "failed to get firewall rules object"); if (S_FALSE == hr) // user or package author chose to ignore missing firewall { ExitFunction(); } hr = pNetFwRules->Remove(bstrName); ExitOnFailure(hr, "failed to remove authorized app"); LExit: ReleaseBSTR(bstrName); ReleaseObject(pNetFwRules); return fIgnoreFailures ? S_OK : hr; }
static HRESULT FindObjectForApplicationRole( CPI_APPLICATION_ROLE* pItm, ICatalogObject** ppiRoleObj ) { HRESULT hr = S_OK; ICatalogCollection* piRoleColl = NULL; // get roles collection hr = CpiGetRolesCollForApplication(pItm->pApplication, &piRoleColl); ExitOnFailure(hr, "Failed to get collection"); if (S_FALSE == hr) ExitFunction(); // exit with hr = S_FALSE // find role object hr = CpiFindCollectionObject(piRoleColl, NULL, pItm->wzName, ppiRoleObj); ExitOnFailure(hr, "Failed to find object"); // exit with hr from CpiFindCollectionObject() LExit: // clean up ReleaseObject(piRoleColl); return hr; }
/****************************************************************** RemovePortExceptionFromCurrentProfile ********************************************************************/ static HRESULT RemovePortExceptionFromCurrentProfile( __in int iPort, __in int iProtocol, __in BOOL fIgnoreFailures ) { HRESULT hr = S_OK; INetFwProfile* pfwProfile = NULL; INetFwOpenPorts* pfwPorts = NULL; // get the firewall profile, which is our entry point for adding exceptions hr = GetCurrentFirewallProfile(fIgnoreFailures, &pfwProfile); ExitOnFailure(hr, "failed to get firewall profile"); if (S_FALSE == hr) // user or package author chose to ignore missing firewall { ExitFunction(); } hr = pfwProfile->get_GloballyOpenPorts(&pfwPorts); ExitOnFailure(hr, "failed to get open ports"); hr = pfwPorts->Remove(iPort, static_cast<NET_FW_IP_PROTOCOL>(iProtocol)); ExitOnFailure2(hr, "failed to remove open port %d, protocol %d", iPort, iProtocol); LExit: return fIgnoreFailures ? S_OK : hr; }
HRESULT CpiRemoveUserCollectionObject( ICatalogCollection* piColl, PSID pSid ) { HRESULT hr = S_OK; int i = 0; // find index hr = FindUserCollectionObjectIndex(piColl, pSid, &i); ExitOnFailure(hr, "Failed to find user collection index"); if (S_FALSE == hr) ExitFunction(); // not found, exit with hr = S_FALSE // remove object hr = piColl->Remove(i); ExitOnFailure(hr, "Failed to remove object from collection"); hr = S_OK; LExit: return hr; }
/****************************************************************** RemoveApplicationExceptionFromCurrentProfile ********************************************************************/ static HRESULT RemoveApplicationExceptionFromCurrentProfile( __in LPCWSTR wzFile, __in BOOL fIgnoreFailures ) { HRESULT hr = S_OK; INetFwProfile* pfwProfile = NULL; INetFwAuthorizedApplications* pfwApps = NULL; // convert to BSTRs to make COM happy BSTR bstrFile = ::SysAllocString(wzFile); ExitOnNull(bstrFile, hr, E_OUTOFMEMORY, "failed SysAllocString for path"); // get the firewall profile, which is our entry point for removing exceptions hr = GetCurrentFirewallProfile(fIgnoreFailures, &pfwProfile); ExitOnFailure(hr, "failed to get firewall profile"); if (S_FALSE == hr) // user or package author chose to ignore missing firewall { ExitFunction(); } // now get the list of app exceptions and remove the one hr = pfwProfile->get_AuthorizedApplications(&pfwApps); ExitOnFailure(hr, "failed to get list of authorized apps"); hr = pfwApps->Remove(bstrFile); ExitOnFailure(hr, "failed to remove authorized app"); LExit: ReleaseBSTR(bstrFile); ReleaseObject(pfwApps); ReleaseObject(pfwProfile); return fIgnoreFailures ? S_OK : 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; }
/******************************************************************** MessageQueuingExecuteInstall - CUSTOM ACTION ENTRY POINT Input: deferred CustomActionData - MessageQueuingExecuteInstall ********************************************************************/ extern "C" UINT __stdcall MessageQueuingExecuteInstall(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; LPWSTR pwzCustomActionData = NULL; LPWSTR pwzData = NULL; // initialize hr = WcaInitialize(hInstall, "MessageQueuingExecuteInstall"); ExitOnFailure(hr, "Failed to initialize MessageQueuingExecuteInstall"); hr = MqiInitialize(); ExitOnFailure(hr, "Failed to initialize"); // get custom action data hr = WcaGetProperty(L"CustomActionData", &pwzCustomActionData); ExitOnFailure(hr, "Failed to get CustomActionData"); pwzData = pwzCustomActionData; // create message queues hr = MqiCreateMessageQueues(&pwzData); ExitOnFailure(hr, "Failed to create message queues"); if (S_FALSE == hr) ExitFunction(); // add message queue permissions hr = MqiAddMessageQueuePermissions(&pwzData); ExitOnFailure(hr, "Failed to add message queue permissions"); if (S_FALSE == hr) ExitFunction(); hr = S_OK; LExit: // clean up ReleaseStr(pwzCustomActionData); // uninitialize MqiUninitialize(); er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); }
void LibES::Abort (const std::string& aMessage) { printf("ABORT: %s\n", aMessage.c_str()); if(ExitFunction) { ExitFunction(); } abort(); }
HRESULT ProductSet( __in CFGDB_STRUCT *pcdb, __in_z LPCWSTR wzProductName, __in_z LPCWSTR wzVersion, __in_z LPCWSTR wzPublicKey, __in BOOL fDontCreate, __out_opt BOOL *pfLegacy ) { HRESULT hr = S_OK; SCE_ROW_HANDLE sceRow = NULL; pcdb->fProductSet = FALSE; pcdb->fProductIsLegacy = FALSE; pcdb->dwAppID = DWORD_MAX; if (fDontCreate) { // Just query for an existing product - if it exists, we'll use it hr = ProductFindRow(pcdb, PRODUCT_INDEX_TABLE, wzProductName, wzVersion, wzPublicKey, &sceRow); if (E_NOTFOUND == hr) { ExitFunction(); } ExitOnFailure(hr, "Failed to query for product"); hr = SceGetColumnDword(sceRow, PRODUCT_ID, &pcdb->dwAppID); ExitOnFailure(hr, "Failed to get App ID of application"); hr = SceGetColumnBool(sceRow, PRODUCT_IS_LEGACY, &pcdb->fProductIsLegacy); ExitOnFailure(hr, "Failed to get IsLegacy flag of application"); } else { hr = ProductEnsureCreated(pcdb, wzProductName, wzVersion, wzPublicKey, &pcdb->dwAppID, &pcdb->fProductIsLegacy); ExitOnFailure(hr, "Failed to ensure product exists: %ls", wzProductName); } // Get the AppID (of either the found row, or the recently created row) hr = StrAllocString(&pcdb->sczProductName, wzProductName, 0); ExitOnFailure(hr, "Failed to copy product name string"); if (pfLegacy) { *pfLegacy = pcdb->fProductIsLegacy; } pcdb->fProductSet = TRUE; LExit: ReleaseSceRow(sceRow); return hr; }
/******************************************************************** WcaGetRecordFormattedString() - gets formatted string filed from record ********************************************************************/ extern "C" HRESULT WIXAPI WcaGetRecordFormattedString( __in MSIHANDLE hRec, __in UINT uiField, __inout LPWSTR* ppwzData ) { if (!hRec || !ppwzData) { return E_INVALIDARG; } HRESULT hr = S_OK; UINT er; DWORD_PTR cch = 0; PMSIHANDLE hRecFormat; // get the format string hr = WcaGetRecordString(hRec, uiField, ppwzData); ExitOnFailure(hr, "failed to get string from record"); if (!**ppwzData) { ExitFunction(); } // hide the nulls '[~]' so we can get them back after formatting HideNulls(*ppwzData); // set up the format record hRecFormat = ::MsiCreateRecord(1); ExitOnNull(hRecFormat, hr, E_UNEXPECTED, "Failed to create record to format string"); hr = WcaSetRecordString(hRecFormat, 0, *ppwzData); ExitOnFailure(hr, "failed to set string to format record"); // format the string hr = StrMaxLength(*ppwzData, &cch); ExitOnFailure(hr, "failed to get max length of string"); er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); if (ERROR_MORE_DATA == er) { hr = StrAlloc(ppwzData, ++cch); ExitOnFailure(hr, "Failed to allocate memory for record string"); er = ::MsiFormatRecordW(WcaGetInstallHandle(), hRecFormat, *ppwzData, (DWORD*)&cch); } ExitOnWin32Error(er, hr, "Failed to format string"); // put the nulls back RevealNulls(*ppwzData); LExit: return hr; }
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; }
volatile bool LibES::WantToDie () { want_to_die = LibESPlatform::WantToDie(); if(want_to_die && ExitFunction) { ExitFunction(); exit(1); } return want_to_die; }
HRESULT CpiGetUsersInRoleCollection( LPCWSTR pwzPartID, LPCWSTR pwzAppID, LPCWSTR pwzRoleName, ICatalogCollection** ppiUsrInRoleColl ) { HRESULT hr = S_OK; ICatalogCollection* piRoleColl = NULL; ICatalogObject* piRoleObj = NULL; // get roles collection hr = CpiGetRolesCollection(pwzPartID, pwzAppID, &piRoleColl); ExitOnFailure(hr, "Failed to get roles collection"); if (S_FALSE == hr) ExitFunction(); // roles collection not found, exit with hr = S_FALSE // find object hr = CpiFindCollectionObjectByName(piRoleColl, pwzRoleName, &piRoleObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // role not found, exit with hr = S_FALSE // get roles collection hr = CpiGetCatalogCollection(piRoleColl, piRoleObj, L"UsersInRole", ppiUsrInRoleColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: // clean up ReleaseObject(piRoleColl); ReleaseObject(piRoleObj); return hr; }
HRESULT CpiGetSubscriptionsCollection( LPCWSTR pwzPartID, LPCWSTR pwzAppID, LPCWSTR pwzCompCLSID, ICatalogCollection** ppiSubsColl ) { HRESULT hr = S_OK; ICatalogCollection* piCompColl = NULL; ICatalogObject* piCompObj = NULL; // get components collection hr = CpiGetComponentsCollection(pwzPartID, pwzAppID, &piCompColl); ExitOnFailure(hr, "Failed to get components collection"); if (S_FALSE == hr) ExitFunction(); // components collection not found, exit with hr = S_FALSE // find object hr = CpiFindCollectionObjectByStringKey(piCompColl, pwzCompCLSID, &piCompObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // component not found, exit with hr = S_FALSE // get subscriptions collection hr = CpiGetCatalogCollection(piCompColl, piCompObj, L"SubscriptionsForComponent", ppiSubsColl); ExitOnFailure(hr, "Failed to get catalog collection"); hr = S_OK; LExit: // clean up ReleaseObject(piCompColl); ReleaseObject(piCompObj); return hr; }
HRESULT ScaWebAppExtensionsWrite(IMSAdminBase* piMetabase, LPCWSTR wzRootOfWeb, SCA_WEB_APPLICATION_EXTENSION* pswappextList ) { HRESULT hr = S_OK; LPWSTR wzAppExt = NULL; DWORD cchAppExt; WCHAR wzAppExtension[1024]; WCHAR wzAppExtensions[65536]; SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL; if (!pswappextList) ExitFunction(); ::ZeroMemory(wzAppExtensions, sizeof(wzAppExtensions)); wzAppExt = wzAppExtensions; cchAppExt = countof(wzAppExtensions); pswappext = pswappextList; while (pswappext) { if (0 == lstrcmpW(wzAppExtension, L"*")) StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes); else if (*pswappext->wzExtension) StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L".%s,%s,%d", pswappext->wzExtension, pswappext->wzExecutable, pswappext->iAttributes); else // blank means "*" (all) StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes); // if verbs were specified and not the keyword "all" if (pswappext->wzVerbs[0] && CSTR_EQUAL != CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pswappext->wzVerbs, -1, L"all", -1)) { StringCchCatW(wzAppExtension, countof(wzAppExtension), L","); StringCchCatW(wzAppExtension, countof(wzAppExtension), pswappext->wzVerbs); } StringCchCopyW(wzAppExt, cchAppExt, wzAppExtension); wzAppExt += lstrlenW(wzAppExtension) + 1; cchAppExt -= lstrlenW(wzAppExtension) + 1; pswappext = pswappext->pswappextNext; } if (*wzAppExtensions) { hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_SCRIPT_MAPS, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, wzAppExtensions); ExitOnFailure1(hr, "Failed to write AppExtension: '%S'", wzAppExtension); } LExit: return hr; }
HRESULT ScaFiltersInstall7( __in SCA_FILTER* psfList ) { HRESULT hr = S_OK; SCA_FILTER* psf = psfList; if (!psf) { ExitFunction(); } //write global filters hr = ScaWriteConfigID(IIS_FILTER_GLOBAL_BEGIN); ExitOnFailure(hr, "Failed to write filter begin ID"); while (psf) { if (WcaIsInstalling(psf->isInstalled, psf->isAction)) { if (0 == wcscmp(psf->wzFilterRoot, L"/")) { hr = WriteFilter(psf); } } psf = psf->psfNext; } hr = ScaWriteConfigID(IIS_FILTER_END); ExitOnFailure(hr, "Failed to write filter ID"); psf = psfList; //Write Web Site Filters hr = ScaWriteConfigID(IIS_FILTER_BEGIN); ExitOnFailure(hr, "Failed to write filter begin ID"); while (psf) { if (WcaIsInstalling(psf->isInstalled, psf->isAction)) { if (0 != wcscmp(psf->wzFilterRoot, L"/")) { hr = WriteFilter(psf); } } psf = psf->psfNext; } hr = ScaWriteConfigID(IIS_FILTER_END); ExitOnFailure(hr, "Failed to write filter ID"); LExit: return hr; }
HRESULT CpiGetRolesCollection( LPCWSTR pwzPartID, LPCWSTR pwzAppID, ICatalogCollection** ppiRolesColl ) { HRESULT hr = S_OK; ICatalogCollection* piAppColl = NULL; ICatalogObject* piAppObj = NULL; // get applications collection hr = CpiGetApplicationsCollection(pwzPartID, &piAppColl); ExitOnFailure(hr, "Failed to get applications collection"); if (S_FALSE == hr) ExitFunction(); // applications collection not found, exit with hr = S_FALSE // find object hr = CpiFindCollectionObjectByStringKey(piAppColl, pwzAppID, &piAppObj); ExitOnFailure(hr, "Failed to find collection object"); if (S_FALSE == hr) ExitFunction(); // application not found, exit with hr = S_FALSE // get roles collection hr = CpiGetCatalogCollection(piAppColl, piAppObj, L"Roles", ppiRolesColl); ExitOnFailure(hr, "Failed to catalog collection"); hr = S_OK; LExit: // clean up ReleaseObject(piAppColl); ReleaseObject(piAppObj); return hr; }
/******************************************************************** XmlInitialize - finds an appropriate version of the XML DOM *********************************************************************/ extern "C" HRESULT DAPI XmlInitialize( ) { HRESULT hr = S_OK; if (!fComInitialized) { hr = ::CoInitialize(0); if (RPC_E_CHANGED_MODE != hr) { ExitOnFailure(hr, "failed to initialize COM"); fComInitialized = TRUE; } } LONG cInitialized = ::InterlockedIncrement(&vcXmlInitialized); if (1 == cInitialized) { // NOTE: 4.0 behaves differently than 3.0 so there may be problems doing this #if 0 hr = ::CLSIDFromProgID(L"Msxml2.DOMDocument.4.0", &vclsidXMLDOM); if (S_OK == hr) { vfMsxml40 = TRUE; Trace(REPORT_VERBOSE, "found Msxml2.DOMDocument.4.0"); ExitFunction(); } #endif hr = ::CLSIDFromProgID(L"Msxml2.DOMDocument", &vclsidXMLDOM); if (FAILED(hr)) { // try to fall back to old MSXML hr = ::CLSIDFromProgID(L"MSXML.DOMDocument", &vclsidXMLDOM); } ExitOnFailure(hr, "failed to get CLSID for XML DOM"); Assert(IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument26) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument40) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument50) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument60)); } hr = S_OK; 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; }
static HRESULT ReadDirWriteLegacyDb( __in CFGDB_STRUCT *pcdb, __in LEGACY_SYNC_PRODUCT_SESSION *pSyncProductSession, __in LEGACY_FILE *pFile, __in_z LPCWSTR wzSubDir ) { HRESULT hr = S_OK; LPWSTR sczFullPathToVirtualDirectory = NULL; LPWSTR wzFullPathBackup = pFile->sczExpandedPath; BOOL fWritePermission = TRUE; hr = UtilTestWriteAccess(pcdb->hToken, wzSubDir); if (E_ACCESSDENIED == hr || E_PATHNOTFOUND == hr) { fWritePermission = FALSE; hr = S_OK; } ExitOnFailure(hr, "Failed to check for write access to directory: %ls", wzSubDir); if (!fWritePermission) { // If we don't have write permission to the directory, prefer files in virtualstore hr = UtilConvertToVirtualStorePath(wzSubDir, &sczFullPathToVirtualDirectory); ExitOnFailure(hr, "Failed to get path equivalent under virtualstore for directory: %ls", sczFullPathToVirtualDirectory); // Make the LEGACY_FILE struct temporarily appear as though its natural base path was under virtualstore pFile->sczExpandedPath = sczFullPathToVirtualDirectory; hr = ReadDirWriteLegacyDbHelp(pcdb, pSyncProductSession, pFile, sczFullPathToVirtualDirectory); ExitOnFailure(hr, "Failed to read files out of virtual store subdirectory: %ls", sczFullPathToVirtualDirectory); // Restore it back so it isn't pointing to virtualstore anymore pFile->sczExpandedPath = wzFullPathBackup; } hr = ReadDirWriteLegacyDbHelp(pcdb, pSyncProductSession, pFile, wzSubDir); if (E_PATHNOTFOUND == hr) { ExitFunction(); } ExitOnFailure(hr, "Failed to read files out of subdirectory: %ls", wzSubDir); LExit: ReleaseStr(sczFullPathToVirtualDirectory); pFile->sczExpandedPath = wzFullPathBackup; return hr; }
extern "C" HRESULT LoggingSetPackageVariable( __in BURN_PACKAGE* pPackage, __in_z_opt LPCWSTR wzSuffix, __in BOOL fRollback, __in BURN_LOGGING* pLog, __in BURN_VARIABLES* pVariables, __out_opt LPWSTR* psczLogPath ) { HRESULT hr = S_OK; LPWSTR sczLogPath = NULL; if (BURN_LOGGING_STATE_DISABLED == pLog->state) { if (psczLogPath) { *psczLogPath = NULL; } ExitFunction(); } if ((!fRollback && pPackage->sczLogPathVariable && *pPackage->sczLogPathVariable) || (fRollback && pPackage->sczRollbackLogPathVariable && *pPackage->sczRollbackLogPathVariable)) { hr = StrAllocFormatted(&sczLogPath, L"%ls%hs%ls_%03u_%ls%ls.%ls", pLog->sczPrefix, wzSuffix && *wzSuffix ? "_" : "", wzSuffix && *wzSuffix ? wzSuffix : L"", vdwPackageSequence, pPackage->sczId, fRollback ? L"_rollback" : L"", pLog->sczExtension); ExitOnFailure(hr, "Failed to allocate path for package log."); hr = VariableSetString(pVariables, fRollback ? pPackage->sczRollbackLogPathVariable : pPackage->sczLogPathVariable, sczLogPath, FALSE); ExitOnFailure(hr, "Failed to set log path into variable."); if (psczLogPath) { hr = StrAllocString(psczLogPath, sczLogPath, 0); ExitOnFailure(hr, "Failed to copy package log path."); } } LExit: ReleaseStr(sczLogPath); return hr; }