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
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31 #include "wbemprox_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
35 struct client_security
37 IClientSecurity IClientSecurity_iface
;
40 static inline struct client_security
*impl_from_IClientSecurity( IClientSecurity
*iface
)
42 return CONTAINING_RECORD( iface
, struct client_security
, IClientSecurity_iface
);
45 static HRESULT WINAPI
client_security_QueryInterface(
46 IClientSecurity
*iface
,
50 struct client_security
*cs
= impl_from_IClientSecurity( iface
);
52 TRACE("%p %s %p\n", cs
, debugstr_guid( riid
), ppvObject
);
54 if ( IsEqualGUID( riid
, &IID_IClientSecurity
) ||
55 IsEqualGUID( riid
, &IID_IUnknown
) )
61 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
64 IClientSecurity_AddRef( iface
);
68 static ULONG WINAPI
client_security_AddRef(
69 IClientSecurity
*iface
)
75 static ULONG WINAPI
client_security_Release(
76 IClientSecurity
*iface
)
82 static HRESULT WINAPI
client_security_QueryBlanket(
83 IClientSecurity
*iface
,
87 OLECHAR
**pServerPrincName
,
91 DWORD
*pCapabilities
)
97 static HRESULT WINAPI
client_security_SetBlanket(
98 IClientSecurity
*iface
,
102 OLECHAR
*pServerPrincName
,
108 static const OLECHAR defaultW
[] =
109 {'<','C','O','L','E','_','D','E','F','A','U','L','T','_','P','R','I','N','C','I','P','A','L','>',0};
110 const OLECHAR
*princname
= (pServerPrincName
== COLE_DEFAULT_PRINCIPAL
) ? defaultW
: pServerPrincName
;
112 FIXME("%p, %p, %u, %u, %s, %u, %u, %p, 0x%08x\n", iface
, pProxy
, AuthnSvc
, AuthzSvc
,
113 debugstr_w(princname
), AuthnLevel
, ImpLevel
, pAuthInfo
, Capabilities
);
114 return WBEM_NO_ERROR
;
117 static HRESULT WINAPI
client_security_CopyProxy(
118 IClientSecurity
*iface
,
123 return WBEM_E_FAILED
;
126 static const IClientSecurityVtbl client_security_vtbl
=
128 client_security_QueryInterface
,
129 client_security_AddRef
,
130 client_security_Release
,
131 client_security_QueryBlanket
,
132 client_security_SetBlanket
,
133 client_security_CopyProxy
136 IClientSecurity client_security
= { &client_security_vtbl
};
140 IWbemServices IWbemServices_iface
;
145 static inline struct wbem_services
*impl_from_IWbemServices( IWbemServices
*iface
)
147 return CONTAINING_RECORD( iface
, struct wbem_services
, IWbemServices_iface
);
150 static ULONG WINAPI
wbem_services_AddRef(
151 IWbemServices
*iface
)
153 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
154 return InterlockedIncrement( &ws
->refs
);
157 static ULONG WINAPI
wbem_services_Release(
158 IWbemServices
*iface
)
160 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
161 LONG refs
= InterlockedDecrement( &ws
->refs
);
164 TRACE("destroying %p\n", ws
);
165 heap_free( ws
->namespace );
171 static HRESULT WINAPI
wbem_services_QueryInterface(
172 IWbemServices
*iface
,
176 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
178 TRACE("%p %s %p\n", ws
, debugstr_guid( riid
), ppvObject
);
180 if ( IsEqualGUID( riid
, &IID_IWbemServices
) ||
181 IsEqualGUID( riid
, &IID_IUnknown
) )
185 else if ( IsEqualGUID( riid
, &IID_IClientSecurity
) )
187 *ppvObject
= &client_security
;
192 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
193 return E_NOINTERFACE
;
195 IWbemServices_AddRef( iface
);
199 static HRESULT WINAPI
wbem_services_OpenNamespace(
200 IWbemServices
*iface
,
201 const BSTR strNamespace
,
204 IWbemServices
**ppWorkingNamespace
,
205 IWbemCallResult
**ppResult
)
207 static const WCHAR cimv2W
[] = {'c','i','m','v','2',0};
208 static const WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0};
209 struct wbem_services
*ws
= impl_from_IWbemServices( iface
);
211 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface
, debugstr_w(strNamespace
), lFlags
,
212 pCtx
, ppWorkingNamespace
, ppResult
);
214 if ((strcmpiW( strNamespace
, cimv2W
) && strcmpiW( strNamespace
, defaultW
)) || ws
->namespace)
215 return WBEM_E_INVALID_NAMESPACE
;
217 return WbemServices_create( NULL
, cimv2W
, (void **)ppWorkingNamespace
);
220 static HRESULT WINAPI
wbem_services_CancelAsyncCall(
221 IWbemServices
*iface
,
222 IWbemObjectSink
*pSink
)
225 return WBEM_E_FAILED
;
228 static HRESULT WINAPI
wbem_services_QueryObjectSink(
229 IWbemServices
*iface
,
231 IWbemObjectSink
**ppResponseHandler
)
234 return WBEM_E_FAILED
;
245 static HRESULT
parse_path( const WCHAR
*str
, struct path
**ret
)
248 const WCHAR
*p
= str
, *q
;
251 if (!(path
= heap_alloc_zero( sizeof(*path
) ))) return E_OUTOFMEMORY
;
253 while (*p
&& *p
!= '.') p
++;
256 if (!(path
->class = heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
259 return E_OUTOFMEMORY
;
261 memcpy( path
->class, str
, len
* sizeof(WCHAR
) );
262 path
->class[len
] = 0;
263 path
->class_len
= len
;
265 if (p
[0] == '.' && p
[1])
271 if (!(path
->filter
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
273 heap_free( path
->class );
275 return E_OUTOFMEMORY
;
277 memcpy( path
->filter
, p
, len
* sizeof(WCHAR
) );
278 path
->filter
[len
] = 0;
279 path
->filter_len
= len
;
285 static void free_path( struct path
*path
)
287 heap_free( path
->class );
288 heap_free( path
->filter
);
292 static HRESULT
create_instance_enum( const struct path
*path
, IEnumWbemClassObject
**iter
)
294 static const WCHAR selectW
[] =
295 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','%','s',' ',
296 'W','H','E','R','E',' ','%','s',0};
297 static const WCHAR select_allW
[] =
298 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',0};
305 len
= path
->class_len
+ path
->filter_len
+ SIZEOF(selectW
);
306 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
307 sprintfW( query
, selectW
, path
->class, path
->filter
);
311 len
= path
->class_len
+ SIZEOF(select_allW
);
312 if (!(query
= heap_alloc( len
* sizeof(WCHAR
) ))) return E_OUTOFMEMORY
;
313 strcpyW( query
, select_allW
);
314 strcatW( query
, path
->class );
316 hr
= exec_query( query
, iter
);
321 HRESULT
get_object( const WCHAR
*object_path
, IWbemClassObject
**obj
)
323 IEnumWbemClassObject
*iter
;
327 hr
= parse_path( object_path
, &path
);
328 if (hr
!= S_OK
) return hr
;
330 hr
= create_instance_enum( path
, &iter
);
336 hr
= create_class_object( path
->class, iter
, 0, NULL
, obj
);
337 IEnumWbemClassObject_Release( iter
);
342 static HRESULT WINAPI
wbem_services_GetObject(
343 IWbemServices
*iface
,
344 const BSTR strObjectPath
,
347 IWbemClassObject
**ppObject
,
348 IWbemCallResult
**ppCallResult
)
350 TRACE("%p, %s, 0x%08x, %p, %p, %p\n", iface
, debugstr_w(strObjectPath
), lFlags
,
351 pCtx
, ppObject
, ppCallResult
);
353 if (lFlags
) FIXME("unsupported flags 0x%08x\n", lFlags
);
357 FIXME("no support for creating new classes\n");
358 return WBEM_E_FAILED
;
360 return get_object( strObjectPath
, ppObject
);
363 static HRESULT WINAPI
wbem_services_GetObjectAsync(
364 IWbemServices
*iface
,
365 const BSTR strObjectPath
,
368 IWbemObjectSink
*pResponseHandler
)
371 return WBEM_E_FAILED
;
374 static HRESULT WINAPI
wbem_services_PutClass(
375 IWbemServices
*iface
,
376 IWbemClassObject
*pObject
,
379 IWbemCallResult
**ppCallResult
)
382 return WBEM_E_FAILED
;
385 static HRESULT WINAPI
wbem_services_PutClassAsync(
386 IWbemServices
*iface
,
387 IWbemClassObject
*pObject
,
390 IWbemObjectSink
*pResponseHandler
)
393 return WBEM_E_FAILED
;
396 static HRESULT WINAPI
wbem_services_DeleteClass(
397 IWbemServices
*iface
,
401 IWbemCallResult
**ppCallResult
)
404 return WBEM_E_FAILED
;
407 static HRESULT WINAPI
wbem_services_DeleteClassAsync(
408 IWbemServices
*iface
,
412 IWbemObjectSink
*pResponseHandler
)
415 return WBEM_E_FAILED
;
418 static HRESULT WINAPI
wbem_services_CreateClassEnum(
419 IWbemServices
*iface
,
420 const BSTR strSuperclass
,
423 IEnumWbemClassObject
**ppEnum
)
426 return WBEM_E_FAILED
;
429 static HRESULT WINAPI
wbem_services_CreateClassEnumAsync(
430 IWbemServices
*iface
,
431 const BSTR strSuperclass
,
434 IWbemObjectSink
*pResponseHandler
)
437 return WBEM_E_FAILED
;
440 static HRESULT WINAPI
wbem_services_PutInstance(
441 IWbemServices
*iface
,
442 IWbemClassObject
*pInst
,
445 IWbemCallResult
**ppCallResult
)
448 return WBEM_E_FAILED
;
451 static HRESULT WINAPI
wbem_services_PutInstanceAsync(
452 IWbemServices
*iface
,
453 IWbemClassObject
*pInst
,
456 IWbemObjectSink
*pResponseHandler
)
459 return WBEM_E_FAILED
;
462 static HRESULT WINAPI
wbem_services_DeleteInstance(
463 IWbemServices
*iface
,
464 const BSTR strObjectPath
,
467 IWbemCallResult
**ppCallResult
)
470 return WBEM_E_FAILED
;
473 static HRESULT WINAPI
wbem_services_DeleteInstanceAsync(
474 IWbemServices
*iface
,
475 const BSTR strObjectPath
,
478 IWbemObjectSink
*pResponseHandler
)
481 return WBEM_E_FAILED
;
484 static HRESULT WINAPI
wbem_services_CreateInstanceEnum(
485 IWbemServices
*iface
,
489 IEnumWbemClassObject
**ppEnum
)
494 TRACE("%p, %s, 0%08x, %p, %p\n", iface
, debugstr_w(strClass
), lFlags
, pCtx
, ppEnum
);
496 if (lFlags
) FIXME("unsupported flags 0x%08x\n", lFlags
);
498 hr
= parse_path( strClass
, &path
);
499 if (hr
!= S_OK
) return hr
;
501 hr
= create_instance_enum( path
, ppEnum
);
506 static HRESULT WINAPI
wbem_services_CreateInstanceEnumAsync(
507 IWbemServices
*iface
,
508 const BSTR strFilter
,
511 IWbemObjectSink
*pResponseHandler
)
514 return WBEM_E_FAILED
;
517 static HRESULT WINAPI
wbem_services_ExecQuery(
518 IWbemServices
*iface
,
519 const BSTR strQueryLanguage
,
523 IEnumWbemClassObject
**ppEnum
)
525 static const WCHAR wqlW
[] = {'W','Q','L',0};
527 TRACE("%p, %s, %s, 0x%08x, %p, %p\n", iface
, debugstr_w(strQueryLanguage
),
528 debugstr_w(strQuery
), lFlags
, pCtx
, ppEnum
);
530 if (!strQueryLanguage
|| !strQuery
) return WBEM_E_INVALID_PARAMETER
;
531 if (strcmpiW( strQueryLanguage
, wqlW
)) return WBEM_E_INVALID_QUERY_TYPE
;
532 return exec_query( strQuery
, ppEnum
);
535 static HRESULT WINAPI
wbem_services_ExecQueryAsync(
536 IWbemServices
*iface
,
537 const BSTR strQueryLanguage
,
541 IWbemObjectSink
*pResponseHandler
)
544 return WBEM_E_FAILED
;
547 static HRESULT WINAPI
wbem_services_ExecNotificationQuery(
548 IWbemServices
*iface
,
549 const BSTR strQueryLanguage
,
553 IEnumWbemClassObject
**ppEnum
)
556 return WBEM_E_FAILED
;
559 static HRESULT WINAPI
wbem_services_ExecNotificationQueryAsync(
560 IWbemServices
*iface
,
561 const BSTR strQueryLanguage
,
565 IWbemObjectSink
*pResponseHandler
)
568 return WBEM_E_FAILED
;
571 static HRESULT WINAPI
wbem_services_ExecMethod(
572 IWbemServices
*iface
,
573 const BSTR strObjectPath
,
574 const BSTR strMethodName
,
577 IWbemClassObject
*pInParams
,
578 IWbemClassObject
**ppOutParams
,
579 IWbemCallResult
**ppCallResult
)
581 IWbemClassObject
*obj
;
587 TRACE("%p, %s, %s, %08x, %p, %p, %p, %p\n", iface
, debugstr_w(strObjectPath
),
588 debugstr_w(strMethodName
), lFlags
, pCtx
, pInParams
, ppOutParams
, ppCallResult
);
590 if (lFlags
) FIXME("flags %08x not supported\n", lFlags
);
592 if ((hr
= get_object( strObjectPath
, &obj
))) return hr
;
593 if ((hr
= parse_path( strObjectPath
, &path
)) != S_OK
)
595 IWbemClassObject_Release( obj
);
598 table
= grab_table( path
->class );
602 IWbemClassObject_Release( obj
);
603 return WBEM_E_NOT_FOUND
;
605 hr
= get_method( table
, strMethodName
, &func
);
606 release_table( table
);
609 IWbemClassObject_Release( obj
);
612 hr
= func( obj
, pInParams
, ppOutParams
);
613 IWbemClassObject_Release( obj
);
617 static HRESULT WINAPI
wbem_services_ExecMethodAsync(
618 IWbemServices
*iface
,
619 const BSTR strObjectPath
,
620 const BSTR strMethodName
,
623 IWbemClassObject
*pInParams
,
624 IWbemObjectSink
*pResponseHandler
)
627 return WBEM_E_FAILED
;
630 static const IWbemServicesVtbl wbem_services_vtbl
=
632 wbem_services_QueryInterface
,
633 wbem_services_AddRef
,
634 wbem_services_Release
,
635 wbem_services_OpenNamespace
,
636 wbem_services_CancelAsyncCall
,
637 wbem_services_QueryObjectSink
,
638 wbem_services_GetObject
,
639 wbem_services_GetObjectAsync
,
640 wbem_services_PutClass
,
641 wbem_services_PutClassAsync
,
642 wbem_services_DeleteClass
,
643 wbem_services_DeleteClassAsync
,
644 wbem_services_CreateClassEnum
,
645 wbem_services_CreateClassEnumAsync
,
646 wbem_services_PutInstance
,
647 wbem_services_PutInstanceAsync
,
648 wbem_services_DeleteInstance
,
649 wbem_services_DeleteInstanceAsync
,
650 wbem_services_CreateInstanceEnum
,
651 wbem_services_CreateInstanceEnumAsync
,
652 wbem_services_ExecQuery
,
653 wbem_services_ExecQueryAsync
,
654 wbem_services_ExecNotificationQuery
,
655 wbem_services_ExecNotificationQueryAsync
,
656 wbem_services_ExecMethod
,
657 wbem_services_ExecMethodAsync
660 HRESULT
WbemServices_create( IUnknown
*pUnkOuter
, const WCHAR
*namespace, LPVOID
*ppObj
)
662 struct wbem_services
*ws
;
664 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
666 ws
= heap_alloc( sizeof(*ws
) );
667 if (!ws
) return E_OUTOFMEMORY
;
669 ws
->IWbemServices_iface
.lpVtbl
= &wbem_services_vtbl
;
671 ws
->namespace = heap_strdupW( namespace );
673 *ppObj
= &ws
->IWbemServices_iface
;
675 TRACE("returning iface %p\n", *ppObj
);