Beispiel #1
0
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));
}
Beispiel #2
0
    void Context::Deallocate(void* ptr, std::size_t size)
    {
		if (POOL && size < 8192)
    	{
    		std::vector<void*>& poolForSize = pools[size];
    		if (poolForSize.size() < 16384)
    			poolForSize.push_back(ptr);
    		else
    			ReleaseMem(ptr);
    	}
    	else
    	{
    		ReleaseMem(ptr);
    	}
    }
Beispiel #3
0
/******************************************************************
 SendApplicationMessage - helper function to iterate through the 
 processes for the specified application and send all
 applicable process Ids a message and give them time to process
 the message.

******************************************************************/
void SendApplicationMessage(
    __in LPCWSTR wzApplication,
    __in DWORD dwMessageId,
    __in DWORD dwTimeout
    )
{
    DWORD *prgProcessIds = NULL;
    DWORD cProcessIds = 0, iProcessId;
    HRESULT hr = S_OK;

    WcaLog(LOGMSG_VERBOSE, "Checking App: %ls ", wzApplication);

    hr = ProcFindAllIdsFromExeName(wzApplication, &prgProcessIds, &cProcessIds);

    if (SUCCEEDED(hr) && 0 < cProcessIds)
    {
        WcaLog(LOGMSG_VERBOSE, "App: %ls found running, %d processes, attempting to send message.", wzApplication, cProcessIds);

        for (iProcessId = 0; iProcessId < cProcessIds; ++iProcessId)
        {
            SendProcessMessage(prgProcessIds[iProcessId], dwMessageId, dwTimeout);
        }

        ProcWaitForIds(prgProcessIds, cProcessIds, dwTimeout);
    }

    ReleaseMem(prgProcessIds);
}
// ================================================================================
// FUNCTION		: ResetContact
// DESCRIPTION	: Reset the resource associate with contact.
// ================================================================================
void CContactInfo::ResetContact()
{
	ReleaseMem();

	m_nContactId = 0;
	m_psFName = NULL;
	m_psMName = NULL;
	m_psLName = NULL;  
	m_psCompany = NULL;	         
	m_psJTitle = NULL;	         
	m_psFaxH = NULL;
	m_psFaxW = NULL;
	m_psFax = NULL;
	m_psMobileH = NULL;	         
	m_psMobileW = NULL;
	m_psMobile = NULL;
	m_psTelephoneH = NULL;
	m_psTelephoneW = NULL;
	m_psTelephone = NULL;
	m_psEmailW = NULL;
	m_psEmailH = NULL;
	m_psEmail = NULL;

	m_nState = SM_DBERROR;
	m_psGlobalId = NULL;//invalid global id
}
Beispiel #5
0
extern "C" void MspEnginePackageUninitialize(
    __in BURN_PACKAGE* pPackage
    )
{
    ReleaseStr(pPackage->Msp.sczPatchCode);
    ReleaseStr(pPackage->Msp.sczApplicabilityXml);

    // free properties
    if (pPackage->Msp.rgProperties)
    {
        for (DWORD i = 0; i < pPackage->Msp.cProperties; ++i)
        {
            BURN_MSIPROPERTY* pProperty = &pPackage->Msp.rgProperties[i];

            ReleaseStr(pProperty->sczId);
            ReleaseStr(pProperty->sczValue);
            ReleaseStr(pProperty->sczRollbackValue);
        }
        MemFree(pPackage->Msp.rgProperties);
    }

    // free target products
    ReleaseMem(pPackage->Msp.rgTargetProducts);

    // clear struct
    memset(&pPackage->Msp, 0, sizeof(pPackage->Msp));
}
    void CfgTest::CheckCfgAndFile(CFGDB_HANDLE cdhDb, LPCWSTR wzFileName, LPCWSTR wzFilePath, BYTE *pbBuffer, SIZE_T cbBuffer)
    {
        HRESULT hr = S_OK;
        BYTE *pbDataReadFromFile = NULL;
        DWORD cbDataReadFromFile = 0;

        ExpectFile(cdhDb, wzFileName, pbBuffer, cbBuffer);

        hr = FileRead(&pbDataReadFromFile, &cbDataReadFromFile, wzFilePath);
        ExitOnFailure1(hr, "Failed to read file: %ls", wzFilePath);

        if (cbBuffer != cbDataReadFromFile)
        {
            hr = E_FAIL;
            ExitOnFailure3(hr, "File %ls should be size %u, but was size %u instead", wzFilePath, cbBuffer, cbDataReadFromFile);
        }

        if (0 != memcmp(pbBuffer, pbDataReadFromFile, cbBuffer))
        {
            hr = E_FAIL;
            ExitOnFailure1(hr, "File contents don't match for file of name: %ls", wzFilePath);
        }
    LExit:
        ReleaseMem(pbDataReadFromFile);
    }
