-
Notifications
You must be signed in to change notification settings - Fork 21
/
CSampleProvider.h
153 lines (126 loc) · 4.32 KB
/
CSampleProvider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// 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 "helpers.h"
#include <windows.h>
#include <strsafe.h>
#include <new>
//#include <iostream>
#include <vector>
#include "CSampleCredential.h"
#define SHIFTED 0x8000
//using namespace std;
#pragma once
class CSampleProvider : public ICredentialProvider,
public ICredentialProviderSetUserArray
{
public:
// IUnknown
IFACEMETHODIMP_(ULONG) AddRef()
{
return ++_cRef;
}
IFACEMETHODIMP_(ULONG) Release()
{
long cRef = --_cRef;
if (!cRef)
{
delete this;
}
return cRef;
}
IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv)
{
static const QITAB qit[] =
{
QITABENT(CSampleProvider, ICredentialProvider), // IID_ICredentialProvider
QITABENT(CSampleProvider, ICredentialProviderSetUserArray), // IID_ICredentialProviderSetUserArray
{0},
};
return QISearch(this, qit, riid, ppv);
}
public:
IFACEMETHODIMP SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags);
IFACEMETHODIMP SetSerialization(_In_ CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION const *pcpcs);
IFACEMETHODIMP Advise(_In_ ICredentialProviderEvents *pcpe, _In_ UINT_PTR upAdviseContext);
IFACEMETHODIMP UnAdvise();
IFACEMETHODIMP GetFieldDescriptorCount(_Out_ DWORD *pdwCount);
IFACEMETHODIMP GetFieldDescriptorAt(DWORD dwIndex, _Outptr_result_nullonfailure_ CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppcpfd);
IFACEMETHODIMP GetCredentialCount(_Out_ DWORD *pdwCount,
_Out_ DWORD *pdwDefault,
_Out_ BOOL *pbAutoLogonWithDefault);
IFACEMETHODIMP GetCredentialAt(DWORD dwIndex,
_Outptr_result_nullonfailure_ ICredentialProviderCredential **ppcpc);
IFACEMETHODIMP SetUserArray(_In_ ICredentialProviderUserArray *users);
friend HRESULT CSample_CreateInstance(_In_ REFIID riid, _Outptr_ void** ppv);
protected:
CSampleProvider();
__override ~CSampleProvider();
private:
void _ReleaseEnumeratedCredentials();
void _CreateEnumeratedCredentials();
// std::ofstream logfile;
HRESULT _EnumerateEmpty();
HRESULT _EnumerateCredentials();
HRESULT _EnumerateEmptyTileCredential();
private:
long _cRef; // Used for reference counting.
//CSampleCredential *_pCredential[10]; // SampleV2Credential
std::vector<CSampleCredential*> _pCredential; // SampleV2Credential array
bool _fRecreateEnumeratedCredentials;
CREDENTIAL_PROVIDER_USAGE_SCENARIO _cpus;
ICredentialProviderUserArray *_pCredProviderUserArray;
};
class CLMSFilter : public ICredentialProviderFilter
{
public:
//This section contains some COM boilerplate code
// IUnknown
STDMETHOD_(ULONG, AddRef)()
{
return _cRef++;
}
STDMETHOD_(ULONG, Release)()
{
LONG cRef = _cRef--;
if (!cRef)
{
delete this;
}
return cRef;
}
STDMETHOD(QueryInterface)(REFIID riid, void** ppv)
{
HRESULT hr;
if (IID_IUnknown == riid || IID_ICredentialProviderFilter == riid)
{
*ppv = this;
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
hr = S_OK;
}
else
{
*ppv = NULL;
hr = E_NOINTERFACE;
}
return hr;
}
#pragma warning(disable:4100)
public:
friend HRESULT CLMSFilter_CreateInstance(REFIID riid, __deref_out void** ppv);
//Implementation of ICredentialProviderFilter
IFACEMETHODIMP Filter(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD
dwFlags, GUID* rgclsidProviders, BOOL* rgbAllow, DWORD cProviders);
IFACEMETHODIMP UpdateRemoteCredential(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcsIn,
CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcsOut);
protected:
CLMSFilter();
__override ~CLMSFilter();
private:
LONG _cRef;
};