Ejemplo n.º 1
0
HRESULT CNodeFactory::GetPrivatePath(LPWSTR *ppwzPrivatePath)
{
    HRESULT                                     hr = S_OK;

    if (!ppwzPrivatePath) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    *ppwzPrivatePath = NULL;

    if (!_pwzPrivatePath) {
        hr = S_FALSE;
        goto Exit;
    }

    *ppwzPrivatePath = WSTRDupDynamic(_pwzPrivatePath);
    if (!*ppwzPrivatePath) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

Exit:
    return hr;
}
Ejemplo n.º 2
0
HRESULT VersionFromString(LPCWSTR wzVersionIn, WORD *pwVerMajor, WORD *pwVerMinor,
                          WORD *pwVerBld, WORD *pwVerRev)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzVersion = NULL;
    WCHAR                                   *pchStart = NULL;
    WCHAR                                   *pch = NULL;
    WORD                                    *pawVersions[4] = {pwVerMajor, pwVerMinor, pwVerBld, pwVerRev};
    int                                      i;

    if (!wzVersionIn || !pwVerMajor || !pwVerMinor || !pwVerRev || !pwVerBld) {
        hr = E_INVALIDARG;
        goto Exit;
    }                          

    wzVersion = WSTRDupDynamic(wzVersionIn);
    if (!wzVersion) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    pchStart = wzVersion;
    pch = wzVersion;

    *pwVerMajor = 0;
    *pwVerMinor = 0;
    *pwVerRev = 0;
    *pwVerBld = 0;

    for (i = 0; i < 4; i++) {

        while (*pch && *pch != L'.') {
            pch++;
        }
    
        if (i < 3) {
            if (!*pch) {
                // Badly formatted string
                hr = E_UNEXPECTED;
                goto Exit;
            }

            *pch++ = L'\0';
        }
    
        *(pawVersions[i]) = (WORD)StrToIntW(pchStart);
        pchStart = pch;
    }