Beispiel #7
0
static HRESULT ParseWxl(
    __in IXMLDOMDocument* pixd,
    __out WIX_LOCALIZATION** ppWixLoc
    )
{
    HRESULT hr = S_OK;
    IXMLDOMElement *pWxlElement = NULL;
    WIX_LOCALIZATION* pWixLoc = NULL;

    pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE));
    ExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file.");

    // read the WixLocalization tag
    hr = pixd->get_documentElement(&pWxlElement);
    ExitOnFailure(hr, "Failed to get localization element.");

    // store the strings and controls in a node list
    hr = ParseWxlStrings(pWxlElement, pWixLoc);
    ExitOnFailure(hr, "Parsing localization strings failed.");

    hr = ParseWxlControls(pWxlElement, pWixLoc);
    ExitOnFailure(hr, "Parsing localization controls failed.");

    *ppWixLoc = pWixLoc;
    pWixLoc = NULL;

LExit:
    ReleaseObject(pWxlElement);
    ReleaseMem(pWixLoc);

    return hr;
}
Beispiel #8
0
// Static functions
static HRESULT RegDefaultReadValueBinary(
    __in CFGDB_STRUCT *pcdb,
    __in HKEY hkKey,
    __in_z LPCWSTR wzValueName,
    __in_z LPCWSTR wzCfgValueName
    )
{
    HRESULT hr = S_OK;
    BYTE *pbBuffer = NULL;
    SIZE_T cbBuffer = 0;
    CONFIG_VALUE cvNewValue = { };

    hr = RegReadBinary(hkKey, wzValueName, &pbBuffer, &cbBuffer);
    ExitOnFailure(hr, "Failed to read binary value from registry: %ls", wzValueName);

    hr = ValueSetBlob(pbBuffer, cbBuffer, FALSE, NULL, pcdb->sczGuid, &cvNewValue);
    ExitOnFailure(hr, "Failed to set string value %ls in memory", wzCfgValueName);

    hr = ValueWrite(pcdb, pcdb->dwAppID, wzCfgValueName, &cvNewValue, TRUE, NULL);
    ExitOnFailure(hr, "Failed to set value in db: %ls", wzCfgValueName);

LExit:
    ReleaseMem(pbBuffer);
    ReleaseCfgValue(cvNewValue);

    return hr;
}
Beispiel #9
0
static int CreateDir(Directory *d)
{ char        pathName[PATHNAMESIZE];

  if (verbose)
    printf("CreateDir called on directory '%s'\n", d->DirPathName);

  if ( !FindUnusedDirName(d, pathName) )
  { if (verbose)
      printf("CreateDir: FindUnusedDirName failed\n");
    return 0;
  }

  printf("Creating directory %s\n", pathName);

  if ( mkdir(pathName, S_IRWXU) == -1 )
  { printf("CreateDir: failed to create directory %s\n", pathName);

    free(safetyBlock);
    ReleaseMem();

    return 0;
  }
  else
    return 1;
}
Beispiel #10
0
extern "C" HRESULT DAPI CertGetAuthenticodeSigningTimestamp(
    __in CMSG_SIGNER_INFO* pSignerInfo,
    __out FILETIME* pftSigningTimestamp
    )
{
    HRESULT hr = S_OK;
    CRYPT_INTEGER_BLOB* pBlob = NULL;
    PCMSG_SIGNER_INFO pCounterSignerInfo = NULL;
    DWORD cbSigningTimestamp = sizeof(FILETIME);

    // Find the countersigner blob. The countersigner in Authenticode contains the time
    // that signing took place. It's a "countersigner" because the signing time was sent
    // off to the certificate authority in the sky to return the verified time signed.
    for (DWORD i = 0; i < pSignerInfo->UnauthAttrs.cAttr; ++i)
    {
        if (CSTR_EQUAL == ::CompareStringA(LOCALE_NEUTRAL, 0, szOID_RSA_counterSign, -1, pSignerInfo->UnauthAttrs.rgAttr[i].pszObjId, -1))
        {
            pBlob = pSignerInfo->UnauthAttrs.rgAttr[i].rgValue;
            break;
        }
    }

    if (!pBlob)
    {
        hr = TRUST_E_FAIL;
        ExitOnFailure(hr, "Failed to find countersigner in signer information.");
    }

    hr = CrypDecodeObject(PKCS7_SIGNER_INFO, pBlob->pbData, pBlob->cbData, 0, reinterpret_cast<LPVOID*>(&pCounterSignerInfo), NULL);
    ExitOnFailure(hr, "Failed to decode countersigner information.");

    pBlob = NULL; // reset the blob before searching for the signing time.

    // Find the signing time blob in the countersigner.
    for (DWORD i = 0; i < pCounterSignerInfo->AuthAttrs.cAttr; ++i)
    {
        if (CSTR_EQUAL == ::CompareStringA(LOCALE_NEUTRAL, 0, szOID_RSA_signingTime, -1, pCounterSignerInfo->AuthAttrs.rgAttr[i].pszObjId, -1))
        {
            pBlob = pCounterSignerInfo->AuthAttrs.rgAttr[i].rgValue;
            break;
        }
    }

    if (!pBlob)
    {
        hr = TRUST_E_FAIL;
        ExitOnFailure(hr, "Failed to find signing time in countersigner information.");
    }

    if (!::CryptDecodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, szOID_RSA_signingTime, pBlob->pbData, pBlob->cbData, 0, pftSigningTimestamp, &cbSigningTimestamp))
    {
        ExitWithLastError(hr, "Failed to decode countersigner signing timestamp.");
    }

