VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp@ 40268

Last change on this file since 40268 was 40268, checked in by vboxsync, 13 years ago

VBoxCredProv: Rewritten VirtualBox credential provider; now uses proper (optional) guest logging, added auto-logon facility status reporting.

File size: 5.0 KB
Line 
1/* $Id$ */
2/** @file
3 * VBoxCredentialProvider - Main file of the VirtualBox Credential Provider.
4 */
5
6/*
7 * Copyright (C) 2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <windows.h>
22#include <initguid.h>
23
24#include <iprt/buildconfig.h>
25#include <iprt/initterm.h>
26
27#include <VBox/VBoxGuestLib.h>
28
29#include "VBoxCredentialProvider.h"
30#include "VBoxCredProvFactory.h"
31
32/*******************************************************************************
33* Global Variables *
34*******************************************************************************/
35static LONG g_cDllRefCount = 0; /* Global DLL reference count. */
36HINSTANCE g_hDllInst = NULL; /* Global DLL hInstance. */
37
38
39
40BOOL WINAPI DllMain(HINSTANCE hInst,
41 DWORD dwReason,
42 LPVOID pReserved)
43{
44 NOREF(pReserved);
45
46 g_hDllInst = hInst;
47
48 switch (dwReason)
49 {
50 case DLL_PROCESS_ATTACH:
51 {
52 int rc = RTR3InitDll(0 /* Flags */);
53 if (RT_SUCCESS(rc))
54 rc = VbglR3Init();
55
56 if (RT_SUCCESS(rc))
57 {
58 VBoxCredProvVerbose(0, "VBoxCredProv: v%s r%s (%s %s) loaded\n",
59 RTBldCfgVersion(), RTBldCfgRevisionStr(),
60 __DATE__, __TIME__);
61 }
62
63 DisableThreadLibraryCalls(hInst);
64 break;
65 }
66
67 case DLL_PROCESS_DETACH:
68
69 VbglR3Term();
70 break;
71
72 case DLL_THREAD_ATTACH:
73 case DLL_THREAD_DETACH:
74 break;
75 }
76
77 return TRUE;
78}
79
80
81/**
82 * Increments the reference count by one. Must be released
83 * with VBoxCredentialProviderRelease() when finished.
84 *
85 * @return LONG The current referecne count.
86 */
87LONG VBoxCredentialProviderAcquire(void)
88{
89 VBoxCredProvVerbose(0, "VBoxCredProv: Increasing global refcount to %ld\n",
90 g_cDllRefCount + 1);
91 return InterlockedIncrement(&g_cDllRefCount);
92}
93
94
95/**
96 * Decrements the reference count by one.
97 *
98 * @return LONG The current referecne count.
99 */
100LONG VBoxCredentialProviderRelease(void)
101{
102 VBoxCredProvVerbose(0, "VBoxCredProv: Decreasing global refcount to %ld\n",
103 g_cDllRefCount - 1);
104 return InterlockedDecrement(&g_cDllRefCount);
105}
106
107
108/**
109 * Returns the current DLL reference count.
110 *
111 * @return LONG The current reference count.
112 */
113LONG VBoxCredentialProviderRefCount(void)
114{
115 return g_cDllRefCount;
116}
117
118
119/**
120 * Entry point for determining whether the credential
121 * provider DLL can be uloaded or not.
122 *
123 * @return HRESULT
124 */
125HRESULT __stdcall DllCanUnloadNow(void)
126{
127 return (g_cDllRefCount > 0) ? S_FALSE : S_OK;
128}
129
130
131/**
132 * Create the VirtualBox credential provider by creating
133 * its factory which then in turn can create instances of the
134 * provider itself.
135 *
136 * @return HRESULT
137 * @param classID The class ID.
138 * @param interfaceID The interface ID.
139 * @param ppvInterface Receives the interface pointer on successful
140 * object creation.
141 */
142HRESULT VBoxCredentialProviderCreate(REFCLSID classID, REFIID interfaceID, void **ppvInterface)
143{
144 HRESULT hr;
145 if (classID == CLSID_VBoxCredProvider)
146 {
147 VBoxCredProvFactory* pFactory = new VBoxCredProvFactory();
148 if (pFactory)
149 {
150 hr = pFactory->QueryInterface(interfaceID,
151 ppvInterface);
152 pFactory->Release();
153 }
154 else
155 hr = E_OUTOFMEMORY;
156 }
157 else
158 hr = CLASS_E_CLASSNOTAVAILABLE;
159
160 return hr;
161}
162
163
164/**
165 * Entry point for getting the actual credential provider
166 * class object.
167 *
168 * @return HRESULT
169 * @param classID The class ID.
170 * @param interfaceID The interface ID.
171 * @param ppvInterface Receives the interface pointer on successful
172 * object creation.
173 */
174HRESULT __stdcall DllGetClassObject(REFCLSID classID, REFIID interfaceID, void **ppvInterface)
175{
176 return VBoxCredentialProviderCreate(classID, interfaceID, ppvInterface);
177}
178
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette