ReactOS 0.4.16-dev-336-gb667d82
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
33typedef struct
34{
38
40{
41 return CONTAINING_RECORD(iface, wbem_locator, IWbemLocator_iface);
42}
43
45 IWbemLocator *iface )
46{
48 return InterlockedIncrement( &wl->refs );
49}
50
52 IWbemLocator *iface )
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}
63
65 IWbemLocator *iface,
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
99static 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 {
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}
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
204static 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 void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
const GUID IID_IUnknown
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR rootW[]
Definition: chain.c:69
OLECHAR * BSTR
Definition: compat.h:2293
#define wcsicmp
Definition: compat.h:15
#define lstrlenW
Definition: compat.h:750
HRESULT WbemServices_create(const WCHAR *namespace, LPVOID *ppObj)
Definition: services.c:925
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define resource
Definition: kernel32.h:9
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const WCHAR dotW[]
Definition: directory.c:80
static const WCHAR localhostW[]
Definition: notification.c:35
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_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
#define TRACE(s)
Definition: solgame.cpp:4
IWbemLocator IWbemLocator_iface
Definition: wbemlocator.c:35
@ Password
Definition: telnetd.h:65
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
static const WCHAR defaultW[]
Definition: lex.c:42
static rfbScreenInfoPtr server
Definition: vnc.c:74
@ WBEM_NO_ERROR
Definition: wbemcli.idl:36
@ WBEM_E_TRANSPORT_FAILURE
Definition: wbemcli.idl:71
@ WBEM_E_INVALID_NAMESPACE
Definition: wbemcli.idl:64
@ WBEM_E_INVALID_PARAMETER
Definition: wbemcli.idl:58
@ WBEM_E_FAILED
Definition: wbemcli.idl:51
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 BOOL is_local_machine(const WCHAR *server)
Definition: wbemlocator.c:87
static wbem_locator * impl_from_IWbemLocator(IWbemLocator *iface)
Definition: wbemlocator.c:39
static HRESULT parse_resource(const WCHAR *resource, WCHAR **server, WCHAR **namespace)
Definition: wbemlocator.c:99
static HRESULT WINAPI wbem_locator_QueryInterface(IWbemLocator *iface, REFIID riid, void **ppvObject)
Definition: wbemlocator.c:64
static const IWbemLocatorVtbl wbem_locator_vtbl
Definition: wbemlocator.c:204
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
HRESULT WbemLocator_create(LPVOID *ppObj)
Definition: wbemlocator.c:212
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
__wchar_t WCHAR
Definition: xmlstorage.h:180