LExit:
    ReleaseMem(pCounterSignerInfo);

    return hr;
}
// ================================================================================
// FUNCTION		: SetDeletedContact
// DESCRIPTION	: Delete a contact resource.
// ================================================================================
bool CContactInfo::SetDeletedContact(int nRecId)
{
	ReleaseMem();

	m_nContactId = nRecId;

	return true;
}
// ================================================================================
// FUNCTION		: SetContactFromXml
// DESCRIPTION	: Set contact from a xml.
// ================================================================================
bool CContactInfo::SetContactFromXml(char *pszXml, char *pszType)
{
	DBGPRINTF(pszXml);

	ReleaseMem();

	char *pszFound=NULL;

	//set type of contact
	if ( 0==STRCMP("add", pszType))
		m_nState = SM_RECORD_ADD;
	else if ( 0==STRCMP("update", pszType))
		m_nState = SM_RECORD_UPDATE;
	else if ( 0==STRCMP("delete", pszType))
		m_nState = SM_RECORD_DELETE;
	else
		return false;

	int nLen=0;
	char *pszEndTag=NULL;
	char *pszNumber=NULL;
	
	//set contact id
	if ( !SetValue(&pszNumber, pszXml, "id")) return false;
	if ( NULL!=pszNumber ) m_nContactId = (uint16)STRTOUL(pszNumber, NULL, 10);
	DBGPRINTF("Contact id= %d", m_nContactId);
	FREEIF(pszNumber);

	//set global id
	if ( !SetValue(&m_psGlobalId, pszXml, "gcid")) return false;
	
	//set first name
	if ( !SetValue(&m_psFName, pszXml, "fn")) return false;
    if (NULL!=m_psFName) DBGPRINTF("%S", m_psFName);  
	if ( !SetValue(&m_psLName, pszXml, "ln")) return false;  
	if (NULL!=m_psLName) DBGPRINTF("%S", m_psLName);
	if ( !SetValue(&m_psCompany, pszXml, "cn")) return false;
	if (NULL!=m_psCompany) DBGPRINTF("%S", m_psCompany);
	if ( !SetMultiValue(&m_psJTitle, pszXml, "ttls", "ttl")) return false;
	if (NULL!=m_psJTitle) DBGPRINTF("%S", m_psJTitle);
	if ( !SetMultiValue(&m_psFaxH, pszXml, "fxsh", "fxh")) return false;
	if (NULL!=m_psFaxH) DBGPRINTF("%S", m_psFaxH);
	if ( !SetMultiValue(&m_psFaxW, pszXml, "fxsw", "fxw")) return false;
	if (NULL!=m_psFaxW) DBGPRINTF("%S", m_psFaxW);
	if ( !SetMultiValue(&m_psFax, pszXml, "fxs", "fx")) return false;
	if ( !SetMultiValue(&m_psMobileH, pszXml, "mblsh", "mblh")) return false;	         
	if ( !SetMultiValue(&m_psMobileW, pszXml, "mblsb", "mblb")) return false;
	if ( !SetMultiValue(&m_psMobile, pszXml, "mbls", "mbl")) return false;
	if ( !SetMultiValue(&m_psTelephoneH, pszXml, "telsh", "telh")) return false;
	if ( !SetMultiValue(&m_psTelephoneW, pszXml, "telsb", "telb")) return false;
	if ( !SetMultiValue(&m_psTelephone, pszXml, "tels", "tel")) return false;
	if ( !SetMultiValue(&m_psEmailW, pszXml, "emlsb", "emlb")) return false;
	if ( !SetMultiValue(&m_psEmailH, pszXml, "emlsh", "emlh")) return false;
	if ( !SetMultiValue(&m_psEmail, pszXml, "emls", "eml")) return false;
	if (NULL!=m_psEmail) DBGPRINTF("%S", m_psEmail);

	return true;
}
Beispiel #13
0
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;
}
Beispiel #14
0
DAPI_(void) JsonUninitializeWriter(
    __in JSON_WRITER* pWriter
    )
{
    ReleaseMem(pWriter->rgTokenStack);
    ReleaseStr(pWriter->sczJson);

    ::DeleteCriticalSection(&pWriter->cs);
    memset(pWriter, 0, sizeof(JSON_WRITER));
}
Beispiel #15
0
static HRESULT EnsureWUServiceEnabled(
    __in BOOL fStopWusaService,
    __out SC_HANDLE* pschWu,
    __out BOOL* pfPreviouslyDisabled
    )
{
    HRESULT hr = S_OK;
    SC_HANDLE schSCM = NULL;
    SC_HANDLE schWu = NULL;
    SERVICE_STATUS serviceStatus = { };
    QUERY_SERVICE_CONFIGW* pConfig = NULL;

    schSCM = ::OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    ExitOnNullWithLastError(schSCM, hr, "Failed to open service control manager.");

    schWu = ::OpenServiceW(schSCM, L"wuauserv", SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS | SERVICE_STOP );
    ExitOnNullWithLastError(schWu, hr, "Failed to open WU service.");

    if (!::QueryServiceStatus(schWu, &serviceStatus) )
    {
        ExitWithLastError(hr, "Failed to query status of WU service.");
    }

    // Stop service if requested to.
    if (SERVICE_STOPPED != serviceStatus.dwCurrentState && fStopWusaService)
    {
        hr = StopWUService(schWu);
    }

    // If the service is not running then it might be disabled so let's check.
    if (SERVICE_RUNNING != serviceStatus.dwCurrentState)
    {
        hr = SvcQueryConfig(schWu, &pConfig);
        ExitOnFailure(hr, "Failed to read configuration for WU service.");

        // If WU is disabled, change it to a demand start service (but touch nothing else).
        if (SERVICE_DISABLED == pConfig->dwStartType)
        {
            hr = SetServiceStartType(schWu, SERVICE_DEMAND_START);
            ExitOnFailure(hr, "Failed to mark WU service to start on demand.");

            *pfPreviouslyDisabled = TRUE;
        }
    }

    *pschWu = schWu;
    schWu = NULL;

LExit:
    ReleaseMem(pConfig);
    ReleaseServiceHandle(schWu);
    ReleaseServiceHandle(schSCM);

    return hr;
}
Beispiel #16
0
DAPI_(void) BalConditionsUninitialize(
    __in BAL_CONDITIONS* pConditions
    )
{
    for (DWORD i = 0; i < pConditions->cConditions; ++i)
    {
        ReleaseStr(pConditions->rgConditions[i].sczMessage);
        ReleaseStr(pConditions->rgConditions[i].sczCondition);
    }

    ReleaseMem(pConditions->rgConditions);
    memset(pConditions, 0, sizeof(BAL_CONDITIONS));
}
Beispiel #17
0
static HRESULT ParseWxlControls(
    __in IXMLDOMElement* pElement,
    __in WIX_LOCALIZATION* pWixLoc
    )
{
    HRESULT hr = S_OK;
    IXMLDOMNode* pixn = NULL;
    IXMLDOMNodeList* pixnl = NULL;
    DWORD dwIdx = 0;

    hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl);
    ExitOnLastError(hr, "Failed to get UI child nodes of Wxl File.");

    hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls));
    ExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File.");

    if (0 < pWixLoc->cLocControls)
    {
        pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE));
        ExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls.");

        while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL)))
        {
            hr = ParseWxlControl(pixn, dwIdx, pWixLoc);
            ExitOnFailure(hr, "Failed to parse localized control.");

            ++dwIdx;
            ReleaseNullObject(pixn);
        }

        hr = S_OK;
        ExitOnFailure(hr, "Failed to enumerate all localized controls.");
    }

