ReactOS 0.4.16-dev-297-gc569aee
wbemlocator.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wbemcli.h"
#include "wine/debug.h"
#include "wbemprox_private.h"
Include dependency graph for wbemlocator.c:

Go to the source code of this file.

Classes

struct  wbem_locator
 

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wbemprox)
 
static wbem_locatorimpl_from_IWbemLocator (IWbemLocator *iface)
 
static ULONG WINAPI wbem_locator_AddRef (IWbemLocator *iface)
 
static ULONG WINAPI wbem_locator_Release (IWbemLocator *iface)
 
static HRESULT WINAPI wbem_locator_QueryInterface (IWbemLocator *iface, REFIID riid, void **ppvObject)
 
static BOOL is_local_machine (const WCHAR *server)
 
static HRESULT parse_resource (const WCHAR *resource, WCHAR **server, WCHAR **namespace)
 
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, IWbemContext *pCtx, IWbemServices **ppNamespace)
 
HRESULT WbemLocator_create (LPVOID *ppObj)
 

Variables

static const IWbemLocatorVtbl wbem_locator_vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 19 of file wbemlocator.c.

Function Documentation

◆ impl_from_IWbemLocator()

static wbem_locator * impl_from_IWbemLocator ( IWbemLocator iface)
inlinestatic

Definition at line 39 of file wbemlocator.c.

40{
41 return CONTAINING_RECORD(iface, wbem_locator, IWbemLocator_iface);
42}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by wbem_locator_AddRef(), wbem_locator_QueryInterface(), and wbem_locator_Release().

◆ is_local_machine()

static BOOL is_local_machine ( const WCHAR server)
static

Definition at line 87 of file wbemlocator.c.

88{
89 static const WCHAR dotW[] = {'.',0};
90 static const WCHAR localhostW[] = {'l','o','c','a','l','h','o','s','t',0};
93
94 if (!server || !wcscmp( server, dotW ) || !wcsicmp( server, localhostW )) return TRUE;
95 if (GetComputerNameW( buffer, &len ) && !wcsicmp( server, buffer )) return TRUE;
96 return FALSE;
97}
#define ARRAY_SIZE(A)
Definition: main.h:20
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcsicmp
Definition: compat.h:15
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR dotW[]
Definition: directory.c:80
static const WCHAR localhostW[]
Definition: notification.c:35
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by wbem_locator_ConnectServer().

◆ parse_resource()

static HRESULT parse_resource ( const WCHAR resource,
WCHAR **  server,
WCHAR **  namespace 
)
static

Definition at line 99 of file wbemlocator.c.

100{
101 static const WCHAR rootW[] = {'R','O','O','T'};
102 static const WCHAR cimv2W[] = {'C','I','M','V','2',0};
103 static const WCHAR defaultW[] = {'D','E','F','A','U','L','T',0};
105 const WCHAR *p, *q;
106 unsigned int len;
107
108 *server = NULL;
109 *namespace = NULL;
110 p = q = resource;
111 if (*p == '\\' || *p == '/')
112 {
113 p++;
114 if (*p == '\\' || *p == '/') p++;
115 if (!*p) return WBEM_E_INVALID_NAMESPACE;
116 if (*p == '\\' || *p == '/') return WBEM_E_INVALID_PARAMETER;
117 q = p + 1;
118 while (*q && *q != '\\' && *q != '/') q++;
119 if (!*q) return WBEM_E_INVALID_NAMESPACE;
120 len = q - p;
121 if (!(*server = heap_alloc( (len + 1) * sizeof(WCHAR) )))
122 {
124 goto done;
125 }
126 memcpy( *server, p, len * sizeof(WCHAR) );
127 (*server)[len] = 0;
128 q++;
129 }
130 if (!*q) goto done;
131 p = q;
132 while (*q && *q != '\\' && *q != '/') q++;
133 len = q - p;
134 if (len >= ARRAY_SIZE( rootW ) && _wcsnicmp( rootW, p, len )) goto done;
135 if (!*q)
136 {
137 hr = S_OK;
138 goto done;
139 }
140 q++;
141 len = lstrlenW( q );
142 if (wcsicmp( q, cimv2W ) && wcsicmp( q, defaultW ))
143 goto done;
144 if (!(*namespace = heap_alloc( (len + 1) * sizeof(WCHAR) ))) hr = E_OUTOFMEMORY;
145 else
146 {
147 memcpy( *namespace, p, len * sizeof(WCHAR) );
148 (*namespace)[len] = 0;
149 hr = S_OK;
150 }
151
152done:
153 if (hr != S_OK)
154 {
155 heap_free( *server );
156 heap_free( *namespace );
157 }
158 return hr;
159}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
static const WCHAR rootW[]
Definition: chain.c:69
#define lstrlenW
Definition: compat.h:750
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define S_OK
Definition: intsafe.h:52
#define resource
Definition: kernel32.h:9
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
HRESULT hr
Definition: shlfolder.c:183
static const WCHAR defaultW[]
Definition: lex.c:42
@ WBEM_E_INVALID_NAMESPACE
Definition: wbemcli.idl:64
@ WBEM_E_INVALID_PARAMETER
Definition: wbemcli.idl:58

