Changeset 69804 in vbox
- Timestamp:
- Nov 22, 2017 12:11:32 PM (7 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
-
include/VirtualBoxClientImpl.h (modified) (1 diff)
-
src-client/VirtualBoxClientImpl.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/VirtualBoxClientImpl.h
r69791 r69804 72 72 73 73 #ifdef VBOX_WITH_SDS 74 int i_getServiceAccount (const wchar_t *pwszServiceName, wchar_t *pwszAccountName, size_t cwcAccountName);75 HRESULT i_isServiceDisabled(const wchar_t *pwszServiceName, bool *pfOutIsDisabled);74 int i_getServiceAccountAndStartType(const wchar_t *pwszServiceName, 75 wchar_t *pwszAccountName, size_t cwcAccountName, uint32_t *puStartType); 76 76 #endif 77 77 -
trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp
r69792 r69804 197 197 * Check that the VBoxSDS service is configured to run as LocalSystem and is enabled. 198 198 */ 199 WCHAR wszBuffer[256]; 200 int vrc = i_getServiceAccount(L"VBoxSDS", wszBuffer, RT_ELEMENTS(wszBuffer)); 199 WCHAR wszBuffer[256]; 200 uint32_t uStartType; 201 int vrc = i_getServiceAccountAndStartType(L"VBoxSDS", wszBuffer, RT_ELEMENTS(wszBuffer), &uStartType); 201 202 if (RT_SUCCESS(vrc)) 202 203 { 203 LogRelFunc(("VBoxSDS service is running under the '%ls' account .\n", wszBuffer));204 LogRelFunc(("VBoxSDS service is running under the '%ls' account with start type %u.\n", wszBuffer, uStartType)); 204 205 if (RTUtf16Cmp(wszBuffer, L"LocalSystem") != 0) 205 206 return setError(hrcCaller, 206 tr("VBoxSDS should be run under SYSTEM account, but it started under '%ls' account:\n" 207 "Change VBoxSDS Windows Service Logon parameters in Service Control Manager. \n%Rhrc"), 208 wszBuffer, hrcCaller); 207 tr("VBoxSDS is misconfigured to run under the '%ls' account instead of the SYSTEM one.\n" 208 "You ccan fix this by using the Windows Service Control Manager or by running\n" 209 "'qc config VBoxSDS obj=LocalSystem' on a command line."), wszBuffer); 210 if (uStartType == SERVICE_DISABLED) 211 return setError(hrcCaller, 212 tr("The VBoxSDS windows service is disabled.\n" 213 "To reenable the service, set it to 'Manual' startup type in the Windows Service\n" 214 "management console, or run 'sc config VBoxSDS start=demand' on a command line")); 209 215 } 210 216 else 211 217 LogRelFunc(("VirtualBoxClient::i_getServiceAccount failed: %Rrc\n", vrc)); 212 213 bool fIsVBoxSDSDisabled = false; 214 hrc = i_isServiceDisabled(L"VBoxSDS", &fIsVBoxSDSDisabled); 215 if (SUCCEEDED(hrc) && fIsVBoxSDSDisabled) 216 return setError(hrcCaller, 217 tr("The VBoxSDS windows service is disabled.\n" 218 "Enable VBoxSDS Windows Service using Windows Service Management Console.\n %Rhrc"), hrcCaller); 219 if (FAILED(hrc)) 220 LogRelFunc(("Warning: Failed to get information about VBoxSDS using WMI:: %Rhrc", hrc)); 221 # endif /* VBOX_WITH_SDS */ 218 # endif 222 219 223 220 /* … … 380 377 381 378 # ifdef VBOX_WITH_SDS 382 383 int VirtualBoxClient::i_getServiceAccount(const wchar_t *pwszServiceName, wchar_t *pwszAccountName, size_t cwcAccountName)379 int VirtualBoxClient::i_getServiceAccountAndStartType(const wchar_t *pwszServiceName, 380 wchar_t *pwszAccountName, size_t cwcAccountName, uint32_t *puStartType) 384 381 { 385 382 AssertPtr(pwszServiceName); … … 387 384 Assert(cwcAccountName); 388 385 *pwszAccountName = '\0'; 386 *puStartType = SERVICE_DEMAND_START; 389 387 390 388 int vrc; 391 389 392 390 // Get a handle to the SCM database. 393 SC_HANDLE hSCManager = OpenSCManagerW(NULL /*pwszMachineName*/, NULL /*pwszDatabaseName*/, SC_MANAGER_ ALL_ACCESS);391 SC_HANDLE hSCManager = OpenSCManagerW(NULL /*pwszMachineName*/, NULL /*pwszDatabaseName*/, SC_MANAGER_CONNECT); 394 392 if (hSCManager != NULL) 395 393 { … … 401 399 { 402 400 Assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER); 403 LPQUERY_SERVICE_CONFIGW pSc = (LPQUERY_SERVICE_CONFIGW)RTMemTmpAllocZ(cbNeeded );401 LPQUERY_SERVICE_CONFIGW pSc = (LPQUERY_SERVICE_CONFIGW)RTMemTmpAllocZ(cbNeeded + _1K); 404 402 if (pSc) 405 403 { 406 404 DWORD cbNeeded2 = 0; 407 if (QueryServiceConfigW(hService, pSc, cbNeeded , &cbNeeded2))405 if (QueryServiceConfigW(hService, pSc, cbNeeded + _1K, &cbNeeded2)) 408 406 { 407 *puStartType = pSc->dwStartType; 409 408 vrc = RTUtf16Copy(pwszAccountName, cwcAccountName, pSc->lpServiceStartName); 410 409 if (RT_FAILURE(vrc)) … … 422 421 else 423 422 { 424 LogRel(("Error: Failed allocating %#x bytes of memory for service config!\n", cbNeeded ));423 LogRel(("Error: Failed allocating %#x bytes of memory for service config!\n", cbNeeded + _1K)); 425 424 vrc = VERR_NO_TMP_MEMORY; 426 425 } … … 449 448 return vrc; 450 449 } 451 452 453 HRESULT VirtualBoxClient::i_isServiceDisabled(const wchar_t *pwszServiceName, bool* pfOutIsDisabled)454 {455 /** @todo r=bird: there must be a way we can get this information from the456 * service manager. This is overly complicated. */457 AssertPtr(pwszServiceName);458 AssertPtr(pfOutIsDisabled);459 *pfOutIsDisabled = false;460 461 ComPtr<IWbemLocator> aLocator;462 HRESULT hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (void **)aLocator.asOutParam());463 if (FAILED(hr))464 {465 LogRel(("Error: Cannot instantiate WbemLocator: %Rhrc", hr));466 return hr;467 }468 469 ComPtr<IWbemServices> aService;470 hr = aLocator->ConnectServer(com::Bstr(L"ROOT\\CIMV2").raw(), // Object path of WMI namespace471 NULL, // User name. NULL = current user472 NULL, // User password. NULL = current473 0, // Locale. NULL indicates current474 NULL, // Security flags.475 0, // Authority (for example, Kerberos)476 0, // Context object477 aService.asOutParam()); // pointer to IWbemServices proxy478 if (FAILED(hr))479 {480 LogRel(("Error: Cannot connect to Wbem Service: %Rhrc\n", hr));481 return hr;482 }483 484 // query settings for VBoxSDS windows service485 ComPtr<IEnumWbemClassObject> aEnumerator;486 hr = aService->ExecQuery(com::Bstr("WQL").raw(),487 com::BstrFmt("SELECT * FROM Win32_Service WHERE Name='%ls'", pwszServiceName).raw(),488 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,489 NULL,490 aEnumerator.asOutParam());491 if (FAILED(hr) || aEnumerator == NULL)492 {493 LogRel(("Error: querying service settings from WMI: %Rhrc\n", hr));494 return hr;495 }496 497 ULONG uReturn = 0;498 ComPtr<IWbemClassObject> aVBoxSDSObj;499 hr = aEnumerator->Next(WBEM_INFINITE, 1, aVBoxSDSObj.asOutParam(), &uReturn);500 if (FAILED(hr))501 {502 LogRel(("Error: Cannot get Service WMI record: %Rhrc\n", hr));503 return hr;504 }505 if (aVBoxSDSObj == NULL || uReturn == 0)506 {507 LogRel(("Error: Service record didn't exist in WMI: %Rhrc\n", hr));508 return hr;509 }510 511 // Get "StartMode" property512 VARIANT vtProp;513 VariantInit(&vtProp);514 hr = aVBoxSDSObj->Get(L"StartMode", 0, &vtProp, 0, 0);515 if (FAILED(hr) || (vtProp.vt & VT_NULL) == VT_NULL)516 {517 LogRel(("Error: Didn't found StartMode property: %Rhrc\n", hr));518 return hr;519 }520 521 Assert((vtProp.vt & VT_BSTR) == VT_BSTR);522 523 *pfOutIsDisabled = RTUtf16Cmp((RTUTF16*)vtProp.bstrVal, (RTUTF16*)L"Disabled") == 0;524 525 LogRel(("Service start mode is '%ls' \n", vtProp.bstrVal));526 VariantClear(&vtProp);527 return S_OK;528 }529 530 450 # endif /* VBOX_WITH_SDS */ 531 451
Note:
See TracChangeset
for help on using the changeset viewer.

