1 | //
|
---|
2 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
---|
3 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
---|
4 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
---|
5 | // PARTICULAR PURPOSE.
|
---|
6 | //
|
---|
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
---|
8 | //
|
---|
9 | // Modifications (c) 2009 Sun Microsystems, Inc.
|
---|
10 | //
|
---|
11 |
|
---|
12 | #ifndef ___VBoxCredProv_h
|
---|
13 | #define ___VBoxCredProv_h
|
---|
14 |
|
---|
15 | #include <credentialprovider.h>
|
---|
16 | #include <windows.h>
|
---|
17 | #include <strsafe.h>
|
---|
18 |
|
---|
19 | #include "VBoxCredential.h"
|
---|
20 | #include "VBoxCredPoller.h"
|
---|
21 | #include "helpers.h"
|
---|
22 |
|
---|
23 | class VBoxCredProv : public ICredentialProvider
|
---|
24 | {
|
---|
25 | public:
|
---|
26 |
|
---|
27 | // IUnknown
|
---|
28 | STDMETHOD_(ULONG, AddRef)()
|
---|
29 | {
|
---|
30 | return m_cRef++;
|
---|
31 | }
|
---|
32 |
|
---|
33 | STDMETHOD_(ULONG, Release)()
|
---|
34 | {
|
---|
35 | LONG cRef = m_cRef--;
|
---|
36 | if (!cRef)
|
---|
37 | {
|
---|
38 | delete this;
|
---|
39 | }
|
---|
40 | return cRef;
|
---|
41 | }
|
---|
42 |
|
---|
43 | STDMETHOD (QueryInterface)(REFIID riid, void **ppv)
|
---|
44 | {
|
---|
45 | HRESULT hr;
|
---|
46 | if (IID_IUnknown == riid ||
|
---|
47 | IID_ICredentialProvider == riid)
|
---|
48 | {
|
---|
49 | *ppv = this;
|
---|
50 | reinterpret_cast<IUnknown*>(*ppv)->AddRef();
|
---|
51 | hr = S_OK;
|
---|
52 | }
|
---|
53 | else
|
---|
54 | {
|
---|
55 | *ppv = NULL;
|
---|
56 | hr = E_NOINTERFACE;
|
---|
57 | }
|
---|
58 | return hr;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public:
|
---|
62 |
|
---|
63 | // ICredentialProvider
|
---|
64 | IFACEMETHODIMP SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags);
|
---|
65 | IFACEMETHODIMP SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcs);
|
---|
66 |
|
---|
67 | IFACEMETHODIMP Advise(__in ICredentialProviderEvents *pcpe, UINT_PTR upAdviseContext);
|
---|
68 | IFACEMETHODIMP UnAdvise();
|
---|
69 |
|
---|
70 | IFACEMETHODIMP GetFieldDescriptorCount(__out DWORD* pdwCount);
|
---|
71 | IFACEMETHODIMP GetFieldDescriptorAt(DWORD dwIndex, __deref_out CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppcpfd);
|
---|
72 |
|
---|
73 | IFACEMETHODIMP GetCredentialCount(__out DWORD *pdwCount,
|
---|
74 | __out DWORD *pdwDefault,
|
---|
75 | __out BOOL *pbAutoLogonWithDefault);
|
---|
76 | IFACEMETHODIMP GetCredentialAt(DWORD dwIndex,
|
---|
77 | __out ICredentialProviderCredential **ppcpc);
|
---|
78 |
|
---|
79 | friend HRESULT VBoxCredProv_CreateInstance(REFIID riid, __deref_out void **ppv);
|
---|
80 |
|
---|
81 | protected:
|
---|
82 |
|
---|
83 | VBoxCredProv(void);
|
---|
84 | __override ~VBoxCredProv(void);
|
---|
85 |
|
---|
86 | public:
|
---|
87 |
|
---|
88 | // Events
|
---|
89 | void OnCredentialsProvided(const char *pszUser,
|
---|
90 | const char *pszPw,
|
---|
91 | const char *pszDomain);
|
---|
92 | private:
|
---|
93 |
|
---|
94 | LONG m_cRef; /* Reference count */
|
---|
95 | VBoxCredential *m_pCred; /* Our one and only credential */
|
---|
96 | VBoxCredPoller *m_pPoller; /* Poller thread for credential lookup */
|
---|
97 | ICredentialProviderEvents *m_pCredProvEvents; /* Used to tell our owner to re-enumerate credentials */
|
---|
98 | UINT_PTR m_upAdviseContext; /* Used to tell our owner who we are when asking to re-enumerate credentials */
|
---|
99 | CREDENTIAL_PROVIDER_USAGE_SCENARIO m_cpUS; /* Saved usage scenario */
|
---|
100 | bool m_fGotCredentials; /* Flag indicating we got some credentials to work with */
|
---|
101 | };
|
---|
102 |
|
---|
103 | #endif /* ___VBoxCredProv_h */
|
---|
104 |
|
---|