Exit:
    SAFEDELETEARRAY(wzVersion);

    return hr;
}
Ejemplo n.º 3
0
HRESULT CDebugLog::SetProperties(IApplicationContext *pAppCtx)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzAppName = NULL;

    // Get the executable name
    if (pAppCtx) {
        hr = ::AppCtxGetWrapper(pAppCtx, ACTAG_APP_NAME, &wzAppName);
        if (FAILED(hr)) {
            goto Exit;
        }
    }

    if (wzAppName && lstrlenW(wzAppName)) {
        _wzEXEName = WSTRDupDynamic(wzAppName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
    else {
        LPWSTR               wzFileName;

        // Didn't find EXE name in appctx. Use the .EXE name.
        wzFileName = PathFindFileName(g_wzEXEPath);
        _ASSERTE(wzFileName);

        _wzEXEName = WSTRDupDynamic(wzFileName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }

Exit:
    SAFEDELETEARRAY(wzAppName);

    return hr;
}
Ejemplo n.º 4
0
HRESULT ExtractXMLAttribute(LPWSTR *ppwzValue, XML_NODE_INFO **aNodeInfo,
                            USHORT *pCurIdx, USHORT cNumRecs)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   pwzCurBuf = NULL;

    ASSERT(ppwzValue && aNodeInfo && pCurIdx && cNumRecs);

    // There shouldn't really be a previous value, but clear just to be safe.

    SAFEDELETEARRAY(*ppwzValue);

    (*pCurIdx)++;
    while (*pCurIdx < cNumRecs) {
        
        if (aNodeInfo[*pCurIdx]->dwType == XML_PCDATA ||
            aNodeInfo[*pCurIdx]->dwType == XML_ENTITYREF) {

            hr = AppendString(&pwzCurBuf, aNodeInfo[*pCurIdx]->pwcText,
                              aNodeInfo[*pCurIdx]->ulLen);
            if (FAILED(hr)) {
                goto Exit;
            }
        }
        else {
            // Reached end of data
            break;
        }

        (*pCurIdx)++;
    }

    if (!pwzCurBuf || !lstrlenW(pwzCurBuf)) {
        *ppwzValue = NULL;

        goto Exit;
    }

    *ppwzValue = WSTRDupDynamic(pwzCurBuf);
    if (!*ppwzValue) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

Exit:
    SAFEDELETEARRAY(pwzCurBuf);

    return hr;
}
Ejemplo n.º 5
0
HRESULT CDebugLogElement::Init(LPCWSTR pwzMsg)
{
    HRESULT                                    hr = S_OK;

    ASSERT(pwzMsg);

    _pszMsg = WSTRDupDynamic(pwzMsg);
    if (!_pszMsg) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }
    
Exit:
    return hr;
}
Ejemplo n.º 6
0
HRESULT CDebugLog::Init(IApplicationContext *pAppCtx, LPCWSTR szAsmName)
{
    HRESULT hr = S_OK;
    _ASSERTE(szAsmName);

    _pwzAsmName = WSTRDupDynamic(szAsmName);
    if (!_pwzAsmName) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    hr = SetProperties(pAppCtx);

Exit:
    return hr;
}
Ejemplo n.º 7
0
HRESULT ParseDirName( CTransCache *pTransCache, LPWSTR pszParentDir, LPWSTR pszAsmDir)
{
    HRESULT hr=S_OK;
    DWORD dwCache = 0;

    ASSERT(pTransCache && pszParentDir && pszAsmDir);

    dwCache = pTransCache->GetCacheType();

    ASSERT(lstrlenW(pszAsmDir) < MAX_PATH);

    if((dwCache & ASM_CACHE_GAC) || (dwCache & ASM_CACHE_ZAP))
    {
        pTransCache->_pInfo->pwzName = WSTRDupDynamic(pszParentDir);
        hr = ParseAsmDir(pszAsmDir, pTransCache);
    }
    else if(dwCache & ASM_CACHE_DOWNLOAD)
    {
        hr = ParseDLAsmDir(pszAsmDir, &(pTransCache->_pInfo->ftLastModified));
    }
    else ASSERT(0);

    return hr;
}
Ejemplo n.º 8
0
HRESULT CDebugLog::SetAsmName(IAssemblyName *pName, LPCWSTR szCodebase)
{
    HRESULT     hr = S_OK;
    DWORD       dwSize = 0;
    BOOL        bWhereRefBind = FALSE;
    LPWSTR      wzBuf = NULL;

    if(!pName) {
        bWhereRefBind = TRUE;
    }
    else {
        dwSize = 0;
        hr = pName->GetProperty(ASM_NAME_NAME, NULL, &dwSize);
        if(FAILED(hr) && hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) {
            goto Exit;
        }
        if (!dwSize) {
            bWhereRefBind = TRUE;
        }
        hr = S_OK;
    }

    if(bWhereRefBind) {
        if(!szCodebase) {
            hr = E_INVALIDARG;
            goto Exit;
        }

        wzBuf = NEW(WCHAR[MAX_URL_LENGTH+1]);
        if (!wzBuf) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
        wzBuf[0] = L'\0';
        dwSize = MAX_URL_LENGTH;
        hr = UrlCanonicalizeUnescape(szCodebase, wzBuf, &dwSize, 0);
        if (SUCCEEDED(hr)) {
            _pwzAsmName = WSTRDupDynamic(wzBuf);
            if (!_pwzAsmName) {
                hr = E_OUTOFMEMORY;
                goto Exit;
            }
        }
    }
    else {
        dwSize = 0;
        hr = pName->GetDisplayName(NULL, &dwSize, 0);
        if (FAILED(hr) && hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) {
            goto Exit;
        }

        if (dwSize) {
            _pwzAsmName = NEW(WCHAR[dwSize]);
            if (!_pwzAsmName) {
                hr = E_OUTOFMEMORY;
                goto Exit;
            }

            hr = pName->GetDisplayName(_pwzAsmName, &dwSize, 0);
            if (FAILED(hr)) {
                goto Exit;
            }
        }
    }

Exit:
    SAFEDELETEARRAY(wzBuf);
    return hr;
}
Ejemplo n.º 9
0
HRESULT CDebugLogElement::Init(LPCWSTR pwzMsg, BOOL bEscapeEntities)
{
    HRESULT                     hr = S_OK;
    const DWORD                 cchReplacementSize = sizeof("&gt;") - 1;
    LPWSTR                      pwzCur;
    DWORD                       dwLen;
    DWORD                       dwSize;
    DWORD                       dwEntities;
    DWORD                       i;
    LPWSTR                      pwzEnd;
    SIZE_T                      cch;

    _ASSERTE(pwzMsg);

    if (!bEscapeEntities) {
        _pszMsg = WSTRDupDynamic(pwzMsg);
        if (!_pszMsg) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
    else {
        // Perform entity replacement on all ">" and "<" characters
    
        dwLen = lstrlenW(pwzMsg);
        dwEntities = CountEntities(pwzMsg);
    
        dwSize = dwLen + dwEntities * cchReplacementSize + 1;
    
        _pszMsg = NEW(WCHAR[dwSize]);
        if (!_pszMsg) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    
        pwzCur = _pszMsg;
        pwzEnd = _pszMsg + dwSize;
    
        for (i = 0; i < dwLen; i++) {
            cch = (SIZE_T)(pwzEnd - pwzCur);

            if (pwzMsg[i] == L'<') {
                hr = StringCchCopy(pwzCur, cch, L"&lt;");
                if (FAILED(hr)) {
                    goto Exit;
                }
                pwzCur += cchReplacementSize;
            }
            else if (pwzMsg[i] == L'>') {
                hr = StringCchCopy(pwzCur, cch, L"&gt;");
                if (FAILED(hr)) {
                    goto Exit;
                }
                pwzCur += cchReplacementSize;
            }
            else {
                *pwzCur++ = pwzMsg[i];
            }
        }
    
        *pwzCur = L'\0';
    }
    
Exit:
    return hr;
}
Ejemplo n.º 10
0
HRESULT CDebugLog::Init(IApplicationContext *pAppCtx, LPCWSTR pwzAsmName)
{
    HRESULT                                  hr = S_OK;
    LPWSTR                                   wzAppName = NULL;

    if (!pwzAsmName) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    hr = SetAsmName(pwzAsmName);
    if (FAILED(hr)) {
        goto Exit;
    }
    
    // Get the executable name

    hr = ::AppCtxGetWrapper(pAppCtx, ACTAG_APP_NAME, &wzAppName);
    if (FAILED(hr)) {
        goto Exit;
    }

    if (wzAppName && lstrlenW(wzAppName)) {
        _wzEXEName = WSTRDupDynamic(wzAppName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }
    else {
        LPWSTR               wzFileName;

        // Didn't find EXE name in appctx. Use the .EXE name.

        wzFileName = PathFindFileName(g_wzEXEPath);
        ASSERT(wzFileName);

        _wzEXEName = WSTRDupDynamic(wzFileName);
        if (!_wzEXEName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }
    }

    // Log path
    
    if (!PAL_FetchConfigurationString(TRUE, REG_VAL_FUSION_LOG_PATH, _szLogPath, MAX_PATH))
    {
        // fallback to default
        if (!PAL_GetUserConfigurationDirectory(_szLogPath, MAX_PATH))
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto Exit;
        }

        StrCatBuff(_szLogPath, L"\\FusionLogs", MAX_PATH);
    }

    PathRemoveBackslashW(_szLogPath);

Exit:
    SAFEDELETEARRAY(wzAppName);

    return hr;
}
Ejemplo n.º 11
0
HRESULT CNodeFactory::ProcessQualifyAssemblyTag(XML_NODE_INFO **aNodeInfo, USHORT cNumRecs)
{
    HRESULT                                            hr = S_OK;
    USHORT                                             idx = 1;
    LPWSTR                                             pwzAttributeNS = NULL;
    LPWSTR                                             pwzPartialName = NULL;
    LPWSTR                                             pwzFullName = NULL;
    CQualifyAssembly                                  *pqa = NULL;
    IAssemblyName                                     *pNameFull = NULL;
    IAssemblyName                                     *pNamePartial = NULL;
    IAssemblyName                                     *pNameQualified = NULL;
    LPWSTR                              wzCanonicalDisplayName=NULL;

    ASSERT(aNodeInfo && cNumRecs);

    while (idx < cNumRecs) {
        if (aNodeInfo[idx]->dwType == XML_ATTRIBUTE) {
            // Found an attribute. Find out which one, and extract the data.
            // Node: ::ExtractXMLAttribute increments idx.

            hr = ApplyNamespace(aNodeInfo[idx], &pwzAttributeNS, 0);
            if (FAILED(hr)) {
                goto Exit;
            }

            if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_PARTIALNAME)) {
                SAFEDELETEARRAY(pwzAttributeNS);

                if (pwzPartialName) {
                    // Ignore duplicate attribute
                    idx++;
                }
                else {
                    hr = ::ExtractXMLAttribute(&pwzPartialName, aNodeInfo, &idx, cNumRecs);
                    if (FAILED(hr)) {
                        goto Exit;
                    }
                }
            }
            else if (!lstrcmpW(pwzAttributeNS, XML_ATTRIBUTE_FULLNAME)) {
                SAFEDELETEARRAY(pwzAttributeNS);

                if (pwzFullName) {
                    // Ignore duplicate attribute
                    idx++;
                }
                else {
                    hr = ::ExtractXMLAttribute(&pwzFullName, aNodeInfo, &idx, cNumRecs);
                    if (FAILED(hr)) {
                        goto Exit;
                    }
                }

            }
            else {
                SAFEDELETEARRAY(pwzAttributeNS);
                idx++;
            }
        }
        else {
            idx++;
        }
    }

    if (pwzPartialName && pwzFullName) {
        DWORD                               dwSize;
        DWORD                               adwProperties[] = { ASM_NAME_NAME,
                                                                ASM_NAME_MAJOR_VERSION,
                                                                ASM_NAME_MINOR_VERSION,
                                                                ASM_NAME_BUILD_NUMBER,
                                                                ASM_NAME_REVISION_NUMBER,
                                                                ASM_NAME_CULTURE,
                                                                ASM_NAME_PUBLIC_KEY_TOKEN
                                                              };
        DWORD                               adwCmpFlags[] = { ASM_CMPF_NAME,
                                                              ASM_CMPF_MAJOR_VERSION,
                                                              ASM_CMPF_MINOR_VERSION,
                                                              ASM_CMPF_BUILD_NUMBER,
                                                              ASM_CMPF_REVISION_NUMBER,
                                                              ASM_CMPF_CULTURE,
                                                              ASM_CMPF_PUBLIC_KEY_TOKEN
                                                            };
        DWORD                               dwNumProps = sizeof(adwProperties) / sizeof(adwProperties[0]);

        if (FAILED(CreateAssemblyNameObject(&pNameFull, pwzFullName,
                                            CANOF_PARSE_DISPLAY_NAME, 0))) {
            goto Exit;
        }

        if (FAILED(CreateAssemblyNameObject(&pNamePartial, pwzPartialName,
                                            CANOF_PARSE_DISPLAY_NAME, 0))) {
            goto Exit;
        }

        // Check validity of qualification

        if (CAssemblyName::IsPartial(pNameFull) || !CAssemblyName::IsPartial(pNamePartial)) {
            goto Exit;
        }

        if (FAILED(pNamePartial->Clone(&pNameQualified))) {
            goto Exit;
        }

        for (DWORD i = 0; i < dwNumProps; i++) {
            dwSize = 0;
            if (pNamePartial->GetProperty(adwProperties[i], NULL, &dwSize) != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) {
                // Partial on this field. Set pNameQualified's corresponding
                // property to whatever is in pNameFull.

                dwSize = 0;
                pNameFull->GetProperty(adwProperties[i], NULL, &dwSize);
                if (!dwSize) {
                    goto Exit;
                }
                else {
                    BYTE                       *pBuf;

                    pBuf = NEW(BYTE[dwSize]);
                    if (!pBuf) {
                        hr = E_OUTOFMEMORY;
                        goto Exit;
                    }

                    if (FAILED(pNameFull->GetProperty(adwProperties[i], pBuf, &dwSize))) {
                        SAFEDELETEARRAY(pBuf);
                        goto Exit;
                    }

                    if (FAILED(pNameQualified->SetProperty(adwProperties[i], pBuf, dwSize))) {
                        SAFEDELETEARRAY(pBuf);
                        goto Exit;
                    }

                    SAFEDELETEARRAY(pBuf);
                }
            }
            else {
                // Full-specified on this field. Make sure it matches the full ref specified.

                if (pNamePartial->IsEqual(pNameFull, adwCmpFlags[i]) != S_OK) {
                    goto Exit;
                }
            }
        }

        if (CAssemblyName::IsPartial(pNameQualified)) {
            goto Exit;
        }

        // Get canonical display name format

        wzCanonicalDisplayName = NEW(WCHAR[MAX_URL_LENGTH+1]);
        if (!wzCanonicalDisplayName)
        {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        dwSize = MAX_URL_LENGTH;
        if (FAILED(pNamePartial->GetDisplayName(wzCanonicalDisplayName, &dwSize, 0))) {
            goto Exit;
        }

        // Add qualified assembly entry to list

        pqa = new CQualifyAssembly;
        if (!pqa) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        pqa->_pwzPartialName = WSTRDupDynamic(wzCanonicalDisplayName);
        if (!pqa->_pwzPartialName) {
            hr = E_OUTOFMEMORY;
            goto Exit;
        }

        pqa->_pNameFull = pNameQualified;
        pNameQualified->AddRef();

        _listQualifyAssembly.AddTail(pqa);
    }

Exit:
    SAFEDELETEARRAY(pwzPartialName);
    SAFEDELETEARRAY(pwzFullName);

    SAFERELEASE(pNameFull);
    SAFERELEASE(pNamePartial);
    SAFERELEASE(pNameQualified);

    SAFEDELETEARRAY(wzCanonicalDisplayName);
    return hr;
}
Ejemplo n.º 12
0
HRESULT GetFusionInfo(CTransCache *pTC, LPWSTR pszAsmDir)
{
    HRESULT hr = S_OK;
    WCHAR   wzFilePath[MAX_PATH+1];
    DWORD  cbSize=0;
    PBYTE pMVID=NULL;
    DWORD dwAttrib;
    DWORD cb;
    IAssemblyName *pName=NULL;
    LPWSTR pszBuf=NULL;
    BOOL bMVIDFailed=FALSE;
    BOOL bCustomFailed=FALSE;
    BOOL bURLFailed=FALSE;
    BOOL bDispNameFailed=FALSE;
    HINI hIni=NULL;
    TRANSCACHEINFO *pTCInfo = NULL;

    ASSERT(pszAsmDir || (pTC && pTC->_pInfo->pwzPath));

    pszBuf = NEW(WCHAR[MAX_URL_LENGTH+1]);
    if (!pszBuf)
    {
        hr = E_OUTOFMEMORY;
        goto exit;
    }

    if(pTC && pTC->_pInfo->pwzPath)
    {  
        // if there is path is transprtCache obj use it. else use second param pszAsmDir
        wnsprintf(wzFilePath, MAX_PATH, L"%s", pTC->_pInfo->pwzPath);
    }
    else
    {
        wnsprintf(wzFilePath, MAX_PATH, L"%s", pszAsmDir);
    }

    if((dwAttrib = GetFileAttributes(wzFilePath)) == (DWORD) -1)
    {
        hr = E_FAIL;
        goto exit;
    }

    if(!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
    {
        // looks manifestFilePath is passed in. knock-off the filename.
        LPWSTR pszTemp = PathFindFileName(wzFilePath);
        if(pszTemp > wzFilePath)
        {
            *(pszTemp-1) = L'\0';
        }
    }
    // else we have assembly dir;

    wnsprintf(wzFilePath, MAX_PATH, L"%s\\%s", wzFilePath, g_FusionInfoFile);

    if ((hIni = PAL_IniCreate()) == NULL)
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    if (!PAL_IniLoad(hIni, wzFilePath))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

#define _ReadString(section, key, buf, size) PAL_IniReadString(hIni, section, key, buf, size)

    pTCInfo = (TRANSCACHEINFO*) pTC->_pInfo;

    cbSize = _ReadString(ASSEMBLY_INFO_STRING, MVID_KEY_STRING, pszBuf, MAX_URL_LENGTH);

    if(cbSize == MVID_LENGTH*2)
    {
        pMVID = NEW(BYTE[MVID_LENGTH]);
        if (!pMVID)
        {
            hr = E_OUTOFMEMORY;
            goto exit;
        }

        CParseUtils::UnicodeHexToBin(pszBuf, MVID_LENGTH*2, (LPBYTE) pMVID);

        SAFEDELETEARRAY(pTCInfo->blobMVID.pBlobData);
        pTCInfo->blobMVID.pBlobData = pMVID;
        pTCInfo->blobMVID.cbSize = MVID_LENGTH;
        pMVID = NULL;
    }
    else
        bMVIDFailed = TRUE;

    if(pTC->GetCacheType() & ASM_CACHE_ZAP)
    {
        cbSize = _ReadString(ASSEMBLY_INFO_STRING, CUSTOM_BLOB_STRING, pszBuf, MAX_URL_LENGTH);

        if(cbSize)
        {
            SAFEDELETEARRAY(pTCInfo->blobCustom.pBlobData);
            pTCInfo->blobCustom.pBlobData = (PBYTE) WSTRDupDynamic(pszBuf);
            if (!pTCInfo->blobCustom.pBlobData)
            {
                hr = E_OUTOFMEMORY;
                goto exit;
            }
            pTCInfo->blobCustom.cbSize = (cbSize + 1) * sizeof(WCHAR) ;
        }
        else
            bCustomFailed = TRUE;

    }
    else
    {
        cbSize = _ReadString(ASSEMBLY_INFO_STRING, URL_STRING, pszBuf, MAX_URL_LENGTH);

        if(cbSize)
        {
            SAFEDELETEARRAY(pTCInfo->pwzCodebaseURL);
            pTCInfo->pwzCodebaseURL = WSTRDupDynamic(pszBuf);

            if (!pTCInfo->pwzCodebaseURL)
            {
                hr = E_OUTOFMEMORY;
                goto exit;
            }
        }
        else
            bURLFailed = TRUE;

        if(pTC->GetCacheType() & ASM_CACHE_DOWNLOAD)
        {
            cbSize = _ReadString(ASSEMBLY_INFO_STRING, DISPLAY_NAME_STRING, pszBuf, MAX_URL_LENGTH);

            if(cbSize)
            {
                if (FAILED(hr = CreateAssemblyNameObject(&pName, pszBuf, CANOF_PARSE_DISPLAY_NAME, 0)))
                    goto exit;

                SAFEDELETEARRAY(pTCInfo->pwzName);

                if (FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_NAME,
                        (LPBYTE*) &pTCInfo->pwzName, &(cb = 0))))
                    goto exit;

                // Version
                if(FAILED(hr = pName->GetVersion(&pTCInfo->dwVerHigh, &pTCInfo->dwVerLow)))
                    goto exit;

                SAFEDELETEARRAY(pTCInfo->pwzCulture);

                // Culture
                if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CULTURE,
                    (LPBYTE*) &pTCInfo->pwzCulture, &cb))
                        || (pTCInfo->pwzCulture && !_wcslwr(pTCInfo->pwzCulture)))
                    goto exit;

                SAFEDELETEARRAY(pTCInfo->blobPKT.pBlobData);

                // PublicKeyToken
                if(FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY_TOKEN, 
                    &pTCInfo->blobPKT.pBlobData, &pTCInfo->blobPKT.cbSize)))
                    goto exit;
            }
            else
                bDispNameFailed = TRUE;
        }
    }

