VirtualBox

Changeset 69729 in vbox


Ignore:
Timestamp:
Nov 17, 2017 7:55:33 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119120
Message:

Main: Outlined a possible plan B for the VBoxSDS stuff.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/log.h

    r69107 r69729  
    636636    /** Main group, IVBoxSVCAvailabilityChangedEvent. */
    637637    LOG_GROUP_MAIN_VBOXSVCAVAILABILITYCHANGEDEVENT,
     638    /** Main group, IVBoxSVC. */
     639    LOG_GROUP_MAIN_VBOXSVC,
    638640    /** Main group, IVetoEvent. */
    639641    LOG_GROUP_MAIN_VETOEVENT,
  • trunk/src/VBox/Main/Makefile.kmk

    r69683 r69729  
    278278 PROGRAMS += VBoxSDS
    279279 VBoxSDS_TEMPLATE = VBOXMAINEXE
    280  VBoxSDS_DEFS = \
     280 VBoxSDS_DEFS = $(if $(VBOX_WITH_SDS_PLAN_B),VBOX_WITH_SDS_PLAN_B,)
    281281 VBoxSDS_DEFS.win += VBOX_COM_OUTOFPROC_MODULE
    282282 VBoxSDS_DEFS.win += _WIN32_WINNT=0x0510
     
    367367        $(if $(VBOX_WITH_NAT_SERVICE),VBOX_WITH_NAT_SERVICE,) \
    368368        $(if $(VBOX_WITH_CROGL),VBOX_WITH_CROGL,) \
    369         $(if $(VBOX_WITH_CRHGSMI),VBOX_WITH_CRHGSMI,)
     369        $(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,)
    370371ifdef VBOX_WITH_USB
    371372 VBoxSVC_DEFS += \
     
    763764        $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,) \
    764765        $(if $(VBOX_WITH_VRDEAUTH_IN_VBOXSVC),VBOX_WITH_VRDEAUTH_IN_VBOXSVC,) \
    765         $(if $(VBOX_WITH_SDS),VBOX_WITH_SDS,)
     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,)
    766768ifdef VBOX_WITH_CRHGSMI
    767769 VBoxC_DEFS += VBOX_WITH_CRHGSMI
     
    11941196 VBoxProxyStub_TEMPLATE = VBOXMAINCOMP
    11951197 VBoxProxyStub_DEFS     = REGISTER_PROXY_DLL PROXY_CLSID_IS="$(VBOX_MIDL_PROXY_CLSID_IS)" \
    1196         $(if $(VBOX_WITH_SDS),VBOX_WITH_SDS,)
     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,)
    11971200 VBoxProxyStub_DEFS.win.x86 = WIN32
    11981201 VBoxProxyStub_SDKS     = VBOX_NTDLL
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r69379 r69729  
    2437324373
    2437424374<if target="midl">
     24375
     24376  <!-- VBOX_SDS_PLAN_B start -->
     24377  <!--
     24378  // IVBoxSVC
     24379  //////////////////////////////////////////////////////////////////////////
     24380  -->
     24381  <interface
     24382    name="IVBoxSVC" extends="$unknown"
     24383    uuid="8876e618-8936-4b2c-3015-aaebe6d479b9"
     24384    wsmap="suppress"
     24385    reservedMethods="2" reservedAttributes="4"
     24386    >
     24387      <desc>
     24388          Implemented by the VirtualBox class factory and registered with VBoxSDS
     24389          so it can retrieve IVirtualBox on behalf of other VBoxSVCs.
     24390      </desc>
     24391
     24392      <method name="getVirtualBox" >
     24393        <desc> Gets an IUnknown interface to the VirtualBox object in the VBoxSVC process. </desc>
     24394        <param name="result" type="$unknown" dir="return" >
     24395          <desc> Where to return the IUnknown interface. </desc>
     24396        </param>
     24397      </method>
     24398
     24399  </interface>
     24400  <!-- VBOX_SDS_PLAN_B end -->
     24401
    2437524402  <!--
    2437624403  // IVirtualBoxSDS
     
    2440724434      </method>
    2440824435
     24436      <!-- VBOX_SDS_PLAN_B start -->
     24437      <method name="registerVBoxSVC">
     24438        <desc>Registers a VBoxSVC instance with the SDS.</desc>
     24439        <param name="vboxSVC" type="IVBoxSVC" dir="in">
     24440          <desc>Interface implemented by the VirtualBox class factory.</desc>
     24441        </param>
     24442        <param name="pid" type="long" dir="in">
     24443          <desc>The process ID of the VBoxSVC instance.</desc>
     24444        </param>
     24445        <param name="existingVirtualBox" type="$unknown" dir="return">
     24446          <desc>If there is already an VBoxSVC for this user, the an IUnknown
     24447            interface to its VirtualBox object is returned here, otherwise it
     24448            is set to NULL.</desc>
     24449        </param>
     24450      </method>
     24451
     24452      <method name="deregisterVBoxSVC">
     24453        <desc>Registers a VBoxSVC instance with the SDS.</desc>
     24454        <param name="vboxSVC" type="IVBoxSVC" dir="in">
     24455          <desc>Same as specified during registration.</desc>
     24456        </param>
     24457        <param name="pid" type="long" dir="in">
     24458          <desc>The process ID of the VBoxSVC instance (same as during registration).</desc>
     24459        </param>
     24460      </method>
     24461      <!-- VBOX_SDS_PLAN_B end -->
     24462
    2440924463  </interface>
     24464
    2441024465</if>
    2441124466
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r69500 r69729  
    5959}
    6060
     61
     62#if defined(VBOX_WITH_SDS_PLAN_B) && !defined(VBOX_WITH_XPCOM)
     63class VirtualBoxClassFactory; /* See ../src-server/win/svcmain.cpp  */
     64#endif
     65
     66
    6167class ATL_NO_VTABLE VirtualBox :
    6268    public VirtualBoxWrap
     
    7480    friend class CallbackEvent;
    7581
     82#ifndef VBOX_WITH_XPCOM
     83# ifdef VBOX_WITH_SDS_PLAN_B
     84    DECLARE_CLASSFACTORY_EX(VirtualBoxClassFactory)
     85# else
    7686    DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
     87# endif
     88#endif
    7789
    7890    // Do not use any ATL registry support.
  • trunk/src/VBox/Main/include/VirtualBoxSDSImpl.h

    r69500 r69729  
    110110    HRESULT getVirtualBox(ComPtr<IVirtualBox> &aVirtualBox, ComPtr<IToken> &aToken);
    111111
     112    /* SDS plan B interfaces: */
     113    HRESULT registerVBoxSVC(const ComPtr<IVBoxSVC> &aVBoxSVC, LONG aPid, ComPtr<IUnknown> &aExistingVirtualBox);
     114    HRESULT deregisterVBoxSVC(const ComPtr<IVBoxSVC> &aVBoxSVC, LONG aPid);
     115
    112116    // Wrapped IVirtualBoxSDS methods
    113117
  • trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp

    r69500 r69729  
    6767/////////////////////////////////////////////////////////////////////////////
    6868
    69 #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS)
     69#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)
    7070
    7171HRESULT CreateVirtualBoxThroughSDS(ComPtr<IVirtualBox> &aVirtualBox, ComPtr<IToken> &aToken)
     
    238238}
    239239
    240 #endif
     240#endif /* RT_OS_WINDOWS && VBOX_WITH_SDS && !VBOX_WITH_SDS_PLAN_B */
    241241
    242242/**
     
    250250#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS)
    251251    // setup COM Security to enable impersonation
    252     // This works for console Virtual Box clients, GUI has own security settings
     252    // This works for console VirtualBox clients, GUI has own security settings
    253253    //  For GUI Virtual Box it will be second call so can return TOO_LATE error
    254254    HRESULT hrGUICoInitializeSecurity = CoInitializeSecurity(NULL,
     
    289289        mData.m_SemEvWatcher = NIL_RTSEMEVENT;
    290290
    291 #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS)
     291#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)
    292292        rc = CreateVirtualBoxThroughSDS(mData.m_pVirtualBox, mData.m_pToken);
    293293#else
     
    383383    IUnknown *pUnknown = NULL;
    384384
    385 # ifdef VBOX_WITH_SDS
     385# if defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)
    386386    // Check the VBOXSDS service running account name is SYSTEM
    387387    wchar_t wszBuffer[256];
     
    746746                ComPtr<IVirtualBox> pVirtualBox;
    747747                ComPtr<IToken> pToken;
    748 #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS)
     748#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_SDS_PLAN_B)
    749749                rc = CreateVirtualBoxThroughSDS(pVirtualBox, pToken);
    750750#else
  • trunk/src/VBox/Main/src-server/win/svcmain.cpp

    r69500 r69729  
    138138
    139139
     140#ifdef VBOX_WITH_SDS_PLAN_B
     141
     142/**
     143 * Custom class factory for the VirtualBox singleton.
     144 *
     145 * The implementation of CreateInstance is found in win/svcmain.cpp.
     146 */
     147class VirtualBoxClassFactory : public ATL::CComClassFactory
     148{
     149private:
     150    /** Tri state: 0=uninitialized or initializing; 1=success; -1=failure.
     151     * This will be updated after both m_hrcCreate and m_pObj have been set. */
     152    volatile int32_t    m_iState;
     153    /** The result of the instantiation attempt. */
     154    HRESULT             m_hrcCreate;
     155    /** The IUnknown of the VirtualBox object/interface we're working with. */
     156    IUnknown           *m_pObj;
     157
     158public:
     159    VirtualBoxClassFactory() : m_iState(0), m_hrcCreate(S_OK), m_pObj(NULL) { }
     160    virtual ~VirtualBoxClassFactory()
     161    {
     162        if (m_pObj)
     163        {
     164            m_pObj->Release();
     165            m_pObj = NULL;
     166        }
     167        /** @todo Need to check if this is okay wrt COM termination. */
     168        i_deregisterWithSds();
     169    }
     170
     171    // IClassFactory
     172    STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvObj);
     173
     174    // IVBoxSVC
     175    STDMETHOD(GetVirtualBox)(IUnknown **ppOtherObj);
     176
     177private:
     178    HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox);
     179    void    VirtualBoxClassFactory::i_deregisterWithSds(void);
     180};
     181
     182
     183HRESULT VirtualBoxClassFactory::i_registerWithSds(IUnknown **ppOtherVirtualBox)
     184{
     185    *ppOtherVirtualBox = NULL;
     186    return S_OK;
     187}
     188
     189
     190void VirtualBoxClassFactory::i_deregisterWithSds(void)
     191{
     192    Log(("VirtualBoxClassFactory::i_deregisterWithSds\n"));
     193}
     194
     195
     196STDMETHODIMP VirtualBoxClassFactory::GetVirtualBox(IUnknown **ppUnkVirtualBox)
     197{
     198    IUnknown *pObj = m_pObj;
     199    if (pObj)
     200    {
     201        /** @todo Do we need to do something regarding server locking?  Hopefully COM
     202         *        deals with that........... */
     203        pObj->AddRef();
     204        *ppUnkVirtualBox = pObj;
     205        Log(("VirtualBoxClassFactory::GetVirtualBox: S_OK - %p\n", pObj));
     206        return S_OK;
     207    }
     208    *ppUnkVirtualBox = NULL;
     209    Log(("VirtualBoxClassFactory::GetVirtualBox: E_FAIL\n"));
     210    return E_FAIL;
     211}
     212
     213
     214/**
     215 * Custom class factory impl for the VirtualBox singleton.
     216 *
     217 * This will consult with VBoxSDS on whether this VBoxSVC instance should
     218 * provide the actual VirtualBox instance or just forward the instance from
     219 * some other SVC instance.
     220 *
     221 * @param   pUnkOuter       This must be NULL.
     222 * @param   riid            Reference to the interface ID to provide.
     223 * @param   ppvObj          Where to return the pointer to the riid instance.
     224 *
     225 * @return  COM status code.
     226 */
     227STDMETHODIMP VirtualBoxClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvObj)
     228{
     229    HRESULT hrc = E_POINTER;
     230    if (ppvObj != NULL)
     231    {
     232        *ppvObj = NULL;
     233        // no aggregation for singletons
     234        AssertReturn(pUnkOuter == NULL, CLASS_E_NOAGGREGATION);
     235
     236        /*
     237         * We must make sure there is only one instance around.
     238         * So, we check without locking and then again after locking.
     239         */
     240        if (ASMAtomicReadS32(&m_iState) == 0)
     241        {
     242            Lock();
     243            __try
     244            {
     245                if (ASMAtomicReadS32(&m_iState) == 0)
     246                {
     247                    /*
     248                     * lock the module to indicate activity
     249                     * (necessary for the monitor shutdown thread to correctly
     250                     * terminate the module in case when CreateInstance() fails)
     251                     */
     252                    ATL::_pAtlModule->Lock();
     253                    __try
     254                    {
     255                        /*
     256                         * Now we need to connect to VBoxSDS to register ourselves.
     257                         */
     258                        IUnknown *pOtherVirtualBox = NULL;
     259                        m_hrcCreate = hrc = i_registerWithSds(&pOtherVirtualBox);
     260                        if (SUCCEEDED(hrc) && pOtherVirtualBox)
     261                            m_pObj = pOtherVirtualBox;
     262                        else if (SUCCEEDED(hrc))
     263                        {
     264                            ATL::_pAtlModule->Lock();
     265                            ATL::CComObjectCached<VirtualBox> *p;
     266                            m_hrcCreate = hrc = ATL::CComObjectCached<VirtualBox>::CreateInstance(&p);
     267                            if (SUCCEEDED(hrc))
     268                            {
     269                                m_hrcCreate = hrc = p->QueryInterface(IID_IUnknown, (void **)&m_pObj);
     270                                if (FAILED(hrc))
     271                                {
     272                                    delete p;
     273                                    i_deregisterWithSds();
     274                                    m_pObj = NULL;
     275                                }
     276                            }
     277                        }
     278                        ASMAtomicWriteS32(&m_iState, SUCCEEDED(hrc) ? 1 : -1);
     279                    }
     280                    __finally
     281                    {
     282                        ATL::_pAtlModule->Unlock();
     283                    }
     284                }
     285            }
     286            __finally
     287            {
     288                if (ASMAtomicReadS32(&m_iState) == 0)
     289                {
     290                    ASMAtomicWriteS32(&m_iState, -1);
     291                    if (SUCCEEDED(m_hrcCreate))
     292                        m_hrcCreate = E_FAIL;
     293                }
     294                Unlock();
     295            }
     296        }
     297
     298        /*
     299         * Query the requested interface from the IUnknown one we're keeping around.
     300         */
     301        if (m_hrcCreate == S_OK)
     302            hrc = m_pObj->QueryInterface(riid, ppvObj);
     303        else
     304            hrc = m_hrcCreate;
     305    }
     306    return hrc;
     307}
     308
     309#endif /* VBOX_WITH_SDS_PLAN_B */
     310
     311
    140312BEGIN_OBJECT_MAP(ObjectMap)
    141313    OBJECT_ENTRY(CLSID_VirtualBox, VirtualBox)
     
    146318HINSTANCE g_hInstance = NULL;
    147319#define MAIN_WND_CLASS L"VirtualBox Interface"
     320
    148321
    149322/*
Note: See TracChangeset for help on using the changeset viewer.

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