-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWrappedCredentialEvents.cpp
187 lines (143 loc) · 5.55 KB
/
CWrappedCredentialEvents.cpp
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// 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.
//
// CWrappedCredentialEvents is our implementation of ICredentialProviderCredentialEvents (ICPCE).
// Most credential provider authors will not need to implement this interface,
// but a credential provider that wraps another (as this sample does) must.
// The wrapped credential will pass its "this" pointer into any calls to ICPCE,
// but LogonUI will not recognize the wrapped "this" pointer as a valid credential.
// Our implementation translates from the wrapped "this" pointer to the wrapper "this".
#include <unknwn.h>
#include "CWrappedCredentialEvents.h"
HRESULT CWrappedCredentialEvents::SetFieldState(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in CREDENTIAL_PROVIDER_FIELD_STATE cpfs)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldState(_pWrapperCredential, dwFieldID, cpfs);
}
return hr;
}
HRESULT CWrappedCredentialEvents::SetFieldInteractiveState(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE cpfis)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldInteractiveState(_pWrapperCredential, dwFieldID, cpfis);
}
return hr;
}
HRESULT CWrappedCredentialEvents::SetFieldString(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in PCWSTR psz)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldString(_pWrapperCredential, dwFieldID, psz);
}
return hr;
}
HRESULT CWrappedCredentialEvents::SetFieldBitmap(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in HBITMAP hbmp)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldBitmap(_pWrapperCredential, dwFieldID, hbmp);
}
return hr;
}
HRESULT CWrappedCredentialEvents::SetFieldCheckbox(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in BOOL bChecked, __in PCWSTR pszLabel)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldCheckbox(_pWrapperCredential, dwFieldID, bChecked, pszLabel);
}
return hr;
}
HRESULT CWrappedCredentialEvents::SetFieldComboBoxSelectedItem(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in DWORD dwSelectedItem)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldComboBoxSelectedItem(_pWrapperCredential, dwFieldID, dwSelectedItem);
}
return hr;
}
HRESULT CWrappedCredentialEvents::DeleteFieldComboBoxItem(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in DWORD dwItem)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->DeleteFieldComboBoxItem(_pWrapperCredential, dwFieldID, dwItem);
}
return hr;
}
HRESULT CWrappedCredentialEvents::AppendFieldComboBoxItem(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in PCWSTR pszItem)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->AppendFieldComboBoxItem(_pWrapperCredential, dwFieldID, pszItem);
}
return hr;
}
HRESULT CWrappedCredentialEvents::SetFieldSubmitButton(__in ICredentialProviderCredential* pcpc, __in DWORD dwFieldID, __in DWORD dwAdjacentTo)
{
UNREFERENCED_PARAMETER(pcpc);
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->SetFieldSubmitButton(_pWrapperCredential, dwFieldID, dwAdjacentTo);
}
return hr;
}
HRESULT CWrappedCredentialEvents::OnCreatingWindow(__out HWND* phwndOwner)
{
HRESULT hr = E_FAIL;
if (_pWrapperCredential && _pEvents)
{
hr = _pEvents->OnCreatingWindow(phwndOwner);
}
return hr;
}
CWrappedCredentialEvents::CWrappedCredentialEvents() :
_cRef(1), _pWrapperCredential(NULL), _pEvents(NULL)
{}
//
// Save a copy of LogonUI's ICredentialProviderCredentialEvents pointer for doing callbacks
// and the "this" pointer of the wrapper credential to specify events as coming from.
//
// Pointers are saved as weak references (ie, without a reference count) to avoid circular
// references. (For instance, The wrapper credential has a reference on the wrapped credential
// and the wrapped credential should take a reference on this object. If we had a reference
// on the wrapper credential, there would be a cycle.) The wrapper credential must manage
// the lifetime of our weak references through calls to Initialize and Uninitialize to
// prevent our weak references from becoming invalid.
//
void CWrappedCredentialEvents::Initialize(__in ICredentialProviderCredential* pWrapperCredential, __in ICredentialProviderCredentialEvents* pEvents)
{
_pWrapperCredential = pWrapperCredential;
_pEvents = pEvents;
}
//
// Erase our weak references on the wrapper credential and LogonUI's
// ICredentialProviderCredentialEvents pointer.
//
void CWrappedCredentialEvents::Uninitialize()
{
_pWrapperCredential = NULL;
_pEvents = NULL;
}