wbemprox: Keep context object per services instance.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2021-03-03 09:05:48 +03:00 committed by Alexandre Julliard
parent 2ed349488c
commit 4a97c6b03c
4 changed files with 36 additions and 8 deletions

View File

@ -210,6 +210,7 @@ struct wbem_services
CRITICAL_SECTION cs;
WCHAR *namespace;
struct async_header *async;
IWbemContext *context;
};
static inline struct wbem_services *impl_from_IWbemServices( IWbemServices *iface )
@ -243,6 +244,8 @@ static ULONG WINAPI wbem_services_Release(
}
ws->cs.DebugInfo->Spare[0] = 0;
DeleteCriticalSection( &ws->cs );
if (ws->context)
IWbemContext_Release( ws->context );
heap_free( ws->namespace );
heap_free( ws );
}
@ -293,7 +296,7 @@ static HRESULT WINAPI wbem_services_OpenNamespace(
if ((wcsicmp( strNamespace, L"cimv2" ) && wcsicmp( strNamespace, L"default" )) || ws->namespace)
return WBEM_E_INVALID_NAMESPACE;
return WbemServices_create( L"cimv2", (void **)ppWorkingNamespace );
return WbemServices_create( L"cimv2", NULL, (void **)ppWorkingNamespace );
}
static HRESULT WINAPI wbem_services_CancelAsyncCall(
@ -933,21 +936,22 @@ static const IWbemServicesVtbl wbem_services_vtbl =
wbem_services_ExecMethodAsync
};
HRESULT WbemServices_create( const WCHAR *namespace, LPVOID *ppObj )
HRESULT WbemServices_create( const WCHAR *namespace, IWbemContext *context, LPVOID *ppObj )
{
struct wbem_services *ws;
TRACE("(%p)\n", ppObj);
ws = heap_alloc( sizeof(*ws) );
ws = heap_alloc_zero( sizeof(*ws) );
if (!ws) return E_OUTOFMEMORY;
ws->IWbemServices_iface.lpVtbl = &wbem_services_vtbl;
ws->refs = 1;
ws->namespace = heap_strdupW( namespace );
ws->async = NULL;
InitializeCriticalSection( &ws->cs );
ws->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": wbemprox_services.cs");
if (context)
IWbemContext_Clone( context, &ws->context );
*ppObj = &ws->IWbemServices_iface;

View File

@ -24,6 +24,15 @@
#include "wbemcli.h"
#include "wine/test.h"
#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
static void _expect_ref(IUnknown* obj, ULONG ref, int line)
{
ULONG rc;
IUnknown_AddRef(obj);
rc = IUnknown_Release(obj);
ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
}
static void test_IClientSecurity(void)
{
HRESULT hr;
@ -124,6 +133,7 @@ static void test_IWbemLocator(void)
};
IWbemLocator *locator;
IWbemServices *services;
IWbemContext *context;
unsigned int i;
HRESULT hr;
BSTR resource;
@ -146,6 +156,20 @@ static void test_IWbemLocator(void)
SysFreeString( resource );
if (hr == S_OK) IWbemServices_Release( services );
}
hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext, (void **)&context );
ok(hr == S_OK, "Failed to create context object, hr %#x.\n", hr);
EXPECT_REF(context, 1);
resource = SysAllocString( L"root\\default" );
hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, context, &services );
ok(hr == S_OK, "Failed to connect, hr %#x.\n", hr);
SysFreeString( resource );
EXPECT_REF(context, 1);
IWbemServices_Release( services );
IWbemContext_Release( context );
IWbemLocator_Release( locator );
}

View File

@ -161,14 +161,14 @@ static HRESULT WINAPI wbem_locator_ConnectServer(
const BSTR Locale,
LONG SecurityFlags,
const BSTR Authority,
IWbemContext *pCtx,
IWbemContext *context,
IWbemServices **ppNamespace)
{
HRESULT hr;
WCHAR *server, *namespace;
TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface, debugstr_w(NetworkResource), debugstr_w(User),
debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), pCtx, ppNamespace);
debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), context, ppNamespace);
hr = parse_resource( NetworkResource, &server, &namespace );
if (hr != S_OK) return hr;
@ -187,7 +187,7 @@ static HRESULT WINAPI wbem_locator_ConnectServer(
if (SecurityFlags)
FIXME("unsupported flags\n");
hr = WbemServices_create( namespace, (void **)ppNamespace );
hr = WbemServices_create( namespace, context, (void **)ppNamespace );
heap_free( namespace );
heap_free( server );
if (SUCCEEDED( hr ))

View File

@ -236,7 +236,7 @@ HRESULT create_signature( const WCHAR *, const WCHAR *, enum param_direction,
IWbemClassObject ** ) DECLSPEC_HIDDEN;
HRESULT WbemLocator_create(LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemServices_create(const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemServices_create(const WCHAR *, IWbemContext *, LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemContext_create(void **) DECLSPEC_HIDDEN;
HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;