2025-11-28 00:35:46 +09:00

93 lines
3.1 KiB
C++

//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#include <credentialprovider.h>
#include <windows.h>
#include <strsafe.h>
#include "CSampleCredential.h"
#include <helpers.h>
#define MAX_CREDENTIALS 3
#define MAX_DWORD 0xffffffff // maximum DWORD
class CSampleProvider : public ICredentialProvider
{
public:
// IUnknown
IFACEMETHODIMP_(ULONG) AddRef()
{
return ++_cRef;
}
IFACEMETHODIMP_(ULONG) Release()
{
LONG cRef = --_cRef;
if (!cRef)
{
delete this;
}
return cRef;
}
IFACEMETHODIMP QueryInterface(__in REFIID riid, __deref_out void** ppv)
{
static const QITAB qit[] =
{
QITABENT(CSampleProvider, ICredentialProvider), // IID_ICredentialProvider
{0},
};
return QISearch(this, qit, riid, ppv);
}
public:
IFACEMETHODIMP SetUsageScenario(__in CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, __in DWORD dwFlags);
IFACEMETHODIMP SetSerialization(__in const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs);
IFACEMETHODIMP Advise(__in ICredentialProviderEvents* pcpe, __in UINT_PTR upAdviseContext);
IFACEMETHODIMP UnAdvise();
IFACEMETHODIMP GetFieldDescriptorCount(__out DWORD* pdwCount);
IFACEMETHODIMP GetFieldDescriptorAt(__in DWORD dwIndex, __deref_out CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd);
IFACEMETHODIMP GetCredentialCount(__out DWORD* pdwCount,
__out_range(<,*pdwCount) DWORD* pdwDefault,
__out BOOL* pbAutoLogonWithDefault);
IFACEMETHODIMP GetCredentialAt(__in DWORD dwIndex,
__deref_out ICredentialProviderCredential** ppcpc);
friend HRESULT CSample_CreateInstance(__in REFIID riid, __deref_out void** ppv);
protected:
CSampleProvider();
__override ~CSampleProvider();
private:
HRESULT _EnumerateOneCredential(__in DWORD dwCredientialIndex,
__in PCWSTR pwzUsername);
HRESULT _EnumerateSetSerialization();
// Create/free enumerated credentials.
HRESULT _EnumerateCredentials();
void _ReleaseEnumeratedCredentials();
void _CleanupSetSerialization();
private:
LONG _cRef;
CSampleCredential *_rgpCredentials[MAX_CREDENTIALS]; // Pointers to the credentials which will be enumerated by
// this Provider.
DWORD _dwNumCreds;
KERB_INTERACTIVE_UNLOCK_LOGON* _pkiulSetSerialization;
DWORD _dwSetSerializationCred; //index into rgpCredentials for the SetSerializationCred
bool _bAutoSubmitSetSerializationCred;
CREDENTIAL_PROVIDER_USAGE_SCENARIO _cpus;
};