1 | /* $Id: VBoxCredProvFactory.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxCredentialProvFactory - The VirtualBox Credential Provider Factory.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #include "VBoxCredentialProvider.h"
|
---|
33 | #include "VBoxCredProvFactory.h"
|
---|
34 | #include "VBoxCredProvProvider.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | /*********************************************************************************************************************************
|
---|
38 | * Internal Functions *
|
---|
39 | *********************************************************************************************************************************/
|
---|
40 | extern HRESULT VBoxCredProvProviderCreate(REFIID interfaceID, void **ppvInterface);
|
---|
41 |
|
---|
42 |
|
---|
43 | VBoxCredProvFactory::VBoxCredProvFactory(void) :
|
---|
44 | m_cRefs(1) /* Start with one instance. */
|
---|
45 | {
|
---|
46 | }
|
---|
47 |
|
---|
48 | VBoxCredProvFactory::~VBoxCredProvFactory(void)
|
---|
49 | {
|
---|
50 | }
|
---|
51 |
|
---|
52 | ULONG
|
---|
53 | VBoxCredProvFactory::AddRef(void)
|
---|
54 | {
|
---|
55 | LONG cRefs = InterlockedIncrement(&m_cRefs);
|
---|
56 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: AddRef: Returning refcount=%ld\n",
|
---|
57 | cRefs);
|
---|
58 | return cRefs;
|
---|
59 | }
|
---|
60 |
|
---|
61 | ULONG
|
---|
62 | VBoxCredProvFactory::Release(void)
|
---|
63 | {
|
---|
64 | LONG cRefs = InterlockedDecrement(&m_cRefs);
|
---|
65 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: Release: Returning refcount=%ld\n",
|
---|
66 | cRefs);
|
---|
67 | if (!cRefs)
|
---|
68 | {
|
---|
69 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: Calling destructor\n");
|
---|
70 | delete this;
|
---|
71 | }
|
---|
72 | return cRefs;
|
---|
73 | }
|
---|
74 |
|
---|
75 | HRESULT
|
---|
76 | VBoxCredProvFactory::QueryInterface(REFIID interfaceID, void **ppvInterface)
|
---|
77 | {
|
---|
78 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: QueryInterface\n");
|
---|
79 |
|
---|
80 | HRESULT hr = S_OK;
|
---|
81 | if (ppvInterface)
|
---|
82 | {
|
---|
83 | if ( IID_IClassFactory == interfaceID
|
---|
84 | || IID_IUnknown == interfaceID)
|
---|
85 | {
|
---|
86 | *ppvInterface = static_cast<IUnknown*>(this);
|
---|
87 | reinterpret_cast<IUnknown*>(*ppvInterface)->AddRef();
|
---|
88 | }
|
---|
89 | else
|
---|
90 | {
|
---|
91 | *ppvInterface = NULL;
|
---|
92 | hr = E_NOINTERFACE;
|
---|
93 | }
|
---|
94 | }
|
---|
95 | else
|
---|
96 | hr = E_INVALIDARG;
|
---|
97 | return hr;
|
---|
98 | }
|
---|
99 |
|
---|
100 | HRESULT
|
---|
101 | VBoxCredProvFactory::CreateInstance(IUnknown *pUnkOuter, REFIID interfaceID, void **ppvInterface)
|
---|
102 | {
|
---|
103 | if (pUnkOuter)
|
---|
104 | return CLASS_E_NOAGGREGATION;
|
---|
105 | return VBoxCredProvProviderCreate(interfaceID, ppvInterface);
|
---|
106 | }
|
---|
107 |
|
---|
108 | HRESULT
|
---|
109 | VBoxCredProvFactory::LockServer(BOOL fLock)
|
---|
110 | {
|
---|
111 | if (fLock)
|
---|
112 | VBoxCredentialProviderAcquire();
|
---|
113 | else
|
---|
114 | VBoxCredentialProviderRelease();
|
---|
115 | return S_OK;
|
---|
116 | }
|
---|
117 |
|
---|