exit:

    SAFEDELETEARRAY(pszBuf);
    SAFEDELETEARRAY(pMVID);
    SAFERELEASE(pName);

    if(SUCCEEDED(hr))
    {
        if(bMVIDFailed || bCustomFailed)
            hr = E_FAIL;
        else if(bDispNameFailed || bURLFailed)
            hr = S_FALSE;
    }

    return hr;
}
Ejemplo n.º 13
0
// ---------------------------------------------------------------------------
// CEnumCache::GetNextAssemblyDir
// ---------------------------------------------------------------------------
HRESULT
CEnumCache::GetNextAssemblyDir(CTransCache* pOutRecord)
{
    HRESULT hr = S_FALSE;
    DWORD dwCmpResult = 0;
    BOOL fIsMatch = FALSE;
    BOOL fFound = FALSE;
    WIN32_FIND_DATA FindFileData;
    WCHAR           wzFullSearchPath[MAX_PATH+1];
    DWORD dwAttr=0;
    WCHAR wzFullPath[MAX_PATH+1];
    DWORD dwCacheType=0;

    if( !pOutRecord )
    {
        hr = E_INVALIDARG;
        goto exit;
    }

    if(_fAllDone)
    {
        hr = S_FALSE;
        goto exit;
    }

    ASSERT(lstrlenW(_wzParentDir));

    if(_hAsmDir == INVALID_HANDLE_VALUE)
    {
        if( (lstrlenW(_wzCachePath) + lstrlenW(_wzParentDir) + lstrlenW(g_szFindAllMask) + 4) >= MAX_PATH)
        {
            hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
            goto exit;
        }

        StrCpy(wzFullSearchPath, _wzCachePath);
        PathAddBackslash(wzFullSearchPath);
        StrCat(wzFullSearchPath, _wzParentDir);

        dwAttr = GetFileAttributes(wzFullSearchPath);
        if((dwAttr == (DWORD) -1) || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY ))
        {
            hr = S_FALSE;
            goto exit;
        }

        StrCat(wzFullSearchPath, g_szFindAllMask);
        
        _hAsmDir = FindFirstFile(wzFullSearchPath, &FindFileData);

        if(_hAsmDir == INVALID_HANDLE_VALUE)
        {
            hr = FusionpHresultFromLastError();
            goto exit;
        }

        fFound = TRUE;
    }
    else
    {   
        if(FindNextFile(_hAsmDir, &FindFileData))
            fFound = TRUE;
    }

    do
    {
        if(!fFound)
            break;

        if (!StrCmp(FindFileData.cFileName, L"."))
                continue;

        if (!StrCmp(FindFileData.cFileName, L".."))
                continue;

        if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
            continue;

        hr = ParseDirName ( pOutRecord, _wzParentDir, FindFileData.cFileName );
        if(hr != S_OK)
        {
            pOutRecord->CleanInfo(pOutRecord->_pInfo, TRUE);
            continue;
        }

        if( (lstrlenW(_wzCachePath) + lstrlenW(_wzParentDir) + lstrlenW(FindFileData.cFileName) + 4) >= MAX_PATH)
        {
            hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
            goto exit;
        }

        StrCpy(wzFullPath, _wzCachePath);
        PathAddBackslash(wzFullPath);
        StrCat(wzFullPath, _wzParentDir);
        PathAddBackslash(wzFullPath);
        StrCat(wzFullPath, FindFileData.cFileName);

        dwCacheType = _pQry->GetCacheType();
        hr = GetFusionInfo( pOutRecord, wzFullPath);
        if((hr != S_OK) && (dwCacheType != ASM_CACHE_GAC) && !_bShowAll)
        {
            pOutRecord->CleanInfo(pOutRecord->_pInfo, TRUE);
            continue;
        }

        PathAddBackslash(wzFullPath);

        DWORD dwLen = 0;

        if(dwCacheType & ASM_CACHE_DOWNLOAD)
        {
            if(!pOutRecord->_pInfo->pwzName)
            {
                if(_bShowAll)
                    goto Done;
                else
                    continue;
            }

            StrCatBuff(wzFullPath, pOutRecord->_pInfo->pwzName, MAX_PATH);
        }
        else
        {
            StrCatBuff(wzFullPath, _wzParentDir, MAX_PATH);
        }

        dwLen = lstrlenW(wzFullPath);

        StrCatBuff(wzFullPath, g_szDotDLL, MAX_PATH);
        if(((dwCacheType & ASM_CACHE_DOWNLOAD) || (dwCacheType & ASM_CACHE_ZAP) ) &&
                    (GetFileAttributes(wzFullPath) == (DWORD) -1) )
        {
            // there is no AsmName.dll look for AsmName.exe

            if( (dwLen + lstrlenW(g_szDotEXE)) >= MAX_PATH)
            {
                hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
                goto exit;
            }

            StrCpy(wzFullPath+dwLen, g_szDotEXE);
        }

        if(!_bShowAll)
        {
            fIsMatch = _pQry->IsMatch(pOutRecord, _dwCmpMask, &dwCmpResult);                
            if(!fIsMatch)
            {
                pOutRecord->CleanInfo(pOutRecord->_pInfo, TRUE);
                continue;
            }
        }

Done :
        SAFEDELETEARRAY(pOutRecord->_pInfo->pwzPath);
        pOutRecord->_pInfo->pwzPath = WSTRDupDynamic(wzFullPath);

        hr = S_OK;
        goto exit;

    }while(FindNextFile(_hAsmDir, &FindFileData)); // while 

    if( GetLastError() != ERROR_NO_MORE_FILES)
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    hr = S_FALSE;
    FindClose(_hAsmDir);
    _hAsmDir = INVALID_HANDLE_VALUE;

    if(_hParentDir == INVALID_HANDLE_VALUE)
        _fAllDone = TRUE;

