-
Notifications
You must be signed in to change notification settings - Fork 21
/
CSampleCredential.h
128 lines (111 loc) · 6.73 KB
/
CSampleCredential.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
//
// 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.
//
// CSampleCredential is our implementation of ICredentialProviderCredential.
// ICredentialProviderCredential is what LogonUI uses to let a credential
// provider specify what a user tile looks like and then tell it what the
// user has entered into the tile. ICredentialProviderCredential is also
// responsible for packaging up the users credentials into a buffer that
// LogonUI then sends on to LSA.
#pragma once
#include <windows.h>
#include <strsafe.h>
#include <shlguid.h>
#include <propkey.h>
#include "common.h"
#include "dll.h"
#define ENDPOINT_AUTH_OK ((HRESULT)0x78809001)
#define ENDPOINT_AUTH_FAIL ((HRESULT)0x88809001)
#define ENDPOINT_AUTH_CONTINUE ((HRESULT)0x88809002)
class CSampleCredential : public ICredentialProviderCredential2, ICredentialProviderCredential, ICredentialProviderCredentialWithFieldOptions
{
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(CSampleCredential, ICredentialProviderCredential), // IID_ICredentialProviderCredential
QITABENT(CSampleCredential, ICredentialProviderCredential2), // IID_ICredentialProviderCredential2
QITABENT(CSampleCredential, ICredentialProviderCredentialWithFieldOptions), //IID_ICredentialProviderCredentialWithFieldOptions
{0},
};
return QISearch(this, qit, riid, ppv);
}
public:
// ICredentialProviderCredential
IFACEMETHODIMP Advise(_In_ ICredentialProviderCredentialEvents *pcpce);
IFACEMETHODIMP UnAdvise();
IFACEMETHODIMP SetSelected(_Out_ BOOL *pbAutoLogon);
IFACEMETHODIMP SetDeselected();
IFACEMETHODIMP GetFieldState(DWORD dwFieldID,
_Out_ CREDENTIAL_PROVIDER_FIELD_STATE *pcpfs,
_Out_ CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE *pcpfis);
IFACEMETHODIMP GetStringValue(DWORD dwFieldID, _Outptr_result_nullonfailure_ PWSTR *ppwsz);
IFACEMETHODIMP GetBitmapValue(DWORD dwFieldID, _Outptr_result_nullonfailure_ HBITMAP *phbmp);
IFACEMETHODIMP GetCheckboxValue(DWORD dwFieldID, _Out_ BOOL *pbChecked, _Outptr_result_nullonfailure_ PWSTR *ppwszLabel);
IFACEMETHODIMP GetComboBoxValueCount(DWORD dwFieldID, _Out_ DWORD *pcItems, _Deref_out_range_(<, *pcItems) _Out_ DWORD *pdwSelectedItem);
IFACEMETHODIMP GetComboBoxValueAt(DWORD dwFieldID, DWORD dwItem, _Outptr_result_nullonfailure_ PWSTR *ppwszItem);
IFACEMETHODIMP GetSubmitButtonValue(DWORD dwFieldID, _Out_ DWORD *pdwAdjacentTo);
IFACEMETHODIMP SetStringValue(DWORD dwFieldID, _In_ PCWSTR pwz);
IFACEMETHODIMP SetCheckboxValue(DWORD dwFieldID, BOOL bChecked);
IFACEMETHODIMP SetComboBoxSelectedValue(DWORD dwFieldID, DWORD dwSelectedItem);
IFACEMETHODIMP CommandLinkClicked(DWORD dwFieldID);
IFACEMETHODIMP GetSerialization(_Out_ CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE *pcpgsr,
_Out_ CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcs,
_Outptr_result_maybenull_ PWSTR *ppwszOptionalStatusText,
_Out_ CREDENTIAL_PROVIDER_STATUS_ICON *pcpsiOptionalStatusIcon);
IFACEMETHODIMP ReportResult(NTSTATUS ntsStatus,
NTSTATUS ntsSubstatus,
_Outptr_result_maybenull_ PWSTR *ppwszOptionalStatusText,
_Out_ CREDENTIAL_PROVIDER_STATUS_ICON *pcpsiOptionalStatusIcon);
// ICredentialProviderCredential2
IFACEMETHODIMP GetUserSid(_Outptr_result_nullonfailure_ PWSTR *ppszSid);
// ICredentialProviderCredentialWithFieldOptions
IFACEMETHODIMP GetFieldOptions(DWORD dwFieldID,
_Out_ CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS *pcpcfo);
public:
HRESULT Initialize(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
_In_ CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR const *rgcpfd,
_In_ FIELD_STATE_PAIR const *rgfsp,
_In_ ICredentialProviderUser *pcpUser);
CSampleCredential();
PWSTR _pszUserSid;
private:
HRESULT call_multiotp(_In_ PCWSTR username,
_In_ PCWSTR PREV_PIN,
_In_ PCWSTR PIN);
virtual ~CSampleCredential();
long _cRef;
CREDENTIAL_PROVIDER_USAGE_SCENARIO _cpus; // The usage scenario for which we were enumerated.
CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR _rgCredProvFieldDescriptors[SFI_NUM_FIELDS]; // An array holding the type and name of each field in the tile.
FIELD_STATE_PAIR _rgFieldStatePairs[SFI_NUM_FIELDS]; // An array holding the state of each field in the tile.
PWSTR _rgFieldStrings[SFI_NUM_FIELDS]; // An array holding the string value of each field. This is different from the name of the field held in _rgCredProvFieldDescriptors.
PWSTR _pszQualifiedUserName; // The user name that's used to pack the authentication buffer
ICredentialProviderCredentialEvents2* _pCredProvCredentialEventsV2; // CredentialEvents2 for Begin and EndFieldUpdates.
ICredentialProviderCredentialEvents* _pCredProvCredentialEventsV1; // Old CredentialEvents
ICredentialProviderCredentialEvents* _pCredProvCredentialEvents; // Used to update fields.
BOOL _fChecked; // Tracks the state of our checkbox.
DWORD _dwComboIndex; // Tracks the current index of our combobox.
bool _fShowControls; // Tracks the state of our show/hide controls link.
bool _fIsLocalUser; // If the cred prov is assosiating with a local user tile
bool _fUserNameVisible; // User can enter username
};