wbemprox: Support IClientSecurity on the class enumerator object;.
[wine] / dlls / wbemprox / class.c
1 /*
2  * Copyright 2012 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 "wbemprox_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
33
34 struct enum_class_object
35 {
36     IEnumWbemClassObject IEnumWbemClassObject_iface;
37     LONG refs;
38     struct query *query;
39     UINT index;
40 };
41
42 static inline struct enum_class_object *impl_from_IEnumWbemClassObject(
43     IEnumWbemClassObject *iface )
44 {
45     return CONTAINING_RECORD(iface, struct enum_class_object, IEnumWbemClassObject_iface);
46 }
47
48 static ULONG WINAPI enum_class_object_AddRef(
49     IEnumWbemClassObject *iface )
50 {
51     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
52     return InterlockedIncrement( &ec->refs );
53 }
54
55 static ULONG WINAPI enum_class_object_Release(
56     IEnumWbemClassObject *iface )
57 {
58     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
59     LONG refs = InterlockedDecrement( &ec->refs );
60     if (!refs)
61     {
62         TRACE("destroying %p\n", ec);
63         free_query( ec->query );
64         heap_free( ec );
65     }
66     return refs;
67 }
68
69 static HRESULT WINAPI enum_class_object_QueryInterface(
70     IEnumWbemClassObject *iface,
71     REFIID riid,
72     void **ppvObject )
73 {
74     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
75
76     TRACE("%p, %s, %p\n", ec, debugstr_guid( riid ), ppvObject );
77
78     if ( IsEqualGUID( riid, &IID_IEnumWbemClassObject ) ||
79          IsEqualGUID( riid, &IID_IUnknown ) )
80     {
81         *ppvObject = ec;
82     }
83     else if ( IsEqualGUID( riid, &IID_IClientSecurity ) )
84     {
85         *ppvObject = &client_security;
86         return S_OK;
87     }
88     else
89     {
90         FIXME("interface %s not implemented\n", debugstr_guid(riid));
91         return E_NOINTERFACE;
92     }
93     IEnumWbemClassObject_AddRef( iface );
94     return S_OK;
95 }
96
97 static HRESULT WINAPI enum_class_object_Reset(
98     IEnumWbemClassObject *iface )
99 {
100     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
101
102     TRACE("%p\n", iface);
103
104     ec->index = 0;
105     return WBEM_S_NO_ERROR;
106 }
107
108 static HRESULT WINAPI enum_class_object_Next(
109     IEnumWbemClassObject *iface,
110     LONG lTimeout,
111     ULONG uCount,
112     IWbemClassObject **apObjects,
113     ULONG *puReturned )
114 {
115     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
116     struct view *view = ec->query->view;
117     HRESULT hr;
118
119     TRACE("%p, %d, %u, %p, %p\n", iface, lTimeout, uCount, apObjects, puReturned);
120
121     if (!uCount) return WBEM_S_FALSE;
122     if (!apObjects || !puReturned) return WBEM_E_INVALID_PARAMETER;
123     if (lTimeout != WBEM_INFINITE) FIXME("timeout not supported\n");
124
125     *puReturned = 0;
126     if (ec->index + uCount > view->count) return WBEM_S_FALSE;
127
128     hr = WbemClassObject_create( NULL, iface, ec->index, (void **)apObjects );
129     if (hr != S_OK) return hr;
130
131     ec->index++;
132     *puReturned = 1;
133     if (ec->index == view->count) return WBEM_S_FALSE;
134     if (uCount > 1) return WBEM_S_TIMEDOUT;
135     return WBEM_S_NO_ERROR;
136 }
137
138 static HRESULT WINAPI enum_class_object_NextAsync(
139     IEnumWbemClassObject *iface,
140     ULONG uCount,
141     IWbemObjectSink *pSink )
142 {
143     FIXME("%p, %u, %p\n", iface, uCount, pSink);
144     return E_NOTIMPL;
145 }
146
147 static HRESULT WINAPI enum_class_object_Clone(
148     IEnumWbemClassObject *iface,
149     IEnumWbemClassObject **ppEnum )
150 {
151     FIXME("%p, %p\n", iface, ppEnum);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI enum_class_object_Skip(
156     IEnumWbemClassObject *iface,
157     LONG lTimeout,
158     ULONG nCount )
159 {
160     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( iface );
161     struct view *view = ec->query->view;
162
163     TRACE("%p, %d, %u\n", iface, lTimeout, nCount);
164
165     if (lTimeout != WBEM_INFINITE) FIXME("timeout not supported\n");
166
167     if (ec->index + nCount >= view->count)
168     {
169         ec->index = view->count - 1;
170         return WBEM_S_FALSE;
171     }
172     ec->index += nCount;
173     return WBEM_S_NO_ERROR;
174 }
175
176 static const IEnumWbemClassObjectVtbl enum_class_object_vtbl =
177 {
178     enum_class_object_QueryInterface,
179     enum_class_object_AddRef,
180     enum_class_object_Release,
181     enum_class_object_Reset,
182     enum_class_object_Next,
183     enum_class_object_NextAsync,
184     enum_class_object_Clone,
185     enum_class_object_Skip
186 };
187
188 HRESULT EnumWbemClassObject_create(
189     IUnknown *pUnkOuter, struct query *query, LPVOID *ppObj )
190 {
191     struct enum_class_object *ec;
192
193     TRACE("%p, %p\n", pUnkOuter, ppObj);
194
195     ec = heap_alloc( sizeof(*ec) );
196     if (!ec) return E_OUTOFMEMORY;
197
198     ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl;
199     ec->refs  = 1;
200     ec->query = query;
201     ec->index = 0;
202
203     *ppObj = &ec->IEnumWbemClassObject_iface;
204
205     TRACE("returning iface %p\n", *ppObj);
206     return S_OK;
207 }
208
209 struct class_object
210 {
211     IWbemClassObject IWbemClassObject_iface;
212     LONG refs;
213     IEnumWbemClassObject *iter;
214     UINT index;
215 };
216
217 static inline struct class_object *impl_from_IWbemClassObject(
218     IWbemClassObject *iface )
219 {
220     return CONTAINING_RECORD(iface, struct class_object, IWbemClassObject_iface);
221 }
222
223 static ULONG WINAPI class_object_AddRef(
224     IWbemClassObject *iface )
225 {
226     struct class_object *co = impl_from_IWbemClassObject( iface );
227     return InterlockedIncrement( &co->refs );
228 }
229
230 static ULONG WINAPI class_object_Release(
231     IWbemClassObject *iface )
232 {
233     struct class_object *co = impl_from_IWbemClassObject( iface );
234     LONG refs = InterlockedDecrement( &co->refs );
235     if (!refs)
236     {
237         TRACE("destroying %p\n", co);
238         if (co->iter) IEnumWbemClassObject_Release( co->iter );
239         heap_free( co );
240     }
241     return refs;
242 }
243
244 static HRESULT WINAPI class_object_QueryInterface(
245     IWbemClassObject *iface,
246     REFIID riid,
247     void **ppvObject )
248 {
249     struct class_object *co = impl_from_IWbemClassObject( iface );
250
251     TRACE("%p, %s, %p\n", co, debugstr_guid( riid ), ppvObject );
252
253     if ( IsEqualGUID( riid, &IID_IWbemClassObject ) ||
254          IsEqualGUID( riid, &IID_IUnknown ) )
255     {
256         *ppvObject = co;
257     }
258     else
259     {
260         FIXME("interface %s not implemented\n", debugstr_guid(riid));
261         return E_NOINTERFACE;
262     }
263     IWbemClassObject_AddRef( iface );
264     return S_OK;
265 }
266
267 static HRESULT WINAPI class_object_GetQualifierSet(
268     IWbemClassObject *iface,
269     IWbemQualifierSet **ppQualSet )
270 {
271     FIXME("%p, %p\n", iface, ppQualSet);
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI class_object_Get(
276     IWbemClassObject *iface,
277     LPCWSTR wszName,
278     LONG lFlags,
279     VARIANT *pVal,
280     CIMTYPE *pType,
281     LONG *plFlavor )
282 {
283     struct class_object *co = impl_from_IWbemClassObject( iface );
284     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
285     struct view *view = ec->query->view;
286
287     TRACE("%p, %s, %08x, %p, %p, %p\n", iface, debugstr_w(wszName), lFlags, pVal, pType, plFlavor);
288
289     if (plFlavor)
290     {
291         FIXME("flavor parameter not supported\n");
292         *plFlavor = 0;
293     }
294     return get_propval( view, co->index, wszName, pVal, pType );
295 }
296
297 static HRESULT WINAPI class_object_Put(
298     IWbemClassObject *iface,
299     LPCWSTR wszName,
300     LONG lFlags,
301     VARIANT *pVal,
302     CIMTYPE Type )
303 {
304     FIXME("%p, %s, %08x, %p, %u\n", iface, debugstr_w(wszName), lFlags, pVal, Type);
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI class_object_Delete(
309     IWbemClassObject *iface,
310     LPCWSTR wszName )
311 {
312     FIXME("%p, %s\n", iface, debugstr_w(wszName));
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI class_object_GetNames(
317     IWbemClassObject *iface,
318     LPCWSTR wszQualifierName,
319     LONG lFlags,
320     VARIANT *pQualifierVal,
321     SAFEARRAY **pNames )
322 {
323     struct class_object *co = impl_from_IWbemClassObject( iface );
324     struct enum_class_object *ec = impl_from_IEnumWbemClassObject( co->iter );
325
326     TRACE("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszQualifierName), lFlags, pQualifierVal, pNames);
327
328     if (wszQualifierName || pQualifierVal)
329     {
330         FIXME("qualifier not supported\n");
331         return E_NOTIMPL;
332     }
333     if (lFlags != WBEM_FLAG_ALWAYS)
334     {
335         FIXME("flags %08x not supported\n", lFlags);
336         return E_NOTIMPL;
337     }
338     return get_properties( ec->query->view, pNames );
339 }
340
341 static HRESULT WINAPI class_object_BeginEnumeration(
342     IWbemClassObject *iface,
343     LONG lEnumFlags )
344 {
345     FIXME("%p, %08x\n", iface, lEnumFlags);
346     return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI class_object_Next(
350     IWbemClassObject *iface,
351     LONG lFlags,
352     BSTR *strName,
353     VARIANT *pVal,
354     CIMTYPE *pType,
355     LONG *plFlavor )
356 {
357     FIXME("%p, %08x, %p, %p, %p, %p\n", iface, lFlags, strName, pVal, pType, plFlavor);
358     return E_NOTIMPL;
359 }
360
361 static HRESULT WINAPI class_object_EndEnumeration(
362     IWbemClassObject *iface )
363 {
364     FIXME("%p\n", iface);
365     return E_NOTIMPL;
366 }
367
368 static HRESULT WINAPI class_object_GetPropertyQualifierSet(
369     IWbemClassObject *iface,
370     LPCWSTR wszProperty,
371     IWbemQualifierSet **ppQualSet )
372 {
373     FIXME("%p, %s, %p\n", iface, debugstr_w(wszProperty), ppQualSet);
374     return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI class_object_Clone(
378     IWbemClassObject *iface,
379     IWbemClassObject **ppCopy )
380 {
381     FIXME("%p, %p\n", iface, ppCopy);
382     return E_NOTIMPL;
383 }
384
385 static HRESULT WINAPI class_object_GetObjectText(
386     IWbemClassObject *iface,
387     LONG lFlags,
388     BSTR *pstrObjectText )
389 {
390     FIXME("%p, %08x, %p\n", iface, lFlags, pstrObjectText);
391     return E_NOTIMPL;
392 }
393
394 static HRESULT WINAPI class_object_SpawnDerivedClass(
395     IWbemClassObject *iface,
396     LONG lFlags,
397     IWbemClassObject **ppNewClass )
398 {
399     FIXME("%p, %08x, %p\n", iface, lFlags, ppNewClass);
400     return E_NOTIMPL;
401 }
402
403 static HRESULT WINAPI class_object_SpawnInstance(
404     IWbemClassObject *iface,
405     LONG lFlags,
406     IWbemClassObject **ppNewInstance )
407 {
408     FIXME("%p, %08x, %p\n", iface, lFlags, ppNewInstance);
409     return E_NOTIMPL;
410 }
411
412 static HRESULT WINAPI class_object_CompareTo(
413     IWbemClassObject *iface,
414     LONG lFlags,
415     IWbemClassObject *pCompareTo )
416 {
417     FIXME("%p, %08x, %p\n", iface, lFlags, pCompareTo);
418     return E_NOTIMPL;
419 }
420
421 static HRESULT WINAPI class_object_GetPropertyOrigin(
422     IWbemClassObject *iface,
423     LPCWSTR wszName,
424     BSTR *pstrClassName )
425 {
426     FIXME("%p, %s, %p\n", iface, debugstr_w(wszName), pstrClassName);
427     return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI class_object_InheritsFrom(
431     IWbemClassObject *iface,
432     LPCWSTR strAncestor )
433 {
434     FIXME("%p, %s\n", iface, debugstr_w(strAncestor));
435     return E_NOTIMPL;
436 }
437
438 static HRESULT WINAPI class_object_GetMethod(
439     IWbemClassObject *iface,
440     LPCWSTR wszName,
441     LONG lFlags,
442     IWbemClassObject **ppInSignature,
443     IWbemClassObject **ppOutSignature )
444 {
445     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, ppInSignature, ppOutSignature);
446     return E_NOTIMPL;
447 }
448
449 static HRESULT WINAPI class_object_PutMethod(
450     IWbemClassObject *iface,
451     LPCWSTR wszName,
452     LONG lFlags,
453     IWbemClassObject *pInSignature,
454     IWbemClassObject *pOutSignature )
455 {
456     FIXME("%p, %s, %08x, %p, %p\n", iface, debugstr_w(wszName), lFlags, pInSignature, pOutSignature);
457     return E_NOTIMPL;
458 }
459
460 static HRESULT WINAPI class_object_DeleteMethod(
461     IWbemClassObject *iface,
462     LPCWSTR wszName )
463 {
464     FIXME("%p, %s\n", iface, debugstr_w(wszName));
465     return E_NOTIMPL;
466 }
467
468 static HRESULT WINAPI class_object_BeginMethodEnumeration(
469     IWbemClassObject *iface,
470     LONG lEnumFlags)
471 {
472     FIXME("%p, %08x\n", iface, lEnumFlags);
473     return E_NOTIMPL;
474 }
475
476 static HRESULT WINAPI class_object_NextMethod(
477     IWbemClassObject *iface,
478     LONG lFlags,
479     BSTR *pstrName,
480     IWbemClassObject **ppInSignature,
481     IWbemClassObject **ppOutSignature)
482 {
483     FIXME("%p, %08x, %p, %p, %p\n", iface, lFlags, pstrName, ppInSignature, ppOutSignature);
484     return E_NOTIMPL;
485 }
486
487 static HRESULT WINAPI class_object_EndMethodEnumeration(
488     IWbemClassObject *iface )
489 {
490     FIXME("%p\n", iface);
491     return E_NOTIMPL;
492 }
493
494 static HRESULT WINAPI class_object_GetMethodQualifierSet(
495     IWbemClassObject *iface,
496     LPCWSTR wszMethod,
497     IWbemQualifierSet **ppQualSet)
498 {
499     FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethod), ppQualSet);
500     return E_NOTIMPL;
501 }
502
503 static HRESULT WINAPI class_object_GetMethodOrigin(
504     IWbemClassObject *iface,
505     LPCWSTR wszMethodName,
506     BSTR *pstrClassName)
507 {
508     FIXME("%p, %s, %p\n", iface, debugstr_w(wszMethodName), pstrClassName);
509     return E_NOTIMPL;
510 }
511
512 static const IWbemClassObjectVtbl class_object_vtbl =
513 {
514     class_object_QueryInterface,
515     class_object_AddRef,
516     class_object_Release,
517     class_object_GetQualifierSet,
518     class_object_Get,
519     class_object_Put,
520     class_object_Delete,
521     class_object_GetNames,
522     class_object_BeginEnumeration,
523     class_object_Next,
524     class_object_EndEnumeration,
525     class_object_GetPropertyQualifierSet,
526     class_object_Clone,
527     class_object_GetObjectText,
528     class_object_SpawnDerivedClass,
529     class_object_SpawnInstance,
530     class_object_CompareTo,
531     class_object_GetPropertyOrigin,
532     class_object_InheritsFrom,
533     class_object_GetMethod,
534     class_object_PutMethod,
535     class_object_DeleteMethod,
536     class_object_BeginMethodEnumeration,
537     class_object_NextMethod,
538     class_object_EndMethodEnumeration,
539     class_object_GetMethodQualifierSet,
540     class_object_GetMethodOrigin
541 };
542
543 HRESULT WbemClassObject_create(
544     IUnknown *pUnkOuter, IEnumWbemClassObject *iter, UINT index, LPVOID *ppObj )
545 {
546     struct class_object *co;
547
548     TRACE("%p, %p\n", pUnkOuter, ppObj);
549
550     co = heap_alloc( sizeof(*co) );
551     if (!co) return E_OUTOFMEMORY;
552
553     co->IWbemClassObject_iface.lpVtbl = &class_object_vtbl;
554     co->refs  = 1;
555     co->iter  = iter;
556     co->index = index;
557     if (iter) IEnumWbemClassObject_AddRef( iter );
558
559     *ppObj = &co->IWbemClassObject_iface;
560
561     TRACE("returning iface %p\n", *ppObj);
562     return S_OK;
563 }