1 karl 1.11 //%2006////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 karl 1.6 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.4 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.6 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.7 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 kumpf 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Barbara Packard (barbara_packard@hp.com)
33 //
|
34 kumpf 1.2 // Modified By: Adriano Zanuz (adriano.zanuz@hp.com)
|
35 kumpf 1.3 // Jair Santos, Hewlett-Packard Company (jair.santos@hp.com)
|
36 kumpf 1.5 // Terry Martin, Hewlett-Packard Company (terry.martin@hp.com)
|
37 kumpf 1.1 //
38 //%/////////////////////////////////////////////////////////////////////////////
39
40 /////////////////////////////////////////////////////////////////////////////
41 // WMICollector::
42 //
|
43 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
44 kumpf 1.1
45 #include "StdAfx.h"
46
47 #include "WMIType.h"
48 #include "WMIFlavor.h"
49 #include "WMIValue.h"
50 #include "WMIString.h"
51 #include "WMIProperty.h"
|
52 kumpf 1.5 #include "WMIMethod.h"
|
53 kumpf 1.1 #include "WMICollector.h"
54
55 PEGASUS_USING_STD;
56
57 PEGASUS_NAMESPACE_BEGIN
58
59 //////////////////////////////////////////////////////////////////////
60 // Construction/Destruction
61 //////////////////////////////////////////////////////////////////////
|
62 kumpf 1.2 WMICollector::WMICollector(bool bLocal)
|
63 kumpf 1.1 {
64 m_bInitialized = false;
|
65 kumpf 1.2 m_bIsLocalNamespace = false;
66 m_bImpersonate = false;
67 m_bLocalConnection = bLocal;
|
68 kumpf 1.1 }
69
70 WMICollector::~WMICollector(void)
71 {
72 }
73
74 void WMICollector::terminate(void)
75 {
76 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::terminate()");
|
77 kumpf 1.2
|
78 kumpf 1.1 if (m_bInitialized)
79 {
80 CoUninitialize();
81 m_bInitialized = false;
|
82 kumpf 1.2
83 if(m_bImpersonate)
84 {
85 revertToSelf();
86 m_bImpersonate = false;
87 }
|
88 kumpf 1.5
89 m_bIsLocalNamespace = false;
90 }
|
91 kumpf 1.2
|
92 kumpf 1.1 PEG_METHOD_EXIT();
93 }
94
95 /////////////////////////////////////////////////////////////////////////////
96 // WMICollector::setup - calls CoInitialize stuff
97 //
|
98 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
99 kumpf 1.1 bool WMICollector::setup()
100 {
101 HRESULT hr;
102
103 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::setup()");
104
|
105 kumpf 1.3 if (!m_bInitialized)
106 {
107 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
108 kumpf 1.2
|
109 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
110 "WMICollector::setup() - return from CoInitializeEx() is %x", hr));
|
111 kumpf 1.1
|
112 kumpf 1.3 m_bInitialized = (SUCCEEDED(hr));
|
113 kumpf 1.1
|
114 kumpf 1.5 if (m_bInitialized)
115 {
116 hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
117 RPC_C_AUTHN_LEVEL_DEFAULT,
118 RPC_C_IMP_LEVEL_IMPERSONATE,
119 NULL,
|
120 mateus.baur 1.10 EOAC_DYNAMIC_CLOAKING,
|
121 kumpf 1.5 0);
122 }
|
123 kumpf 1.3 }
|
124 kumpf 1.1
|
125 kumpf 1.5 PEG_METHOD_EXIT();
|
126 kumpf 1.1 return (m_bInitialized);
127 }
128
129 /////////////////////////////////////////////////////////////////////////////
130 // WMICollector::Connect- attempt to establish a WMI connection with the local
131 // host
132 //
|
133 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
134 kumpf 1.1 bool WMICollector::Connect(IWbemServices **ppServices)
135 {
|
136 kumpf 1.5 //
137 // CComPtr is a smart pointer, therefore, it doesn't need to be explicitely
138 // released.
139 //
|
140 kumpf 1.2 CComPtr<IWbemLocator> pLocator;
141 CComPtr<IWbemServices> pServices;
|
142 kumpf 1.5 HRESULT hr = S_OK;
|
143 kumpf 1.1
144 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::Connect()");
|
145 kumpf 1.2
|
146 kumpf 1.1 // get the Locator object
147 hr = pLocator.CoCreateInstance(CLSID_WbemLocator);
|
148 kumpf 1.2
|
149 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
150 "WMICollector::Connect() - return from CoCreateInstance() is %x", hr));
|
151 kumpf 1.1
|
152 kumpf 1.2 if (SUCCEEDED(hr))
153 {
154 if(m_bIsLocalNamespace)
155 {
|
156 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
157 kumpf 1.5 "WMICollector::Connect() - m_bIsLocalNamespace is true");
|
158 kumpf 1.2
159 //Does not impersonate if is being called from a client app
160 //Impersonate if it is being called from the Mapper service
161 if (!m_bLocalConnection)
|
162 kumpf 1.5 {
|
163 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
164 kumpf 1.5 "WMICollector::Connect() - m_bLocalConnection is false, call logonUser()");
|
165 kumpf 1.2 logonUser();
|
166 kumpf 1.5 }
|
167 kumpf 1.2
168 hr = pLocator->ConnectServer(m_bsNamespace,
169 NULL,
170 NULL,
171 NULL, 0L, NULL, NULL,
172 &pServices);
173 }
174 else
175 {
|
176 kumpf 1.1
|
177 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
178 kumpf 1.5 "WMICollector::Connect() - m_bIsLocalNamespace is false");
|
179 kumpf 1.2 //---------------------------------------------------
180 //by Jair
181 //adjusting the username in order to add the domain
182 //reference
|
183 kumpf 1.3 CComBSTR bsUser = m_bsDomain;
184 bsUser.Append("\\");
185 bsUser.Append(m_bsUserName);
|
186 kumpf 1.1
|
187 kumpf 1.2 //---------------------------------------------------
188
189 hr = pLocator->ConnectServer(m_bsNamespace,
190 bsUser,
191 m_bsPassword,
192 NULL, 0L, NULL, NULL,
|
193 kumpf 1.3 &pServices);
|
194 kumpf 1.2 }
|
195 kumpf 1.1
|
196 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
197 "WMICollector::Connect() - return from ConnectServer() is %x", hr));
|
198 kumpf 1.2
199 if (FAILED(hr))
200 {
201 switch(hr)
202 {
|
203 kumpf 1.5 case E_ACCESSDENIED:
|
204 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
205 kumpf 1.5 "WMICollector::Connect() connectServer() - throw CIM_ERR_ACCESS_DENIED for E_ACCESSDENIED error");
206 throw CIMException(CIM_ERR_ACCESS_DENIED);
207 break;
208 case WBEM_E_ACCESS_DENIED:
|
209 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
210 kumpf 1.5 "WMICollector::Connect() - connectServer() - throw CIM_ERR_ACCESS_DENIED error");
211 throw CIMException(CIM_ERR_ACCESS_DENIED);
212 break;
213 default:
|
214 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
215 kumpf 1.5 "WMICollector::Connect() - connectServer() - throw CIM_ERR_INVALID_NAMESPACE error");
216 throw CIMException(CIM_ERR_INVALID_NAMESPACE);
|
217 kumpf 1.2 }
218 }
|
219 kumpf 1.5
220 if (SUCCEEDED(hr))
221 {
222 // set security attributes on pServices
223 if(setProxySecurity(pServices))
224 {
225 pServices.CopyTo(ppServices);
226 }
227 else
228 {
229 *ppServices = NULL;
230 }
231 }
|
232 kumpf 1.2 }
233
|
234 kumpf 1.1 PEG_METHOD_EXIT();
|
235 kumpf 1.2
|
236 kumpf 1.1 return (SUCCEEDED(hr));
237 }
238
239 /////////////////////////////////////////////////////////////////////////////
240 // WMICollector::getInstanceEnum - fetch a pointer to an enumeration of the
241 // instances of sClassname
242 //
|
243 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
244 kumpf 1.1 bool WMICollector::getInstanceEnum(
245 IEnumWbemClassObject **ppInstances,
246 const String & sClassName,
247 Boolean deepInheritance)
248 {
|
249 kumpf 1.5 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getInstanceEnum()");
|
250 kumpf 1.1
251 HRESULT hr;
|
252 mateus.baur 1.8 long lFlags = WBEM_FLAG_FORWARD_ONLY;
|
253 kumpf 1.1
|
254 kumpf 1.5 //
255 // CComPtr is a smart pointer, therefore, it doesn't need to be explicitely
256 // released.
257 //
|
258 kumpf 1.2 CComPtr<IWbemServices> pServices;
|
259 kumpf 1.1 CComPtr<IEnumWbemClassObject> p_inst;
260
261 bool bConnected = Connect(&pServices);
262
263 if (!bConnected)
264 {
|
265 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
266 kumpf 1.5 "WMICollector::getInstanceEnum,() - bConnected is false - throw Connect failed error");
267
|
268 kumpf 1.1 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, "Connect failed.");
269 }
270
|
271 kumpf 1.3 CComBSTR bsClassName = sClassName.getCString();
|
272 kumpf 1.1
273 deepInheritance ? lFlags |= WBEM_FLAG_DEEP : lFlags |= WBEM_FLAG_SHALLOW;
274
275 // retrieve instances
276 hr = pServices->CreateInstanceEnum(
277 bsClassName,
278 lFlags,
279 NULL,
280 &p_inst);
281
|
282 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
283 "WMICollector::getInstanceEnum() return from CreateInstanceEnum()- hr value is %x", hr));
|
284 kumpf 1.3
|
285 kumpf 1.5 if (SUCCEEDED(hr))
|
286 kumpf 1.1 {
287 p_inst.CopyTo(ppInstances);
288
289 // set security attributes on *ppInstances
|
290 kumpf 1.2 bool bSecurity = setProxySecurity(*ppInstances);
|
291 kumpf 1.1 }
292 else
293 {
294 *ppInstances = NULL;
|
295 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
296 "WMICollector::getInstanceEnum() - hr value is %x", hr));
|
297 kumpf 1.2
298 switch(hr)
299 {
300 case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
301 case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_INVALID_CLASS); break;
|
302 kumpf 1.3 default: throw CIMException(CIM_ERR_FAILED, "[getInstanceEnum] general");
|
303 kumpf 1.2 }
|
304 kumpf 1.1 }
305
306 PEG_METHOD_EXIT();
|
307 kumpf 1.2
|
308 kumpf 1.1 return (SUCCEEDED(hr));
309 }
310
311 /////////////////////////////////////////////////////////////////////////////
312 // WMICollector::getClassEnum - fetch a pointer to an enumeration of the
313 // classes satisfying the criteria
314 //
|
315 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
316 kumpf 1.1 bool WMICollector::getClassEnum(
317 IEnumWbemClassObject **ppClasses,
318 const String & sSuperClass,
319 Boolean deepInheritance)
320 {
321
322 HRESULT hr;
|
323 mateus.baur 1.8
324 long lFlags = WBEM_FLAG_FORWARD_ONLY ;
|
325 kumpf 1.1 CComBSTR bsSuperClass = NULL;
326
|
327 kumpf 1.3 CComPtr<IWbemServices> pServices;
328 CComPtr<IEnumWbemClassObject> p_class;
|
329 kumpf 1.1
330 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getClassEnum()");
|
331 kumpf 1.2
|
332 kumpf 1.1 bool bConnected = Connect(&pServices);
333
334 if (!bConnected)
335 {
|
336 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
337 kumpf 1.5 "WMICollector::getClassEnum,() - bConnected is false - throw Connect failed error");
|
338 kumpf 1.3
|
339 kumpf 1.1 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, "Connect failed.");
340 }
341
342 //
343 // workaround because there is no NULL for String class...
344 //
345 if (0 != sSuperClass.size())
346 {
|
347 kumpf 1.3 bsSuperClass = sSuperClass.getCString();
|
348 kumpf 1.1 }
349
350 deepInheritance ? lFlags |= WBEM_FLAG_DEEP : lFlags |= WBEM_FLAG_SHALLOW;
351
|
352 kumpf 1.5 if (0 != sSuperClass.size())
353 {
354 // retrieve classes
355 hr = pServices->CreateClassEnum(
356 bsSuperClass,
357 lFlags,
358 NULL,
359 &p_class);
360 }
361 else
362 {
363 // retrieve classes
364 hr = pServices->CreateClassEnum(
365 NULL,
366 lFlags,
367 NULL,
368 &p_class);
369 }
|
370 kumpf 1.1
|
371 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
372 "WMICollector::getClassEnum() returns from CreateClassEnum() - hr value is %x", hr));
|
373 kumpf 1.3
|
374 kumpf 1.1 if (SUCCEEDED(hr))
375 {
376 p_class.CopyTo(ppClasses);
377
|
378 kumpf 1.2 // set security attributes on *ppClasses
379 bool bSecurity = setProxySecurity(*ppClasses);
|
380 kumpf 1.1 }
381 else
382 {
|
383 kumpf 1.5 *ppClasses = NULL;
|
384 kumpf 1.3
|
385 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
386 "WMICollector::getClassEnum() - hr value is %x", hr));
|
387 kumpf 1.2
388 switch(hr)
389 {
|
390 kumpf 1.5 case WBEM_E_ACCESS_DENIED:
|
391 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
392 kumpf 1.5 "WMICollector::getClassEnum() - createClassEnum() returns ACCESS_DENIED- throw CIM_ERROR_ACCESS_DENIED error");
393 throw CIMException(CIM_ERR_ACCESS_DENIED);
394 break;
395 case WBEM_E_INVALID_CLASS:
|
396 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
397 kumpf 1.5 "WMICollector::getClassEnum() - createClassEnum() returns INVALID_CLASS- throw CIM_INVALID_CLASS error");
398 throw CIMException(CIM_ERR_INVALID_CLASS);
399 break;
400 default:
|
401 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
402 kumpf 1.5 "WMICollector::getClassEnum() - createClassEnum() returns default - throw getClassEnum general error");
403 throw CIMException(CIM_ERR_FAILED, "[getClassEnum] general");
|
404 kumpf 1.2 }
|
405 kumpf 1.1 }
406
407 PEG_METHOD_EXIT();
|
408 kumpf 1.2
|
409 kumpf 1.1 return (SUCCEEDED(hr));
410 }
411
412
413 /////////////////////////////////////////////////////////////////////////////
414 // WMICollector::getQueryResult - fetch a point to the enumeration of
415 // instances returned from an ExecQuery request
416 //
|
417 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
418 kumpf 1.1 bool WMICollector::getQueryResult(
|
419 kumpf 1.2 IEnumWbemClassObject **ppInstances,
420 const String &query,
421 const String &queryLanguage)
|
422 kumpf 1.1 {
423 HRESULT hr;
|
424 kumpf 1.2
|
425 kumpf 1.1 CComPtr<IWbemServices> pServices;
|
426 kumpf 1.2 CComPtr<IEnumWbemClassObject> p_inst;
|
427 kumpf 1.1
428 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getQueryResult()");
|
429 kumpf 1.2
|
430 kumpf 1.1 bool bConnected = Connect(&pServices);
431
432 if (!bConnected)
433 {
|
434 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
435 kumpf 1.5 "WMICollector::getQueryResult,() - bConnected is false - throw Connect failed error");
436
|
437 kumpf 1.1 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED, "Connect failed.");
438 }
439
|
440 kumpf 1.2 //if QueryLanguage is not WQL, throws an exception error informing
441 //that the query language is not supported
|
442 kumpf 1.3 if (!String::equalNoCase("WQL", queryLanguage))
|
443 kumpf 1.2 {
444 throw CIMException(CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED);
445 }
|
446 kumpf 1.1
|
447 kumpf 1.3 CComBSTR bsQuery = query.getCString();
448 CComBSTR bsQueryLanguage = queryLanguage.getCString();
|
449 kumpf 1.1
450 // retrieve query result
451 hr = pServices->ExecQuery(
452 bsQueryLanguage,
453 bsQuery,
|
454 mateus.baur 1.8 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_ENSURE_LOCATABLE,
|
455 kumpf 1.1 NULL,
456 &p_inst);
457
|
458 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
459 "WMICollector::getQueryResult(), return from ExecQuery - hr value is %x", hr));
|
460 kumpf 1.3
|
461 kumpf 1.1 if (SUCCEEDED(hr))
462 {
463 p_inst.CopyTo(ppInstances);
|
464 kumpf 1.3
|
465 kumpf 1.1 // set security attributes on *ppInstances
|
466 kumpf 1.2 bool bSecurity = setProxySecurity(*ppInstances);
|
467 kumpf 1.1 }
468 else
469 {
|
470 kumpf 1.5 *ppInstances = NULL;
|
471 kumpf 1.3
|
472 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
473 "WMICollector::getQueryResult() - hr value is %x", hr));
|
474 kumpf 1.2
475 switch(hr)
476 {
477 case WBEM_E_INVALID_QUERY: throw CIMException(CIM_ERR_INVALID_QUERY); break;
478 case WBEM_E_INVALID_QUERY_TYPE: throw CIMException(CIM_ERR_QUERY_LANGUAGE_NOT_SUPPORTED); break;
|
479 kumpf 1.3 default: throw CIMException(CIM_ERR_FAILED, "[getQueryResult] general");
|
480 kumpf 1.2 }
|
481 kumpf 1.1 }
482
483 PEG_METHOD_EXIT();
|
484 kumpf 1.2
|
485 kumpf 1.1 return (SUCCEEDED(hr));
486 }
487
488 /////////////////////////////////////////////////////////////////////////////
489 // WMICollector::getObject - fetch a pointer to the object
490 // represented by sObjectName
491 // Can be either a class or an instance
492 //
493 /////////////////////////////////////////////////////////////////////////////
494 bool WMICollector::getObject(IWbemClassObject **ppObject,
495 const String & sObjectName)
496 {
497 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getObject()");
|
498 kumpf 1.2
|
499 kumpf 1.3 HRESULT hr;
|
500 kumpf 1.1 CComPtr<IWbemServices> pServices;
|
501 kumpf 1.3 CComPtr<IWbemClassObject> p_obj;
|
502 kumpf 1.1
503 bool bConnected = Connect(&pServices);
504
505 if (!bConnected)
506 {
|
507 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
508 kumpf 1.5 "WMICollector::getObject,() - bConnected is false - throw Connect failed error");
|
509 kumpf 1.3
|
510 kumpf 1.1 throw CIMException(CIM_ERR_ACCESS_DENIED);
511 }
512
|
513 kumpf 1.3 CComBSTR bsObjectName = sObjectName.getCString();
|
514 kumpf 1.1 LONG lFlags = WBEM_FLAG_USE_AMENDED_QUALIFIERS | WBEM_FLAG_RETURN_WBEM_COMPLETE;
515
516 // retrieve class object
517 hr = pServices->GetObject(
|
518 kumpf 1.5 bsObjectName,
519 lFlags,
520 NULL,
521 &p_obj,
522 NULL);
|
523 kumpf 1.1
|
524 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
525 "WMICollector::getObject() - GetObject result is %x", hr));
|
526 kumpf 1.1
|
527 kumpf 1.5 if (SUCCEEDED(hr))
|
528 kumpf 1.1 {
529 p_obj.CopyTo(ppObject);
530
531 // set security attributes on result
|
532 kumpf 1.2 bool bSecurity = setProxySecurity(*ppObject);
|
533 kumpf 1.1 }
534 else
535 {
536 *ppObject = NULL;
537
|
538 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
539 "WMICollector::getObject() - GetObject result is %x", hr));
|
540 kumpf 1.2
541 //generate error
542 switch(hr)
543 {
544 case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_INVALID_CLASS); break;
545 case WBEM_E_NOT_FOUND: throw CIMException(CIM_ERR_NOT_FOUND); break;
|
546 kumpf 1.3 default: throw CIMException(CIM_ERR_FAILED, "[getObject] general");
|
547 kumpf 1.2 }
|
548 kumpf 1.1 }
549
550 PEG_METHOD_EXIT();
|
551 kumpf 1.2
|
552 kumpf 1.3 return (SUCCEEDED(hr));
|
553 kumpf 1.1 }
554
555
556 /////////////////////////////////////////////////////////////////////////////
557 // getProperties - retrieves selected
558 // properties for a CIMClass or
559 // CIMInstance object
560 //
|
561 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
562 kumpf 1.1 template<class CONTAINER>
563 void getProperties(IWbemClassObject *pClass,
564 Boolean localOnly,
565 Boolean includeQualifiers,
566 Boolean includeClassOrigin,
567 const CIMPropertyList& propertyList,
568 CONTAINER & container)
569 {
570 HRESULT hr = S_OK;
|
571 kumpf 1.3 String sMessage;
|
572 kumpf 1.1
573 CComBSTR bsName; // of the property
574 CComVariant vValue; // of the property
575 long lFlavor; // of the property
576 CIMTYPE type;
577 CIMProperty property;
|
578 kumpf 1.2
579 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"getProperties()");
|
580 kumpf 1.1
581 Uint32 size = propertyList.size();
582
583 for (Uint32 i = 0; ((i < size) && SUCCEEDED(hr)); i++)
584 {
|
585 kumpf 1.3 String sPropName = propertyList[i].getString();
|
586 kumpf 1.1
587 bsName.Empty();
588 vValue.Clear();
589 sMessage = "Get()";
590
|
591 kumpf 1.3 bsName = sPropName.getCString();
|
592 kumpf 1.1
593 // fetch the property
|
594 kumpf 1.5 hr = pClass->Get(
595 bsName,
596 0,
597 &vValue,
598 &type,
599 &lFlavor);
|
600 kumpf 1.1
601 // process each property
602 if (SUCCEEDED(hr))
603 {
|
604 kumpf 1.2
|
605 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
606 kumpf 1.2 "getProperties() - CIMTYPE[%x] - WMITYPE[%x]",
607 type,
|
608 marek 1.12 vValue.vt));
|
609 kumpf 1.2
|
610 kumpf 1.1 bool bPropagated = (lFlavor & WBEM_FLAVOR_ORIGIN_PROPAGATED) ? true : false;
611
612 try
613 {
614 property = WMICollector::getProperty(pClass, bsName, vValue,
615 type, includeClassOrigin,
616 includeQualifiers, bPropagated);
617 }
618 catch( TypeMismatchException & e )
619 {
620 // ATTN:
621 // unsupported for now - do some tracing...
622 String sClass = WMICollector::getClassName(pClass);
|
623 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
624 kumpf 1.1 "getProperties() - Ignoring invalid type for %s in %s. %s, unsupported WMI CIM type is %x",
|
625 marek 1.12 sPropName, sClass, e.getMessage(), type));
|
626 kumpf 1.2
|
627 kumpf 1.1 continue;
628 }
|
629 kumpf 1.5 vValue.Clear();
|
630 kumpf 1.1
631 if (bPropagated && localOnly)
632 {
|
633 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
634 kumpf 1.5 "getProperties() - Property %s was defined in a superclass",
|
635 marek 1.12 (LPCTSTR)sPropName.getCString()));
|
636 kumpf 1.1 }
637
638 else
639 // try to add it
640 {
641 try
642 {
643 container.addProperty(property);
644 }
645 catch( AlreadyExistsException& e )
646 {
647 // ignore this
|
648 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
649 "getProperties() - Property %s is already defined. %s", sPropName, e.getMessage()));
|
650 kumpf 1.1 }
651 catch( Exception & e )
652 {
653 // ignore this
|
654 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
655 "getAllProperties() - Ignoring AddedReferenceToClass. %s", e.getMessage()));
|
656 kumpf 1.1
657 }
658 catch(... )
659 {
|
660 kumpf 1.3 throw CIMException(CIM_ERR_FAILED, "[getProperties] general");
|
661 kumpf 1.1 }
662 }
663
664 }
665 else if (WBEM_E_NOT_FOUND == hr)
666 { // we are supposed to keep going...
|
667 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
668 "getProperties() - %s property not found", (LPCTSTR)sPropName.getCString()));
|
669 kumpf 1.2
|
670 kumpf 1.1 //reset
|
671 mateus.baur 1.9 throw CIMException(CIM_ERR_FAILED, "[getProperties] Property Not Found");
672
|
673 kumpf 1.1 hr = S_OK;
674 }
675 }
676
677 if (FAILED(hr))
678 {
|
679 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
680 "getProperties() - failed, return result is %x", hr));
|
681 kumpf 1.5
682 throw CIMException(CIM_ERR_FAILED, "[getProperties] general 2");
|
683 kumpf 1.1 }
684
685 PEG_METHOD_EXIT();
686 }
687
688 /////////////////////////////////////////////////////////////////////////////
689 // getAllProperties - retrieves all the
690 // properties for a CIMClass or
691 // CIMInstance object
692 //
|
693 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
694 kumpf 1.1 template<class CONTAINER>
695 bool getAllProperties(IWbemClassObject *pClass,
696 long lFlags,
697 Boolean includeQualifiers,
698 Boolean includeClassOrigin,
699 CONTAINER & container)
700 {
701 HRESULT hr;
|
702 kumpf 1.3 String sMessage;
|
703 kumpf 1.1
704 CComBSTR bsName; // of the property
705 CComVariant vValue; // of the property
706 long lFlavor; // of the property
707 CIMTYPE type;
708 CIMProperty property;
709
710 bool bFound = false;
|
711 kumpf 1.2
712 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"getAllProperties()");
|
713 kumpf 1.1
714 hr = pClass->BeginEnumeration(lFlags);
715 sMessage = "BeginEnumeration()";
716
717 if (SUCCEEDED(hr))
718 {
719 bsName.Empty();
720 vValue.Clear();
721 sMessage = "Next()";
722
723 hr = pClass->Next(0, &bsName, &vValue, &type, &lFlavor);
724 }
725
726 // process each property
727 while (SUCCEEDED(hr))
728 {
729 if (WBEM_S_NO_MORE_DATA == hr)
730 {
731 break;
732 }
733
|
734 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
735 kumpf 1.2 "getAllProperties() - CIMTYPE[%x] - WMITYPE[%x]",
736 type,
|
737 marek 1.12 vValue.vt));
|
738 kumpf 1.2
|
739 kumpf 1.1 bFound = true;
740
|
741 kumpf 1.3 CMyString sPropName; sPropName = bsName;
742
|
743 kumpf 1.1 bool bPropagated = (lFlavor & WBEM_FLAVOR_ORIGIN_PROPAGATED) ? true : false;
744
745 try
746 {
747 property = WMICollector::getProperty(pClass, bsName, vValue,
748 type, includeClassOrigin,
749 includeQualifiers, bPropagated);
750 }
751 catch( TypeMismatchException & e )
752 {
753 // ATTN:
754 // unsupported for now - do some tracing...
755 String sClass = WMICollector::getClassName(pClass);
|
756 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
757 kumpf 1.1 "getAllProperties() - Ignoring invalid type for %s in %s. %s, unsupported WMI CIM type is %x",
|
758 marek 1.12 (LPCTSTR)sPropName, sClass, e.getMessage(), type));
|
759 kumpf 1.1
760 bsName.Empty();
761 vValue.Clear();
762
763 sMessage = "Next()";
764 hr = pClass->Next(0, &bsName, &vValue, &type, &lFlavor);
765
766 continue;
767 }
|
768 kumpf 1.3
|
769 kumpf 1.1 try
770 {
771 container.addProperty(property);
772 }
773 catch( AlreadyExistsException& e )
774 {
775 // ignore this
|
776 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
777 "getAllProperties() - Property %s is already defined", (LPCTSTR)sPropName));
778 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllProperties() - %s", e.getMessage()));
|
779 kumpf 1.1
780 }
781 catch( Exception & e )
782 {
783 // ignore this
|
784 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
785 "getAllProperties() - Ignoring AddedReferenceToClass. %s", e.getMessage()));
|
786 kumpf 1.1
787 }
788 catch(... )
789 {
|
790 kumpf 1.3 throw CIMException(CIM_ERR_FAILED, "[getAllProperties] general 1");
|
791 kumpf 1.1 }
792
793 bsName.Empty();
|
794 kumpf 1.5 vValue.Clear();
|
795 kumpf 1.1
796 sMessage = "Next()";
797 hr = pClass->Next(0, &bsName, &vValue, &type, &lFlavor);
798 }
|
799 kumpf 1.3 pClass->EndEnumeration();
|
800 kumpf 1.5 vValue.Clear();
|
801 kumpf 1.1
802 if (FAILED(hr))
803 {
|
804 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
805 "getAllProperties() - %s result is %x", sMessage.getCString(), hr));
|
806 kumpf 1.3 throw CIMException(CIM_ERR_FAILED, "[getAllProperties] general 2");
|
807 kumpf 1.1 }
808
809 PEG_METHOD_EXIT();
810
811 return bFound;
812 }
813
814 /////////////////////////////////////////////////////////////////////////////
|
815 kumpf 1.5 // getAllMethods - retrieves all the
816 // methods for a CIMClass or
817 // CIMInstance object
818 //
819 /////////////////////////////////////////////////////////////////////////////
820 bool getAllMethods(IWbemClassObject *pClass,
821 long lFlags,
822 Boolean includeQualifiers,
823 Boolean includeClassOrigin,
824 CIMClass & container)
825 {
826 HRESULT hr;
827 String sMessage;
828
829 CComBSTR bsName; // of the method
830 CComPtr<IWbemClassObject> inParameters; // of the method
831 CComPtr<IWbemClassObject> outParameters; // of the method
832 CIMMethod method;
833
834 bool bFound = false;
835
836 kumpf 1.5 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"getAllMethods()");
837
838 hr = pClass->BeginMethodEnumeration(lFlags);
839 sMessage = "BeginMethodEnumeration()";
840
841 if (WBEM_E_INVALID_PARAMETER == hr)
842 {
843 // Windows 2000 does not accept any flags for BeginMethodEnumeration()
844 // (e.g., WBEM_FLAG_LOCAL_ONLY, which is used when localOnly==true)
845 // so try again with no flags (assuming Windows 2000 here):
846 hr = pClass->BeginMethodEnumeration(0L);
847 }
848
849 if (SUCCEEDED(hr))
850 {
851 bsName.Empty();
852 sMessage = "NextMethod()";
853
854 hr = pClass->NextMethod(0, &bsName, &inParameters, &outParameters);
855 }
856
857 kumpf 1.5 // process each method
858 while (SUCCEEDED(hr))
859 {
860 if (WBEM_S_NO_MORE_DATA == hr)
861 {
862 break;
863 }
864
|
865 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
866 kumpf 1.5 "getAllMethods() - name [%S]",
|
867 marek 1.12 bsName));
|
868 kumpf 1.5
869 bFound = true;
870
871 CMyString sMethodName; sMethodName = bsName;
872
873 // TODO: investigate propigation in terms of Methods. Is this applicable? Without a flavor,
874 // where would this come from?
875 bool bPropagated = false; //(lFlavor & WBEM_FLAVOR_ORIGIN_PROPAGATED) ? true : false;
876
877 method = WMICollector::getMethod(pClass,
878 bsName,
879 inParameters,
880 outParameters,
881 includeClassOrigin,
882 includeQualifiers,
883 bPropagated);
884
885 try
886 {
887 container.addMethod(method);
888 }
889 kumpf 1.5 catch( AlreadyExistsException& e )
890 {
891 // ignore this
|
892 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
893 "getAllMethods() - Method %s is already defined", (LPCTSTR)sMethodName));
894 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3, "getAllMethods() - %s", e.getMessage()));
|
895 kumpf 1.5
896 }
897 catch( Exception & e )
898 {
899 // ignore this
|
900 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
901 "getAllMethods() - Ignoring AddedReferenceToClass. %s", e.getMessage()));
|
902 kumpf 1.5
903 }
904 catch(... )
905 {
906 throw CIMException(CIM_ERR_FAILED, "[getAllProperties] general 1");
907 }
908
909 bsName.Empty();
910
911 if (inParameters)
912 inParameters.Release();
913
914 if (outParameters)
915 outParameters.Release();
916
917 sMessage = "NextMethod()";
918 hr = pClass->NextMethod(0, &bsName, &inParameters, &outParameters);
919 }
920 pClass->EndMethodEnumeration();
921
922 if (inParameters)
923 kumpf 1.5 inParameters.Release();
924
925 if (outParameters)
926 outParameters.Release();
927
928 if (FAILED(hr))
929 {
|
930 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
931 "getAllMethods() - %s result is %x", sMessage.getCString(), hr));
|
932 kumpf 1.5 throw CIMException(CIM_ERR_FAILED, "[getAllMethods] general 2");
933 }
934
935 PEG_METHOD_EXIT();
936
937 return bFound;
938 }
939
940 /////////////////////////////////////////////////////////////////////////////
|
941 kumpf 1.1 // getClassQualifiers - retrieves the
942 // class qualifier definitions for a
943 // class or instance and adds
944 // them to the CIMClass or CIMInstance
945 //
|
946 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
947 kumpf 1.1 template<class CONTAINER>
948 void getClassQualifiers(IWbemClassObject *pClass,
949 CONTAINER & container)
950 {
951 HRESULT hr;
|
952 kumpf 1.3 String sMessage;
|
953 kumpf 1.1
|
954 kumpf 1.3 CComPtr<IWbemQualifierSet> pQualifiers;
|
955 kumpf 1.1
|
956 kumpf 1.3 CComBSTR bsName = NULL; // of the qualifier
|
957 kumpf 1.1 CComVariant vValue; // of the qualifier
|
958 kumpf 1.3 long lFlavor; // of the qualifier
959 bool bPropagated; // true if propated from a superclass
960 CIMQualifier qualifier;
|
961 kumpf 1.1
962 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"getClassQualifiers()");
963
964 // get the qualifiers enumerator
|
965 kumpf 1.3 hr = pClass->GetQualifierSet(&pQualifiers);
|
966 kumpf 1.1
967 sMessage = "GetQualifier()";
968
969 if (SUCCEEDED(hr))
970 {
971 hr = pQualifiers->BeginEnumeration(0);
972 sMessage = "BeginEnumeration()";
973 }
974
975 if (SUCCEEDED(hr))
976 {
|
977 kumpf 1.5 bsName.Empty();
978 vValue.Clear();
|
979 kumpf 1.1 sMessage = "Next()";
|
980 kumpf 1.5
981 hr = pQualifiers->Next(0, &bsName, &vValue, &lFlavor);
|
982 kumpf 1.1 }
983
984 // process each qualifier
985 while (SUCCEEDED(hr))
986 {
987 if (WBEM_S_NO_MORE_DATA == hr)
988 {
989 break;
990 }
|
991 kumpf 1.2
|
992 kumpf 1.1 bPropagated = (lFlavor & WBEM_FLAVOR_ORIGIN_PROPAGATED) ? true : false;
993
994 qualifier = CIMQualifier(WMIString(bsName), WMIValue(vValue),
995 WMIFlavor(lFlavor), bPropagated);
|
996 kumpf 1.2
|
997 kumpf 1.3 bsName.Empty();
|
998 kumpf 1.5 vValue.Clear();
|
999 kumpf 1.3
|
1000 kumpf 1.1 try
1001 {
1002 container.addQualifier(qualifier);
1003 }
1004 catch (...)
1005 {
|
1006 kumpf 1.5 throw CIMException(CIM_ERR_FAILED, "[getClassQualifiers] general 1");
1007 }
|
1008 kumpf 1.3
|
1009 kumpf 1.5 bsName.Empty();
1010 vValue.Clear();
|
1011 kumpf 1.1
1012 hr = pQualifiers->Next(0, &bsName, &vValue, &lFlavor);
1013 }
|
1014 kumpf 1.5
1015 pQualifiers->EndEnumeration();
1016
|
1017 kumpf 1.3 bsName.Empty();
|
1018 kumpf 1.5 vValue.Clear();
|
1019 kumpf 1.1
1020 if (FAILED(hr))
1021 {
|
1022 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1023 "getClassQualifiers() - %s result is %x", sMessage.getCString(), hr));
|
1024 kumpf 1.3
|
1025 kumpf 1.1 throw CIMException(CIM_ERR_FAILED);
1026 }
1027
1028 PEG_METHOD_EXIT();
1029 }
1030
1031 ////////////////////////////////////////////////////////////////////////////
1032 // WMICollector::getCIMObject - set up a getCIMObject structure
1033 //
|
1034 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1035 kumpf 1.1 bool WMICollector::getCIMObject(IWbemClassObject *pObject,
1036 CIMObject & cimObj,
1037 Boolean localOnly,
1038 Boolean includeQualifiers,
1039 Boolean includeClassOrigin,
1040 const CIMPropertyList& propertyList,
1041 Boolean getKeyProperties)
1042 {
1043 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getCIMObject()");
1044
1045 // first get the qualifiers if wanted
1046 if (includeQualifiers)
1047 {
1048 getClassQualifiers(pObject, cimObj);
1049 }
1050
1051 // then the properties
1052 getObjectProperties(pObject, cimObj, localOnly,
1053 includeQualifiers, includeClassOrigin,
1054 propertyList, getKeyProperties);
1055
1056 kumpf 1.1 PEG_METHOD_EXIT();
|
1057 kumpf 1.3
|
1058 kumpf 1.1 return true;
1059 }
1060
1061 ////////////////////////////////////////////////////////////////////////////
1062 // WMICollector::getCIMInstance - set up a CIMInstance structure
1063 //
|
1064 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1065 kumpf 1.1 bool WMICollector::getCIMInstance(IWbemClassObject *pObject,
1066 CIMInstance & cimInst,
1067 Boolean localOnly,
1068 Boolean includeQualifiers,
1069 Boolean includeClassOrigin,
1070 const CIMPropertyList& propertyList,
1071 Boolean getKeyProperties)
1072 {
1073 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getCIMInstance()");
1074
1075 CIMObject cimObj = cimInst;
1076
1077 getCIMObject(pObject, cimObj, localOnly, includeQualifiers,
1078 includeClassOrigin, propertyList, getKeyProperties);
1079
1080 CIMInstance newInstance(cimObj);
1081 cimInst = newInstance;
1082
1083 PEG_METHOD_EXIT();
|
1084 kumpf 1.3
|
1085 kumpf 1.1 return true;
1086 }
1087
1088 /////////////////////////////////////////////////////////////////////////////
1089 // WMICollector::getCIMClass - set up a
1090 // CIMClass structure
1091 //
|
1092 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1093 kumpf 1.1 bool WMICollector::getCIMClass(IWbemClassObject *pObject,
1094 CIMClass & cimClass,
1095 Boolean localOnly,
1096 Boolean includeQualifiers,
1097 Boolean includeClassOrigin,
1098 const CIMPropertyList& propertyList)
1099 {
1100 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getCIMClass()");
1101
1102 CIMObject cimObj = cimClass;
1103
1104 getCIMObject(pObject, cimObj, localOnly, includeQualifiers,
1105 includeClassOrigin, propertyList);
1106
1107 CIMClass newClass(cimObj);
1108 cimClass = newClass;
1109
|
1110 kumpf 1.5 // Get methods for classes only
1111 getClassMethods(pObject, cimClass, localOnly, includeQualifiers,
1112 includeClassOrigin);
1113
|
1114 kumpf 1.1 PEG_METHOD_EXIT();
|
1115 kumpf 1.3
|
1116 kumpf 1.1 return true;
1117 }
1118
1119 /////////////////////////////////////////////////////////////////////////////
1120 // WMICollector::getClassName - return the value of the __CLASS
1121 // property of pObject
1122 //
|
1123 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1124 kumpf 1.1 String WMICollector::getClassName(IWbemClassObject *pObject)
1125 {
1126 CComBSTR bsClass = "__CLASS";
1127
1128 return getStringProperty(pObject, bsClass);
1129 }
1130
1131 /////////////////////////////////////////////////////////////////////////////
1132 // WMICollector::getRelativePath - return the value of the __RELPATH
1133 // property of pClass
1134 //
|
1135 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1136 kumpf 1.1 String WMICollector::getRelativePath(IWbemClassObject *pObject)
1137 {
1138 CComBSTR bsRelPath = "__RELPATH";
1139
1140 return getStringProperty(pObject, bsRelPath);
1141 }
1142
1143 /////////////////////////////////////////////////////////////////////////////
1144 // WMICollector::getSuperClass - return the value of the __SUPERCLASS
1145 // property of pClass
1146 //
|
1147 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1148 kumpf 1.1 String WMICollector::getSuperClass(IWbemClassObject *pClass)
1149 {
1150 CComBSTR bsSuperClass = "__SUPERCLASS";
1151
1152 return getStringProperty(pClass, bsSuperClass);
1153 }
1154
1155 /////////////////////////////////////////////////////////////////////////////
1156 // WMICollector::isInstance - returns true if pObject represents a
1157 // WMI instance - false if it is a class
1158 //
|
1159 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1160 kumpf 1.1 bool WMICollector::isInstance(IWbemClassObject *pObject)
1161 {
1162 String sClass = getClassName(pObject);
1163 String sRelPath = getRelativePath(pObject);
1164
1165 return (!String::equal(sClass, sRelPath));
1166 }
1167
1168 /////////////////////////////////////////////////////////////////////////////
1169 // WMICollector::getStringProperty - helper function to retrieve specific
1170 // string properties from a class or instance object
1171 //
|
1172 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1173 kumpf 1.1 String WMICollector::getStringProperty(IWbemClassObject *pObject,
1174 const CComBSTR &bsPropertyName)
1175 {
|
1176 kumpf 1.3 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getStringProperty()");
1177
|
1178 kumpf 1.1 HRESULT hr;
1179 CComVariant vValue;
1180 CComBSTR bs;
|
1181 kumpf 1.3 CMyString s = "";
1182 CMyString name; name = bsPropertyName;
1183
|
1184 kumpf 1.1 hr = pObject->Get(bsPropertyName, 0, &vValue, NULL, NULL);
1185 if (SUCCEEDED(hr))
1186 {
1187 if (VT_NULL != vValue.vt)
1188 { // there is a value... if not we will return an empty string...
1189 bs = vValue.bstrVal;
1190
1191 if (0 != bs.Length())
1192 {
1193 s = bs;
1194 }
1195 }
1196
|
1197 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1198 kumpf 1.1 "WMICollector::getStringProperty() - Value for %s is %s",
|
1199 marek 1.12 (LPCTSTR)name, (LPCTSTR)s));
|
1200 kumpf 1.1 }
1201 else
1202 {
|
1203 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1204 kumpf 1.1 "WMICollector::getStringProperty() - get result for %s is %x",
|
1205 marek 1.12 (LPCTSTR)name, hr));
|
1206 kumpf 1.1 }
1207
1208 PEG_METHOD_EXIT();
1209
1210 if (VT_NULL == vValue.vt)
1211 {
|
1212 kumpf 1.5 vValue.Clear();
|
1213 kumpf 1.1 return String::EMPTY;
1214 }
1215 else
1216 {
|
1217 kumpf 1.5 vValue.Clear();
|
1218 kumpf 1.1 return String((LPCTSTR)s);
1219 }
1220 }
1221
1222 /////////////////////////////////////////////////////////////////////////////
1223 // WMICollector::getObjectProperties - retrieves the
1224 // object property definitions and values, if any,
1225 // and adds them to the CIMObject instance
1226 //
|
1227 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1228 kumpf 1.1 bool WMICollector::getObjectProperties(IWbemClassObject *pObject,
1229 CIMObject & cimObj,
1230 Boolean localOnly,
1231 Boolean includeQualifiers,
1232 Boolean includeClassOrigin,
1233 const CIMPropertyList& propertyList,
1234 Boolean bGetKeyProperties)
1235 {
1236 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getObjectProperties()");
1237
1238 long lFlags = (localOnly) ? WBEM_FLAG_LOCAL_ONLY : WBEM_FLAG_NONSYSTEM_ONLY;
1239
1240 if (propertyList.isNull())
1241 { // we want all the properties...
1242 getAllProperties(pObject, lFlags,
1243 includeQualifiers, includeClassOrigin,
1244 cimObj);
1245 }
1246
1247 else if (0 != propertyList.size())
1248 { // just get the ones requested
1249 kumpf 1.1 getProperties(pObject, localOnly, includeQualifiers,
1250 includeClassOrigin, propertyList, cimObj);
1251 }
1252
1253 // else we have an empty list and don't want any
1254
1255 // if being called from getInstance, need to be sure that
1256 // the key properties are retrieved...
1257 if (bGetKeyProperties)
1258 {
1259 getAllProperties(pObject, WBEM_FLAG_KEYS_ONLY,
1260 includeQualifiers, includeClassOrigin,
1261 cimObj);
1262 }
1263
1264 PEG_METHOD_EXIT();
1265
1266 return true;
1267 }
1268
1269 /////////////////////////////////////////////////////////////////////////////
1270 kumpf 1.1 // WMICollector::getProperty
1271 // create a CIMProperty object from
1272 // WMI data
1273 //
|
1274 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1275 kumpf 1.3 CIMProperty WMICollector::getProperty(IWbemClassObject *pClass,
1276 const CComBSTR &bsName,
1277 const CComVariant &vValue,
1278 CIMTYPE type,
1279 Boolean includeClassOrigin,
1280 Boolean includeQualifiers,
|
1281 kumpf 1.1 Boolean bPropagated)
1282 {
|
1283 kumpf 1.3 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getProperty()");
1284
|
1285 kumpf 1.1 HRESULT hr = S_OK;
|
1286 kumpf 1.3 String sMessage;
|
1287 kumpf 1.2 CIMProperty property;
|
1288 kumpf 1.3 CMyString sPropName; sPropName = bsName;
|
1289 kumpf 1.1 long iSize = sPropName.GetLength();
1290
|
1291 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1292 kumpf 1.1 "WMICollector::getProperty() - Property Name is %s, type is %x, CIMTYPE is %x",
|
1293 marek 1.12 (LPCTSTR)sPropName, vValue.vt, type));
|
1294 kumpf 1.1
1295 // put this in to check XP - @bbp
1296 if (VT_BSTR == vValue.vt)
1297 {
1298 CComBSTR bs;
1299 bs.Empty();
1300 bs.Append(vValue.bstrVal);
1301 sPropName = bs;
1302 iSize = sPropName.GetLength();
|
1303 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1304 kumpf 1.1 "WMICollector::getProperty() - Property Value is %s, size is %x",
|
1305 marek 1.12 (LPCTSTR)sPropName, iSize));
|
1306 kumpf 1.1 }
1307
|
1308 kumpf 1.2 CComPtr<IWbemQualifierSet> pQualifiers;
|
1309 kumpf 1.1
1310 // get the qualifier set for the properties
1311 sMessage = "GetPropertyQualifierSet()";
1312 hr = pClass->GetPropertyQualifierSet(bsName, &pQualifiers);
1313
1314 if (SUCCEEDED(hr))
1315 {
1316 property = WMIProperty(bsName, vValue, type, pQualifiers, includeQualifiers);
1317
1318 // set the property qualifier
1319 property.setPropagated(bPropagated);
1320 }
1321
1322 // check if requested ClassOrigin qualifier
1323 // ATTN:
1324 // This is a bug in Pegasus. It will put it
1325 // the current class for GetClass if it isn't
1326 // there.
1327 if ((includeClassOrigin /*|| bPropagated*/) && SUCCEEDED(hr))
1328 {
1329 CComBSTR bsClassOrigin;
1330 kumpf 1.1 sMessage = "GetPropertyOrigin()";
1331
1332 hr = pClass->GetPropertyOrigin(bsName, & bsClassOrigin);
1333
1334 if (SUCCEEDED(hr))
1335 {
1336 property.setClassOrigin(WMIString(bsClassOrigin));
1337 }
1338 }
1339
|
1340 kumpf 1.3 if (pQualifiers)
1341 pQualifiers.Release();
1342
|
1343 kumpf 1.1 if (FAILED(hr))
1344 {
|
1345 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1346 "WMICollector::getProperty() - %s result is %x", sMessage, hr));
|
1347 kumpf 1.3
|
1348 kumpf 1.1 throw CIMException(CIM_ERR_FAILED);
1349 }
1350
1351 PEG_METHOD_EXIT();
|
1352 kumpf 1.3
|
1353 kumpf 1.1 return property;
1354 }
1355
1356 /////////////////////////////////////////////////////////////////////////////
|
1357 kumpf 1.5 // WMICollector::getClassMethods - retrieves the
1358 // class method definitions and parameters, if any,
1359 // and adds them to the CIMClass instance
1360 //
1361 /////////////////////////////////////////////////////////////////////////////
1362 bool WMICollector::getClassMethods(IWbemClassObject *pObject,
1363 CIMClass & cimClass,
1364 Boolean localOnly,
1365 Boolean includeQualifiers,
1366 Boolean includeClassOrigin)
1367 {
1368 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getClasslMethods()");
1369
1370 long lFlags = (localOnly) ? WBEM_FLAG_LOCAL_ONLY : 0L;
1371
1372 // we want all the methods...
1373 getAllMethods(pObject, lFlags, includeQualifiers, includeClassOrigin, cimClass);
1374
1375 PEG_METHOD_EXIT();
1376
1377 return true;
1378 kumpf 1.5 }
1379
1380 /////////////////////////////////////////////////////////////////////////////
1381 // WMICollector::getMethod
1382 // create a CIMMethod object from
1383 // WMI data
1384 //
1385 /////////////////////////////////////////////////////////////////////////////
1386 CIMMethod WMICollector::getMethod(IWbemClassObject *pClass,
1387 const CComBSTR &bsName,
1388 const CComPtr<IWbemClassObject> &inParameters,
1389 const CComPtr<IWbemClassObject> &outParameters,
1390 Boolean includeClassOrigin,
1391 Boolean includeQualifiers,
1392 Boolean bPropagated)
1393 {
1394 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::getMethod()");
1395
1396 HRESULT hr = S_OK;
1397 String sMessage;
1398 CIMMethod method;
1399 kumpf 1.5 CMyString sMethodName; sMethodName = bsName;
1400 long iSize = sMethodName.GetLength();
1401
|
1402 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1403 kumpf 1.5 "WMICollector::getMethod() - Method Name is %s",
|
1404 marek 1.12 (LPCTSTR)sMethodName));
|
1405 kumpf 1.5
1406
1407 CComPtr<IWbemQualifierSet> pQualifiers;
1408
1409 // get the qualifier set for the method
1410 sMessage = "GetMethodQualifierSet()";
1411 hr = pClass->GetMethodQualifierSet(bsName, &pQualifiers);
1412
1413 if (SUCCEEDED(hr))
1414 {
1415 method = WMIMethod(bsName, inParameters, outParameters, pQualifiers, includeQualifiers);
1416
1417 // set the method qualifier
1418 method.setPropagated(bPropagated);
1419 }
1420
1421 // check if requested ClassOrigin qualifier
1422 // ATTN:
1423 // This is a bug in Pegasus. It will put it
1424 // the current class for GetClass if it isn't
1425 // there.
1426 kumpf 1.5 if ((includeClassOrigin /*|| bPropagated*/) && SUCCEEDED(hr))
1427 {
1428 CComBSTR bsClassOrigin;
1429 sMessage = "GetMethodOrigin()";
1430
1431 hr = pClass->GetMethodOrigin(bsName, & bsClassOrigin);
1432
1433 if (SUCCEEDED(hr))
1434 {
1435 method.setClassOrigin(WMIString(bsClassOrigin));
1436 }
1437 }
1438
1439 if (pQualifiers)
1440 pQualifiers.Release();
1441
1442 if (FAILED(hr))
1443 {
|
1444 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1445 "WMICollector::getMethod() - %s result is %x", sMessage, hr));
|
1446 kumpf 1.5
1447 throw CIMException(CIM_ERR_FAILED);
1448 }
1449
1450 PEG_METHOD_EXIT();
1451
1452 return method;
1453 }
1454
1455 /////////////////////////////////////////////////////////////////////////////
|
1456 kumpf 1.1 // WMICollector::setNamespace
1457 //
1458 //
|
1459 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
|
1460 kumpf 1.1 void WMICollector::setNamespace(const String & sNamespace)
1461 {
|
1462 kumpf 1.3 String s;
|
1463 kumpf 1.1
1464 String sLower = sNamespace;
1465 sLower.toLower();
|
1466 kumpf 1.3 Uint32 pos = sLower.find("root");
|
1467 kumpf 1.1
|
1468 kumpf 1.2 m_bIsLocalNamespace = (0 == pos);
|
1469 kumpf 1.1
|
1470 kumpf 1.2 if (m_bIsLocalNamespace)
|
1471 kumpf 1.1 {
|
1472 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1473 "WMICollector::setNamespace() - Namespace %s is local", sNamespace.getCString()));
|
1474 kumpf 1.3 s = sNamespace;
|
1475 kumpf 1.1 }
1476 else
1477 {
|
1478 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1479 "WMICollector::setNamespace() - Namespace %s is remote", sNamespace.getCString()));
|
1480 kumpf 1.1
|
1481 kumpf 1.2 // by Jair
1482 // adjust the namespace to accept DNS fully qualified names
1483 // and IP addresses.
1484 String str = sNamespace;
1485 for (Uint32 i = 0; i < pos - 1; i++)
1486 {
1487 if (str[i] == '/')
1488 {
|
1489 kumpf 1.5 // have a '.' encoded as '/' -- convert back to '.':
|
1490 kumpf 1.2 str[i] = '.';
1491 }
1492 else if (str[i] == '_')
1493 {
|
1494 kumpf 1.5 if (str[i + 1] == '_' &&
1495 iswxdigit(str[i + 2]) &&
1496 iswxdigit(str[i + 3]))
1497 {
1498 // have a non-alpha char (punctuation, etc.) encoded as
1499 // "__XX", where XX is the hex representation of the char
1500 String hexStr = str.subString(i+2, 2);
1501 Char16 punctChar = (Char16)wcstol(
1502 (const wchar_t *)hexStr.getChar16Data(), NULL, 16);
1503 // replace the first underscore with the non-alpha char:
1504 str[i] = punctChar;
1505 // remove the second underscore + 2 hex chars:
1506 str.remove(i+1, 3);
1507 pos -= 3;
1508 }
1509 else if (iswdigit(str[i + 1]))
|
1510 kumpf 1.2 {
|
1511 kumpf 1.5 if ((i == 0) || (str[i - 1] == '.'))
|
1512 kumpf 1.2 {
|
1513 kumpf 1.5 // have a leading digit pre-pended with an underscore
1514 // remove the underscore:
|
1515 kumpf 1.2 str.remove(i, 1);
1516 pos--;
1517 }
1518 }
1519 }
1520 }
1521
1522 //prepend "//" to namespace
|
1523 kumpf 1.3 s = "//";
1524 s.append(str);
|
1525 kumpf 1.2 }
1526
|
1527 kumpf 1.3 m_bsNamespace = s.getCString();
|
1528 kumpf 1.2 }
1529
1530 /////////////////////////////////////////////////////////////////////////////
1531 // WMICollector::setUserName
1532 //
1533 //
1534 /////////////////////////////////////////////////////////////////////////////
1535 void WMICollector::setUserName(const String & sUserName)
1536 {
|
1537 kumpf 1.3 String sUser = sUserName;
1538 String sDomain = ".";
1539
1540 Uint32 pos = sUser.find("/");
1541
1542 if (PEG_NOT_FOUND == pos)
1543 pos = sUser.find("\\");
1544
1545 if (pos != PEG_NOT_FOUND)
1546 {
|
1547 kumpf 1.5 sDomain = sUser.subString(0, pos);
1548 sUser.remove(0, pos + 1);
|
1549 kumpf 1.3 }
1550
|
1551 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1552 kumpf 1.3 "WMICollector::setUserName() - UserName [%s], Domain [%s]",
|
1553 marek 1.12 sUser.getCString(), sDomain.getCString()));
|
1554 kumpf 1.3
1555 m_bsUserName = sUser.getCString();
1556 m_bsDomain = sDomain.getCString();
|
1557 kumpf 1.2 }
|
1558 kumpf 1.1
|
1559 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
1560 // WMICollector::setPassword
1561 //
1562 //
1563 // ///////////////////////////////////////////////////////////////////////////
1564 void WMICollector::setPassword(const String & sPassword)
1565 {
|
1566 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1567 "WMICollector::setPassword() - Password %s", sPassword.getCString()));
|
1568 kumpf 1.2
|
1569 kumpf 1.3 m_bsPassword = sPassword.getCString();
|
1570 kumpf 1.1 }
1571
|
1572 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
1573 // WMICollector::setProxySecurity
1574 //
1575 //
1576 /////////////////////////////////////////////////////////////////////////////
1577 bool WMICollector::setProxySecurity(IUnknown * pProxy)
1578 {
|
1579 kumpf 1.5 PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMICollector::setProxySecurity()");
1580
1581 HRESULT hr;
|
1582 kumpf 1.2
1583 if(m_bIsLocalNamespace)
1584 {
|
1585 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1586 kumpf 1.5 "WMICollector::setProxySecurity() - m_bIsLocalNamespace is true");
1587
1588 hr = CoSetProxyBlanket(
|
1589 kumpf 1.2 pProxy,
1590 RPC_C_AUTHN_WINNT, // NTLM authentication service
1591 RPC_C_AUTHZ_NONE, // default authorization service...
1592 NULL, // no mutual authentication
1593 RPC_C_AUTHN_LEVEL_PKT, // authentication Tracer::LEVEL
1594 RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation Tracer::LEVEL
1595 NULL,
|
1596 mateus.baur 1.10 EOAC_DYNAMIC_CLOAKING); // enable dynamic cloaking, so
1597 // impersonation token is propagated to WMI
|
1598 kumpf 1.2 }
1599 else
1600 {
|
1601 marek 1.12 PEG_TRACE_CSTRING(TRC_WMIPROVIDER, Tracer::LEVEL3,
|
1602 kumpf 1.5 "WMICollector::setProxySecurity() - m_bIsLocalNamespace is false");
1603
1604 // set security attributes on pProxy
|
1605 kumpf 1.2 COAUTHIDENTITY authident;
1606
1607 memset((void *)&authident,0,sizeof(COAUTHIDENTITY));
|
1608 kumpf 1.1
|
1609 kumpf 1.2 authident.UserLength = (ULONG)m_bsUserName.Length();
1610 authident.User = (LPWSTR)m_bsUserName.m_str;
1611 authident.PasswordLength = (ULONG)m_bsPassword.Length();
1612 authident.Password = (LPWSTR)m_bsPassword.m_str;
1613 authident.DomainLength = (ULONG)m_bsDomain.Length();
1614 authident.Domain = (LPWSTR)m_bsDomain.m_str;
1615 authident.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
1616 kumpf 1.1
|
1617 kumpf 1.2 hr = CoSetProxyBlanket(
1618 pProxy,
1619 RPC_C_AUTHN_WINNT, // NTLM authentication service
1620 RPC_C_AUTHZ_NONE, // default authorization service...
1621 NULL, // no mutual authentication
1622 RPC_C_AUTHN_LEVEL_PKT, // authentication Tracer::LEVEL
1623 RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation Tracer::LEVEL
1624 &authident,
|
1625 mateus.baur 1.10 EOAC_NONE); // EOAC_DYNAMIC_CLOAKING seems to fail on remote WMI calls,
1626 // or when COAUTHIDENTITY info is sent (as in this case),
1627 // so going back to EOC_NONE for this case only.
|
1628 kumpf 1.2 }
|
1629 kumpf 1.5
|
1630 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1631 "WMICollector::setProxySecurity() - return from CoSetProxyBlanket() is %x", hr));
|
1632 kumpf 1.5
1633 PEG_METHOD_EXIT();
|
1634 kumpf 1.2 return SUCCEEDED(hr);
1635 }
|
1636 kumpf 1.1
1637 /////////////////////////////////////////////////////////////////////////////
|
1638 kumpf 1.2 // WMICollector::logonUser
1639 //
|
1640 kumpf 1.1 //
|
1641 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
1642 void WMICollector::logonUser()
1643 {
1644 CMyString sUserName, sDomain, sPassword;
1645
1646 sUserName = (LPWSTR)m_bsUserName.m_str;
1647 sDomain = (LPWSTR)m_bsDomain.m_str;
1648 sPassword = (LPWSTR)m_bsPassword.m_str;
1649
1650 LPTSTR pszUserName = (LPTSTR)(LPCTSTR)sUserName;
1651 LPTSTR pszDomain = (LPTSTR)(LPCTSTR)sDomain;
1652 LPTSTR pszPassword = (LPTSTR)(LPCTSTR)sPassword;
1653
1654 //Logon and impersonate the user
1655 if(!RevertToSelf())
1656 {
1657 DWORD error = GetLastError();
1658
|
1659 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1660 "WMICollector::logonUser() - return from RevertToSelf() is %d", error));
|
1661 kumpf 1.2
1662 throw CIMException(CIM_ERR_ACCESS_DENIED, "RevertToSelf()");
1663 }
1664
1665 HANDLE htok = 0;
1666 if(!LogonUser(pszUserName,
1667 pszDomain,
1668 pszPassword,
1669 LOGON32_LOGON_INTERACTIVE,
1670 LOGON32_PROVIDER_DEFAULT,
1671 &htok))
1672 {
1673 DWORD error = GetLastError();
1674
|
1675 marek 1.12 PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL3,
1676 "WMICollector::logonUser() - return from LogonUser() is %d", error));
|
1677 kumpf 1.2
|
1678 kumpf 1.5 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1679 "Failed to login user \"$0/$1\". Invalid username or password.",
1680 pszDomain, pszUserName);
1681
1682 throw CIMException(CIM_ERR_ACCESS_DENIED, "LogonUser()");
|
1683 kumpf 1.2 }
1684
1685 if(!ImpersonateLoggedOnUser(htok))
1686 {
1687 DWORD error = GetLastError();
|
1688 kumpf 1.3 CloseHandle(htok);
|
1689 kumpf 1.2
|
1690 kumpf 1.5 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1691 "Failed to impersonate logged-in user \"$0/$1\".",
1692 pszDomain, pszUserName);
1693
|
1694 kumpf 1.2 throw CIMException(CIM_ERR_ACCESS_DENIED, "ImpersonateLoggedOnUser()");
1695 }
|
1696 kumpf 1.1
|
1697 kumpf 1.3 CloseHandle(htok);
|
1698 kumpf 1.2 m_bImpersonate = true;
1699 }
|
1700 kumpf 1.1
|
1701 kumpf 1.2 /////////////////////////////////////////////////////////////////////////////
1702 // WMICollector::revertToSelf
1703 //
1704 //
1705 /////////////////////////////////////////////////////////////////////////////
1706 void WMICollector::revertToSelf()
1707 {
1708 if(!RevertToSelf())
1709 {
1710 throw CIMException(CIM_ERR_FAILED, "RevertToSelf()");
1711 }
1712 }
|
1713 kumpf 1.1
|
1714 kumpf 1.3 PEGASUS_NAMESPACE_END
|