VirtualBox

Changeset 69783 in vbox


Ignore:
Timestamp:
Nov 20, 2017 6:58:25 PM (7 years ago)
Author:
vboxsync
Message:

Main: SDS plan B it is.

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r69731 r69783  
    278278 PROGRAMS += VBoxSDS
    279279 VBoxSDS_TEMPLATE = VBOXMAINEXE
    280  VBoxSDS_DEFS = $(if-expr defined(VBOX_WITH_SDS_PLAN_B),VBOX_WITH_SDS_PLAN_B,)
    281280 VBoxSDS_DEFS.win += VBOX_COM_OUTOFPROC_MODULE
    282281 VBoxSDS_DEFS.win += _WIN32_WINNT=0x0510
     
    368367        $(if $(VBOX_WITH_CROGL),VBOX_WITH_CROGL,) \
    369368        $(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,)
    371370ifdef VBOX_WITH_USB
    372371 VBoxSVC_DEFS += \
     
    764763        $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,) \
    765764        $(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,)
    768766ifdef VBOX_WITH_CRHGSMI
    769767 VBoxC_DEFS += VBOX_WITH_CRHGSMI
     
    11961194 VBoxProxyStub_TEMPLATE = VBOXMAINCOMP
    11971195 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,)
    12001197 VBoxProxyStub_DEFS.win.x86 = WIN32
    12011198 VBoxProxyStub_SDKS     = VBOX_NTDLL
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r69729 r69783  
    6060
    6161
    62 #if defined(VBOX_WITH_SDS_PLAN_B) && !defined(VBOX_WITH_XPCOM)
     62#if defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_XPCOM)
    6363class VirtualBoxClassFactory; /* See ../src-server/win/svcmain.cpp  */
    6464#endif
     
    8181
    8282#ifndef VBOX_WITH_XPCOM
    83 # ifdef VBOX_WITH_SDS_PLAN_B
     83# ifdef VBOX_WITH_SDS
    8484    DECLARE_CLASSFACTORY_EX(VirtualBoxClassFactory)
    8585# else
  • trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp

    r69729 r69783  
    6666// public initializer/uninitializer for internal purposes only
    6767/////////////////////////////////////////////////////////////////////////////
    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                     else
    119                     {
    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                 else
    128                 {
    129                     LogRel(("Error: Failed allocating %#x bytes of memory for service config!\n", cbNeeded));
    130                     vrc = VERR_NO_TMP_MEMORY;
    131                 }
    132             }
    133             else
    134             {
    135                 AssertLogRelMsgFailed(("Error: QueryServiceConfigW returns success with zero buffer!\n"));
    136                 vrc = VERR_IPE_UNEXPECTED_STATUS;
    137             }
    138             CloseServiceHandle(hService);
    139         }
    140         else
    141         {
    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     else
    149     {
    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 namespace
    175         NULL,                    // User name. NULL = current user
    176         NULL,                    // User password. NULL = current
    177         0,                       // Locale. NULL indicates current
    178         NULL,                    // Security flags.
    179         0,                       // Authority (for example, Kerberos)
    180         0,                       // Context object
    181         aService.asOutParam()    // pointer to IWbemServices proxy
    182     );
    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 service
    190     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" property
    221     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 */
    24168
    24269/**
     
    289116        mData.m_SemEvWatcher = NIL_RTSEMEVENT;
    290117
    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 #else
    294118        rc = mData.m_pVirtualBox.createLocalObject(CLSID_VirtualBox);
    295 #endif
    296119        if (FAILED(rc))
    297120#ifdef RT_OS_WINDOWS
     
    382205     */
    383206    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 SYSTEM
    387     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 enabled
    418     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 # else
    436207    HRESULT hrc = CoCreateInstance(CLSID_VirtualBox, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void **)&pUnknown);
    437208    if (FAILED(hrc))
     
    441212        return setError(hrcCaller, tr("Completely failed to instantiate CLSID_VirtualBox: %Rhrc & %Rhrc"), hrcCaller, hrc);
    442213    }
    443 # endif
    444214
    445215    /*
     
    746516                ComPtr<IVirtualBox> pVirtualBox;
    747517                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 #else
    751518                rc = pVirtualBox.createLocalObject(CLSID_VirtualBox);
    752 #endif
    753519                if (FAILED(rc))
    754520                    cMillies = 3 * VBOXCLIENT_DEFAULT_INTERVAL;
  • trunk/src/VBox/Main/src-server/win/svcmain.cpp

    r69775 r69783  
    7878HWND        g_hMainWindow = NULL;
    7979HINSTANCE   g_hInstance   = NULL;
    80 #ifdef VBOX_WITH_SDS_PLAN_B
     80#ifdef VBOX_WITH_SDS
    8181/** This is set if we're connected to SDS and should discount a server lock
    8282 * that it is holding when deciding whether we're idle or not. */
     
    121121/*static*/ bool CExeModule::isIdleLockCount(LONG cLocks)
    122122{
    123 #ifdef VBOX_WITH_SDS_PLAN_B
     123#ifdef VBOX_WITH_SDS
    124124    if (g_fRegisteredWithVBoxSDS)
    125125        return cLocks <= 1;
     
    185185
    186186
    187 #ifdef VBOX_WITH_SDS_PLAN_B
     187#ifdef VBOX_WITH_SDS
    188188class VBoxSVCRegistration;
    189189
     
    473473}
    474474
    475 #endif /* VBOX_WITH_SDS_PLAN_B */
     475#endif /* VBOX_WITH_SDS */
    476476
    477477
     
    807807                                    RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG,
    808808                                    VBOXSVC_LOG_DEFAULT, "VBOXSVC_RELEASE_LOG",
    809 #ifdef VBOX_WITH_SDS_PLAN_B
     809#ifdef VBOX_WITH_SDS
    810810                                    RTLOGDEST_FILE | RTLOGDEST_F_DELAY_FILE,
    811811#else
Note: See TracChangeset for help on using the changeset viewer.

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