Changeset 40939 in vbox for trunk/src/VBox/Additions/WINNT
- Timestamp:
- Apr 16, 2012 1:10:30 PM (13 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/VBoxCredProv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxCredProv/Makefile.kmk
r40435 r40939 21 21 DLLS += VBoxCredProv 22 22 VBoxCredProv_TEMPLATE = VBOXGUESTR3DLL 23 VBoxCredProv_DEFS = VBGL_VBOXGUEST VBOX_WITH_HGCM UNICODE23 VBoxCredProv_DEFS = VBGL_VBOXGUEST VBOX_WITH_HGCM VBOX_WITH_SENS UNICODE 24 24 VBoxCredProv_SDKS.x86 = WINDDK 25 25 VBoxCredProv_SOURCES = \ -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
r40435 r40939 24 24 #include <iprt/buildconfig.h> 25 25 #include <iprt/initterm.h> 26 26 #ifdef VBOX_WITH_SENS 27 # include <iprt/string.h> 28 #endif 27 29 #include <VBox/VBoxGuestLib.h> 28 30 29 31 #include "VBoxCredentialProvider.h" 30 32 #include "VBoxCredProvFactory.h" 33 34 #include <eventsys.h> 35 #include <sens.h> 36 #include <Sensevts.h> 37 38 #include <stdio.h> 31 39 32 40 /******************************************************************************* … … 36 44 static HINSTANCE g_hDllInst = NULL; /**< Global DLL hInstance. */ 37 45 46 #ifdef VBOX_WITH_SENS 47 static IEventSystem *g_pIEventSystem; /**< Pointer to IEventSystem interface. */ 48 49 /** 50 * Subscribed SENS events. 51 */ 52 static struct VBOXCREDPROVSENSEVENTS 53 { 54 /** The actual method name the subscription is for. */ 55 char *pszMethod; 56 /** A friendly name for the subscription. */ 57 char *pszSubscriptionName; 58 /** The actual subscription UUID. 59 * Should not be changed. */ 60 char *pszSubscriptionUUID; 61 } g_aSENSEvents[] = { 62 { "Logon", "VBoxCredProv SENS Logon", "{561D0791-47C0-4BC3-87C0-CDC2621EA653}" }, 63 { "Logoff", "VBoxCredProv SENS Logoff", "{12B618B1-F2E0-4390-BADA-7EB1DC31A70A}" }, 64 { "StartShell", "VBoxCredProv SENS StartShell", "{5941931D-015A-4F91-98DA-81AAE262D090}" }, 65 { "DisplayLock", "VBoxCredProv SENS DisplayLock", "{B7E2C510-501A-4961-938F-A458970930D7}" }, 66 { "DisplayUnlock", "VBoxCredProv SENS DisplayUnlock", "{11305987-8FFC-41AD-A264-991BD5B7488A}" }, 67 { "StartScreenSaver", "VBoxCredProv SENS StartScreenSaver", "{6E2D26DF-0095-4EC4-AE00-2395F09AF7F2}" }, 68 { "StopScreenSaver", "VBoxCredProv SENS StopScreenSaver", "{F53426BC-412F-41E8-9A5F-E5FA8A164BD6}" } 69 }; 70 71 /** 72 * Implementation of the ISensLogon interface for getting 73 * SENS (System Event Notification Service) events. SENS must be up 74 * and running on this OS! 75 */ 76 interface VBoxCredProvSensLogon : public ISensLogon 77 { 78 public: 79 80 VBoxCredProvSensLogon(void) : 81 m_cRefs(1) 82 { 83 } 84 85 STDMETHODIMP QueryInterface(REFIID interfaceID, void **ppvInterface) 86 { 87 if ( IsEqualIID(interfaceID, IID_IUnknown) 88 || IsEqualIID(interfaceID, IID_IDispatch) 89 || IsEqualIID(interfaceID, IID_ISensLogon)) 90 { 91 *ppvInterface = this; 92 AddRef(); 93 return S_OK; 94 } 95 96 *ppvInterface = NULL; 97 return E_NOINTERFACE; 98 } 99 100 ULONG STDMETHODCALLTYPE AddRef(void) 101 { 102 return InterlockedIncrement(&m_cRefs); 103 } 104 105 ULONG STDMETHODCALLTYPE Release(void) 106 { 107 ULONG ulTemp = InterlockedDecrement(&m_cRefs); 108 return ulTemp; 109 } 110 111 HRESULT STDMETHODCALLTYPE GetTypeInfoCount(unsigned int FAR* pctinfo) 112 { 113 return E_NOTIMPL; 114 } 115 116 HRESULT STDMETHODCALLTYPE GetTypeInfo(unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo) 117 { 118 return E_NOTIMPL; 119 } 120 121 HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, 122 OLECHAR FAR* FAR* rgszNames, unsigned int cNames, 123 LCID lcid, DISPID FAR* rgDispId) 124 { 125 return E_NOTIMPL; 126 } 127 128 HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, 129 DISPPARAMS FAR* pDispParams, VARIANT FAR* parResult, EXCEPINFO FAR* pExcepInfo, 130 unsigned int FAR* puArgErr) 131 { 132 return E_NOTIMPL; 133 } 134 135 /* ISensLogon methods */ 136 STDMETHODIMP Logon(BSTR bstrUserName) 137 { 138 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: Logon\n"); 139 return S_OK; 140 } 141 142 STDMETHODIMP Logoff(BSTR bstrUserName) 143 { 144 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: Logoff\n"); 145 return S_OK; 146 } 147 148 STDMETHODIMP StartShell(BSTR bstrUserName) 149 { 150 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: Logon\n"); 151 return S_OK; 152 } 153 154 STDMETHODIMP DisplayLock(BSTR bstrUserName) 155 { 156 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: DisplayLock\n"); 157 return S_OK; 158 } 159 160 STDMETHODIMP DisplayUnlock(BSTR bstrUserName) 161 { 162 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: DisplayUnlock\n"); 163 return S_OK; 164 } 165 166 STDMETHODIMP StartScreenSaver(BSTR bstrUserName) 167 { 168 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: StartScreenSaver\n"); 169 return S_OK; 170 } 171 172 STDMETHODIMP StopScreenSaver(BSTR bstrUserName) 173 { 174 VBoxCredProvVerbose(0, "VBoxCredProvSensLogon: StopScreenSaver\n"); 175 return S_OK; 176 } 177 178 protected: 179 180 LONG m_cRefs; 181 }; 182 static VBoxCredProvSensLogon *g_pISensLogon; 183 184 185 /** 186 * Register events to be called by SENS. 187 * 188 * @return HRESULT 189 */ 190 static HRESULT VBoxCredentialProviderRegisterSENS(void) 191 { 192 VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS\n"); 193 194 HRESULT hr = CoCreateInstance(CLSID_CEventSystem, 0, CLSCTX_SERVER, IID_IEventSystem, (void**)&g_pIEventSystem); 195 if (FAILED(hr)) 196 { 197 VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not connect to CEventSystem, hr=%Rhrc\n", 198 hr); 199 return hr; 200 } 201 202 g_pISensLogon = new VBoxCredProvSensLogon(); 203 if (!g_pISensLogon) 204 { 205 VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not create interface instance; out of memory\n"); 206 return ERROR_OUTOFMEMORY; 207 } 208 209 IEventSubscription *pIEventSubscription; 210 for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++) 211 { 212 VBoxCredProvVerbose(0, "VBoxCredProv: Registering \"%s\" (%s) ...\n", 213 g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName); 214 215 hr = CoCreateInstance(CLSID_CEventSubscription, 0, CLSCTX_SERVER, IID_IEventSubscription, (LPVOID*)&pIEventSubscription); 216 if (FAILED(hr)) 217 continue; 218 219 hr = pIEventSubscription->put_EventClassID(L"{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */); 220 if (FAILED(hr)) 221 break; 222 223 hr = pIEventSubscription->put_SubscriberInterface((IUnknown*)g_pISensLogon); 224 if (FAILED(hr)) 225 break; 226 227 PRTUTF16 pwszTemp; 228 int rc = RTStrToUtf16(g_aSENSEvents[i].pszMethod, &pwszTemp); 229 if (RT_SUCCESS(rc)) 230 { 231 hr = pIEventSubscription->put_MethodName(pwszTemp); 232 RTUtf16Free(pwszTemp); 233 } 234 else 235 hr = ERROR_OUTOFMEMORY; 236 if (FAILED(hr)) 237 break; 238 239 rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionName, &pwszTemp); 240 if (RT_SUCCESS(rc)) 241 { 242 hr = pIEventSubscription->put_SubscriptionName(pwszTemp); 243 RTUtf16Free(pwszTemp); 244 } 245 else 246 hr = ERROR_OUTOFMEMORY; 247 if (FAILED(hr)) 248 break; 249 250 rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionUUID, &pwszTemp); 251 if (RT_SUCCESS(rc)) 252 { 253 hr = pIEventSubscription->put_SubscriptionID(pwszTemp); 254 RTUtf16Free(pwszTemp); 255 } 256 else 257 hr = ERROR_OUTOFMEMORY; 258 if (FAILED(hr)) 259 break; 260 261 hr = pIEventSubscription->put_PerUser(TRUE); 262 if (FAILED(hr)) 263 break; 264 265 hr = g_pIEventSystem->Store(PROGID_EventSubscription, (IUnknown*)pIEventSubscription); 266 if (FAILED(hr)) 267 break; 268 269 pIEventSubscription->Release(); 270 pIEventSubscription = NULL; 271 } 272 273 if (FAILED(hr)) 274 VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not register \"%s\" (%s), hr=%Rhrc\n", 275 g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName, hr); 276 277 if (pIEventSubscription != NULL) 278 pIEventSubscription->Release(); 279 280 return hr; 281 } 282 283 /** 284 * Unregisters registered SENS events. 285 */ 286 static void VBoxCredentialProviderUnregisterSENS(void) 287 { 288 if (g_pIEventSystem) 289 g_pIEventSystem->Release(); 290 291 /* We need to reconnecto to the event system because we can be called 292 * in a different context COM can't handle. */ 293 HRESULT hr = CoCreateInstance(CLSID_CEventSystem, 0, CLSCTX_SERVER, IID_IEventSystem, (void**)&g_pIEventSystem); 294 if (SUCCEEDED(hr)) 295 { 296 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS\n"); 297 298 HRESULT hr; 299 300 for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++) 301 { 302 int iErrorIdX; 303 304 char *pszSubToRemove; 305 if (!RTStrAPrintf(&pszSubToRemove, "SubscriptionID=%s", 306 g_aSENSEvents[i].pszSubscriptionUUID)) 307 { 308 continue; /* Keep going. */ 309 } 310 311 PRTUTF16 pwszTemp; 312 int rc2 = RTStrToUtf16(pszSubToRemove, &pwszTemp); 313 if (RT_SUCCESS(rc2)) 314 { 315 hr = g_pIEventSystem->Remove(PROGID_EventSubscription, pwszTemp, 316 &iErrorIdX); 317 RTUtf16Free(pwszTemp); 318 } 319 else 320 hr = ERROR_OUTOFMEMORY; 321 322 if (FAILED(hr)) 323 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not unregister \"%s\" (query: %s), hr=%Rhrc (index: %d)\n", 324 g_aSENSEvents[i].pszMethod, pszSubToRemove, hr, iErrorIdX); 325 /* Keep going. */ 326 327 RTStrFree(pszSubToRemove); 328 } 329 330 g_pIEventSystem->Release(); 331 } 332 333 if (g_pISensLogon) 334 delete g_pISensLogon; 335 } 336 #endif /* VBOX_WITH_SENS */ 38 337 39 338 … … 65 364 case DLL_PROCESS_DETACH: 66 365 366 VBoxCredProvVerbose(0, "VBoxCredProv: Unloaded (refs=%ld)\n", g_cDllRefs); 67 367 if (!g_cDllRefs) 68 368 VbglR3Term(); … … 120 420 HRESULT __stdcall DllCanUnloadNow(void) 121 421 { 422 VBoxCredProvVerbose(0, "DllCanUnloadNow (refs=%ld)\n", 423 g_cDllRefs); 424 425 #ifdef VBOX_WITH_SENS 426 if (!g_cDllRefs) 427 { 428 VBoxCredentialProviderUnregisterSENS(); 429 430 CoUninitialize(); 431 } 432 #endif 122 433 return (g_cDllRefs > 0) ? S_FALSE : S_OK; 123 434 } … … 147 458 ppvInterface); 148 459 pFactory->Release(); 460 461 #ifdef VBOX_WITH_SENS 462 if (SUCCEEDED(hr)) 463 { 464 HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); 465 VBoxCredentialProviderRegisterSENS(); 466 } 467 #endif 149 468 } 150 469 else … … 171 490 void **ppvInterface) 172 491 { 492 VBoxCredProvVerbose(0, "DllGetClassObject (refs=%ld)\n", 493 g_cDllRefs); 494 173 495 return VBoxCredentialProviderCreate(classID, interfaceID, ppvInterface); 174 496 } -
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.def
r40435 r40939 1 ;/** @file 2 ; * 3 ; * VBoxCredProv -- Windows Credential Provider DLL for VirtualBox 4 ; * 5 ; Copyright (C) 2012 Oracle Corporation 6 ; 7 ; This file is part of VirtualBox Open Source Edition (OSE), as 8 ; available from http://www.virtualbox.org. This file is free software; 9 ; you can redistribute it and/or modify it under the terms of the GNU 10 ; General Public License (GPL) as published by the Free Software 11 ; Foundation, in version 2 as it comes in the "COPYING" file of the 12 ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the 13 ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 14 ; 15 ; */ 16 1 17 LIBRARY VBoxCredProv.dll 2 18 … … 4 20 DllCanUnloadNow PRIVATE 5 21 DllGetClassObject PRIVATE 6
Note:
See TracChangeset
for help on using the changeset viewer.