ReactOS  0.4.14-dev-115-g4576127
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 "config.h"
22 #include <stdarg.h>
23 
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wbemcli.h"
28 
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31 #include "wbemprox_private.h"
32 
34 
35 typedef struct
36 {
39 } wbem_locator;
40 
42 {
43  return CONTAINING_RECORD(iface, wbem_locator, IWbemLocator_iface);
44 }
45 
47  IWbemLocator *iface )
48 {
49  wbem_locator *wl = impl_from_IWbemLocator( iface );
50  return InterlockedIncrement( &wl->refs );
51 }
52 
54  IWbemLocator *iface )
55 {
56  wbem_locator *wl = impl_from_IWbemLocator( iface );
58  if (!refs)
59  {
60  TRACE("destroying %p\n", wl);
61  heap_free( wl );
62  }
63  return refs;
64 }
65 
67  IWbemLocator *iface,
68  REFIID riid,
69  void **ppvObject )
70 {
72 
73  TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
74 
75  if ( IsEqualGUID( riid, &IID_IWbemLocator ) ||
77  {
78  *ppvObject = iface;
79  }
80  else
81  {
82  FIXME("interface %s not implemented\n", debugstr_guid(riid));
83  return E_NOINTERFACE;
84  }
85  IWbemLocator_AddRef( iface );
86  return S_OK;
87 }
88 
90 {
91  static const WCHAR dotW[] = {'.',0};
92  static const WCHAR localhostW[] = {'l','o','c','a','l','h','o','s','t',0};
95 
96  if (!server || !strcmpW( server, dotW ) || !strcmpiW( server, localhostW )) return TRUE;
97  if (GetComputerNameW( buffer, &len ) && !strcmpiW( server, buffer )) return TRUE;
98  return FALSE;
99 }
100 
101 static HRESULT parse_resource( const WCHAR *resource, WCHAR **server, WCHAR **namespace )
102 {
103  static const WCHAR rootW[] = {'R','O','O','T'};
104  static const WCHAR cimv2W[] = {'C','I','M','V','2'};
105  static const WCHAR defaultW[] = {'D','E','F','A','U','L','T'};
107  const WCHAR *p, *q;
108  unsigned int len;
109 
110  *server = NULL;
111  *namespace = NULL;
112  p = q = resource;
113  if (*p == '\\' || *p == '/')
114  {
115  p++;
116  if (*p == '\\' || *p == '/') p++;
117  if (!*p) return WBEM_E_INVALID_NAMESPACE;
118  if (*p == '\\' || *p == '/') return WBEM_E_INVALID_PARAMETER;
119  q = p + 1;
120  while (*q && *q != '\\' && *q != '/') q++;
121  if (!*q) return WBEM_E_INVALID_NAMESPACE;
122  len = q - p;
123  if (!(*server = heap_alloc( (len + 1) * sizeof(WCHAR) )))
124  {
125  hr = E_OUTOFMEMORY;
126  goto done;
127  }
128  memcpy( *server, p, len * sizeof(WCHAR) );
129  (*server)[len] = 0;
130  q++;
131  }
132  if (!*q) goto done;
133  p = q;
134  while (*q && *q != '\\' && *q != '/') q++;
135  len = q - p;
136  if (len >= ARRAY_SIZE( rootW ) && memicmpW( rootW, p, len )) goto done;
137  if (!*q)
138  {
139  hr = S_OK;
140  goto done;
141  }
142  q++;
143  len = strlenW( q );
144  if ((len != ARRAY_SIZE( cimv2W ) || memicmpW( q, cimv2W, len )) &&
145  (len != ARRAY_SIZE( defaultW ) || memicmpW( q, defaultW, len )))
146  goto done;
147  if (!(*namespace = heap_alloc( (len + 1) * sizeof(WCHAR) ))) hr = E_OUTOFMEMORY;
148  else
149  {
150  memcpy( *namespace, p, len * sizeof(WCHAR) );
151  (*namespace)[len] = 0;
152  hr = S_OK;
153  }
154 
155 done:
156  if (hr != S_OK)
157  {
158  heap_free( *server );
159  heap_free( *namespace );
160  }
161  return hr;
162 }
163 
165  IWbemLocator *iface,
166  const BSTR NetworkResource,
167  const BSTR User,
168  const BSTR Password,
169  const BSTR Locale,
170  LONG SecurityFlags,
171  const BSTR Authority,
172  IWbemContext *pCtx,
173  IWbemServices **ppNamespace)
174 {
175  HRESULT hr;
176  WCHAR *server, *namespace;
177 
178  TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface, debugstr_w(NetworkResource), debugstr_w(User),
179  debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), pCtx, ppNamespace);
180 
181  hr = parse_resource( NetworkResource, &server, &namespace );
182  if (hr != S_OK) return hr;
183 
184  if (!is_local_machine( server ))
185  {
186  FIXME("remote computer not supported\n");
187  heap_free( server );
188  heap_free( namespace );
190  }
191  if (User || Password || Authority)
192  FIXME("authentication not supported\n");
193  if (Locale)
194  FIXME("specific locale not supported\n");
195  if (SecurityFlags)
196  FIXME("unsupported flags\n");
197 
198  hr = WbemServices_create( namespace, (void **)ppNamespace );
199  heap_free( namespace );
200  heap_free( server );
201  if (SUCCEEDED( hr ))
202  return WBEM_NO_ERROR;
203 
204  return WBEM_E_FAILED;
205 }
206 
207 static const IWbemLocatorVtbl wbem_locator_vtbl =
208 {
213 };
214 
216 {
217  wbem_locator *wl;
218 
219  TRACE("(%p)\n", ppObj);
220 
221  wl = heap_alloc( sizeof(*wl) );
222  if (!wl) return E_OUTOFMEMORY;
223 
225  wl->refs = 1;
226 
227  *ppObj = &wl->IWbemLocator_iface;
228 
229  TRACE("returning iface %p\n", *ppObj);
230  return S_OK;
231 }
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
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
HRESULT hr
Definition: shlfolder.c:183
REFIID riid
Definition: precomp.h:44
static const WCHAR rootW[]
Definition: chain.c:69
static const WCHAR defaultW[]
Definition: lex.c:47
static BOOL is_local_machine(const WCHAR *server)
Definition: wbemlocator.c:89
GLuint buffer
Definition: glext.h:5915
IWbemLocator IWbemLocator_iface
Definition: wbemlocator.c:37
OLECHAR * BSTR
Definition: compat.h:1934
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:440
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:66
static ULONG WINAPI wbem_locator_AddRef(IWbemLocator *iface)
Definition: wbemlocator.c:46
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:207
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:8
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:913
static HRESULT parse_resource(const WCHAR *resource, WCHAR **server, WCHAR **namespace)
Definition: wbemlocator.c:101
#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:41
#define strcmpiW(s1, s2)
Definition: unicode.h:39
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
#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:53
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
unsigned int ULONG
Definition: retypes.h:1
#define memicmpW(s1, s2, n)
Definition: unicode.h:27
GLfloat GLfloat p
Definition: glext.h:8902
HRESULT WbemLocator_create(LPVOID *ppObj)
Definition: wbemlocator.c:215
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:164
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static BOOL heap_free(void *mem)
Definition: appwiz.h:75