2009-07-14 12:26:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Hans Leidekker for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "wbemcli.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wbemprox_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-12-05 15:15:04 +01:00
|
|
|
IWbemLocator IWbemLocator_iface;
|
2009-07-14 12:26:38 +02:00
|
|
|
LONG refs;
|
|
|
|
} wbem_locator;
|
|
|
|
|
|
|
|
static inline wbem_locator *impl_from_IWbemLocator( IWbemLocator *iface )
|
|
|
|
{
|
2010-12-05 15:15:04 +01:00
|
|
|
return CONTAINING_RECORD(iface, wbem_locator, IWbemLocator_iface);
|
2009-07-14 12:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI wbem_locator_AddRef(
|
|
|
|
IWbemLocator *iface )
|
|
|
|
{
|
|
|
|
wbem_locator *wl = impl_from_IWbemLocator( iface );
|
|
|
|
return InterlockedIncrement( &wl->refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI wbem_locator_Release(
|
|
|
|
IWbemLocator *iface )
|
|
|
|
{
|
|
|
|
wbem_locator *wl = impl_from_IWbemLocator( iface );
|
|
|
|
LONG refs = InterlockedDecrement( &wl->refs );
|
|
|
|
if (!refs)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", wl);
|
2012-06-14 16:03:26 +02:00
|
|
|
heap_free( wl );
|
2009-07-14 12:26:38 +02:00
|
|
|
}
|
|
|
|
return refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI wbem_locator_QueryInterface(
|
|
|
|
IWbemLocator *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject )
|
|
|
|
{
|
|
|
|
wbem_locator *This = impl_from_IWbemLocator( iface );
|
|
|
|
|
|
|
|
TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
|
|
|
|
|
|
|
|
if ( IsEqualGUID( riid, &IID_IWbemLocator ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
IWbemLocator_AddRef( iface );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-25 11:20:21 +02:00
|
|
|
static BOOL is_local_machine( const WCHAR *server )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 1];
|
2018-09-11 22:08:07 +02:00
|
|
|
DWORD len = ARRAY_SIZE( buffer );
|
2012-06-25 11:20:21 +02:00
|
|
|
|
2020-04-20 10:38:10 +02:00
|
|
|
if (!server || !wcscmp( server, L"." ) || !wcsicmp( server, L"localhost" )) return TRUE;
|
2019-07-04 09:27:39 +02:00
|
|
|
if (GetComputerNameW( buffer, &len ) && !wcsicmp( server, buffer )) return TRUE;
|
2012-06-25 11:20:21 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT parse_resource( const WCHAR *resource, WCHAR **server, WCHAR **namespace )
|
|
|
|
{
|
|
|
|
HRESULT hr = WBEM_E_INVALID_NAMESPACE;
|
|
|
|
const WCHAR *p, *q;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
*server = NULL;
|
|
|
|
*namespace = NULL;
|
|
|
|
p = q = resource;
|
|
|
|
if (*p == '\\' || *p == '/')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
if (*p == '\\' || *p == '/') p++;
|
|
|
|
if (!*p) return WBEM_E_INVALID_NAMESPACE;
|
|
|
|
if (*p == '\\' || *p == '/') return WBEM_E_INVALID_PARAMETER;
|
|
|
|
q = p + 1;
|
|
|
|
while (*q && *q != '\\' && *q != '/') q++;
|
|
|
|
if (!*q) return WBEM_E_INVALID_NAMESPACE;
|
|
|
|
len = q - p;
|
|
|
|
if (!(*server = heap_alloc( (len + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
memcpy( *server, p, len * sizeof(WCHAR) );
|
|
|
|
(*server)[len] = 0;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
if (!*q) goto done;
|
|
|
|
p = q;
|
|
|
|
while (*q && *q != '\\' && *q != '/') q++;
|
|
|
|
len = q - p;
|
2020-04-20 10:38:10 +02:00
|
|
|
if (len >= ARRAY_SIZE( L"root" ) - 1 && wcsnicmp( L"root", p, len )) goto done;
|
2012-06-25 11:20:21 +02:00
|
|
|
if (!*q)
|
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
q++;
|
2019-07-04 09:27:39 +02:00
|
|
|
len = lstrlenW( q );
|
2012-06-25 11:20:21 +02:00
|
|
|
if (!(*namespace = heap_alloc( (len + 1) * sizeof(WCHAR) ))) hr = E_OUTOFMEMORY;
|
|
|
|
else
|
|
|
|
{
|
2021-09-13 16:13:25 +02:00
|
|
|
memcpy( *namespace, q, len * sizeof(WCHAR) );
|
2012-06-25 11:20:21 +02:00
|
|
|
(*namespace)[len] = 0;
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
heap_free( *server );
|
|
|
|
heap_free( *namespace );
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-07-14 12:26:38 +02:00
|
|
|
static HRESULT WINAPI wbem_locator_ConnectServer(
|
|
|
|
IWbemLocator *iface,
|
|
|
|
const BSTR NetworkResource,
|
|
|
|
const BSTR User,
|
|
|
|
const BSTR Password,
|
|
|
|
const BSTR Locale,
|
|
|
|
LONG SecurityFlags,
|
|
|
|
const BSTR Authority,
|
2021-03-03 07:05:48 +01:00
|
|
|
IWbemContext *context,
|
2009-07-14 12:26:38 +02:00
|
|
|
IWbemServices **ppNamespace)
|
|
|
|
{
|
2012-06-14 16:02:38 +02:00
|
|
|
HRESULT hr;
|
2012-06-25 11:20:21 +02:00
|
|
|
WCHAR *server, *namespace;
|
2012-06-14 16:02:38 +02:00
|
|
|
|
2012-06-19 10:19:03 +02:00
|
|
|
TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface, debugstr_w(NetworkResource), debugstr_w(User),
|
2021-03-03 07:05:48 +01:00
|
|
|
debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), context, ppNamespace);
|
2012-06-14 16:02:38 +02:00
|
|
|
|
2012-06-25 11:20:21 +02:00
|
|
|
hr = parse_resource( NetworkResource, &server, &namespace );
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
if (!is_local_machine( server ))
|
2012-06-14 16:02:38 +02:00
|
|
|
{
|
|
|
|
FIXME("remote computer not supported\n");
|
2012-06-25 11:20:21 +02:00
|
|
|
heap_free( server );
|
|
|
|
heap_free( namespace );
|
2012-06-14 16:02:38 +02:00
|
|
|
return WBEM_E_TRANSPORT_FAILURE;
|
|
|
|
}
|
2012-06-19 10:19:03 +02:00
|
|
|
if (User || Password || Authority)
|
|
|
|
FIXME("authentication not supported\n");
|
|
|
|
if (Locale)
|
|
|
|
FIXME("specific locale not supported\n");
|
|
|
|
if (SecurityFlags)
|
|
|
|
FIXME("unsupported flags\n");
|
|
|
|
|
2021-03-03 07:05:48 +01:00
|
|
|
hr = WbemServices_create( namespace, context, (void **)ppNamespace );
|
2012-06-26 16:01:43 +02:00
|
|
|
heap_free( namespace );
|
2013-05-09 10:30:44 +02:00
|
|
|
heap_free( server );
|
2012-06-14 16:02:38 +02:00
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
return WBEM_NO_ERROR;
|
|
|
|
|
2021-09-13 16:13:27 +02:00
|
|
|
return hr;
|
2009-07-14 12:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IWbemLocatorVtbl wbem_locator_vtbl =
|
|
|
|
{
|
|
|
|
wbem_locator_QueryInterface,
|
|
|
|
wbem_locator_AddRef,
|
|
|
|
wbem_locator_Release,
|
|
|
|
wbem_locator_ConnectServer
|
|
|
|
};
|
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
HRESULT WbemLocator_create( LPVOID *ppObj )
|
2009-07-14 12:26:38 +02:00
|
|
|
{
|
|
|
|
wbem_locator *wl;
|
|
|
|
|
2013-12-30 10:21:36 +01:00
|
|
|
TRACE("(%p)\n", ppObj);
|
2009-07-14 12:26:38 +02:00
|
|
|
|
2012-06-14 16:03:26 +02:00
|
|
|
wl = heap_alloc( sizeof(*wl) );
|
2009-07-14 12:26:38 +02:00
|
|
|
if (!wl) return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-05 15:15:04 +01:00
|
|
|
wl->IWbemLocator_iface.lpVtbl = &wbem_locator_vtbl;
|
2009-07-14 12:26:38 +02:00
|
|
|
wl->refs = 1;
|
|
|
|
|
2010-12-05 15:15:04 +01:00
|
|
|
*ppObj = &wl->IWbemLocator_iface;
|
2009-07-14 12:26:38 +02:00
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|