2 * Copyright 2009 Hans Leidekker for CodeWeavers
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.
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.
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
19 #include "wbemprox_private.h"
23 IWbemLocator IWbemLocator_iface
;
27 static inline wbem_locator
*impl_from_IWbemLocator( IWbemLocator
*iface
)
29 return CONTAINING_RECORD(iface
, wbem_locator
, IWbemLocator_iface
);
32 static ULONG WINAPI
wbem_locator_AddRef(
35 wbem_locator
*wl
= impl_from_IWbemLocator( iface
);
36 return InterlockedIncrement( &wl
->refs
);
39 static ULONG WINAPI
wbem_locator_Release(
42 wbem_locator
*wl
= impl_from_IWbemLocator( iface
);
43 LONG refs
= InterlockedDecrement( &wl
->refs
);
46 TRACE("destroying %p\n", wl
);
52 static HRESULT WINAPI
wbem_locator_QueryInterface(
57 wbem_locator
*This
= impl_from_IWbemLocator( iface
);
59 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
61 if ( IsEqualGUID( riid
, &IID_IWbemLocator
) ||
62 IsEqualGUID( riid
, &IID_IUnknown
) )
68 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
71 IWbemLocator_AddRef( iface
);
75 static BOOL
is_local_machine( const WCHAR
*server
)
77 static const WCHAR dotW
[] = {'.',0};
78 WCHAR buffer
[MAX_COMPUTERNAME_LENGTH
+ 1];
79 DWORD len
= sizeof(buffer
) / sizeof(buffer
[0]);
81 if (!server
|| !strcmpW( server
, dotW
)) return TRUE
;
82 if (GetComputerNameW( buffer
, &len
) && !strcmpiW( server
, buffer
)) return TRUE
;
86 static HRESULT
parse_resource( const WCHAR
*resource
, WCHAR
**server
, WCHAR
**namespace )
88 static const WCHAR rootW
[] = {'R','O','O','T'};
89 static const WCHAR cimv2W
[] = {'C','I','M','V','2'};
90 static const WCHAR defaultW
[] = {'D','E','F','A','U','L','T'};
91 HRESULT hr
= WBEM_E_INVALID_NAMESPACE
;
98 if (*p
== '\\' || *p
== '/')
101 if (*p
== '\\' || *p
== '/') p
++;
102 if (!*p
) return WBEM_E_INVALID_NAMESPACE
;
103 if (*p
== '\\' || *p
== '/') return WBEM_E_INVALID_PARAMETER
;
105 while (*q
&& *q
!= '\\' && *q
!= '/') q
++;
106 if (!*q
) return WBEM_E_INVALID_NAMESPACE
;
108 if (!(*server
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
113 memcpy( *server
, p
, len
* sizeof(WCHAR
) );
119 while (*q
&& *q
!= '\\' && *q
!= '/') q
++;
121 if (len
>= sizeof(rootW
) / sizeof(rootW
[0]) && memicmpW( rootW
, p
, len
)) goto done
;
129 if ((len
!= sizeof(cimv2W
) / sizeof(cimv2W
[0]) || memicmpW( q
, cimv2W
, len
)) &&
130 (len
!= sizeof(defaultW
) / sizeof(defaultW
[0]) || memicmpW( q
, defaultW
, len
)))
132 if (!(*namespace = heap_alloc( (len
+ 1) * sizeof(WCHAR
) ))) hr
= E_OUTOFMEMORY
;
135 memcpy( *namespace, p
, len
* sizeof(WCHAR
) );
136 (*namespace)[len
] = 0;
143 heap_free( *server
);
144 heap_free( *namespace );
149 static HRESULT WINAPI
wbem_locator_ConnectServer(
151 const BSTR NetworkResource
,
156 const BSTR Authority
,
158 IWbemServices
**ppNamespace
)
161 WCHAR
*server
, *namespace;
163 TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface
, debugstr_w(NetworkResource
), debugstr_w(User
),
164 debugstr_w(Password
), debugstr_w(Locale
), SecurityFlags
, debugstr_w(Authority
), pCtx
, ppNamespace
);
166 hr
= parse_resource( NetworkResource
, &server
, &namespace );
167 if (hr
!= S_OK
) return hr
;
169 if (!is_local_machine( server
))
171 FIXME("remote computer not supported\n");
173 heap_free( namespace );
174 return WBEM_E_TRANSPORT_FAILURE
;
176 if (User
|| Password
|| Authority
)
177 FIXME("authentication not supported\n");
179 FIXME("specific locale not supported\n");
181 FIXME("unsupported flags\n");
183 hr
= WbemServices_create( namespace, (void **)ppNamespace
);
184 heap_free( namespace );
187 return WBEM_NO_ERROR
;
189 return WBEM_E_FAILED
;
192 static const IWbemLocatorVtbl wbem_locator_vtbl
=
194 wbem_locator_QueryInterface
,
196 wbem_locator_Release
,
197 wbem_locator_ConnectServer
200 HRESULT
WbemLocator_create( LPVOID
*ppObj
)
204 TRACE("(%p)\n", ppObj
);
206 wl
= heap_alloc( sizeof(*wl
) );
207 if (!wl
) return E_OUTOFMEMORY
;
209 wl
->IWbemLocator_iface
.lpVtbl
= &wbem_locator_vtbl
;
212 *ppObj
= &wl
->IWbemLocator_iface
;
214 TRACE("returning iface %p\n", *ppObj
);