LExit:
    if (FAILED(hr) && pWixLoc->rgLocControls)
    {
        for (DWORD idx = 0; idx < pWixLoc->cLocControls; ++idx)
        {
            ReleaseStr(pWixLoc->rgLocControls[idx].wzControl);
            ReleaseStr(pWixLoc->rgLocControls[idx].wzText);
        }

        ReleaseMem(pWixLoc->rgLocControls);
    }

    ReleaseObject(pixn);
    ReleaseObject(pixnl);

    return hr;
}
Beispiel #18
0
extern "C" void DAPI LocFree(
    __in_opt WIX_LOCALIZATION* pWixLoc
    )
{
    if (pWixLoc)
    {
        for (DWORD idx = 0; idx < pWixLoc->cLocStrings; ++idx)
        {
            ReleaseStr(pWixLoc->rgLocStrings[idx].wzId);
            ReleaseStr(pWixLoc->rgLocStrings[idx].wzText);
        }

        for (DWORD idx = 0; idx < pWixLoc->cLocControls; ++idx)
        {
            ReleaseStr(pWixLoc->rgLocControls[idx].wzControl);
            ReleaseStr(pWixLoc->rgLocControls[idx].wzText);
        }

        ReleaseMem(pWixLoc->rgLocStrings);
        ReleaseMem(pWixLoc->rgLocControls);
        ReleaseMem(pWixLoc);
    }
}
Beispiel #19
0
/******************************************************************
 PromptToContinue - displays the prompt if the application is still
  running.

******************************************************************/
static HRESULT PromptToContinue(
    __in_z LPCWSTR wzApplication,
    __in_z LPCWSTR wzPrompt
    )
{
    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;
    PMSIHANDLE hRecMessage = NULL;
    DWORD *prgProcessIds = NULL;
    DWORD cProcessIds = 0;

    hRecMessage = ::MsiCreateRecord(1);
    ExitOnNull(hRecMessage, hr, E_OUTOFMEMORY, "Failed to create record for prompt.");

    er = ::MsiRecordSetStringW(hRecMessage, 0, wzPrompt);
    ExitOnWin32Error(er, hr, "Failed to set prompt record field string");

    do
    {
        hr = ProcFindAllIdsFromExeName(wzApplication, &prgProcessIds, &cProcessIds);
        if (SUCCEEDED(hr) && 0 < cProcessIds)
        {
            er = WcaProcessMessage(static_cast<INSTALLMESSAGE>(INSTALLMESSAGE_WARNING | MB_ABORTRETRYIGNORE | MB_DEFBUTTON3 | MB_ICONWARNING), hRecMessage);
            if (IDABORT == er)
            {
                hr = HRESULT_FROM_WIN32(ERROR_INSTALL_USEREXIT);
            }
            else if (IDRETRY == er)
            {
                hr = S_FALSE;
            }
            else if (IDIGNORE == er)
            {
                hr = S_OK;
            }
            else
            {
                ExitOnWin32Error(er, hr, "Unexpected return value from prompt to continue.");
            }
        }

        ReleaseNullMem(prgProcessIds);
        cProcessIds = 0;
    } while (S_FALSE == hr);

LExit:
    ReleaseMem(prgProcessIds);
    return hr;
}
Beispiel #20
0
extern "C" void ExeEnginePackageUninitialize(
    __in BURN_PACKAGE* pPackage
    )
{
    ReleaseStr(pPackage->Exe.sczDetectCondition);
    ReleaseStr(pPackage->Exe.sczInstallArguments);
    ReleaseStr(pPackage->Exe.sczRepairArguments);
    ReleaseStr(pPackage->Exe.sczUninstallArguments);
    ReleaseStr(pPackage->Exe.sczIgnoreDependencies);
    //ReleaseStr(pPackage->Exe.sczProgressSwitch);
    ReleaseMem(pPackage->Exe.rgExitCodes);

    // clear struct
    memset(&pPackage->Exe, 0, sizeof(pPackage->Exe));
}
    void CfgTest::ExpectNoFile(CFGDB_HANDLE cdhDb, LPCWSTR wzFileName)
    {
        HRESULT hr = S_OK;
        BYTE *pbLocalBuffer = NULL;
        SIZE_T cbLocalBuffer = 0;

        hr = CfgGetBlob(cdhDb, wzFileName, &pbLocalBuffer, &cbLocalBuffer);
        if (E_NOTFOUND != hr)
        {
            hr = E_FAIL;
            ExitOnFailure(hr, "File shouldn't be here, but it is!");
        }

    LExit:
        ReleaseMem(pbLocalBuffer);
    }
    void CfgTest::CheckCfgAndFileDeleted(CFGDB_HANDLE cdhDb, LPCWSTR wzFileName, LPCWSTR wzFilePath)
    {
        HRESULT hr = S_OK;
        BYTE *pbDataReadFromFile = NULL;
        DWORD cbDataReadFromFile = 0;

        ExpectNoFile(cdhDb, wzFileName);

        hr = FileRead(&pbDataReadFromFile, &cbDataReadFromFile, wzFilePath);
        if (E_FILENOTFOUND != hr && E_PATHNOTFOUND != hr)
        {
            ExitOnFailure1(hr, "Shouldn't have found file: %ls", wzFilePath);
        }
    LExit:
        ReleaseMem(pbDataReadFromFile);
    }
