2 * Copyright 2012 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
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32 #include "wbemprox_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
36 struct client_security
38 IClientSecurity IClientSecurity_iface
;
41 static inline struct client_security
*impl_from_IClientSecurity( IClientSecurity
*iface
)
43 return CONTAINING_RECORD( iface
, struct client_security
, IClientSecurity_iface
);
46 static HRESULT WINAPI
client_security_QueryInterface(
47 IClientSecurity
*iface
,
51 struct client_security
*cs
= impl_from_IClientSecurity( iface
);
53 TRACE("%p %s %p\n", cs
, debugstr_guid( riid
), ppvObject
);
55 if ( IsEqualGUID( riid
, &IID_IClientSecurity
) ||
56 IsEqualGUID( riid
, &IID_IUnknown
) )
62 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
65 IClientSecurity_AddRef( iface
);
69 static ULONG WINAPI
client_security_AddRef(
70 IClientSecurity
*iface
)
76 static ULONG WINAPI
client_security_Release(
77 IClientSecurity
*iface
)
83 static HRESULT WINAPI
client_security_QueryBlanket(
84 IClientSecurity
*iface
,
88 OLECHAR
**pServerPrincName
,
92 DWORD
*pCapabilities
)
98 static HRESULT WINAPI
client_security_SetBlanket(
99 IClientSecurity
*iface
,
103 OLECHAR
*pServerPrincName
,
109 static const OLECHAR defaultW
[] =
110 {'<','C','O','L','E','_','D','E','F','A','U','L','T','_','P','R','I','N','C','I','P','A','L','>',0};
111 const OLECHAR
*princname
= (pServerPrincName
== COLE_DEFAULT_PRINCIPAL
) ? defaultW
: pServerPrincName
;
113 FIXME("%p, %p, %u, %u, %s, %u, %u, %p, 0x%08x\n", iface
, pProxy
, AuthnSvc
, AuthzSvc
,
114 debugstr_w(princname
), AuthnLevel
, ImpLevel
, pAuthInfo
, Capabilities
);
115 return WBEM_NO_ERROR
;
118 static HRESULT WINAPI
client_security_CopyProxy(
119 IClientSecurity
*iface
,
124 return WBEM_E_FAILED
;
127 static const IClientSecurityVtbl client_security_vtbl
=
129 client_security_QueryInterface
,
130 client_security_AddRef
,
131 client_security_Release
,
132 client_security_QueryBlanket
,
133 client_security_SetBlanket
,
134 client_security_CopyProxy
137 IClientSecurity client_security
= { &client_security_vtbl
};
141 IWbemServices IWbemServices_iface
;
146 static inline struct wbem_services
*impl_from_IWbemServices( IWbemServices
*iface
)
148 return CONTAINING_RECORD( iface
, struct wbem_services
, IWbemServices_iface
);
151 static ULONG WINAPI
wbem_services_AddRef(
152 IWbemServices
*iface
)
154 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
155 return InterlockedIncrement( &ws
->refs
);
158 static ULONG WINAPI
wbem_services_Release(
159 IWbemServices
*iface
)
161 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
162 LONG refs
= InterlockedDecrement( &ws
->refs
);
165 TRACE("destroying %p\n", ws
);
166 heap_free( ws
->namespace );
172 static HRESULT WINAPI
wbem_services_QueryInterface(
173 IWbemServices
*iface
,
177 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
179 TRACE("%p %s %p\n", ws
, debugstr_guid( riid
), ppvObject
);
181 if ( IsEqualGUID( riid
, &IID_IWbemServices
) ||
182 IsEqualGUID( riid
, &IID_IUnknown
) )
186 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
188 *ppvObject
= &client_security
;
193 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
194 return E_NOINTERFACE
;
196 IWbemServices_AddRef( iface
);
200 static HRESULT WINAPI
wbem_services_OpenNamespace(
201 IWbemServices
*iface
,
202 const BSTR strNamespace
,
205 IWbemServices
**ppWorkingNamespace
,
206 IWbemCallResult
**ppResult
)
208 static const WCHAR cimv2W
[] = {'c','i','m','v','2',0};
209 static const WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0};
210 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
212 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface
, debugstr_w(strNamespace
), lFlags
,
213 pCtx
, ppWorkingNamespace
, ppResult
);
215 if ((strcmpiW( strNamespace
, cimv2W
) && strcmpiW( strNamespace
, defaultW
)) || ws
->namespace)
216 return WBEM_E_INVALID_NAMESPACE
;
218 return WbemServices_create( NULL
, cimv2W
, (void **)ppWorkingNamespace
);
221 static HRESULT WINAPI
wbem_services_CancelAsyncCall(
222 IWbemServices
*iface
,
223 IWbemObjectSink
*pSink
)
226 return WBEM_E_FAILED
;
229 static HRESULT WINAPI
wbem_services_QueryObjectSink(
230 IWbemServices
*iface
,
232 IWbemObjectSink
**ppResponseHandler
)
235 return WBEM_E_FAILED
;
246 static HRESULT
parse_path( const WCHAR
*str
, struct path
**ret
)
249 const WCHAR
*p
= str
, *q
;
252 if (!(path
= heap_alloc_zero( sizeof(*path
) ))) return E_OUTOFMEMORY
;
254 while (*p
&& *p
!= '.') p
++;
257 if (!(path
->class = heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
260 return E_OUTOFMEMORY
;
262 memcpy( path
->class, str
, len
* sizeof(WCHAR
) );
263 path
->class[len
] = 0;
264 path
->class_len
= len
;
266 if (p
[0] == '.' && p
[1])
272 if (!(path
->filter
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
274 heap_free( path
->class );
276 return E_OUTOFMEMORY
;
278 memcpy( path
->filter
, p
, len
* sizeof(WCHAR
) );
279 path
->filter
[len
] = 0;
280 path
->filter_len
= len
;
286 static void free_path( struct path
*path
)
288 heap_free( path
->class );
289 heap_free( path
->filter
);
293 static HRESULT
create_instance_enum( const struct path
*path
, IEnumWbemClassObject
**iter
)
295 static const WCHAR selectW
[] =
296 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','%','s',' ',
297 'W','H','E','R','E',' ','%','s',0};
298 static const WCHAR select_allW
[] =
299 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0};
306 len
= path
->class_len
+ path
->filter_len
+ SIZEOF(selectW
);
307 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
308 sprintfW( query
, selectW
, path
->class, path
->filter
);
312 len
= path
->class_len
+ SIZEOF(select_allW
);
313 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
314 strcpyW( query
, select_allW
);
315 strcatW( query
, path
->class );
317 hr
= exec_query( query
, iter
);
322 HRESULT
get_object( const WCHAR
*object_path
, IWbemClassObject
**obj
)
324 IEnumWbemClassObject
*iter
;
328 hr
= parse_path( object_path
, &path
);
329 if (hr
!= S_OK
) return hr
;
331 hr
= create_instance_enum( path
, &iter
);
337 hr
= create_class_object( path
->class, iter
, 0, obj
);
338 IEnumWbemClassObject_Release( iter
);
343 static HRESULT WINAPI
wbem_services_GetObject(
344 IWbemServices
*iface
,
345 const BSTR strObjectPath
,
348 IWbemClassObject
**ppObject
,
349 IWbemCallResult
**ppCallResult
)
351 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface
, debugstr_w(strObjectPath
), lFlags
,
352 pCtx
, ppObject
, ppCallResult
);
354 if (lFlags
) FIXME("unsupported flags 0x%08x\n", lFlags
);
358 FIXME("no support for creating new classes\n");
359 return WBEM_E_FAILED
;
361 return get_object( strObjectPath
, ppObject
);
364 static HRESULT WINAPI
wbem_services_GetObjectAsync(
365 IWbemServices
*iface
,
366 const BSTR strObjectPath
,
369 IWbemObjectSink
*pResponseHandler
)
372 return WBEM_E_FAILED
;
375 static HRESULT WINAPI
wbem_services_PutClass(
376 IWbemServices
*iface
,
377 IWbemClassObject
*pObject
,
380 IWbemCallResult
**ppCallResult
)
383 return WBEM_E_FAILED
;
386 static HRESULT WINAPI
wbem_services_PutClassAsync(
387 IWbemServices
*iface
,
388 IWbemClassObject
*pObject
,
391 IWbemObjectSink
*pResponseHandler
)
394 return WBEM_E_FAILED
;
397 static HRESULT WINAPI
wbem_services_DeleteClass(
398 IWbemServices
*iface
,
402 IWbemCallResult
**ppCallResult
)
405 return WBEM_E_FAILED
;
408 static HRESULT WINAPI
wbem_services_DeleteClassAsync(
409 IWbemServices
*iface
,
413 IWbemObjectSink
*pResponseHandler
)
416 return WBEM_E_FAILED
;
419 static HRESULT WINAPI
wbem_services_CreateClassEnum(
420 IWbemServices
*iface
,
421 const BSTR strSuperclass
,
424 IEnumWbemClassObject
**ppEnum
)
427 return WBEM_E_FAILED
;
430 static HRESULT WINAPI
wbem_services_CreateClassEnumAsync(
431 IWbemServices
*iface
,
432 const BSTR strSuperclass
,
435 IWbemObjectSink
*pResponseHandler
)
438 return WBEM_E_FAILED
;
441 static HRESULT WINAPI
wbem_services_PutInstance(
442 IWbemServices
*iface
,
443 IWbemClassObject
*pInst
,
446 IWbemCallResult
**ppCallResult
)
449 return WBEM_E_FAILED
;
452 static HRESULT WINAPI
wbem_services_PutInstanceAsync(
453 IWbemServices
*iface
,
454 IWbemClassObject
*pInst
,
457 IWbemObjectSink
*pResponseHandler
)
460 return WBEM_E_FAILED
;
463 static HRESULT WINAPI
wbem_services_DeleteInstance(
464 IWbemServices
*iface
,
465 const BSTR strObjectPath
,
468 IWbemCallResult
**ppCallResult
)
471 return WBEM_E_FAILED
;
474 static HRESULT WINAPI
wbem_services_DeleteInstanceAsync(
475 IWbemServices
*iface
,
476 const BSTR strObjectPath
,
479 IWbemObjectSink
*pResponseHandler
)
482 return WBEM_E_FAILED
;
485 static HRESULT WINAPI
wbem_services_CreateInstanceEnum(
486 IWbemServices
*iface
,
490 IEnumWbemClassObject
**ppEnum
)
495 TRACE("%p, %s, 0%08x, %p, %p\n", iface
, debugstr_w(strClass
), lFlags
, pCtx
, ppEnum
);
497 if (lFlags
) FIXME("unsupported flags 0x%08x\n", lFlags
);
499 hr
= parse_path( strClass
, &path
);
500 if (hr
!= S_OK
) return hr
;
502 hr
= create_instance_enum( path
, ppEnum
);
507 static HRESULT WINAPI
wbem_services_CreateInstanceEnumAsync(
508 IWbemServices
*iface
,
509 const BSTR strFilter
,
512 IWbemObjectSink
*pResponseHandler
)
515 return WBEM_E_FAILED
;
518 static HRESULT WINAPI
wbem_services_ExecQuery(
519 IWbemServices
*iface
,
520 const BSTR strQueryLanguage
,
524 IEnumWbemClassObject
**ppEnum
)
526 static const WCHAR wqlW
[] = {'W','Q','L',0};
528 TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface
, debugstr_w(strQueryLanguage
),
529 debugstr_w(strQuery
), lFlags
, pCtx
, ppEnum
);
531 if (!strQueryLanguage
|| !strQuery
) return WBEM_E_INVALID_PARAMETER
;
532 if (strcmpiW( strQueryLanguage
, wqlW
)) return WBEM_E_INVALID_QUERY_TYPE
;
533 return exec_query( strQuery
, ppEnum
);
536 static HRESULT WINAPI
wbem_services_ExecQueryAsync(
537 IWbemServices
*iface
,
538 const BSTR strQueryLanguage
,
542 IWbemObjectSink
*pResponseHandler
)
545 return WBEM_E_FAILED
;
548 static HRESULT WINAPI
wbem_services_ExecNotificationQuery(
549 IWbemServices
*iface
,
550 const BSTR strQueryLanguage
,
554 IEnumWbemClassObject
**ppEnum
)
557 return WBEM_E_FAILED
;
560 static HRESULT WINAPI
wbem_services_ExecNotificationQueryAsync(
561 IWbemServices
*iface
,
562 const BSTR strQueryLanguage
,
566 IWbemObjectSink
*pResponseHandler
)
569 return WBEM_E_FAILED
;
572 static HRESULT WINAPI
wbem_services_ExecMethod(
573 IWbemServices
*iface
,
574 const BSTR strObjectPath
,
575 const BSTR strMethodName
,
578 IWbemClassObject
*pInParams
,
579 IWbemClassObject
**ppOutParams
,
580 IWbemCallResult
**ppCallResult
)
583 return WBEM_E_FAILED
;
586 static HRESULT WINAPI
wbem_services_ExecMethodAsync(
587 IWbemServices
*iface
,
588 const BSTR strObjectPath
,
589 const BSTR strMethodName
,
592 IWbemClassObject
*pInParams
,
593 IWbemObjectSink
*pResponseHandler
)
596 return WBEM_E_FAILED
;
599 static const IWbemServicesVtbl wbem_services_vtbl
=
601 wbem_services_QueryInterface
,
602 wbem_services_AddRef
,
603 wbem_services_Release
,
604 wbem_services_OpenNamespace
,
605 wbem_services_CancelAsyncCall
,
606 wbem_services_QueryObjectSink
,
607 wbem_services_GetObject
,
608 wbem_services_GetObjectAsync
,
609 wbem_services_PutClass
,
610 wbem_services_PutClassAsync
,
611 wbem_services_DeleteClass
,
612 wbem_services_DeleteClassAsync
,
613 wbem_services_CreateClassEnum
,
614 wbem_services_CreateClassEnumAsync
,
615 wbem_services_PutInstance
,
616 wbem_services_PutInstanceAsync
,
617 wbem_services_DeleteInstance
,
618 wbem_services_DeleteInstanceAsync
,
619 wbem_services_CreateInstanceEnum
,
620 wbem_services_CreateInstanceEnumAsync
,
621 wbem_services_ExecQuery
,
622 wbem_services_ExecQueryAsync
,
623 wbem_services_ExecNotificationQuery
,
624 wbem_services_ExecNotificationQueryAsync
,
625 wbem_services_ExecMethod
,
626 wbem_services_ExecMethodAsync
629 HRESULT
WbemServices_create( IUnknown
*pUnkOuter
, const WCHAR
*namespace, LPVOID
*ppObj
)
631 struct wbem_services
*ws
;
633 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
635 ws
= heap_alloc( sizeof(*ws
) );
636 if (!ws
) return E_OUTOFMEMORY
;
638 ws
->IWbemServices_iface
.lpVtbl
= &wbem_services_vtbl
;
640 ws
->namespace = heap_strdupW( namespace );
642 *ppObj
= &ws
->IWbemServices_iface
;
644 TRACE("returning iface %p\n", *ppObj
);