Windows凭据提供程序,筛选和解锁工作站方案

时间:2011-07-04 07:50:30

标签: visual-c++ windows-7 credentials boilerplate authentication

我正在开发凭证提供程序和过滤器。锁定方案有一些问题。

首先,我尝试了here的SampleAllControlCredentialProvider。它有效。即使我之后登录并锁定它,它也会显示我的凭证。

其次,我尝试通过添加一些代码行来创建自己的凭据提供程序过滤器。过滤器过滤掉了Windows的凭据,只允许我的凭据出现。这些是我添加的代码:

在CSampleProvider.h中,我让类实现 ICredentialProviderFilter

class CSampleProvider : public ICredentialProvider, public ICredentialProviderFilter

在CSampleProvider.h中,我将STDMETHOD(QueryInterface)更改为

STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
{
    HRESULT hr;
    if (IID_IUnknown == riid)
        {
        *ppv = this;
        AddRef();
        hr = S_OK;
        }
        else if (IID_ICredentialProvider == riid)
        {
        *ppv = static_cast<ICredentialProvider*>(this);
        AddRef();
        hr = S_OK;
        }
        else if (IID_ICredentialProviderFilter == riid)
    {
        *ppv = static_cast<ICredentialProviderFilter*>(this);
        AddRef();
        hr = S_OK;
    }
    else
    {
        *ppv = NULL;
        hr = E_NOINTERFACE;
    }
    return hr;
}

仍然在CSampleProvider.h中,我添加了这些代码行

//ICredentialProviderFilter
  public:
        /**
        * \brief method to filter CPProvider
        * \param cpus - CP usage scenario
        * \param dwFlags
        * \param rgclsidProviders
        * \param rgbAllow
        * \param cProviders
        * \return IFACEMETHODIMP
        */
        IFACEMETHODIMP Filter( 
            CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
            DWORD dwFlags,
            GUID *rgclsidProviders,
            BOOL *rgbAllow,
            DWORD cProviders);

        /**
        * \brief method to update remote logon credential
        * \param pcpcsIn - serialized logon credential
        * \param pcpcsOut - returned logon credential
        * \return IFACEMETHODIMP
        */
        IFACEMETHODIMP UpdateRemoteCredential( 
            const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcsIn,
            CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcsOut);

然后,这是过滤方法的实现(在CSampleProvider.cpp中):

HRESULT CSampleProvider::Filter(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,DWORD dwFlags,GUID* rgclsidProviders,BOOL* rgbAllow,DWORD cProviders)
{
    //UNUSED(dwFlags);
    UNREFERENCED_PARAMETER(dwFlags);
    MessageBox(NULL, "Filter!", "Trace", NULL);
    switch (cpus)
    {
        case CPUS_LOGON:
        case CPUS_UNLOCK_WORKSTATION:
            //Filters out the default Windows provider (only for Logon and Unlock scenarios)
            for (int i = 0; i < (int)cProviders; i++)
            {
                if (IsEqualGUID(rgclsidProviders[i], CLSID_CSampleProvider)) rgbAllow[i]=true;
                else rgbAllow[i] = false;;
                //rgbAllow[i]=true;
            }
        return S_OK;
        case CPUS_CREDUI:
        case CPUS_CHANGE_PASSWORD:
        return E_NOTIMPL;
        default:
        return E_INVALIDARG;
    }
}

HRESULT CSampleProvider::UpdateRemoteCredential(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsIn, CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsOut)
{
    UNREFERENCED_PARAMETER(pcpcsOut);
    UNREFERENCED_PARAMETER(pcpcsIn);
    return E_NOTIMPL;
}

最后,我运行这个.reg文件,其中包含:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{F2ADF4EC-5DAA-407e-9776-10B25A64A435}]
@="SampleAllControlsCredentialProvider"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Provider Filters\{F2ADF4EC-5DAA-407e-9776-10B25A64A435}]
@="SampleAllControlsCredentialProvider"

[HKEY_CLASSES_ROOT\CLSID\{F2ADF4EC-5DAA-407e-9776-10B25A64A435}]
@="SampleAllControlsCredentialProvider"

[HKEY_CLASSES_ROOT\CLSID\{F2ADF4EC-5DAA-407e-9776-10B25A64A435}\InprocServer32]
@="SampleAllControlsCredentialProvider.dll"
"ThreadingModel"="Apartment"

实际上,除了锁定方案之外,一切都运行良好。所以,在我成功登录后,我点击锁定。通常,如果我切换用户或注销,我的凭据应该出现在登录屏幕上。但是现在,在仅实现过滤器之后,没有任何内容,只有没有任何凭据的蓝色登录屏幕。

有谁知道会发生什么以及该怎么做?

1 个答案:

答案 0 :(得分:4)

我知道这个问题已经过时了,但由于它仅在几个月前编辑过,所以它可能仍然有用。

我相信在您的解锁方案中,您将自己的凭据提供程序排除在运行之外;尝试更改:'CLSID_CSampleProvider'到'CLSID_PasswordCredentialProvider',看看它有什么影响。我有一个Wrap Credential Provider正在运行,我正在使用带有此ID的过滤器,并且它的工作正常。我的凭据显示在登录和解锁方案下。