Beispiel #23
0
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));
}
Beispiel #24
0
static int FindUnusedDirName(Directory *d, char *pathName)
{
  int    foundFlag=0;     /* Set if we're successful in finding a filename */
  int    i, fileNum;
  char   fileName[FILENAMESIZE];
  struct stat s;


  /* Try FINDUNUSEDFILETRIES times to find a dirname */

  for (i=0; i<=FINDUNUSEDFILETRIES; i++)
    {
      fileNum=MAXNUMDIRS*rand()/RAND_MAX;
      sprintf(fileName, "/d%d", fileNum);
      strcpy(pathName, d->DirPathName);
      strcat(pathName, fileName);
      if ( stat(pathName, &s) == -1)
	  {
	    if (errno==ENOENT)  /* Here stat has failed because the dir.   */
				/* doesn't exist - so it's ok to create it */
	    { foundFlag=1;
	      break;
	    }
	    else
	    {                 /* Here stat has failed for some unexpected */
			      /* reason                                   */
	      printf("Couldn't stat file '%s' for some reason\n", pathName);

	      free(safetyBlock); /* Could be because we ran out of memory */
	      ReleaseMem();
	      return 0;
	    }
	  }
    }

  /* Give up now if we failed to find a suitable filename */
  if (!foundFlag)
  { if (verbose)
      printf(
	"FindUnusedDirName: couldn't find a suitable name: giving up!\n"
	     );
    return 0;
  }
  else
    return 1;
}
Beispiel #25
0
static HRESULT ParseWxl(
    __in IXMLDOMDocument* pixd,
    __out WIX_LOCALIZATION** ppWixLoc
    )
{
    HRESULT hr = S_OK;
    IXMLDOMElement *pWxlElement = NULL;
    WIX_LOCALIZATION* pWixLoc = NULL;

    pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE));
    ExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file.");

    // read the WixLocalization tag
    hr = pixd->get_documentElement(&pWxlElement);
    ExitOnFailure(hr, "Failed to get localization element.");

    // get the Language attribute if present
    pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET;
    hr = XmlGetAttributeNumber(pWxlElement, L"Language", &pWixLoc->dwLangId);
    if (S_FALSE == hr)
    {
        hr = S_OK;
    }
    ExitOnFailure(hr, "Failed to get Language value.");

    // store the strings and controls in a node list
    hr = ParseWxlStrings(pWxlElement, pWixLoc);
    ExitOnFailure(hr, "Parsing localization strings failed.");

    hr = ParseWxlControls(pWxlElement, pWixLoc);
    ExitOnFailure(hr, "Parsing localization controls failed.");

    *ppWixLoc = pWixLoc;
    pWixLoc = NULL;

