// Sets the value of a field which can accept a string as a value.
// This is called on each keystroke when a user types into an edit field
HRESULT CSampleCredential::SetStringValue(
    __in DWORD dwFieldID, 
    __in PCWSTR pwz      
    )
{
    HRESULT hr;

    // Validate parameters.
    if (dwFieldID < ARRAYSIZE(_rgCredProvFieldDescriptors) && 
        (CPFT_EDIT_TEXT == _rgCredProvFieldDescriptors[dwFieldID].cpft || 
        CPFT_PASSWORD_TEXT == _rgCredProvFieldDescriptors[dwFieldID].cpft)) 
    {
        PWSTR* ppwszStored = &_rgFieldStrings[dwFieldID];
        CoTaskMemFree(*ppwszStored);
        hr = SHStrDupW(pwz, ppwszStored);
    }
    else
    {
        hr = E_INVALIDARG;
    }

    return hr;
}
예제 #2
0
// Sets ppwsz to the string value of the field at the index dwFieldID. We'll check to see if 
// it's for us or the wrapped credential, and then handle or route it as appropriate.
HRESULT CXCreCredential::GetStringValue(
	__in DWORD dwFieldID, 
	__deref_out PWSTR* ppwsz
	)
{
	HRESULT hr = E_UNEXPECTED;

	// Make sure we have a wrapped credential.
	if (NULL != m_pWrappedCredential)
	{
		if (IsFieldInWrappedCredential(dwFieldID))
		{
			hr = m_pWrappedCredential->GetStringValue(dwFieldID, ppwsz);

			wchar_t wszOutLog[1024] = {0};
			swprintf(wszOutLog,L"GET - > %d:%s \r\n",dwFieldID,*ppwsz);
			OutputDebugStringW(wszOutLog);
		}
		else
		{
			FIELD_STATE_PAIR *pfsp = LookupLocalFieldStatePair(dwFieldID);
			if (pfsp != NULL)
			{	
				dwFieldID = dwFieldID - m_dwWrappedDescriptorCount;	

				hr = SHStrDupW(s_rgCredProvFieldDescriptors[dwFieldID].pszLabel,ppwsz);
			}
			else
			{
				hr = E_INVALIDARG;
			}
		}
	}

	return hr;
}
예제 #3
0
/**
 * Retrieves a descriptor of a specified field.
 *
 * @return  HRESULT
 * @param   dwIndex                 ID of field to retrieve descriptor for.
 * @param   ppFieldDescriptor       Pointer which receives the allocated field
 *                                  descriptor.
 */
HRESULT
VBoxCredProvProvider::GetFieldDescriptorAt(DWORD dwIndex, CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppFieldDescriptor)
{
    HRESULT hr = S_OK;
    if (   dwIndex < VBOXCREDPROV_NUM_FIELDS
        && ppFieldDescriptor)
    {
        PCREDENTIAL_PROVIDER_FIELD_DESCRIPTOR pcpFieldDesc =
            (PCREDENTIAL_PROVIDER_FIELD_DESCRIPTOR)CoTaskMemAlloc(sizeof(CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR));

        if (pcpFieldDesc)
        {
            const VBOXCREDPROV_FIELD &field = s_VBoxCredProvFields[dwIndex];

            RT_BZERO(pcpFieldDesc, sizeof(CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR));

            pcpFieldDesc->dwFieldID = field.desc.dwFieldID;
            pcpFieldDesc->cpft      = field.desc.cpft;
            if (field.desc.pszLabel)
                hr = SHStrDupW(field.desc.pszLabel, &pcpFieldDesc->pszLabel);
        }
        else
            hr = E_OUTOFMEMORY;

        if (SUCCEEDED(hr))
            *ppFieldDescriptor = pcpFieldDesc;
        else
            CoTaskMemFree(pcpFieldDesc);
    }
    else
        hr = E_INVALIDARG;

    VBoxCredProvVerbose(0, "VBoxCredProv::GetFieldDescriptorAt: dwIndex=%ld, ppDesc=0x%p, hr=0x%08x\n",
                        dwIndex, ppFieldDescriptor, hr);
    return hr;
}
//
// Initializes one credential with the field information passed in.
// Set the value of the SFI_USERNAME field to pwzUsername.
//
HRESULT CMessageCredential::Initialize(
    __in const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* rgcpfd,
    __in const FIELD_STATE_PAIR* rgfsp,
    __in PWSTR szMessage
    )
{
    HRESULT hr = S_OK;

    // Copy the field descriptors for each field. This is useful if you want to vary the field
    // descriptors based on what Usage scenario the credential was created for.
    for (DWORD i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(_rgCredProvFieldDescriptors); i++)
    {
        _rgFieldStatePairs[i] = rgfsp[i];
        hr = FieldDescriptorCopy(rgcpfd[i], &_rgCredProvFieldDescriptors[i]);
    }

    // Initialize the String value of the message field.
    if (SUCCEEDED(hr))
    {
        hr = SHStrDupW(szMessage, &(_rgFieldStrings[SMFI_MESSAGE]));
    }

    return S_OK;
}
예제 #5
0
/**
 * Retrieves a descriptor of a specified field.
 *
 * @return  HRESULT
 * @param   dwIndex                 ID of field to retrieve descriptor for.
 * @param   ppFieldDescriptor       Pointer which receives the allocated field
 *                                  descriptor.
 */
