VirtualBox

Changeset 60255 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Mar 30, 2016 8:32:04 AM (9 years ago)
Author:
vboxsync
Message:

Additions/VBoxCredProv: Fixes for BSTR handling (untested, thanks PVS).

Location:
trunk/src/VBox/Additions/WINNT/VBoxCredProv
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/Makefile.kmk

    r56301 r60255  
    55
    66#
    7 # Copyright (C) 2009-2015 Oracle Corporation
     7# Copyright (C) 2009-2016 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    1919include $(KBUILD_PATH)/subheader.kmk
    2020
     21# Do we want to use Windows SENS (System Event Notification Service)?
     22VBOX_WITH_WIN_SENS := 1
     23
    2124DLLS += VBoxCredProv
    2225VBoxCredProv_TEMPLATE    = VBOXGUESTR3DLL
    23 VBoxCredProv_DEFS        = VBGL_VBOXGUEST VBOX_WITH_HGCM VBOX_WITH_SENS UNICODE
     26VBoxCredProv_DEFS        = VBGL_VBOXGUEST VBOX_WITH_HGCM UNICODE
     27ifdef VBOX_WITH_WIN_SENS
     28 VBoxService_DEFS       += VBOX_WITH_WIN_SENS
     29endif
    2430VBoxCredProv_SDKS        = ReorderCompilerIncs $(VBOX_WINPSDK_GST_WLH)
    2531VBoxCredProv_SOURCES  = \
     
    3339        VBoxCredProvUtils.cpp
    3440
     41ifdef VBOX_WITH_WIN_SENS
     42 # To use com::Bstr for BSTR handling.
     43 VBoxCredProv_SOURCES += \
     44        $(PATH_ROOT)/src/VBox/Main/glue/string.cpp
     45endif
     46
    3547VBoxCredProv_LIBS     = \
    3648        $(VBOX_LIB_IPRT_GUEST_R3) \
  • trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredentialProvider.cpp

    r57358 r60255  
    55
    66/*
    7  * Copyright (C) 2012-2014 Oracle Corporation
     7 * Copyright (C) 2012-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424#include <new> /* For bad_alloc. */
    2525
    26 #ifdef VBOX_WITH_SENS
     26#ifdef VBOX_WITH_WIN_SENS
    2727# include <eventsys.h>
    2828# include <sens.h>
     
    3232#include <iprt/buildconfig.h>
    3333#include <iprt/initterm.h>
    34 #ifdef VBOX_WITH_SENS
    35 # include <iprt/string.h>
     34#ifdef VBOX_WITH_WIN_SENS
     35# include <VBox/com/string.h>
     36using namespace com;
    3637#endif
    3738#include <VBox/VBoxGuestLib.h>
     
    4748static HINSTANCE g_hDllInst = NULL;          /**< Global DLL hInstance. */
    4849
    49 #ifdef VBOX_WITH_SENS
     50#ifdef VBOX_WITH_WIN_SENS
    5051static bool g_fSENSEnabled = false;
    5152static IEventSystem *g_pIEventSystem = NULL; /**< Pointer to IEventSystem interface. */
     
    199200    if (FAILED(hr))
    200201    {
    201         VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not connect to CEventSystem, hr=%Rhrc\n",
    202                             hr);
     202        VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Could not connect to CEventSystem, hr=%Rhrc\n", hr);
    203203        return hr;
    204204    }
    205205
     206    /* Note: Bstr class can also throw -- therefore including the setup procedure in the following try block as well. */
    206207    try
    207208    {
    208209        g_pISensLogon = new VBoxCredProvSensLogon();
     210
     211        AssertPtr(g_pIEventSystem);
    209212        AssertPtr(g_pISensLogon);
    210     }
    211     catch (std::bad_alloc &ex)
    212     {
    213         NOREF(ex);
    214         hr = E_OUTOFMEMORY;
    215     }
    216 
    217     if (   SUCCEEDED(hr)
    218         && g_pIEventSystem)
    219     {
     213
    220214        IEventSubscription *pIEventSubscription;
    221215        int i;
     
    229223                continue;
    230224
    231             hr = pIEventSubscription->put_EventClassID(L"{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */);
     225            hr = pIEventSubscription->put_EventClassID(Bstr("{d5978630-5b9f-11d1-8dd2-00aa004abd5e}" /* SENSGUID_EVENTCLASS_LOGON */).raw());
    232226            if (FAILED(hr))
    233227                break;
     
    237231                break;
    238232
    239             PRTUTF16 pwszTemp;
    240             int rc = RTStrToUtf16(g_aSENSEvents[i].pszMethod, &pwszTemp);
    241             if (RT_SUCCESS(rc))
    242             {
    243                 hr = pIEventSubscription->put_MethodName(pwszTemp);
    244                 RTUtf16Free(pwszTemp);
    245             }
    246             else
    247                 hr = ERROR_OUTOFMEMORY;
    248             if (FAILED(hr))
    249                 break;
    250 
    251             rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionName, &pwszTemp);
    252             if (RT_SUCCESS(rc))
    253             {
    254                 hr = pIEventSubscription->put_SubscriptionName(pwszTemp);
    255                 RTUtf16Free(pwszTemp);
    256             }
    257             else
    258                 hr = ERROR_OUTOFMEMORY;
    259             if (FAILED(hr))
    260                 break;
    261 
    262             rc = RTStrToUtf16(g_aSENSEvents[i].pszSubscriptionUUID, &pwszTemp);
    263             if (RT_SUCCESS(rc))
    264             {
    265                 hr = pIEventSubscription->put_SubscriptionID(pwszTemp);
    266                 RTUtf16Free(pwszTemp);
    267             }
    268             else
    269                 hr = ERROR_OUTOFMEMORY;
     233            hr = pIEventSubscription->put_MethodName(Bstr(g_aSENSEvents[i].pszMethod).raw());
     234            if (FAILED(hr))
     235                break;
     236
     237            hr = pIEventSubscription->put_SubscriptionName(Bstr(g_aSENSEvents[i].pszSubscriptionName).raw());
     238            if (FAILED(hr))
     239                break;
     240
     241            hr = pIEventSubscription->put_SubscriptionID(Bstr(g_aSENSEvents[i].pszSubscriptionUUID).raw());
    270242            if (FAILED(hr))
    271243                break;
     
    290262            pIEventSubscription->Release();
    291263    }
     264    catch (std::bad_alloc &ex)
     265    {
     266        NOREF(ex);
     267        hr = E_OUTOFMEMORY;
     268    }
    292269
    293270    if (FAILED(hr))
    294271    {
    295272        VBoxCredProvVerbose(0, "VBoxCredentialProviderRegisterSENS: Error registering SENS provider, hr=%Rhrc\n", hr);
     273
     274        if (g_pISensLogon)
     275        {
     276            delete g_pISensLogon;
     277            g_pISensLogon = NULL;
     278        }
     279
    296280        if (g_pIEventSystem)
    297281        {
     
    320304    HRESULT hr = CoCreateInstance(CLSID_CEventSystem, 0,
    321305                                  CLSCTX_SERVER, IID_IEventSystem, (void**)&g_pIEventSystem);
    322     if (   SUCCEEDED(hr)
    323         && g_pIEventSystem)
     306    if (FAILED(hr))
     307        VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not reconnect to CEventSystem, hr=%Rhrc\n", hr);
     308
     309    try
    324310    {
    325311        VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS\n");
     
    329315        for (int i = 0; i < RT_ELEMENTS(g_aSENSEvents); i++)
    330316        {
    331             int iErrorIdX;
    332 
    333             char *pszSubToRemove;
    334             if (!RTStrAPrintf(&pszSubToRemove, "SubscriptionID=%s",
    335                               g_aSENSEvents[i].pszSubscriptionUUID))
     317            int  iErrorIdX;
     318            Bstr strSubToRemove = Utf8StrFmt("SubscriptionID=%s", g_aSENSEvents[i].pszSubscriptionUUID);
     319            hr = g_pIEventSystem->Remove(PROGID_EventSubscription, strSubToRemove.raw(), &iErrorIdX);
     320            if (FAILED(hr))
    336321            {
    337                 continue; /* Keep going. */
     322                VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not unregister \"%s\" (query: %ls), hr=%Rhrc (index: %d)\n",
     323                                    g_aSENSEvents[i].pszMethod, strSubToRemove.raw(), hr, iErrorIdX);
     324                /* Keep going. */
    338325            }
    339 
    340             PRTUTF16 pwszTemp;
    341             int rc2 = RTStrToUtf16(pszSubToRemove, &pwszTemp);
    342             if (RT_SUCCESS(rc2))
    343             {
    344                 hr = g_pIEventSystem->Remove(PROGID_EventSubscription, pwszTemp,
    345                                              &iErrorIdX);
    346                 RTUtf16Free(pwszTemp);
    347             }
    348             else
    349                 hr = ERROR_OUTOFMEMORY;
    350 
    351             if (FAILED(hr))
    352                 VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Could not unregister \"%s\" (query: %s), hr=%Rhrc (index: %d)\n",
    353                                     g_aSENSEvents[i].pszMethod, pszSubToRemove, hr, iErrorIdX);
    354                 /* Keep going. */
    355 
    356             RTStrFree(pszSubToRemove);
    357         }
    358 
     326        }
     327    }
     328    catch (std::bad_alloc &ex)
     329    {
     330        NOREF(ex);
     331        hr = E_OUTOFMEMORY;
     332    }
     333
     334    if (g_pISensLogon)
     335    {
     336        delete g_pISensLogon;
     337        g_pISensLogon = NULL;
     338    }
     339
     340    if (g_pIEventSystem)
     341    {
    359342        g_pIEventSystem->Release();
    360343        g_pIEventSystem = NULL;
    361344    }
    362345
    363     if (g_pISensLogon)
    364     {
    365         delete g_pISensLogon;
    366         g_pISensLogon = NULL;
    367     }
    368 
    369346    VBoxCredProvVerbose(0, "VBoxCredentialProviderUnregisterSENS: Returning hr=%Rhrc\n", hr);
    370347}
    371 #endif /* VBOX_WITH_SENS */
     348#endif /* VBOX_WITH_WIN_SENS */
    372349
    373350
     
    461438                        g_cDllRefs);
    462439
    463 #ifdef VBOX_WITH_SENS
     440#ifdef VBOX_WITH_WIN_SENS
    464441    if (!g_cDllRefs)
    465442    {
     
    499476            pFactory->Release();
    500477
    501 #ifdef VBOX_WITH_SENS
     478#ifdef VBOX_WITH_WIN_SENS
    502479            g_fSENSEnabled = true; /* By default SENS support is enabled. */
    503480
     
    533510#else
    534511            VBoxCredProvVerbose(0, "VBoxCredentialProviderCreate: SENS support is disabled\n");
    535 #endif
     512#endif /* VBOX_WITH_WIN_SENS */
    536513        }
    537514        catch (std::bad_alloc &ex)
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