我正在开发凭据提供程序和过滤器。我对锁定方案有一些问题。
首先,我从这里尝试了 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"
实际上,除了锁定场景之外,一切都运行良好。所以,在我成功登录后,我点击锁定。通常,如果我切换用户或注销,我的凭据应该会出现在登录屏幕上。但是现在,只执行过滤器后,什么都没有出现,只有蓝色的登录屏幕,没有任何凭据。
有谁知道会发生什么以及该怎么做?