HRESULT
VBoxCredProvProvider::GetFieldDescriptorAt(DWORD dwIndex, CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppFieldDescriptor)
{
    HRESULT hr = S_OK;
    if (   dwIndex < VBOXCREDPROV_NUM_FIELDS
        && ppFieldDescriptor)
    {
        PCREDENTIAL_PROVIDER_FIELD_DESCRIPTOR pcpFieldDesc =
            (PCREDENTIAL_PROVIDER_FIELD_DESCRIPTOR)CoTaskMemAlloc(sizeof(CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR));

        if (pcpFieldDesc)
        {
            const VBOXCREDPROV_FIELD &field = s_VBoxCredProvDefaultFields[dwIndex];

            RT_BZERO(pcpFieldDesc, sizeof(CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR));

            pcpFieldDesc->dwFieldID     = field.desc.dwFieldID;
            pcpFieldDesc->cpft          = field.desc.cpft;

            PCRTUTF16 pcwszField = NULL;

            if (dwIndex != VBOXCREDPROV_FIELDID_PASSWORD) /* Don't ever get any password. Never ever, ever. */
            {
                if (m_pCred) /* If we have retrieved credentials, get the actual (current) value. */
                    pcwszField = m_pCred->getField(dwIndex);
                else /* Otherwise get the default value. */
                    pcwszField = field.desc.pszLabel;
            }

            hr = SHStrDupW(pcwszField ? pcwszField : L"", &pcpFieldDesc->pszLabel);

            VBoxCredProvVerbose(0, "VBoxCredProv::GetFieldDescriptorAt: dwIndex=%ld, pszLabel=%ls, hr=0x%08x\n",
                                dwIndex,
#ifdef DEBUG /* Don't show any (sensitive data) in release mode. */
                                pcwszField ? pcwszField : L"",
#else
                                L"XXX",
#endif
                                hr);

            pcpFieldDesc->guidFieldType = field.desc.guidFieldType;
        }
        else
            hr = E_OUTOFMEMORY;

        if (SUCCEEDED(hr))
        {
            *ppFieldDescriptor = pcpFieldDesc;
        }
        else if (pcpFieldDesc)
        {
            if (pcpFieldDesc->pszLabel)
            {
                CoTaskMemFree(pcpFieldDesc->pszLabel);
                pcpFieldDesc->pszLabel = NULL;
            }

            CoTaskMemFree(pcpFieldDesc);
        }
    }
    else
        hr = E_INVALIDARG;

    VBoxCredProvVerbose(0, "VBoxCredProv::GetFieldDescriptorAt: dwIndex=%ld, ppDesc=0x%p, hr=0x%08x\n",
                        dwIndex, ppFieldDescriptor, hr);
    return hr;
}
// Similarly to SetSelected, LogonUI calls this when your tile was selected
// and now no longer is. The most common thing to do here (which we do below)
// is to clear out the password field.
HRESULT COpenOTPCredential::SetDeselected()
{
    HRESULT hr = S_OK;
	if (_cpus != CPUS_UNLOCK_WORKSTATION && _rgFieldStrings[SFI_OTP_USERNAME])
    {
        size_t lenPassword = lstrlen(_rgFieldStrings[SFI_OTP_USERNAME]);
        SecureZeroMemory(_rgFieldStrings[SFI_OTP_USERNAME], lenPassword * sizeof(*_rgFieldStrings[SFI_OTP_USERNAME]));
    
        CoTaskMemFree(_rgFieldStrings[SFI_OTP_USERNAME]);
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_USERNAME]);
        if (SUCCEEDED(hr) && _pCredProvCredentialEvents)
        {
            _pCredProvCredentialEvents->SetFieldString(this, SFI_OTP_USERNAME, _rgFieldStrings[SFI_OTP_USERNAME]);
        }
    }
	if (_rgFieldStrings[SFI_OTP_LDAP_PASS])
    {
        size_t lenPassword = lstrlen(_rgFieldStrings[SFI_OTP_LDAP_PASS]);
        SecureZeroMemory(_rgFieldStrings[SFI_OTP_LDAP_PASS], lenPassword * sizeof(*_rgFieldStrings[SFI_OTP_LDAP_PASS]));
    
        CoTaskMemFree(_rgFieldStrings[SFI_OTP_LDAP_PASS]);
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_LDAP_PASS]);
        if (SUCCEEDED(hr) && _pCredProvCredentialEvents)
        {
            _pCredProvCredentialEvents->SetFieldString(this, SFI_OTP_LDAP_PASS, _rgFieldStrings[SFI_OTP_LDAP_PASS]);
        }
    }
    if (_rgFieldStrings[SFI_OTP_PASS])
    {
        size_t lenPassword = lstrlen(_rgFieldStrings[SFI_OTP_PASS]);
        SecureZeroMemory(_rgFieldStrings[SFI_OTP_PASS], lenPassword * sizeof(*_rgFieldStrings[SFI_OTP_PASS]));
    
        CoTaskMemFree(_rgFieldStrings[SFI_OTP_PASS]);
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_PASS]);
        if (SUCCEEDED(hr) && _pCredProvCredentialEvents)
        {
            _pCredProvCredentialEvents->SetFieldString(this, SFI_OTP_PASS, _rgFieldStrings[SFI_OTP_PASS]);
        }
    }
	if (_rgFieldStrings[SFI_OTP_CHALLENGE])
    {
        size_t lenPassword = lstrlen(_rgFieldStrings[SFI_OTP_CHALLENGE]);
        SecureZeroMemory(_rgFieldStrings[SFI_OTP_CHALLENGE], lenPassword * sizeof(*_rgFieldStrings[SFI_OTP_CHALLENGE]));
    
        CoTaskMemFree(_rgFieldStrings[SFI_OTP_CHALLENGE]);
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_CHALLENGE]);
        if (SUCCEEDED(hr) && _pCredProvCredentialEvents)
        {
            _pCredProvCredentialEvents->SetFieldString(this, SFI_OTP_CHALLENGE, _rgFieldStrings[SFI_OTP_CHALLENGE]);
        }
    }

	if (_cpus == CPUS_UNLOCK_WORKSTATION)
		_SetFieldScenario(SCENARIO_UNLOCK_BASE);
	else
	{
		_SetFieldScenario(SCENARIO_LOGON_BASE);
	}

	// DISABLE OPENOTP IN EVERY CASE
	_openotp_is_challenge_request = false;
	openotp_terminate(NULL);

    return hr;
}
// Initializes one credential with the field information passed in.
// Set the value of the SFI_USERNAME field to pwzUsername.
// Optionally takes a password for the SetSerialization case.
HRESULT COpenOTPCredential::Initialize(
	__in CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 
    __in const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* rgcpfd,
    __in const FIELD_STATE_PAIR* rgfsp,
	__in_opt PWSTR user_name,
	__in_opt PWSTR domain_name
    )
{
    HRESULT hr = S_OK;

	_cpus = cpus;

	if (user_name)
		_user_name = user_name;

	if (domain_name)
		_domain_name = domain_name;

    // Copy the field descriptors for each field. This is useful if you want to vary the 
    // field descriptors based on what Usage scenario the credential was created for.
    for (DWORD i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(_rgCredProvFieldDescriptors); i++)
    {
        _rgFieldStatePairs[i] = rgfsp[i];
        hr = FieldDescriptorCopy(rgcpfd[i], &_rgCredProvFieldDescriptors[i]);
    }

    // Initialize the String values of all the fields.
	if (SUCCEEDED(hr))
    {
		//if (_openotp_login_text[0] == NULL)
		//	hr = SHStrDupW(OPENOTP_DEFAULT_LOGIN_TEXT, &_rgFieldStrings[SFI_OTP_LARGE_TEXT]);
		//else
		//{
			wchar_t large_text[sizeof(_openotp_login_text)];

			int size = MultiByteToWideChar(CP_ACP, 0, _openotp_login_text, -1, large_text, 0);
			MultiByteToWideChar(CP_ACP, 0, _openotp_login_text, -1, large_text, size);

			hr = SHStrDupW(large_text, &_rgFieldStrings[SFI_OTP_LARGE_TEXT]);
		//}

		//hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_LARGE_TEXT]);
    }
	if (SUCCEEDED(hr))
    {
		if (_cpus == CPUS_UNLOCK_WORKSTATION)
			hr = SHStrDupW(WORKSTATION_LOCKED, &_rgFieldStrings[SFI_OTP_SMALL_TEXT]);
		else
			hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_SMALL_TEXT]);
	}
    if (SUCCEEDED(hr))
    {
		if (_cpus == CPUS_UNLOCK_WORKSTATION && _user_name)
		{
			hr = SHStrDupW(_user_name, &_rgFieldStrings[SFI_OTP_USERNAME]);
		}
		else
			hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_USERNAME]);
    }
    if (SUCCEEDED(hr))
    {
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_LDAP_PASS]);
    }
	if (SUCCEEDED(hr))
    {
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_PASS]);
    }
	if (SUCCEEDED(hr))
    {
        hr = SHStrDupW(L"", &_rgFieldStrings[SFI_OTP_CHALLENGE]);
    }
    if (SUCCEEDED(hr))
    {
        hr = SHStrDupW(L"Submit", &_rgFieldStrings[SFI_OTP_SUBMIT_BUTTON]);
    }

    return hr;
}
/**
 * Searches the account name based on a display (real) name (e.g. "John Doe" -> "jdoe").
 * Result "ppwszAccoutName" needs to be freed with CoTaskMemFree!
 */