exit :
    return hr;
}
Ejemplo n.º 14
0
// ---------------------------------------------------------------------------
// CCache::InsertTransCacheEntry
//---------------------------------------------------------------------------
HRESULT CCache::InsertTransCacheEntry(IAssemblyName *pName,
    LPTSTR szPath, DWORD dwKBSize, DWORD dwFlags,
    DWORD dwCommitFlags, DWORD dwPinBits, CTransCache **ppTransCache)
{
    HRESULT hr;
    DWORD cb, dwCacheId;
    TRANSCACHEINFO *pTCInfo = NULL;
    CTransCache *pTransCache = NULL;
    LPWSTR pwzCodebaseUrl = NULL;
    WCHAR pwzCanonicalized[MAX_URL_LENGTH];
    
    
    // Determine which cache index to insert to.
    if (FAILED(hr = ResolveCacheIndex(pName, dwFlags, &dwCacheId)))
        goto exit;

    // Construct new CTransCache object.
    if(FAILED(hr = CreateTransCacheEntry(dwCacheId, &pTransCache)))
        goto exit;
    

    // Cast pTransCache base info ptr to TRANSCACHEINFO ptr
    pTCInfo = (TRANSCACHEINFO*) pTransCache->_pInfo;
    
    // Downcased text name from target
    if (FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_NAME,
            (LPBYTE*) &pTCInfo->pwzName, &(cb = 0))) 
    
        // Version
        || FAILED(hr = pName->GetVersion(&pTCInfo->dwVerHigh, &pTCInfo->dwVerLow))

        // Culture (downcased)
        || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CULTURE,
            (LPBYTE*) &pTCInfo->pwzCulture, &cb))
            || (pTCInfo->pwzCulture && !_wcslwr(pTCInfo->pwzCulture))

        // PublicKeyToken
        || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY_TOKEN, 
            &pTCInfo->blobPKT.pBlobData, &pTCInfo->blobPKT.cbSize))

        // Custom
        || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CUSTOM, 
            &pTCInfo->blobCustom.pBlobData, &pTCInfo->blobCustom.cbSize))

        // MVID
        || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_MVID, 
            &pTCInfo->blobMVID.pBlobData, &pTCInfo->blobMVID.cbSize))    
    
        // Codebase url if any from target
        || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_CODEBASE_URL, 
            (LPBYTE*)&pwzCodebaseUrl, &(cb = 0)))

        // Codebase last modified time if any from target.
        || FAILED(hr = pName->GetProperty(ASM_NAME_CODEBASE_LASTMOD,
            &pTCInfo->ftLastModified, &(cb = sizeof(FILETIME))))

        // PK if any from source.
        || FAILED(hr = NameObjGetWrapper(pName, ASM_NAME_PUBLIC_KEY, 
            &pTCInfo->blobPK.pBlobData, &pTCInfo->blobPK.cbSize))


        )
    {
        goto exit;
    }

    if (pwzCodebaseUrl)
    {
        cb = MAX_URL_LENGTH;
        hr = UrlCanonicalizeUnescape(pwzCodebaseUrl, pwzCanonicalized, &cb, 0);
        if (FAILED(hr)) {
            goto exit;
        }

        pTCInfo->pwzCodebaseURL = WSTRDupDynamic(pwzCanonicalized);
        if (!pTCInfo->pwzCodebaseURL) {
            hr = E_OUTOFMEMORY;
            goto exit;
        }
    }
    else
    {
        pTCInfo->pwzCodebaseURL = NULL;
    }

    // Copy in path.
    if (!(pTCInfo->pwzPath = TSTRDupDynamic(szPath)))
    {
        hr = E_OUTOFMEMORY;
        goto exit;
    }

    // File size
    pTCInfo->dwKBSize = dwKBSize;

    // Set pin Bits
    pTCInfo->dwPinBits = dwPinBits;        
             
