Changeset 95889 in vbox for trunk/src/VBox
- Timestamp:
- Jul 28, 2022 1:48:53 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp
r93115 r95889 49 49 50 50 #ifdef VBOX_WITH_WIN_SENS 51 51 52 static bool g_fSENSEnabled = false; 52 53 static IEventSystem *g_pIEventSystem = NULL; /**< Pointer to IEventSystem interface. */ … … 218 219 } 219 220 220 /* Note: Bstr class can also throw -- therefore including the setup procedure in the following try block as well. */ 221 try 222 { 223 g_pISensLogon = new VBoxCredProvSensLogon(); 224 225 AssertPtr(g_pIEventSystem); 226 AssertPtr(g_pISensLogon); 227 228 IEventSubscription *pIEventSubscription = NULL; 229 int i; 230 for (i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++) 231 { 232 VBoxCredProvVerbose(0, "VBoxCredProv: Registering \"%s\" (%s) ...\n", 233 g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName); 234 235 hr = CoCreateInstance(CLSID_CEventSubscription, 0, CLSCTX_SERVER, IID_IEventSubscription, (LPVOID*)&pIEventSubscription); 236 if (FAILED(hr)) 237 continue; 238 239 hr = pIEventSubscription->put_EventClassID(Bstr("{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */).raw()); 240 if (FAILED(hr)) 241 break; 242 243 hr = pIEventSubscription->put_SubscriberInterface((IUnknown*)g_pISensLogon); 244 if (FAILED(hr)) 245 break; 246 247 hr = pIEventSubscription->put_MethodName(Bstr(g_aSENSEvents[i].pszMethod).raw()); 248 if (FAILED(hr)) 249 break; 250 251 hr = pIEventSubscription->put_SubscriptionName(Bstr(g_aSENSEvents[i].pszSubscriptionName).raw()); 252 if (FAILED(hr)) 253 break; 254 255 hr = pIEventSubscription->put_SubscriptionID(Bstr(g_aSENSEvents[i].pszSubscriptionUUID).raw()); 256 if (FAILED(hr)) 257 break; 258 259 hr = pIEventSubscription->put_PerUser(TRUE); 260 if (FAILED(hr)) 261 break; 262 263 hr = g_pIEventSystem->Store(PROGID_EventSubscription, (IUnknown*)pIEventSubscription); 264 if (FAILED(hr)) 265 break; 266 267 pIEventSubscription->Release(); 268 pIEventSubscription = NULL; 269 } 270 271 if (FAILED(hr)) 272 VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not register \"%s\" (%s), hr=%Rhrc\n", 273 g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName, hr); 274 275 if (pIEventSubscription != NULL) 276 pIEventSubscription->Release(); 277 } 278 catch (std::bad_alloc &ex) 279 { 280 NOREF(ex); 281 hr = E_OUTOFMEMORY; 282 } 221 #ifdef RT_EXCEPTIONS_ENABLED 222 try { g_pISensLogon = new VBoxCredProvSensLogon(); } 223 catch (std::bad_alloc &) { AssertFailedReturn(E_OUTOFMEMORY); } 224 #else 225 g_pISensLogon = new VBoxCredProvSensLogon(); 226 AssertReturn(g_pISensLogon, E_OUTOFMEMORY); 227 #endif 228 229 AssertPtr(g_pIEventSystem); 230 AssertPtr(g_pISensLogon); 231 232 IEventSubscription *pIEventSubscription = NULL; 233 int i; 234 for (i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++) 235 { 236 VBoxCredProvVerbose(0, "VBoxCredProv: Registering \"%s\" (%s) ...\n", 237 g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName); 238 239 hr = CoCreateInstance(CLSID_CEventSubscription, 0, CLSCTX_SERVER, IID_IEventSubscription, (LPVOID*)&pIEventSubscription); 240 if (FAILED(hr)) 241 continue; 242 243 Bstr bstrTmp; 244 hr = bstrTmp.assignEx("{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */); 245 AssertBreak(SUCCEEDED(hr)); 246 hr = pIEventSubscription->put_EventClassID(bstrTmp.raw()); 247 if (FAILED(hr)) 248 break; 249 250 hr = pIEventSubscription->put_SubscriberInterface((IUnknown *)g_pISensLogon); 251 if (FAILED(hr)) 252 break; 253 254 hr = bstrTmp.assignEx(g_aSENSEvents[i].pszMethod); 255 AssertBreak(SUCCEEDED(hr)); 256 hr = pIEventSubscription->put_MethodName(bstrTmp.raw()); 257 if (FAILED(hr)) 258 break; 259 260 hr = bstrTmp.assignEx(g_aSENSEvents[i].pszSubscriptionName); 261 AssertBreak(SUCCEEDED(hr)); 262 hr = pIEventSubscription->put_SubscriptionName(bstrTmp.raw()); 263 if (FAILED(hr)) 264 break; 265 266 hr = bstrTmp.assignEx(g_aSENSEvents[i].pszSubscriptionUUID); 267 AssertBreak(SUCCEEDED(hr)); 268 hr = pIEventSubscription->put_SubscriptionID(bstrTmp.raw()); 269 if (FAILED(hr)) 270 break; 271 272 hr = pIEventSubscription->put_PerUser(TRUE); 273 if (FAILED(hr)) 274 break; 275 276 hr = g_pIEventSystem->Store(PROGID_EventSubscription, (IUnknown*)pIEventSubscription); 277 if (FAILED(hr)) 278 break; 279 280 pIEventSubscription->Release(); 281 pIEventSubscription = NULL; 282 } 283 284 if (FAILED(hr)) 285 VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not register \"%s\" (%s), hr=%Rhrc\n", 286 g_aSENSEvents[i].pszMethod, g_aSENSEvents[i].pszSubscriptionName, hr); 287 288 if (pIEventSubscription != NULL) 289 pIEventSubscription->Release(); 283 290 284 291 if (FAILED(hr)) … … 321 328 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not reconnect to CEventSystem, hr=%Rhrc\n", hr); 322 329 323 try 324 { 325 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS\n"); 326 327 for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++) 328 { 329 int iErrorIdX; 330 Bstr strSubToRemove = Utf8StrFmt("SubscriptionID=%s", g_aSENSEvents[i].pszSubscriptionUUID); 331 hr = g_pIEventSystem->Remove(PROGID_EventSubscription, strSubToRemove.raw(), &iErrorIdX); 332 if (FAILED(hr)) 333 { 334 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not unregister \"%s\" (query: %ls), hr=%Rhrc (index: %d)\n", 335 g_aSENSEvents[i].pszMethod, strSubToRemove.raw(), hr, iErrorIdX); 336 /* Keep going. */ 337 } 338 } 339 } 340 catch (std::bad_alloc &ex) 341 { 342 NOREF(ex); 343 hr = E_OUTOFMEMORY; 330 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS\n"); 331 332 for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++) 333 { 334 Bstr bstrSubToRemove; 335 hr = bstrSubToRemove.printfNoThrow("SubscriptionID=%s", g_aSENSEvents[i].pszSubscriptionUUID); 336 AssertContinue(SUCCEEDED(hr)); /* keep going */ 337 int iErrorIdX; 338 hr = g_pIEventSystem->Remove(PROGID_EventSubscription, bstrSubToRemove.raw(), &iErrorIdX); 339 if (FAILED(hr)) 340 { 341 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not unregister \"%s\" (query: %ls), hr=%Rhrc (index: %d)\n", 342 g_aSENSEvents[i].pszMethod, bstrSubToRemove.raw(), hr, iErrorIdX); 343 /* Keep going. */ 344 } 344 345 } 345 346 … … 358 359 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Returning hr=%Rhrc\n", hr); 359 360 } 361 360 362 #endif /* VBOX_WITH_WIN_SENS */ 361 362 363 363 364 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID pReserved) … … 474 475 * object creation. 475 476 */ 476 HRESULT VBoxCredentialProviderCreate(REFCLSID classID, REFIID interfaceID, 477 void **ppvInterface) 477 HRESULT VBoxCredentialProviderCreate(REFCLSID classID, REFIID interfaceID, void **ppvInterface) 478 478 { 479 479 HRESULT hr; 480 480 if (classID == CLSID_VBoxCredProvider) 481 481 { 482 try 483 { 484 VBoxCredProvFactory* pFactory = new VBoxCredProvFactory(); 485 AssertPtr(pFactory); 486 hr = pFactory->QueryInterface(interfaceID, 487 ppvInterface); 488 pFactory->Release(); 482 { 483 VBoxCredProvFactory *pFactory; 484 #ifdef RT_EXCEPTIONS_ENABLED 485 try { pFactory = new VBoxCredProvFactory(); } 486 catch (std::bad_alloc &) { AssertFailedReturn(E_OUTOFMEMORY); } 487 #else 488 pFactory = new VBoxCredProvFactory(); 489 AssertReturn(pFactory, E_OUTOFMEMORY); 490 #endif 491 492 hr = pFactory->QueryInterface(interfaceID, ppvInterface); 493 pFactory->Release(); /* pFactor is no longer valid (QueryInterface might've failed) */ 494 } 489 495 490 496 #ifdef VBOX_WITH_WIN_SENS 491 g_fSENSEnabled = true; /* By default SENS support is enabled. */ 492 493 HKEY hKey; 494 /** @todo Add some registry wrapper function(s) as soon as we got more values to retrieve. */ 495 DWORD dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Oracle\\VirtualBox Guest Additions\\AutoLogon", 496 0L, KEY_QUERY_VALUE, &hKey); 497 if (dwRet == ERROR_SUCCESS) 497 g_fSENSEnabled = true; /* By default SENS support is enabled. */ 498 499 HKEY hKey; 500 /** @todo Add some registry wrapper function(s) as soon as we got more values to retrieve. */ 501 DWORD dwRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Oracle\\VirtualBox Guest Additions\\AutoLogon", 502 0L, KEY_QUERY_VALUE, &hKey); 503 if (dwRet == ERROR_SUCCESS) 504 { 505 DWORD dwValue; 506 DWORD dwType = REG_DWORD; 507 DWORD dwSize = sizeof(DWORD); 508 dwRet = RegQueryValueExW(hKey, L"HandleSENS", NULL, &dwType, (LPBYTE)&dwValue, &dwSize); 509 if ( dwRet == ERROR_SUCCESS 510 && dwType == REG_DWORD 511 && dwSize == sizeof(DWORD)) 498 512 { 499 DWORD dwValue; 500 DWORD dwType = REG_DWORD; 501 DWORD dwSize = sizeof(DWORD); 502 503 dwRet = RegQueryValueEx(hKey, L"HandleSENS", NULL, &dwType, (LPBYTE)&dwValue, &dwSize); 504 if ( dwRet == ERROR_SUCCESS 505 && dwType == REG_DWORD 506 && dwSize == sizeof(DWORD)) 507 { 508 g_fSENSEnabled = RT_BOOL(dwValue); 509 } 510 511 RegCloseKey(hKey); 513 g_fSENSEnabled = RT_BOOL(dwValue); 512 514 } 513 515 514 VBoxCredProvVerbose(0, "VBoxCredentialProviderCreate: g_fSENSEnabled=%RTbool\n", 515 g_fSENSEnabled); 516 if ( SUCCEEDED(hr) 517 && g_fSENSEnabled) 518 { 519 HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); 520 RT_NOREF(hRes); /* probably a great idea to ignore this */ 521 VBoxCredentialProviderRegisterSENS(); 522 } 516 RegCloseKey(hKey); 517 } 518 519 VBoxCredProvVerbose(0, "VBoxCredentialProviderCreate: g_fSENSEnabled=%RTbool\n", g_fSENSEnabled); 520 if ( SUCCEEDED(hr) 521 && g_fSENSEnabled) 522 { 523 HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); 524 RT_NOREF(hRes); /* probably a great idea to ignore this */ 525 VBoxCredentialProviderRegisterSENS(); 526 } 523 527 #else /* !VBOX_WITH_WIN_SENS */ 524 528 VBoxCredProvVerbose(0, "VBoxCredentialProviderCreate: SENS support is disabled\n"); 525 529 #endif /* !VBOX_WITH_WIN_SENS */ 526 }527 catch (std::bad_alloc &ex)528 {529 NOREF(ex);530 hr = E_OUTOFMEMORY;531 }532 530 } 533 531 else
Note:
See TracChangeset
for help on using the changeset viewer.