LExit:
    ReleaseObject(pWxlElement);
    ReleaseMem(pWixLoc);

    return hr;
}
Beispiel #26
0
/******************************************************************
 SetRunningProcessProperty - helper function that sets the specified
 property if there are any instances of the specified executable
 running. Useful to show custom UI to ask for shutdown.
******************************************************************/
void SetRunningProcessProperty(
    __in LPCWSTR wzApplication,
    __in LPCWSTR wzProperty
    )
{
    DWORD *prgProcessIds = NULL;
    DWORD cProcessIds = 0;
    HRESULT hr = S_OK;

    WcaLog(LOGMSG_VERBOSE, "Checking App: %ls ", wzApplication);

    hr = ProcFindAllIdsFromExeName(wzApplication, &prgProcessIds, &cProcessIds);

    if (SUCCEEDED(hr) && 0 < cProcessIds)
    {
        WcaLog(LOGMSG_VERBOSE, "App: %ls found running, %d processes, setting '%ls' property.", wzApplication, cProcessIds, wzProperty);
        WcaSetIntProperty(wzProperty, cProcessIds);
    }

    ReleaseMem(prgProcessIds);
}
Beispiel #27
0
extern "C" HRESULT AllocHandleTheme(
    __in THEME* pTheme,
    __out HANDLE_THEME** ppHandle
    )
{
    HRESULT hr = S_OK;
    HANDLE_THEME* pHandle = NULL;

    pHandle = static_cast<HANDLE_THEME*>(MemAlloc(sizeof(HANDLE_THEME), TRUE));
    ExitOnNull(pHandle, hr, E_OUTOFMEMORY, "Failed to allocate theme handle.");

    pHandle->cReferences = 1;
    pHandle->pTheme = pTheme;

    *ppHandle = pHandle;
    pHandle = NULL;

LExit:
    ReleaseMem(pHandle);
    return hr;
}
// ================================================================================
// FUNCTION		: SetContactInfo
// DESCRIPTION	: Set contact information from a addressbook record.
// ================================================================================
int CContactInfo::SetContactInfo(IAddrRec *pAddrRec)
{
	//clear memory before setting new values
	ReleaseMem();

	//get fields of a record
	AEEAddrField* pField;

	int noOfFilelds = IADDRREC_GetFieldCount(pAddrRec);
	if ( noOfFilelds<1 ) return SM_ADDRBOOK_NoContactInfo;

	m_nContactId = IADDRREC_GetRecID(pAddrRec);

	for ( int i=0; i<noOfFilelds; i++)
	{
		pField = IADDRREC_GetField(pAddrRec, i);

		if (!SetField(pField)) return SM_MallocFailed;
	}

	return SM_SUCCESS;
}
Beispiel #29
0
/********************************************************************
RmuAddProcessesByName - Adds all processes by the given process name
                        to the Restart Manager Session.

You should call this multiple times as necessary before calling
RmuRegisterResources.

********************************************************************/
extern "C" HRESULT DAPI RmuAddProcessesByName(
    __in PRMU_SESSION pSession,
    __in_z LPCWSTR wzProcessName
    )
{
    HRESULT hr = S_OK;
    DWORD *pdwProcessIds = NULL;
    DWORD cProcessIds = 0;
    BOOL fNotFound = FALSE;

    hr = ProcFindAllIdsFromExeName(wzProcessName, &pdwProcessIds, &cProcessIds);
    ExitOnFailure(hr, "Failed to enumerate all the processes by name %ls.", wzProcessName);

    for (DWORD i = 0; i < cProcessIds; ++i)
    {
        hr = RmuAddProcessById(pSession, pdwProcessIds[i]);
        if (E_NOTFOUND == hr)
        {
            // RmuAddProcessById returns E_NOTFOUND when this setup is not elevated and OpenProcess returned access denied (target process running under another user account). 
            fNotFound = TRUE;
        }
        else
        {
            ExitOnFailure(hr, "Failed to add process %ls (%d) to the Restart Manager session.", wzProcessName, pdwProcessIds[i]);
        }
    }

    // If one or more calls to RmuAddProcessById returned E_NOTFOUND, then return E_NOTFOUND even if other calls succeeded, so that caller can log the issue.
    if (fNotFound)
    {
        hr =  E_NOTFOUND;
    }

LExit:
    ReleaseMem(pdwProcessIds);

    return hr;
}
Beispiel #30
0
/********************************************************************
RmuAddProcessesByName - Adds all processes by the given process name
                        to the Restart Manager Session.

You should call this multiple times as necessary before calling
RmuRegisterResources.

********************************************************************/
extern "C" HRESULT DAPI RmuAddProcessesByName(
    __in PRMU_SESSION pSession,
    __in_z LPCWSTR wzProcessName
    )
{
    HRESULT hr = S_OK;
    DWORD *pdwProcessIds = NULL;
    DWORD cProcessIds = 0;

    hr = ProcFindAllIdsFromExeName(wzProcessName, &pdwProcessIds, &cProcessIds);
    ExitOnFailure1(hr, "Failed to enumerate all the processes by name %ls.", wzProcessName);

    for (DWORD i = 0; i < cProcessIds; ++i)
    {
        hr = RmuAddProcessById(pSession, pdwProcessIds[i]);
        ExitOnFailure2(hr, "Failed to add process %ls (%d) to the Restart Manager session.", wzProcessName, pdwProcessIds[i]);
    }

LExit:
    ReleaseMem(pdwProcessIds);

    return hr;
}