exit:
    SAFEDELETEARRAY(pwzCodebaseUrl);

    // Base destructor takes care
    // of everything.
    if (!ppTransCache 
        || (FAILED(hr) && (hr != DB_E_DUPLICATE)))    
    {
        SAFERELEASE(pTransCache);
    }
    else 
    {
        *ppTransCache = pTransCache;
    }
    return hr;
}
Ejemplo n.º 15
0
HRESULT CNodeFactory::GetPolicyVersion(LPCWSTR wzAssemblyName,
                                       LPCWSTR wzPublicKeyToken,
                                       LPCWSTR wzCulture,
                                       LPCWSTR wzVersionIn,
                                       LPWSTR *ppwzVersionOut)
{
    HRESULT                                hr = S_OK;
    LISTNODE                               pos = NULL;
    LISTNODE                               posVer = NULL;
    LPCWSTR                                pwzCultureFormatted = NULL;
    CBindingRedir                         *pRedir = NULL;
    CAsmBindingInfo                       *pAsmInfo = NULL;

    if (!wzAssemblyName || !wzPublicKeyToken || !wzVersionIn || !ppwzVersionOut) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    if (wzCulture && (!lstrcmpiW(wzCulture, CFG_CULTURE_NEUTRAL) || !lstrlenW(wzCulture))) {
        pwzCultureFormatted = NULL;
    }
    else {
        pwzCultureFormatted = wzCulture;
    }

    *ppwzVersionOut = NULL;

    pos = _listAsmInfo.GetHeadPosition();
    while (pos) {
        pAsmInfo = _listAsmInfo.GetNext(pos);
        ASSERT(pAsmInfo);

        if ((!lstrcmpiW(wzAssemblyName, pAsmInfo->_pwzName) &&
                (pAsmInfo->_pwzPublicKeyToken && !lstrcmpiW(wzPublicKeyToken, pAsmInfo->_pwzPublicKeyToken)) &&
                ((pwzCultureFormatted && pAsmInfo->_pwzCulture && !lstrcmpiW(pwzCultureFormatted, pAsmInfo->_pwzCulture)) ||
                 (!pwzCultureFormatted && !pAsmInfo->_pwzCulture)))) {

            // Match found.

            // Look for matching version.

            posVer = (pAsmInfo->_listBindingRedir).GetHeadPosition();
            while (posVer) {
                pRedir = (pAsmInfo->_listBindingRedir).GetNext(posVer);

                if (IsMatchingVersion(pRedir->_pwzVersionOld, wzVersionIn)) {

                    // Match found

                    *ppwzVersionOut = WSTRDupDynamic(pRedir->_pwzVersionNew);
                    if (!*ppwzVersionOut) {
                        hr = E_OUTOFMEMORY;
                        goto Exit;
                    }

                    goto Exit;
                }
            }

            // We could break out of the loop here, but this prevents
            // multiple matches (ie. XML had many identical <dependentAssembly>
            // tags...
        }
    }

    // If we got here, we didn't find a match. Input Version == Output Version

    *ppwzVersionOut = WSTRDupDynamic(wzVersionIn);
    if (!*ppwzVersionOut) {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

Exit:
    return hr;
}
Ejemplo n.º 16
0
HRESULT RetrieveFromFileStore( CTransCache *pTransCache )
{
    HRESULT hr=S_OK;
    TRANSCACHEINFO *pTCInfo = NULL;
    DWORD dwCache = 0;
    WCHAR wzParentDirName[MAX_PATH+1];
    WCHAR wzSubDirName[MAX_PATH+1];
    DWORD dwLen =0;
    WCHAR wzCacheLocation[MAX_PATH+1];
    ASSERT(pTransCache);

    pTCInfo = (TRANSCACHEINFO*) pTransCache->_pInfo;
    dwCache = pTransCache->GetCacheType();

    dwLen = MAX_PATH;
    if(FAILED(hr = CreateAssemblyDirPath( pTransCache->GetCustomPath(), 0, pTransCache->GetCacheType(),
                                           0, wzCacheLocation, &dwLen)))
        goto exit;

    hr = GetCacheDirsFromTransCache(pTransCache, 0, wzParentDirName, wzSubDirName);
    if(FAILED(hr))
        goto exit;

    if( (lstrlenW(wzCacheLocation) + lstrlenW(wzParentDirName) + lstrlenW(wzSubDirName) +
            lstrlenW(g_szDotDLL) + max(lstrlenW(wzParentDirName), lstrlen(pTCInfo->pwzName)) + 4) >= MAX_PATH)
    {
        hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
        goto exit;
    }

    PathAddBackslash(wzCacheLocation);
    StrCat(wzCacheLocation, wzParentDirName);
    PathAddBackslash(wzCacheLocation);
    StrCat(wzCacheLocation, wzSubDirName);

    if(GetFileAttributes(wzCacheLocation) == (DWORD) -1)
    {
        hr = DB_S_NOTFOUND;
        goto exit;
    }
    else
    {
        hr = DB_S_FOUND;
    }

    PathAddBackslash(wzCacheLocation);

    {
        StrCat(wzCacheLocation, pTCInfo->pwzName);
        dwLen  = lstrlenW(wzCacheLocation);
        StrCat(wzCacheLocation, g_szDotDLL);
        if(GetFileAttributes(wzCacheLocation) == (DWORD) -1)
        {
            // there is no AsmName.dll look for AsmName.exe
            StrCpy(wzCacheLocation+dwLen, g_szDotEXE);
        }
    }

    SAFEDELETEARRAY(pTCInfo->pwzPath);
    pTCInfo->pwzPath = WSTRDupDynamic(wzCacheLocation);

    if(!pTCInfo->pwzPath)
    {
        hr = E_OUTOFMEMORY;
        goto exit;
    }

exit :

    return hr;
}
Ejemplo n.º 17
0
HRESULT CNodeFactory::GetCodebaseHint(LPCWSTR pwzAsmName, LPCWSTR pwzVersion,
                                      LPCWSTR pwzPublicKeyToken, LPCWSTR pwzCulture,
                                      LPCWSTR pwzAppBase, LPWSTR *ppwzCodebase)
{
    HRESULT                                   hr = S_OK;
    LISTNODE                                  pos = NULL;
    LISTNODE                                  posCB = NULL;
    LPCWSTR                                   pwzCultureFormatted;
    LPWSTR                                    wzCombined=NULL;
    DWORD                                     dwSize;
    CAsmBindingInfo                          *pAsmInfo = NULL;
    CCodebaseHint                            *pCodebase = NULL;

    if (!pwzAsmName || (pwzPublicKeyToken && !pwzVersion) || !ppwzCodebase || !pwzAppBase) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    if (pwzCulture && (!lstrcmpiW(pwzCulture, CFG_CULTURE_NEUTRAL) || !lstrlenW(pwzCulture))) {
        pwzCultureFormatted = NULL;
    }
    else {
        pwzCultureFormatted = pwzCulture;
    }

    *ppwzCodebase = NULL;

    wzCombined = NEW(WCHAR[MAX_URL_LENGTH+1]);
    if (!wzCombined)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    pos = _listAsmInfo.GetHeadPosition();
    while (pos) {
        pAsmInfo = _listAsmInfo.GetNext(pos);
        ASSERT(pAsmInfo);

        if ((!lstrcmpiW(pwzAsmName, pAsmInfo->_pwzName)) &&
                ((pwzPublicKeyToken && pAsmInfo->_pwzPublicKeyToken && !lstrcmpiW(pwzPublicKeyToken, pAsmInfo->_pwzPublicKeyToken))
                 || (!pwzPublicKeyToken && !pAsmInfo->_pwzPublicKeyToken)) &&
                ((pwzCultureFormatted && pAsmInfo->_pwzCulture && !lstrcmpiW(pwzCultureFormatted, pAsmInfo->_pwzCulture))
                 || (!pwzCultureFormatted && !pAsmInfo->_pwzCulture))) {

            // Match found.

            posCB = (pAsmInfo->_listCodebase).GetHeadPosition();
            while (posCB) {
                pCodebase = (pAsmInfo->_listCodebase).GetNext(posCB);
                ASSERT(pCodebase);

                if (!pwzPublicKeyToken) {
                    // No PublicKeyToken, take the first codebase (version ignored).

                    dwSize = MAX_URL_LENGTH;
                    hr = UrlCombineUnescape(pwzAppBase, pCodebase->_pwzCodebase,
                                            wzCombined, &dwSize, 0);
                    if (FAILED(hr)) {
                        goto Exit;
                    }

                    *ppwzCodebase = WSTRDupDynamic(wzCombined);
                    if (!*ppwzCodebase) {
                        hr = E_OUTOFMEMORY;
                        goto Exit;
                    }

                    goto Exit;
                }
                else {
                    // Match version.

                    if (pCodebase->_pwzVersion && !lstrcmpiW(pwzVersion, pCodebase->_pwzVersion)) {
                        // Match found.

                        dwSize = MAX_URL_LENGTH;
                        hr = UrlCombineUnescape(pwzAppBase, pCodebase->_pwzCodebase,
                                                wzCombined, &dwSize, 0);
                        if (FAILED(hr)) {
                            goto Exit;
                        }

                        *ppwzCodebase = WSTRDupDynamic(wzCombined);
                        if (!*ppwzCodebase) {
                            hr = E_OUTOFMEMORY;
                            goto Exit;
                        }

                        goto Exit;
                    }
                }
            }
        }
    }

    // Did not find codebase hint.

    hr = S_FALSE;

Exit:
    SAFEDELETEARRAY(wzCombined);
    return hr;
}