Referenced by wbem_locator_ConnectServer().

◆ wbem_locator_AddRef()

static ULONG WINAPI wbem_locator_AddRef ( IWbemLocator iface)
static

Definition at line 44 of file wbemlocator.c.

46{
48 return InterlockedIncrement( &wl->refs );
49}
#define InterlockedIncrement
Definition: armddk.h:53
static wbem_locator * impl_from_IWbemLocator(IWbemLocator *iface)
Definition: wbemlocator.c:39

◆ wbem_locator_ConnectServer()

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,
IWbemContext *  pCtx,
IWbemServices **  ppNamespace 
)
static

Definition at line 161 of file wbemlocator.c.

171{
172 HRESULT hr;
173 WCHAR *server, *namespace;
174
175 TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface, debugstr_w(NetworkResource), debugstr_w(User),
176 debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), pCtx, ppNamespace);
177
178 hr = parse_resource( NetworkResource, &server, &namespace );
179 if (hr != S_OK) return hr;
180
181 if (!is_local_machine( server ))
182 {
183 FIXME("remote computer not supported\n");
184 heap_free( server );
185 heap_free( namespace );
187 }
188 if (User || Password || Authority)
189 FIXME("authentication not supported\n");
190 if (Locale)
191 FIXME("specific locale not supported\n");
192 if (SecurityFlags)
193 FIXME("unsupported flags\n");
194
195 hr = WbemServices_create( namespace, (void **)ppNamespace );
196 heap_free( namespace );
197 heap_free( server );
198 if (SUCCEEDED( hr ))
199 return WBEM_NO_ERROR;
200
201 return WBEM_E_FAILED;
202}
#define FIXME(fmt,...)
Definition: precomp.h:53
HRESULT WbemServices_create(const WCHAR *namespace, LPVOID *ppObj)
Definition: services.c:925
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
@ Password
Definition: telnetd.h:65
@ WBEM_NO_ERROR
Definition: wbemcli.idl:36
@ WBEM_E_TRANSPORT_FAILURE
Definition: wbemcli.idl:71
@ WBEM_E_FAILED
Definition: wbemcli.idl:51
static BOOL is_local_machine(const WCHAR *server)
Definition: wbemlocator.c:87
static HRESULT parse_resource(const WCHAR *resource, WCHAR **server, WCHAR **namespace)
Definition: wbemlocator.c:99

◆ wbem_locator_QueryInterface()

static HRESULT WINAPI wbem_locator_QueryInterface ( IWbemLocator iface,
REFIID  riid,
void **  ppvObject 
)
static

Definition at line 64 of file wbemlocator.c.

68{
70
71 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
72
73 if ( IsEqualGUID( riid, &IID_IWbemLocator ) ||
75 {
76 *ppvObject = iface;
77 }
78 else
79 {
80 FIXME("interface %s not implemented\n", debugstr_guid(riid));
81 return E_NOINTERFACE;
82 }
83 IWbemLocator_AddRef( iface );
84 return S_OK;
85}
const GUID IID_IUnknown
REFIID riid
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ wbem_locator_Release()

static ULONG WINAPI wbem_locator_Release ( IWbemLocator iface)
static

Definition at line 51 of file wbemlocator.c.

53{
55 LONG refs = InterlockedDecrement( &wl->refs );
56 if (!refs)
57 {
58 TRACE("destroying %p\n", wl);
59 heap_free( wl );
60 }
61 return refs;
62}
#define InterlockedDecrement
Definition: armddk.h:52
long LONG
Definition: pedump.c:60

◆ WbemLocator_create()

HRESULT WbemLocator_create ( LPVOID ppObj)

Definition at line 212 of file wbemlocator.c.

213{
214 wbem_locator *wl;
215
216 TRACE("(%p)\n", ppObj);
217
218 wl = heap_alloc( sizeof(*wl) );
219 if (!wl) return E_OUTOFMEMORY;
220
222 wl->refs = 1;
223
224 *ppObj = &wl->IWbemLocator_iface;
225
226 TRACE("returning iface %p\n", *ppObj);
227 return S_OK;
228}
IWbemLocator IWbemLocator_iface
Definition: wbemlocator.c:35
static const IWbemLocatorVtbl wbem_locator_vtbl
Definition: wbemlocator.c:204

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wbemprox  )

Variable Documentation

◆ wbem_locator_vtbl

const IWbemLocatorVtbl wbem_locator_vtbl
static
Initial value:
=
{
}
static ULONG WINAPI wbem_locator_AddRef(IWbemLocator *iface)
Definition: wbemlocator.c:44
static ULONG WINAPI wbem_locator_Release(IWbemLocator *iface)
Definition: wbemlocator.c:51
static HRESULT WINAPI wbem_locator_QueryInterface(IWbemLocator *iface, REFIID riid, void **ppvObject)
Definition: wbemlocator.c:64
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, IWbemContext *pCtx, IWbemServices **ppNamespace)
Definition: wbemlocator.c:161

Definition at line 204 of file wbemlocator.c.

Referenced by WbemLocator_create().