ReactOS  0.4.14-dev-838-g99f979d
wbemlocator.c
Go to the documentation of this file.
1 /*
2  * Copyright 2009 Hans Leidekker for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #define COBJMACROS
20 
21 #include <stdarg.h>
22 
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "wbemcli.h"
27 
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
30 
32 
33 typedef struct
34 {
37 } wbem_locator;
38 
40 {
41  return CONTAINING_RECORD(iface, wbem_locator, IWbemLocator_iface);
42 }
43 
45  IWbemLocator *iface )
46 {
47  wbem_locator *wl = impl_from_IWbemLocator( iface );
48  return InterlockedIncrement( &wl->refs );
49 }
50 
52  IWbemLocator *iface )
53 {
54  wbem_locator *wl = impl_from_IWbemLocator( iface );
56  if (!refs)
57  {
58  TRACE("destroying %p\n", wl);
59  heap_free( wl );
60  }
61  return refs;
62 }
63 
65  IWbemLocator *iface,
66  REFIID riid,
67  void **ppvObject )
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 }
86 
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 }
98 
99 static HRESULT parse_resource( const WCHAR *resource, WCHAR **server, WCHAR **namespace )
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  {
123  hr = E_OUTOFMEMORY;
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 
152 done:
153  if (hr != S_OK)
154  {
155  heap_free( *server );
156  heap_free( *namespace );
157  }
158  return hr;
159 }
160 
162  IWbemLocator *iface,
163  const BSTR NetworkResource,
164  const BSTR User,
165  const BSTR Password,
166  const BSTR Locale,
167  LONG SecurityFlags,
168  const BSTR Authority,
169  IWbemContext *pCtx,
170  IWbemServices **ppNamespace)
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 }
203 
204 static const IWbemLocatorVtbl wbem_locator_vtbl =
205 {
210 };
211 
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 }
static const WCHAR localhostW[]
Definition: notification.c:35
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
static rfbScreenInfoPtr server
Definition: vnc.c:74
HRESULT hr
Definition: shlfolder.c:183
REFIID riid
Definition: precomp.h:44
static const WCHAR rootW[]
Definition: chain.c:69
static BOOL is_local_machine(const WCHAR *server)
Definition: wbemlocator.c:87
static const WCHAR defaultW[]
Definition: lex.c:42
_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)
GLuint buffer
Definition: glext.h:5915
IWbemLocator IWbemLocator_iface
Definition: wbemlocator.c:35
OLECHAR * BSTR
Definition: compat.h:1942
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:443
int resource
Definition: rdpsnd_sgi.c:44
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox)
static HRESULT WINAPI wbem_locator_QueryInterface(IWbemLocator *iface, REFIID riid, void **ppvObject)
Definition: wbemlocator.c:64
#define lstrlenW
Definition: compat.h:415
static ULONG WINAPI wbem_locator_AddRef(IWbemLocator *iface)
Definition: wbemlocator.c:44
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static const IWbemLocatorVtbl wbem_locator_vtbl
Definition: wbemlocator.c:204
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
HRESULT WbemServices_create(const WCHAR *namespace, LPVOID *ppObj)
Definition: services.c:925
static HRESULT parse_resource(const WCHAR *resource, WCHAR **server, WCHAR **namespace)
Definition: wbemlocator.c:99
#define InterlockedDecrement
Definition: armddk.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
REFIID LPVOID * ppvObject
Definition: precomp.h:44
static wbem_locator * impl_from_IWbemLocator(IWbemLocator *iface)
Definition: wbemlocator.c:39
#define wcsicmp
Definition: string.h:1152
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
#define ARRAY_SIZE(a)
Definition: main.h:24
static ULONG WINAPI wbem_locator_Release(IWbemLocator *iface)
Definition: wbemlocator.c:51
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
HRESULT WbemLocator_create(LPVOID *ppObj)
Definition: wbemlocator.c:212
static const WCHAR dotW[]
Definition: directory.c:80
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
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static BOOL heap_free(void *mem)
Definition: appwiz.h:75