BOOL VBoxCredProvCredential::TranslateAccountName(PWSTR pwszDisplayName, PWSTR *ppwszAccoutName)
{
    AssertPtrReturn(pwszDisplayName, FALSE);
    VBoxCredProvVerbose(0, "VBoxCredProvCredential::TranslateAccountName: Getting account name for \"%ls\" ...\n",
                        pwszDisplayName);

    /** @todo Do we need ADS support (e.g. TranslateNameW) here? */
    BOOL fFound = FALSE;                        /* Did we find the desired user? */
    NET_API_STATUS rcStatus;
    DWORD dwLevel = 2;                          /* Detailed information about user accounts. */
    DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
    DWORD dwEntriesRead = 0;
    DWORD dwTotalEntries = 0;
    DWORD dwResumeHandle = 0;
    LPUSER_INFO_2 pBuf = NULL;
    LPUSER_INFO_2 pCurBuf = NULL;
    do
    {
        rcStatus = NetUserEnum(NULL,             /* Server name, NULL for localhost. */
                               dwLevel,
                               FILTER_NORMAL_ACCOUNT,
                               (LPBYTE*)&pBuf,
                               dwPrefMaxLen,
                               &dwEntriesRead,
                               &dwTotalEntries,
                               &dwResumeHandle);
        if (   rcStatus == NERR_Success
            || rcStatus == ERROR_MORE_DATA)
        {
            if ((pCurBuf = pBuf) != NULL)
            {
                for (DWORD i = 0; i < dwEntriesRead; i++)
                {
                    /*
                     * Search for the "display name" - that might be
                     * "John Doe" or something similar the user recognizes easier
                     * and may not the same as the "account" name (e.g. "jdoe").
                     */
                    if (   pCurBuf
                        && pCurBuf->usri2_full_name
                        && StrCmpI(pwszDisplayName, pCurBuf->usri2_full_name) == 0)
                    {
                        /*
                         * Copy the real user name (e.g. "jdoe") to our
                         * output buffer.
                         */
                        LPWSTR pwszTemp;
                        HRESULT hr = SHStrDupW(pCurBuf->usri2_name, &pwszTemp);
                        if (hr == S_OK)
                        {
                            *ppwszAccoutName = pwszTemp;
                            fFound = TRUE;
                        }
                        else
                            VBoxCredProvVerbose(0, "VBoxCredProvCredential::TranslateAccountName: Error copying data, hr=%08x\n", hr);
                        break;
                    }
                    pCurBuf++;
                }
            }
            if (pBuf != NULL)
            {
                NetApiBufferFree(pBuf);
                pBuf = NULL;
            }
        }
    } while (rcStatus == ERROR_MORE_DATA && !fFound);

    if (pBuf != NULL)
    {
        NetApiBufferFree(pBuf);
        pBuf = NULL;
    }

    VBoxCredProvVerbose(0, "VBoxCredProvCredential::TranslateAccountName returned rcStatus=%ld, fFound=%RTbool\n",
                        rcStatus, fFound);
    return fFound;

#if 0
    DWORD dwErr = NO_ERROR;
    ULONG cbLen = 0;
    if (   TranslateNameW(pwszName, NameUnknown, NameUserPrincipal, NULL, &cbLen)
        && cbLen > 0)
    {
        VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetAccountName: Translated ADS name has %u characters\n", cbLen));

        ppwszAccoutName = (PWSTR)RTMemAlloc(cbLen * sizeof(WCHAR));
        AssertPtrReturn(pwszName, FALSE);
        if (TranslateNameW(pwszName, NameUnknown, NameUserPrincipal, ppwszAccoutName, &cbLen))
        {
            VBoxCredProvVerbose(0, "VBoxCredProvCredential::GetAccountName: Real ADS account name of '%ls' is '%ls'\n",
                 pwszName, ppwszAccoutName));
        }
예제 #9
0
// Initializes one credential with the field information passed in.
// Set the value of the SFI_LARGE_TEXT field to pwzUsername.
HRESULT CXCreCredentialV2::Initialize(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
									  _In_ ICredentialProviderUser *pcpUser,
									  CCmdEventWnd * pEventWin)
{
	HRESULT hr = S_OK;
	m_cpus = cpus;

	GUID guidProvider;
	pcpUser->GetProviderID(&guidProvider);
	m_fIsLocalUser = (guidProvider == Identity_LocalUserProvider);

	m_pEventWin = pEventWin;

	// Initialize the String value of all the fields.
	if (SUCCEEDED(hr))
	{
		hr = SHStrDupW(L"Safe Logon", &m_rgFieldStrings[SFI_LABEL]);
	}
	
	if (SUCCEEDED(hr))
	{
		hr = SHStrDupW(L"", &m_rgFieldStrings[SFI_PASSWORD]);
	}
	if (SUCCEEDED(hr))
	{
		hr = SHStrDupW(L"Submit", &m_rgFieldStrings[SFI_SUBMIT_BUTTON]);
	}
		
	if (SUCCEEDED(hr))
	{
		hr = pcpUser->GetStringValue(PKEY_Identity_QualifiedUserName, &m_pszQualifiedUserName);
	}
	/*
	if (SUCCEEDED(hr))
	{
		PWSTR pszUserName;
		pcpUser->GetStringValue(PKEY_Identity_UserName, &pszUserName);
		if (pszUserName != nullptr)
		{
			wchar_t szString[256];
			StringCchPrintf(szString, ARRAYSIZE(szString), L"User Name: %s", pszUserName);
			hr = SHStrDupW(szString, &m_rgFieldStrings[SFI_FULLNAME_TEXT]);
			CoTaskMemFree(pszUserName);
		}
		else
		{
			hr =  SHStrDupW(L"User Name is NULL", &m_rgFieldStrings[SFI_FULLNAME_TEXT]);
		}
	}
	if (SUCCEEDED(hr))
	{
		PWSTR pszDisplayName;
		pcpUser->GetStringValue(PKEY_Identity_DisplayName, &pszDisplayName);
		if (pszDisplayName != nullptr)
		{
			wchar_t szString[256];
			StringCchPrintf(szString, ARRAYSIZE(szString), L"Display Name: %s", pszDisplayName);
			hr = SHStrDupW(szString, &m_rgFieldStrings[SFI_DISPLAYNAME_TEXT]);
			CoTaskMemFree(pszDisplayName);
		}
		else
		{
			hr = SHStrDupW(L"Display Name is NULL", &m_rgFieldStrings[SFI_DISPLAYNAME_TEXT]);
		}
	}
	
	if (SUCCEEDED(hr))
	{
		PWSTR pszLogonStatus;
		pcpUser->GetStringValue(PKEY_Identity_LogonStatusString, &pszLogonStatus);
		if (pszLogonStatus != nullptr)
		{
			wchar_t szString[256];
			StringCchPrintf(szString, ARRAYSIZE(szString), L"Logon Status: %s", pszLogonStatus);
			hr = SHStrDupW(szString, &m_rgFieldStrings[SFI_LOGONSTATUS_TEXT]);
			CoTaskMemFree(pszLogonStatus);
		}
		else
		{
			hr = SHStrDupW(L"Logon Status is NULL", &m_rgFieldStrings[SFI_LOGONSTATUS_TEXT]);
		}
	}
	*/
	if (SUCCEEDED(hr))
	{
		hr = pcpUser->GetSid(&m_pszUserSid);
	}

	return hr;
}
예제 #10
0
파일: fonts.cpp 프로젝트: hackbunny/reactos
HRESULT WINAPI CFontsFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
{
    WCHAR buffer[MAX_PATH] = {0};
    HRESULT hr = E_FAIL;
    PIDLFontStruct * pfont;
    HANDLE hFile;
    LARGE_INTEGER FileSize;
    SHFILEINFOW fi;

    TRACE("(%p, %p, %d, %p)\n", this, pidl, iColumn, psd);

    if (iColumn >= FontsSHELLVIEWCOLUMNS)
        return E_FAIL;

    psd->fmt = FontsSFHeader[iColumn].fmt;
    psd->cxChar = FontsSFHeader[iColumn].cxChar;
    if (pidl == NULL)
    {
        psd->str.uType = STRRET_WSTR;
        if (LoadStringW(shell32_hInstance, FontsSFHeader[iColumn].colnameid, buffer, MAX_PATH))
            hr = SHStrDupW(buffer, &psd->str.pOleStr);

        return hr;
    }

    if (iColumn == COLUMN_NAME)
    {
        psd->str.uType = STRRET_WSTR;
        return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str);
    }

    psd->str.uType = STRRET_CSTR;
    psd->str.cStr[0] = '\0';

    switch(iColumn)
    {
        case COLUMN_TYPE:
            pfont = _ILGetFontStruct(pidl);
            if (pfont)
            {
                if (SHGetFileInfoW(pfont->szName + pfont->offsFile, 0, &fi, sizeof(fi), SHGFI_TYPENAME))
                {
                    psd->str.pOleStr = (LPWSTR)CoTaskMemAlloc((wcslen(fi.szTypeName) + 1) * sizeof(WCHAR));
                    if (!psd->str.pOleStr)
                        return E_OUTOFMEMORY;
                    wcscpy(psd->str.pOleStr, fi.szTypeName);
                    psd->str.uType = STRRET_WSTR;
                    return S_OK;
                }
            }
            break;
        case COLUMN_SIZE:
            pfont = _ILGetFontStruct(pidl);
            if (pfont)
            {
                hFile = CreateFileW(pfont->szName + pfont->offsFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
                if (hFile != INVALID_HANDLE_VALUE)
                {
                    if (GetFileSizeEx(hFile, &FileSize))
                    {
                        if (StrFormatByteSizeW(FileSize.QuadPart, buffer, sizeof(buffer) / sizeof(WCHAR)))
                        {
                            psd->str.pOleStr = (LPWSTR)CoTaskMemAlloc(wcslen(buffer) + 1);
                            if (!psd->str.pOleStr)
                            {
                                CloseHandle(hFile);
                                return E_OUTOFMEMORY;
                            }
                            wcscpy(psd->str.pOleStr, buffer);
                            psd->str.uType = STRRET_WSTR;
                            CloseHandle(hFile);
                            return S_OK;
                        }
                    }
                    CloseHandle(hFile);
                }
            }
            break;
        case COLUMN_FILENAME:
            pfont = _ILGetFontStruct(pidl);
            if (pfont)
            {
                psd->str.pOleStr = (LPWSTR)CoTaskMemAlloc((wcslen(pfont->szName + pfont->offsFile) + 1) * sizeof(WCHAR));
                if (psd->str.pOleStr)
                {
                    psd->str.uType = STRRET_WSTR;
                    wcscpy(psd->str.pOleStr, pfont->szName + pfont->offsFile);
                    return S_OK;
                }
                else
                    return E_OUTOFMEMORY;
            }
            break;
    }

    return E_FAIL;
}
예제 #11
0
HRESULT WINAPI CNetworkConnections::GetDetailsOf(
               PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS * psd)
{
    WCHAR buffer[MAX_PATH] = {0};
    HRESULT hr = E_FAIL;
    const VALUEStruct * val;
    NETCON_PROPERTIES * pProperties;

    if (iColumn >= NETCONNECTSHELLVIEWCOLUMNS)
        return E_FAIL;

    psd->fmt = NetConnectSFHeader[iColumn].fmt;
    psd->cxChar = NetConnectSFHeader[iColumn].cxChar;
    if (pidl == NULL)
    {
        psd->str.uType = STRRET_WSTR;
        if (LoadStringW(netshell_hInstance, NetConnectSFHeader[iColumn].colnameid, buffer, MAX_PATH))
            hr = SHStrDupW(buffer, &psd->str.pOleStr);

        return hr;
    }

    if (iColumn == COLUMN_NAME)
    {
        psd->str.uType = STRRET_WSTR;
        return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str);
    }

    val = _ILGetValueStruct(pidl);
    if (!val)
        return E_FAIL;

   if (!val->pItem)
       return E_FAIL;

    if (val->pItem->GetProperties(&pProperties) != S_OK)
        return E_FAIL;


    switch (iColumn)
    {
        case COLUMN_TYPE:
            if (pProperties->MediaType  == NCM_LAN || pProperties->MediaType == NCM_SHAREDACCESSHOST_RAS)
            {
                if (LoadStringW(netshell_hInstance, IDS_TYPE_ETHERNET, buffer, MAX_PATH))
                {
                    psd->str.uType = STRRET_WSTR;
                    hr = SHStrDupW(buffer, &psd->str.pOleStr);
                }
            }
            break;
        case COLUMN_STATUS:
            buffer[0] = L'\0';
            if (pProperties->Status == NCS_HARDWARE_DISABLED)
                LoadStringW(netshell_hInstance, IDS_STATUS_NON_OPERATIONAL, buffer, MAX_PATH);
            else if (pProperties->Status == NCS_DISCONNECTED)
                LoadStringW(netshell_hInstance, IDS_STATUS_UNREACHABLE, buffer, MAX_PATH);
            else if (pProperties->Status == NCS_MEDIA_DISCONNECTED)
                LoadStringW(netshell_hInstance, IDS_STATUS_DISCONNECTED, buffer, MAX_PATH);
            else if (pProperties->Status == NCS_CONNECTING)
                LoadStringW(netshell_hInstance, IDS_STATUS_CONNECTING, buffer, MAX_PATH);
            else if (pProperties->Status == NCS_CONNECTED)
                LoadStringW(netshell_hInstance, IDS_STATUS_CONNECTED, buffer, MAX_PATH);

            if (buffer[0])
            {
                buffer[MAX_PATH-1] = L'\0';
                psd->str.uType = STRRET_WSTR;
                hr = SHStrDupW(buffer, &psd->str.pOleStr);
            }
            break;
        case COLUMN_DEVNAME:
            if (pProperties->pszwDeviceName)
            {
                wcscpy(buffer, pProperties->pszwDeviceName);
                buffer[MAX_PATH-1] = L'\0';
                psd->str.uType = STRRET_WSTR;
                hr = SHStrDupW(buffer, &psd->str.pOleStr);
            }
            else
            {
                psd->str.cStr[0] = '\0';
                psd->str.uType = STRRET_CSTR;
            }
            break;
        case COLUMN_PHONE:
        case COLUMN_OWNER:
            psd->str.cStr[0] = '\0';
            psd->str.uType = STRRET_CSTR;
            break;
    }

    NcFreeNetconProperties(pProperties);
    return hr;
}
 HRESULT SetIconPath(PCWSTR pszIconPath)
 {
     return SHStrDupW(pszIconPath, &_pszIconPath);
 }