Changeset 69783 in vbox
- Timestamp:
- Nov 20, 2017 6:58:25 PM (7 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r69731 r69783 278 278 PROGRAMS += VBoxSDS 279 279 VBoxSDS_TEMPLATE = VBOXMAINEXE 280 VBoxSDS_DEFS = $(if-expr defined(VBOX_WITH_SDS_PLAN_B),VBOX_WITH_SDS_PLAN_B,)281 280 VBoxSDS_DEFS.win += VBOX_COM_OUTOFPROC_MODULE 282 281 VBoxSDS_DEFS.win += _WIN32_WINNT=0x0510 … … 368 367 $(if $(VBOX_WITH_CROGL),VBOX_WITH_CROGL,) \ 369 368 $(if $(VBOX_WITH_CRHGSMI),VBOX_WITH_CRHGSMI,) \ 370 $(if-expr defined(VBOX_WITH_SDS) && defined(VBOX_WITH_SDS_PLAN_B),VBOX_WITH_SDS_PLAN_B,)369 $(if-expr defined(VBOX_WITH_SDS),VBOX_WITH_SDS,) 371 370 ifdef VBOX_WITH_USB 372 371 VBoxSVC_DEFS += \ … … 764 763 $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,) \ 765 764 $(if $(VBOX_WITH_VRDEAUTH_IN_VBOXSVC),VBOX_WITH_VRDEAUTH_IN_VBOXSVC,) \ 766 $(if $(VBOX_WITH_SDS),VBOX_WITH_SDS,) \ 767 $(if-expr defined(VBOX_WITH_SDS) && defined(VBOX_WITH_SDS_PLAN_B),VBOX_WITH_SDS_PLAN_B,) 765 $(if $(VBOX_WITH_SDS),VBOX_WITH_SDS,) 768 766 ifdef VBOX_WITH_CRHGSMI 769 767 VBoxC_DEFS += VBOX_WITH_CRHGSMI … … 1196 1194 VBoxProxyStub_TEMPLATE = VBOXMAINCOMP 1197 1195 VBoxProxyStub_DEFS = REGISTER_PROXY_DLL PROXY_CLSID_IS="$(VBOX_MIDL_PROXY_CLSID_IS)" \ 1198 $(if $(VBOX_WITH_SDS),VBOX_WITH_SDS,) \ 1199 $(if-expr defined(VBOX_WITH_SDS) && defined(VBOX_WITH_SDS_PLAN_B),VBOX_WITH_SDS_PLAN_B,) 1196 $(if $(VBOX_WITH_SDS),VBOX_WITH_SDS,) 1200 1197 VBoxProxyStub_DEFS.win.x86 = WIN32 1201 1198 VBoxProxyStub_SDKS = VBOX_NTDLL -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r69729 r69783 60 60 61 61 62 #if defined(VBOX_WITH_SDS _PLAN_B) && !defined(VBOX_WITH_XPCOM)62 #if defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_XPCOM) 63 63 class VirtualBoxClassFactory; /* See ../src-server/win/svcmain.cpp */ 64 64 #endif … … 81 81 82 82 #ifndef VBOX_WITH_XPCOM 83 # ifdef VBOX_WITH_SDS _PLAN_B83 # ifdef VBOX_WITH_SDS 84 84 DECLARE_CLASSFACTORY_EX(VirtualBoxClassFactory) 85 85 # else -
trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp
r69729 r69783 66 66 // public initializer/uninitializer for internal purposes only 67 67 ///////////////////////////////////////////////////////////////////////////// 68 69 #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)70 71 HRESULT CreateVirtualBoxThroughSDS(ComPtr<IVirtualBox> &aVirtualBox, ComPtr<IToken> &aToken)72 {73 ComPtr<IVirtualBoxSDS> aVirtualBoxSDS;74 HRESULT hrc = CoCreateInstance(CLSID_VirtualBoxSDS, /* the VirtualBoxSDS object */75 NULL, /* no aggregation */76 CLSCTX_LOCAL_SERVER, /* the object lives in the current process */77 IID_IVirtualBoxSDS, /* IID of the interface */78 (void **)aVirtualBoxSDS.asOutParam());79 AssertComRCReturn(hrc, hrc);80 81 hrc = aVirtualBoxSDS->GetVirtualBox(aVirtualBox.asOutParam(), aToken.asOutParam());82 AssertComRC(hrc);83 84 return hrc;85 }86 87 88 int VirtualBoxClient::getServiceAccount(const wchar_t *pwszServiceName, wchar_t *pwszAccountName, size_t cwcAccountName)89 {90 AssertPtr(pwszServiceName);91 AssertPtr(pwszAccountName);92 Assert(cwcAccountName);93 *pwszAccountName = '\0';94 95 int vrc;96 97 // Get a handle to the SCM database.98 SC_HANDLE hSCManager = OpenSCManagerW(NULL /*pwszMachineName*/, NULL /*pwszDatabaseName*/, SC_MANAGER_ALL_ACCESS);99 if (hSCManager != NULL)100 {101 SC_HANDLE hService = OpenServiceW(hSCManager, pwszServiceName, SERVICE_QUERY_CONFIG);102 if (hService != NULL)103 {104 DWORD cbNeeded = sizeof(QUERY_SERVICE_CONFIGW) + 256;105 if (!QueryServiceConfigW(hService, NULL, 0, &cbNeeded))106 {107 Assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER);108 LPQUERY_SERVICE_CONFIGW pSc = (LPQUERY_SERVICE_CONFIGW)RTMemTmpAllocZ(cbNeeded);109 if (pSc)110 {111 DWORD cbNeeded2 = 0;112 if (QueryServiceConfigW(hService, pSc, cbNeeded, &cbNeeded2))113 {114 vrc = RTUtf16Copy(pwszAccountName, cwcAccountName, pSc->lpServiceStartName);115 if (RT_FAILURE(vrc))116 LogRel(("Error: SDS service name is too long (%Rrc): %ls\n", vrc, pSc->lpServiceStartName));117 }118 else119 {120 int dwError = GetLastError();121 vrc = RTErrConvertFromWin32(dwError);122 LogRel(("Error: Failed querying service config: %Rwc (%u) -> %Rrc; cbNeeded=%d cbNeeded2=%d\n",123 dwError, dwError, vrc, cbNeeded, cbNeeded2));124 }125 RTMemTmpFree(pSc);126 }127 else128 {129 LogRel(("Error: Failed allocating %#x bytes of memory for service config!\n", cbNeeded));130 vrc = VERR_NO_TMP_MEMORY;131 }132 }133 else134 {135 AssertLogRelMsgFailed(("Error: QueryServiceConfigW returns success with zero buffer!\n"));136 vrc = VERR_IPE_UNEXPECTED_STATUS;137 }138 CloseServiceHandle(hService);139 }140 else141 {142 int dwError = GetLastError();143 vrc = RTErrConvertFromWin32(dwError);144 LogRel(("Error: Could not open service: %Rwc (%u) -> %Rrc\n", dwError, dwError, vrc));145 }146 CloseServiceHandle(hSCManager);147 }148 else149 {150 int dwError = GetLastError();151 vrc = RTErrConvertFromWin32(dwError);152 LogRel(("Error: Could not open SCM: %Rwc (%u) -> %Rrc\n", dwError, dwError, vrc));153 }154 return vrc;155 }156 157 158 HRESULT VirtualBoxClient::isServiceDisabled(const wchar_t *pwszServiceName, bool* pOutIsDisabled)159 {160 Assert(pOutIsDisabled);161 Assert(pwszServiceName);162 ComPtr<IWbemLocator> aLocator;163 ComPtr<IWbemServices> aService;164 165 HRESULT hr = CoCreateInstance(CLSID_WbemLocator, 0,166 CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *)aLocator.asOutParam());167 if (FAILED(hr))168 {169 LogRel(("Error: Cannot instantiate WbemLocator: %Rhrc", hr));170 return hr;171 }172 173 hr = aLocator->ConnectServer(174 com::Bstr(L"ROOT\\CIMV2").raw(), // Object path of WMI namespace175 NULL, // User name. NULL = current user176 NULL, // User password. NULL = current177 0, // Locale. NULL indicates current178 NULL, // Security flags.179 0, // Authority (for example, Kerberos)180 0, // Context object181 aService.asOutParam() // pointer to IWbemServices proxy182 );183 if (FAILED(hr))184 {185 LogRel(("Error: Cannot connect to Wbem Service: %Rhrc\n", hr));186 return hr;187 }188 189 // query settings for VBoxSDS windows service190 ComPtr<IEnumWbemClassObject> aEnumerator;191 hr = aService->ExecQuery(192 com::Bstr("WQL").raw(),193 com::BstrFmt("SELECT * FROM Win32_Service WHERE Name='%ls'", pwszServiceName).raw(),194 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,195 NULL,196 aEnumerator.asOutParam());197 if (FAILED(hr) || aEnumerator == NULL)198 {199 LogRel(("Error: querying service settings from WMI: %Rhrc\n", hr));200 return hr;201 }202 203 ULONG uReturn = 0;204 ComPtr<IWbemClassObject> aVBoxSDSObj;205 hr = aEnumerator->Next(WBEM_INFINITE, 1, aVBoxSDSObj.asOutParam(), &uReturn);206 if (FAILED(hr))207 {208 LogRel(("Error: Cannot get Service WMI record: %Rhrc\n", hr));209 return hr;210 }211 if (aVBoxSDSObj == NULL || uReturn == 0)212 {213 LogRel(("Error: Service record didn't exist in WMI: %Rhrc\n", hr));214 return hr;215 }216 217 VARIANT vtProp;218 VariantInit(&vtProp);219 220 // Get "StartMode" property221 hr = aVBoxSDSObj->Get(L"StartMode", 0, &vtProp, 0, 0);222 if (FAILED(hr) || (vtProp.vt & VT_NULL) == VT_NULL)223 {224 LogRel(("Error: Didn't found StartMode property: %Rhrc\n", hr));225 return hr;226 }227 228 Assert((vtProp.vt & VT_BSTR) == VT_BSTR);229 230 *pOutIsDisabled = RTUtf16Cmp((RTUTF16*)vtProp.bstrVal,231 (RTUTF16*)L"Disabled") == 0;232 233 LogRel(("Service start mode is '%ls' \n", vtProp.bstrVal));234 235 VariantClear(&vtProp);236 237 return S_OK;238 }239 240 #endif /* RT_OS_WINDOWS && VBOX_WITH_SDS && !VBOX_WITH_SDS_PLAN_B */241 68 242 69 /** … … 289 116 mData.m_SemEvWatcher = NIL_RTSEMEVENT; 290 117 291 #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)292 rc = CreateVirtualBoxThroughSDS(mData.m_pVirtualBox, mData.m_pToken);293 #else294 118 rc = mData.m_pVirtualBox.createLocalObject(CLSID_VirtualBox); 295 #endif296 119 if (FAILED(rc)) 297 120 #ifdef RT_OS_WINDOWS … … 382 205 */ 383 206 IUnknown *pUnknown = NULL; 384 385 # if defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)386 // Check the VBOXSDS service running account name is SYSTEM387 wchar_t wszBuffer[256];388 int vrc = getServiceAccount(L"VBoxSDS", wszBuffer, RT_ELEMENTS(wszBuffer));389 if (RT_FAILURE(vrc))390 return setError(hrcCaller,391 tr("Failed to instantiate CLSID_VirtualBox using VBoxSDS: The VBoxSDS is unavailable: %Rrc"), vrc);392 393 LogRelFunc(("VBoxSDS service is running under the '%ls' account.\n", wszBuffer));394 395 if (RTUtf16Cmp(wszBuffer, L"LocalSystem") != 0)396 return setError(hrcCaller,397 tr("VBoxSDS should be run under SYSTEM account, but it started under '%ls' account:\n"398 "Change VBoxSDS Windows Service Logon parameters in Service Control Manager. \n%Rhrc"),399 wszBuffer, hrcCaller);400 401 bool fIsVBoxSDSDisabled = false;402 HRESULT hrc = isServiceDisabled(L"VBoxSDS", &fIsVBoxSDSDisabled);403 if (FAILED(hrc))404 {405 LogRelFunc(("Warning: Failed to get information about VBoxSDS using WMI:: %Rhrc & %Rhrc", hrcCaller, hrc));406 fIsVBoxSDSDisabled = false;407 //return setError(hrcCaller, tr("Failed to get information about VBoxSDS using WMI:: %Rhrc & %Rhrc"), hrcCaller, hrc);408 }409 if (fIsVBoxSDSDisabled)410 {411 return setError(hrcCaller,412 tr("Completely failed to instantiate CLSID_VirtualBox using VBoxSDS: "413 "VBoxSDS windows service disabled.\n"414 "Enable VBoxSDS Windows Service using Windows Service Management Console.\n %Rhrc"), hrcCaller);415 }416 417 // Check the VBoxSDS windows service is enabled418 ComPtr<IVirtualBox> aVirtualBox;419 ComPtr<IToken> aToken;420 hrc = CreateVirtualBoxThroughSDS(aVirtualBox, aToken);421 if (FAILED(hrc))422 {423 if (hrc == hrcCaller)424 return setError(hrcCaller, tr("Completely failed to instantiate CLSID_VirtualBox using VBoxSDS: %Rhrc"), hrcCaller);425 return setError(hrcCaller, tr("Completely failed to instantiate CLSID_VirtualBox using VBoxSDS: %Rhrc & %Rhrc"), hrcCaller, hrc);426 }427 428 hrc = aVirtualBox.queryInterfaceTo<IUnknown>(&pUnknown);429 if (FAILED(hrc))430 {431 if (hrc == hrcCaller)432 return setError(hrcCaller, tr("Completely failed to instantiate CLSID_VirtualBox using VBoxSDS: %Rhrc"), hrcCaller);433 return setError(hrcCaller, tr("Completely failed to instantiate CLSID_VirtualBox using VBoxSDS: %Rhrc & %Rhrc"), hrcCaller, hrc);434 }435 # else436 207 HRESULT hrc = CoCreateInstance(CLSID_VirtualBox, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void **)&pUnknown); 437 208 if (FAILED(hrc)) … … 441 212 return setError(hrcCaller, tr("Completely failed to instantiate CLSID_VirtualBox: %Rhrc & %Rhrc"), hrcCaller, hrc); 442 213 } 443 # endif444 214 445 215 /* … … 746 516 ComPtr<IVirtualBox> pVirtualBox; 747 517 ComPtr<IToken> pToken; 748 #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)749 rc = CreateVirtualBoxThroughSDS(pVirtualBox, pToken);750 #else751 518 rc = pVirtualBox.createLocalObject(CLSID_VirtualBox); 752 #endif753 519 if (FAILED(rc)) 754 520 cMillies = 3 * VBOXCLIENT_DEFAULT_INTERVAL; -
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r69775 r69783 78 78 HWND g_hMainWindow = NULL; 79 79 HINSTANCE g_hInstance = NULL; 80 #ifdef VBOX_WITH_SDS _PLAN_B80 #ifdef VBOX_WITH_SDS 81 81 /** This is set if we're connected to SDS and should discount a server lock 82 82 * that it is holding when deciding whether we're idle or not. */ … … 121 121 /*static*/ bool CExeModule::isIdleLockCount(LONG cLocks) 122 122 { 123 #ifdef VBOX_WITH_SDS _PLAN_B123 #ifdef VBOX_WITH_SDS 124 124 if (g_fRegisteredWithVBoxSDS) 125 125 return cLocks <= 1; … … 185 185 186 186 187 #ifdef VBOX_WITH_SDS _PLAN_B187 #ifdef VBOX_WITH_SDS 188 188 class VBoxSVCRegistration; 189 189 … … 473 473 } 474 474 475 #endif /* VBOX_WITH_SDS _PLAN_B*/475 #endif /* VBOX_WITH_SDS */ 476 476 477 477 … … 807 807 RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG, 808 808 VBOXSVC_LOG_DEFAULT, "VBOXSVC_RELEASE_LOG", 809 #ifdef VBOX_WITH_SDS _PLAN_B809 #ifdef VBOX_WITH_SDS 810 810 RTLOGDEST_FILE | RTLOGDEST_F_DELAY_FILE, 811 811 #else
Note:
See TracChangeset
for help on using the changeset viewer.