Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1614 lines
39 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation
  4. //
  5. // SERVICES.CPP
  6. //
  7. // alanbos 15-Aug-96 Created.
  8. //
  9. // Defines the implementation of ISWbemServicesEx
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. //***************************************************************************
  14. //
  15. // CSWbemServices::CSWbemServices
  16. //
  17. // DESCRIPTION:
  18. //
  19. // Constructor.
  20. //
  21. //***************************************************************************
  22. CSWbemServices::CSWbemServices(
  23. IWbemServices *pService,
  24. BSTR bsNamespacePath,
  25. BSTR bsAuthority,
  26. BSTR bsUser,
  27. BSTR bsPassword,
  28. CWbemLocatorSecurity *pSecurityInfo,
  29. BSTR bsLocale)
  30. : m_SecurityInfo (NULL),
  31. m_pUnsecuredApartment(NULL),
  32. m_bsLocale (NULL),
  33. m_cRef (0),
  34. m_pIServiceProvider (NULL)
  35. {
  36. InterlockedIncrement(&g_cObj);
  37. m_Dispatch.SetObj ((ISWbemServicesEx *)this, IID_ISWbemServicesEx,
  38. CLSID_SWbemServicesEx, L"SWbemServicesEx");
  39. m_SecurityInfo = new CSWbemSecurity (pService,
  40. bsAuthority, bsUser, bsPassword, pSecurityInfo);
  41. if (bsLocale)
  42. m_bsLocale = SysAllocString (bsLocale);
  43. if (bsNamespacePath)
  44. m_bsNamespacePath = bsNamespacePath;
  45. }
  46. //***************************************************************************
  47. //
  48. // CSWbemServices::CSWbemServices
  49. //
  50. // DESCRIPTION:
  51. //
  52. // Constructor.
  53. //
  54. //***************************************************************************
  55. CSWbemServices::CSWbemServices(
  56. IWbemServices *pService,
  57. BSTR bsNamespacePath,
  58. COAUTHIDENTITY *pCoAuthIdentity,
  59. BSTR bsPrincipal,
  60. BSTR bsAuthority)
  61. : m_SecurityInfo (NULL),
  62. m_pUnsecuredApartment(NULL),
  63. m_bsLocale (NULL),
  64. m_cRef (0),
  65. m_pIServiceProvider (NULL)
  66. {
  67. InterlockedIncrement(&g_cObj);
  68. m_Dispatch.SetObj ((ISWbemServicesEx *)this, IID_ISWbemServicesEx,
  69. CLSID_SWbemServicesEx, L"SWbemServicesEx");
  70. m_SecurityInfo = new CSWbemSecurity (pService, pCoAuthIdentity,
  71. bsPrincipal, bsAuthority);
  72. if (bsNamespacePath)
  73. m_bsNamespacePath = bsNamespacePath;
  74. }
  75. //***************************************************************************
  76. //
  77. // CSWbemServices::CSWbemServices
  78. //
  79. // DESCRIPTION:
  80. //
  81. // Constructor: used to clone a new CSWbemServices from an exisiting
  82. // instance. The security info object is copied from the original instance
  83. // (which clones the underlying proxy), and the security settings are modified
  84. // appropriately if an override security instance is also passed in. This
  85. // constructor is used when creating a CSWbemObject.
  86. //
  87. //***************************************************************************
  88. CSWbemServices::CSWbemServices(
  89. CSWbemServices *pService,
  90. CSWbemSecurity *pSecurity)
  91. : m_SecurityInfo (NULL),
  92. m_pUnsecuredApartment(NULL),
  93. m_bsLocale (NULL),
  94. m_cRef (0),
  95. m_pIServiceProvider (NULL)
  96. {
  97. InterlockedIncrement(&g_cObj);
  98. m_Dispatch.SetObj ((ISWbemServicesEx *)this, IID_ISWbemServicesEx,
  99. CLSID_SWbemServicesEx, L"SWbemServicesEx");
  100. if (pService)
  101. {
  102. /*
  103. * Make a new security object from the one contained in the original
  104. * CSWbemServices. Note that this will copy the IWbemServices proxy
  105. * so we have an independently securable proxy for this new object.
  106. */
  107. CSWbemSecurity *pServiceSecurity = pService->GetSecurityInfo ();
  108. if (pServiceSecurity)
  109. {
  110. m_SecurityInfo = new CSWbemSecurity (pServiceSecurity);
  111. pServiceSecurity->Release ();
  112. }
  113. /*
  114. * If an overriding security pointer was passed in, use its' settings to
  115. * modify our local security pointer.
  116. */
  117. if (pSecurity)
  118. {
  119. IUnknown *pUnk = pSecurity->GetProxy ();
  120. if (pUnk)
  121. {
  122. if (m_SecurityInfo)
  123. m_SecurityInfo->SecureInterfaceRev (pUnk);
  124. pUnk->Release ();
  125. }
  126. }
  127. // Copy the locale
  128. m_bsLocale = SysAllocString (pService->GetLocale ());
  129. // Copy the path
  130. m_bsNamespacePath = pService->GetPath ();
  131. }
  132. }
  133. //***************************************************************************
  134. //
  135. // CSWbemServices::CSWbemServices
  136. //
  137. // DESCRIPTION:
  138. //
  139. // Constructor: used to clone a new CSWbemServices from an exisiting
  140. // ISWbemInternalServices interface. The security info object is copied from
  141. // the original instance (which clones the underlying proxy). This
  142. // constructor is used when creating a CSWbemRefreshableItem.
  143. //
  144. //***************************************************************************
  145. CSWbemServices::CSWbemServices (
  146. ISWbemInternalServices *pISWbemInternalServices)
  147. : m_SecurityInfo (NULL),
  148. m_pUnsecuredApartment (NULL),
  149. m_bsLocale (NULL),
  150. m_cRef (0),
  151. m_pIServiceProvider (NULL)
  152. {
  153. InterlockedIncrement(&g_cObj);
  154. m_Dispatch.SetObj ((ISWbemServicesEx *)this, IID_ISWbemServicesEx,
  155. CLSID_SWbemServicesEx, L"SWbemServicesEx");
  156. if (pISWbemInternalServices)
  157. {
  158. // Copy the locale
  159. pISWbemInternalServices->GetLocale (&m_bsLocale);
  160. // Copy the path
  161. pISWbemInternalServices->GetNamespacePath (&m_bsNamespacePath);
  162. /*
  163. * Make a new security object from the one contained in the original
  164. * ISWbemServices. Note that this will copy the IWbemServices proxy
  165. * so we have an independently securable proxy for this new object.
  166. */
  167. ISWbemInternalSecurity *pISWbemInternalSecurity = NULL;
  168. pISWbemInternalServices->GetISWbemInternalSecurity (&pISWbemInternalSecurity);
  169. if (pISWbemInternalSecurity)
  170. {
  171. CComPtr<IWbemServices> pIWbemServices;
  172. if (SUCCEEDED(pISWbemInternalServices->GetIWbemServices (&pIWbemServices)))
  173. {
  174. m_SecurityInfo = new CSWbemSecurity (pIWbemServices,
  175. pISWbemInternalSecurity);
  176. pISWbemInternalSecurity->Release ();
  177. }
  178. }
  179. }
  180. }
  181. //***************************************************************************
  182. //
  183. // CSWbemServices::CSWbemServices
  184. //
  185. // DESCRIPTION:
  186. //
  187. // Constructor: used to build a new CSWbemServices from an IWbemServices
  188. // and a existing CSWbemServices
  189. //
  190. //***************************************************************************
  191. CSWbemServices::CSWbemServices(
  192. IWbemServices *pIWbemServices,
  193. CSWbemServices *pCSWbemServices
  194. ) : m_SecurityInfo (NULL),
  195. m_pUnsecuredApartment(NULL),
  196. m_bsLocale (NULL),
  197. m_cRef (0),
  198. m_pIServiceProvider (NULL)
  199. {
  200. InterlockedIncrement(&g_cObj);
  201. m_Dispatch.SetObj ((ISWbemServices *)this, IID_ISWbemServices,
  202. CLSID_SWbemServices, L"SWbemServices");
  203. if (pIWbemServices)
  204. {
  205. // Make a new security cache based on the proxy passed in, but use the
  206. // settings from the existing object
  207. CSWbemSecurity *pSecurity = NULL;
  208. if (pCSWbemServices)
  209. pSecurity = pCSWbemServices->GetSecurityInfo ();
  210. m_SecurityInfo = new CSWbemSecurity (pIWbemServices, pSecurity);
  211. if (pSecurity)
  212. pSecurity->Release ();
  213. // Copy the locale and path
  214. if (pCSWbemServices)
  215. {
  216. m_bsLocale = SysAllocString (pCSWbemServices->GetLocale ());
  217. m_bsNamespacePath = pCSWbemServices->GetPath ();
  218. }
  219. }
  220. }
  221. //***************************************************************************
  222. //
  223. // CSWbemServices::~CSWbemServices
  224. //
  225. // DESCRIPTION:
  226. //
  227. // Destructor.
  228. //
  229. //***************************************************************************
  230. CSWbemServices::~CSWbemServices(void)
  231. {
  232. RELEASEANDNULL(m_SecurityInfo)
  233. FREEANDNULL(m_bsLocale)
  234. RELEASEANDNULL(m_pUnsecuredApartment)
  235. InterlockedDecrement(&g_cObj);
  236. }
  237. IUnsecuredApartment *CSWbemServices::GetCachedUnsecuredApartment()
  238. {
  239. // If we have one just return with it. If not create one.
  240. // This is released in the destructor
  241. if (!m_pUnsecuredApartment)
  242. {
  243. HRESULT hr;
  244. hr = CoCreateInstance(CLSID_UnsecuredApartment, 0, CLSCTX_ALL,
  245. IID_IUnsecuredApartment, (LPVOID *) &m_pUnsecuredApartment);
  246. if (FAILED(hr))
  247. m_pUnsecuredApartment = NULL;
  248. }
  249. // AddRef so caller must release
  250. if (m_pUnsecuredApartment)
  251. m_pUnsecuredApartment->AddRef ();
  252. return m_pUnsecuredApartment;
  253. }
  254. //***************************************************************************
  255. // HRESULT CSWbemServices::QueryInterface
  256. // long CSWbemServices::AddRef
  257. // long CSWbemServices::Release
  258. //
  259. // DESCRIPTION:
  260. //
  261. // Standard Com IUNKNOWN functions.
  262. //
  263. //***************************************************************************
  264. STDMETHODIMP CSWbemServices::QueryInterface (
  265. IN REFIID riid,
  266. OUT LPVOID *ppv
  267. )
  268. {
  269. *ppv = NULL;
  270. if (IID_IUnknown==riid)
  271. *ppv = reinterpret_cast<IUnknown*>(this);
  272. else if (IID_ISWbemServices==riid)
  273. *ppv = (ISWbemServices *)this;
  274. else if (IID_ISWbemServicesEx==riid)
  275. *ppv = (ISWbemServicesEx *)this;
  276. else if (IID_IDispatch==riid)
  277. *ppv = (IDispatch *)((ISWbemServicesEx *)this);
  278. else if (IID_IDispatchEx==riid)
  279. *ppv = (IDispatchEx *)this;
  280. else if (IID_ISupportErrorInfo==riid)
  281. *ppv = (ISupportErrorInfo *)this;
  282. else if (IID_ISWbemInternalServices==riid)
  283. *ppv = (ISWbemInternalServices *)this;
  284. else if (IID_IProvideClassInfo==riid)
  285. *ppv = (IProvideClassInfo *)this;
  286. if (NULL!=*ppv)
  287. {
  288. ((LPUNKNOWN)*ppv)->AddRef();
  289. return NOERROR;
  290. }
  291. return ResultFromScode(E_NOINTERFACE);
  292. }
  293. STDMETHODIMP_(ULONG) CSWbemServices::AddRef(void)
  294. {
  295. InterlockedIncrement(&m_cRef);
  296. return m_cRef;
  297. }
  298. STDMETHODIMP_(ULONG) CSWbemServices::Release(void)
  299. {
  300. InterlockedDecrement(&m_cRef);
  301. if (0L!=m_cRef)
  302. return m_cRef;
  303. delete this;
  304. return 0;
  305. }
  306. // IDispatch methods should be inline
  307. STDMETHODIMP CSWbemServices::GetTypeInfoCount(UINT* pctinfo)
  308. {
  309. _RD(static char *me = "CSWbemServices::GetTypeInfoCount()";)
  310. _RPrint(me, "Called", 0, "");
  311. return m_Dispatch.GetTypeInfoCount(pctinfo);}
  312. STDMETHODIMP CSWbemServices::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  313. {
  314. _RD(static char *me = "CSWbemServices::GetTypeInfo()";)
  315. _RPrint(me, "Called", 0, "");
  316. return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  317. STDMETHODIMP CSWbemServices::GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  318. UINT cNames, LCID lcid, DISPID* rgdispid)
  319. {
  320. _RD(static char *me = "CSWbemServices::GetIdsOfNames()";)
  321. _RPrint(me, "Called", 0, "");
  322. return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  323. lcid,
  324. rgdispid);}
  325. STDMETHODIMP CSWbemServices::Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  326. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  327. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  328. {
  329. _RD(static char *me = "CSWbemServices::Invoke()";)
  330. _RPrint(me, "Called", 0, "");
  331. return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  332. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  333. // IDispatchEx methods should be inline
  334. HRESULT STDMETHODCALLTYPE CSWbemServices::GetDispID(
  335. /* [in] */ BSTR bstrName,
  336. /* [in] */ DWORD grfdex,
  337. /* [out] */ DISPID __RPC_FAR *pid)
  338. {
  339. _RD(static char *me = "CSWbemServices::GetDispID()";)
  340. _RPrint(me, "Called", 0, "");
  341. return m_Dispatch.GetDispID(bstrName, grfdex, pid);
  342. }
  343. /* [local] */ HRESULT STDMETHODCALLTYPE CSWbemServices::InvokeEx(
  344. /* [in] */ DISPID id,
  345. /* [in] */ LCID lcid,
  346. /* [in] */ WORD wFlags,
  347. /* [in] */ DISPPARAMS __RPC_FAR *pdp,
  348. /* [out] */ VARIANT __RPC_FAR *pvarRes,
  349. /* [out] */ EXCEPINFO __RPC_FAR *pei,
  350. /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller)
  351. {
  352. HRESULT hr;
  353. _RD(static char *me = "CSWbemServices::InvokeEx()";)
  354. _RPrint(me, "Called", (long)id, "id");
  355. _RPrint(me, "Called", (long)wFlags, "wFlags");
  356. m_pIServiceProvider = pspCaller;
  357. hr = m_Dispatch.InvokeEx(id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
  358. m_pIServiceProvider = NULL;
  359. return hr;
  360. }
  361. HRESULT STDMETHODCALLTYPE CSWbemServices::DeleteMemberByName(
  362. /* [in] */ BSTR bstr,
  363. /* [in] */ DWORD grfdex)
  364. {
  365. _RD(static char *me = "CSWbemServices::DeleteMemberByName()";)
  366. _RPrint(me, "Called", 0, "");
  367. return m_Dispatch.DeleteMemberByName(bstr, grfdex);
  368. }
  369. HRESULT STDMETHODCALLTYPE CSWbemServices::DeleteMemberByDispID(
  370. /* [in] */ DISPID id)
  371. {
  372. _RD(static char *me = "CSWbemServices::DeletememberByDispId()";)
  373. _RPrint(me, "Called", 0, "");
  374. return m_Dispatch.DeleteMemberByDispID(id);
  375. }
  376. HRESULT STDMETHODCALLTYPE CSWbemServices::GetMemberProperties(
  377. /* [in] */ DISPID id,
  378. /* [in] */ DWORD grfdexFetch,
  379. /* [out] */ DWORD __RPC_FAR *pgrfdex)
  380. {
  381. _RD(static char *me = "CSWbemServices::GetMemberProperties()";)
  382. _RPrint(me, "Called", 0, "");
  383. return m_Dispatch.GetMemberProperties(id, grfdexFetch, pgrfdex);
  384. }
  385. HRESULT STDMETHODCALLTYPE CSWbemServices::GetMemberName(
  386. /* [in] */ DISPID id,
  387. /* [out] */ BSTR __RPC_FAR *pbstrName)
  388. {
  389. _RD(static char *me = "CSWbemServices::GetMemberName()";)
  390. _RPrint(me, "Called", 0, "");
  391. return m_Dispatch.GetMemberName(id, pbstrName);
  392. }
  393. /*
  394. * I don't think this needs implementing
  395. */
  396. HRESULT STDMETHODCALLTYPE CSWbemServices::GetNextDispID(
  397. /* [in] */ DWORD grfdex,
  398. /* [in] */ DISPID id,
  399. /* [out] */ DISPID __RPC_FAR *pid)
  400. {
  401. _RD(static char *me = "CSWbemServices::GetNextDispID()";)
  402. _RPrint(me, "Called", 0, "");
  403. return m_Dispatch.GetNextDispID(grfdex, id, pid);
  404. }
  405. HRESULT STDMETHODCALLTYPE CSWbemServices::GetNameSpaceParent(
  406. /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk)
  407. {
  408. _RD(static char *me = "CSWbemServices::GetNamespaceParent()";)
  409. _RPrint(me, "Called", 0, "");
  410. return m_Dispatch.GetNameSpaceParent(ppunk);
  411. }
  412. //***************************************************************************
  413. // HRESULT CSWbemServices::InterfaceSupportsErrorInfo
  414. //
  415. // DESCRIPTION:
  416. //
  417. // Standard Com ISupportErrorInfo functions.
  418. //
  419. //***************************************************************************
  420. STDMETHODIMP CSWbemServices::InterfaceSupportsErrorInfo (IN REFIID riid)
  421. {
  422. return ((IID_ISWbemServices == riid) ||
  423. (IID_ISWbemServicesEx == riid)) ? S_OK : S_FALSE;
  424. }
  425. //***************************************************************************
  426. //
  427. // SCODE CSWbemServices::Get
  428. //
  429. // DESCRIPTION:
  430. //
  431. // Get an instance or class from a namespace
  432. //
  433. // PARAMETERS:
  434. //
  435. // bsObjectPath Relative object path to class or instance
  436. // lFlags Flags
  437. // pContext If specified, additional context
  438. // ppObject On successful return addresses an
  439. // ISWbemObject
  440. //
  441. // RETURN VALUES:
  442. //
  443. // WBEM_S_NO_ERROR success
  444. // WBEM_E_INVALID_PARAMETER bad input parameters
  445. // WBEM_E_FAILED otherwise
  446. //
  447. //***************************************************************************
  448. HRESULT CSWbemServices::Get (
  449. BSTR objectPath,
  450. long lFlags,
  451. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  452. ISWbemObject **ppObject
  453. )
  454. {
  455. _RD(static char *me = "CSWbemServices::Get";)
  456. HRESULT hr = WBEM_E_FAILED;
  457. ResetLastErrors ();
  458. if (NULL == ppObject)
  459. hr = WBEM_E_INVALID_PARAMETER;
  460. else if (m_SecurityInfo)
  461. {
  462. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  463. if (pIWbemServices)
  464. {
  465. IWbemClassObject *pIWbemClassObject = NULL;
  466. // Get the context
  467. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  468. bool needToResetSecurity = false;
  469. HANDLE hThreadToken = NULL;
  470. _RPrint(me, "Called - context: ", (long)pIContext, "");
  471. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  472. hr = pIWbemServices->GetObject (
  473. (objectPath && (0 < wcslen(objectPath))) ? objectPath : NULL,
  474. lFlags,
  475. pIContext,
  476. &pIWbemClassObject,
  477. NULL);
  478. if (needToResetSecurity)
  479. m_SecurityInfo->ResetSecurity (hThreadToken);
  480. if (SUCCEEDED(hr))
  481. {
  482. // Create a new CSWbemObject using the IWbemClassObject interface
  483. // just returned.
  484. CSWbemObject *pObject = new CSWbemObject (this, pIWbemClassObject);
  485. if (!pObject)
  486. hr = WBEM_E_OUT_OF_MEMORY;
  487. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  488. (PPVOID) ppObject)))
  489. delete pObject;
  490. pIWbemClassObject->Release ();
  491. }
  492. SetWbemError (this);
  493. if (pIContext)
  494. pIContext->Release ();
  495. pIWbemServices->Release ();
  496. }
  497. }
  498. if (FAILED(hr))
  499. m_Dispatch.RaiseException (hr);
  500. return hr;
  501. }
  502. //***************************************************************************
  503. //
  504. // SCODE CSWbemServices::Delete
  505. //
  506. // DESCRIPTION:
  507. //
  508. // Delete an instance or class from a namespace
  509. //
  510. // PARAMETERS:
  511. //
  512. // bsObjectPath Relative path of class or instance
  513. // pKeyValue Single key value
  514. // lFlags Flags
  515. // pContext Any context info
  516. //
  517. // RETURN VALUES:
  518. //
  519. // WBEM_S_NO_ERROR success
  520. // WBEM_E_INVALID_PARAMETER bad input parameters
  521. // WBEM_E_FAILED otherwise
  522. //
  523. //***************************************************************************
  524. HRESULT CSWbemServices::Delete (
  525. BSTR bsObjectPath,
  526. long lFlags,
  527. /*ISWbemValueBag*/ IDispatch *pContext
  528. )
  529. {
  530. HRESULT hr = WBEM_E_FAILED;
  531. ResetLastErrors ();
  532. if (m_SecurityInfo)
  533. {
  534. CWbemPathCracker pathCracker (bsObjectPath);
  535. if ((CWbemPathCracker::WbemPathType::wbemPathTypeError != pathCracker.GetType ()) &&
  536. pathCracker.IsClassOrInstance ())
  537. {
  538. CComPtr<IWbemServices> pIWbemServices = GetIWbemServices ();
  539. if (pIWbemServices)
  540. {
  541. // Get the context
  542. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  543. bool needToResetSecurity = false;
  544. HANDLE hThreadToken = NULL;
  545. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  546. {
  547. if (pathCracker.IsInstance ())
  548. hr = pIWbemServices->DeleteInstance (bsObjectPath, lFlags, pIContext, NULL);
  549. else
  550. hr = pIWbemServices->DeleteClass (bsObjectPath, lFlags, pIContext, NULL);
  551. }
  552. if (needToResetSecurity)
  553. m_SecurityInfo->ResetSecurity (hThreadToken);
  554. SetWbemError (this);
  555. if (pIContext)
  556. pIContext->Release ();
  557. }
  558. }
  559. else
  560. hr = WBEM_E_INVALID_PARAMETER;
  561. }
  562. if (FAILED(hr))
  563. m_Dispatch.RaiseException (hr);
  564. return hr;
  565. }
  566. //***************************************************************************
  567. //
  568. // SCODE CSWbemServices::InstancesOf
  569. //
  570. // DESCRIPTION:
  571. //
  572. // Create an enumerator for instances
  573. //
  574. // PARAMETERS:
  575. //
  576. // bsClass Underlying class basis for enumeration
  577. // lFlags Flags
  578. // pContext Any context info
  579. // ppEnum On successful return holds the enumerator
  580. //
  581. // RETURN VALUES:
  582. //
  583. // WBEM_S_NO_ERROR success
  584. // WBEM_E_INVALID_PARAMETER bad input parameters
  585. // WBEM_E_FAILED otherwise
  586. //
  587. //***************************************************************************
  588. HRESULT CSWbemServices::InstancesOf (
  589. BSTR bsClass,
  590. long lFlags,
  591. /*ISWbemValueBag*/ IDispatch *pContext,
  592. ISWbemObjectSet **ppEnum
  593. )
  594. {
  595. HRESULT hr = WBEM_E_FAILED;
  596. ResetLastErrors ();
  597. if (NULL == ppEnum)
  598. hr = WBEM_E_INVALID_PARAMETER;
  599. else if (m_SecurityInfo)
  600. {
  601. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  602. if (pIWbemServices)
  603. {
  604. IEnumWbemClassObject *pIEnum = NULL;
  605. // Get the context
  606. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  607. bool needToResetSecurity = false;
  608. HANDLE hThreadToken = NULL;
  609. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  610. hr = pIWbemServices->CreateInstanceEnum (bsClass, lFlags, pIContext, &pIEnum);
  611. if (needToResetSecurity)
  612. m_SecurityInfo->ResetSecurity (hThreadToken);
  613. if (SUCCEEDED(hr))
  614. {
  615. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  616. if (!pEnum)
  617. hr = WBEM_E_OUT_OF_MEMORY;
  618. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  619. delete pEnum;
  620. pIEnum->Release ();
  621. }
  622. SetWbemError (this);
  623. if (pIContext)
  624. pIContext->Release ();
  625. pIWbemServices->Release ();
  626. }
  627. }
  628. if (FAILED(hr))
  629. m_Dispatch.RaiseException (hr);
  630. return hr;
  631. }
  632. //***************************************************************************
  633. //
  634. // SCODE CSWbemServices::ExecQuery
  635. //
  636. // DESCRIPTION:
  637. //
  638. // Execute a query
  639. //
  640. // PARAMETERS:
  641. //
  642. // bsQuery The query strimg
  643. // bsQueryLanguage The query language descriptor (e.g."WQL")
  644. // lFlags Flags
  645. // pContext Any context information
  646. // ppEnum Returns the enumerator
  647. //
  648. // RETURN VALUES:
  649. //
  650. // WBEM_S_NO_ERROR success
  651. // WBEM_E_INVALID_PARAMETER bad input parameters
  652. // WBEM_E_FAILED otherwise
  653. //
  654. //***************************************************************************
  655. HRESULT CSWbemServices::ExecQuery (
  656. BSTR bsQuery,
  657. BSTR bsQueryLanguage,
  658. long lFlags,
  659. /*ISWbemValueBag*/ IDispatch *pContext,
  660. ISWbemObjectSet **ppEnum)
  661. {
  662. HRESULT hr = WBEM_E_FAILED;
  663. ResetLastErrors ();
  664. #ifdef __RTEST_RPC_FAILURE
  665. extern int __Rx;
  666. extern bool __Rdone;
  667. __Rx = 0;
  668. __Rdone = false;
  669. #endif
  670. if (NULL == ppEnum)
  671. hr = WBEM_E_INVALID_PARAMETER;
  672. else if (m_SecurityInfo)
  673. {
  674. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  675. if (pIWbemServices)
  676. {
  677. IEnumWbemClassObject *pIEnum = NULL;
  678. // Get the context
  679. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  680. bool needToResetSecurity = false;
  681. HANDLE hThreadToken = NULL;
  682. /*
  683. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  684. * guarantee that the returned objects have the __RELPATH
  685. * property included. This is in case anyone calls a
  686. * method subsequently on such an object, as the "."
  687. * notation requires that the __RELPATH property be present.
  688. */
  689. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  690. hr = pIWbemServices->ExecQuery
  691. (bsQueryLanguage, bsQuery,
  692. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  693. pIContext,
  694. &pIEnum);
  695. if (needToResetSecurity)
  696. m_SecurityInfo->ResetSecurity (hThreadToken);
  697. if (SUCCEEDED(hr))
  698. {
  699. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  700. if (!pEnum)
  701. hr = WBEM_E_OUT_OF_MEMORY;
  702. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  703. delete pEnum;
  704. pIEnum->Release ();
  705. }
  706. SetWbemError (this);
  707. if (pIContext)
  708. pIContext->Release ();
  709. pIWbemServices->Release ();
  710. }
  711. }
  712. if (FAILED(hr))
  713. m_Dispatch.RaiseException (hr);
  714. return hr;
  715. }
  716. //***************************************************************************
  717. //
  718. // SCODE CSWbemServices::AssociatorsOf
  719. //
  720. // DESCRIPTION:
  721. //
  722. // Return the associators of a class or instance
  723. //
  724. // PARAMETERS:
  725. //
  726. // bsQuery The query strimg
  727. // bsQueryLanguage The query language descriptor (e.g."WQL")
  728. // lFlags Flags
  729. // pContext Any context information
  730. // ppEnum Returns the enumerator
  731. //
  732. // RETURN VALUES:
  733. //
  734. // WBEM_S_NO_ERROR success
  735. // WBEM_E_INVALID_PARAMETER bad input parameters
  736. // WBEM_E_FAILED otherwise
  737. //
  738. //***************************************************************************
  739. HRESULT CSWbemServices::AssociatorsOf (
  740. BSTR strObjectPath,
  741. BSTR strAssocClass,
  742. BSTR strResultClass,
  743. BSTR strResultRole,
  744. BSTR strRole,
  745. VARIANT_BOOL bClassesOnly,
  746. VARIANT_BOOL bSchemaOnly,
  747. BSTR strRequiredAssocQualifier,
  748. BSTR strRequiredQualifier,
  749. long lFlags,
  750. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  751. ISWbemObjectSet **ppEnum
  752. )
  753. {
  754. HRESULT hr = WBEM_E_FAILED;
  755. ResetLastErrors ();
  756. if ((NULL == ppEnum) || (NULL == strObjectPath))
  757. hr = WBEM_E_INVALID_PARAMETER;
  758. else if (m_SecurityInfo)
  759. {
  760. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  761. if (pIWbemServices)
  762. {
  763. IEnumWbemClassObject *pIEnum = NULL;
  764. // Get the context
  765. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  766. // Format the query string
  767. BSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  768. BSTR bsQuery = FormatAssociatorsQuery (strObjectPath, strAssocClass, strResultClass, strResultRole,
  769. strRole, bClassesOnly, bSchemaOnly, strRequiredAssocQualifier, strRequiredQualifier);
  770. bool needToResetSecurity = false;
  771. HANDLE hThreadToken = NULL;
  772. /*
  773. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  774. * guarantee that the returned objects have the __RELPATH
  775. * property included. This is in case anyone calls a
  776. * method subsequently on such an object, as the "."
  777. * notation requires that the __RELPATH property be present.
  778. */
  779. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  780. hr = pIWbemServices->ExecQuery
  781. (bsQueryLanguage, bsQuery,
  782. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  783. pIContext,
  784. &pIEnum);
  785. // Restore original privileges on this thread
  786. if (needToResetSecurity)
  787. m_SecurityInfo->ResetSecurity (hThreadToken);
  788. if (SUCCEEDED(hr))
  789. {
  790. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  791. if (!pEnum)
  792. hr = WBEM_E_OUT_OF_MEMORY;
  793. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  794. delete pEnum;
  795. pIEnum->Release ();
  796. }
  797. SetWbemError (this);
  798. SysFreeString (bsQuery);
  799. SysFreeString (bsQueryLanguage);
  800. if (pIContext)
  801. pIContext->Release ();
  802. pIWbemServices->Release ();
  803. }
  804. }
  805. if (FAILED(hr))
  806. m_Dispatch.RaiseException (hr);
  807. return hr;
  808. }
  809. //***************************************************************************
  810. //
  811. // SCODE CSWbemServices::ReferencesTo
  812. //
  813. // DESCRIPTION:
  814. //
  815. // Return the references to a class or instance
  816. //
  817. // PARAMETERS:
  818. //
  819. // bsQuery The query strimg
  820. // bsQueryLanguage The query language descriptor (e.g."WQL")
  821. // lFlags Flags
  822. // pContext Any context information
  823. // ppEnum Returns the enumerator
  824. //
  825. // RETURN VALUES:
  826. //
  827. // WBEM_S_NO_ERROR success
  828. // WBEM_E_INVALID_PARAMETER bad input parameters
  829. // WBEM_E_FAILED otherwise
  830. //
  831. //***************************************************************************
  832. HRESULT CSWbemServices::ReferencesTo (
  833. BSTR strObjectPath,
  834. BSTR strResultClass,
  835. BSTR strRole,
  836. VARIANT_BOOL bClassesOnly,
  837. VARIANT_BOOL bSchemaOnly,
  838. BSTR strRequiredQualifier,
  839. long lFlags,
  840. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  841. ISWbemObjectSet **ppEnum
  842. )
  843. {
  844. HRESULT hr = WBEM_E_FAILED;
  845. ResetLastErrors ();
  846. if ((NULL == ppEnum) || (NULL == strObjectPath))
  847. hr = WBEM_E_INVALID_PARAMETER;
  848. else if (m_SecurityInfo)
  849. {
  850. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  851. if (pIWbemServices)
  852. {
  853. IEnumWbemClassObject *pIEnum = NULL;
  854. // Get the context
  855. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  856. // Format the query string
  857. BSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  858. BSTR bsQuery = FormatReferencesQuery (strObjectPath, strResultClass, strRole,
  859. bClassesOnly, bSchemaOnly, strRequiredQualifier);
  860. bool needToResetSecurity = false;
  861. HANDLE hThreadToken = NULL;
  862. /*
  863. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  864. * guarantee that the returned objects have the __RELPATH
  865. * property included. This is in case anyone calls a
  866. * method subsequently on such an object, as the "."
  867. * notation requires that the __RELPATH property be present.
  868. */
  869. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  870. hr = pIWbemServices->ExecQuery
  871. (bsQueryLanguage, bsQuery,
  872. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  873. pIContext,
  874. &pIEnum);
  875. // Restore original privileges on this thread
  876. if (needToResetSecurity)
  877. m_SecurityInfo->ResetSecurity (hThreadToken);
  878. if (SUCCEEDED(hr))
  879. {
  880. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  881. if (!pEnum)
  882. hr = WBEM_E_OUT_OF_MEMORY;
  883. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  884. delete pEnum;
  885. pIEnum->Release ();
  886. }
  887. SetWbemError (this);
  888. SysFreeString (bsQuery);
  889. SysFreeString (bsQueryLanguage);
  890. if (pIContext)
  891. pIContext->Release ();
  892. pIWbemServices->Release ();
  893. }
  894. }
  895. if (FAILED(hr))
  896. m_Dispatch.RaiseException (hr);
  897. return hr;
  898. }
  899. //***************************************************************************
  900. //
  901. // SCODE CSWbemServices::ExecNotificationQuery
  902. //
  903. // DESCRIPTION:
  904. //
  905. // Execute a notification query
  906. //
  907. // PARAMETERS:
  908. //
  909. // bsQuery The query strimg
  910. // bsQueryLanguage The query language descriptor (e.g."WQL")
  911. // lFlags Flags
  912. // pContext Any context information
  913. // ppEvents Returns the events iterator
  914. //
  915. // RETURN VALUES:
  916. //
  917. // WBEM_S_NO_ERROR success
  918. // WBEM_E_INVALID_PARAMETER bad input parameters
  919. // WBEM_E_FAILED otherwise
  920. //
  921. //***************************************************************************
  922. HRESULT CSWbemServices::ExecNotificationQuery (
  923. BSTR bsQuery,
  924. BSTR bsQueryLanguage,
  925. long lFlags,
  926. /*ISWbemValueBag*/ IDispatch *pContext,
  927. ISWbemEventSource **ppEvents)
  928. {
  929. HRESULT hr = WBEM_E_FAILED;
  930. ResetLastErrors ();
  931. if (NULL == ppEvents)
  932. hr = WBEM_E_INVALID_PARAMETER;
  933. else if (m_SecurityInfo)
  934. {
  935. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  936. if (pIWbemServices)
  937. {
  938. IEnumWbemClassObject *pIEnum = NULL;
  939. // Get the context
  940. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  941. bool needToResetSecurity = false;
  942. HANDLE hThreadToken = NULL;
  943. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  944. hr = pIWbemServices->ExecNotificationQuery
  945. (bsQueryLanguage, bsQuery, lFlags, pIContext, &pIEnum);
  946. if (SUCCEEDED(hr))
  947. {
  948. CSWbemEventSource *pEvents = new CSWbemEventSource (this, pIEnum);
  949. if (!pEvents)
  950. hr = WBEM_E_OUT_OF_MEMORY;
  951. else if (FAILED(hr = pEvents->QueryInterface (IID_ISWbemEventSource, (PPVOID) ppEvents)))
  952. delete pEvents;
  953. pIEnum->Release ();
  954. }
  955. // Restore original privileges on this thread
  956. if (needToResetSecurity)
  957. m_SecurityInfo->ResetSecurity (hThreadToken);
  958. SetWbemError (this);
  959. if (pIContext)
  960. pIContext->Release ();
  961. pIWbemServices->Release ();
  962. }
  963. }
  964. if (FAILED(hr))
  965. m_Dispatch.RaiseException (hr);
  966. return hr;
  967. }
  968. //***************************************************************************
  969. //
  970. // SCODE CSWbemServices::ExecMethod
  971. //
  972. // DESCRIPTION:
  973. //
  974. // Execute a method
  975. //
  976. // PARAMETERS:
  977. //
  978. // bsObjectPath Relative path to object
  979. // bsMethod The name of the method to call
  980. // pInParams The in-parameters
  981. // lFlags Flags
  982. // pContext Any context information
  983. // ppOutParams The out-parameters
  984. //
  985. // RETURN VALUES:
  986. //
  987. // WBEM_S_NO_ERROR success
  988. // WBEM_E_INVALID_PARAMETER bad input parameters
  989. // WBEM_E_FAILED otherwise
  990. //
  991. //***************************************************************************
  992. HRESULT CSWbemServices::ExecMethod (
  993. BSTR bsObjectPath,
  994. BSTR bsMethod,
  995. /*ISWbemObject*/ IDispatch *pInParams,
  996. long lFlags,
  997. /*ISWbemValueBag*/ IDispatch *pContext,
  998. ISWbemObject **ppOutParams
  999. )
  1000. {
  1001. HRESULT hr = WBEM_E_FAILED;
  1002. ResetLastErrors ();
  1003. if (m_SecurityInfo)
  1004. {
  1005. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  1006. if (pIWbemServices)
  1007. {
  1008. IWbemClassObject *pIInParams = CSWbemObject::GetIWbemClassObject (pInParams);
  1009. IWbemClassObject *pIOutParams = NULL;
  1010. // Get the context
  1011. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  1012. bool needToResetSecurity = false;
  1013. HANDLE hThreadToken = NULL;
  1014. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  1015. hr = pIWbemServices->ExecMethod
  1016. (bsObjectPath, bsMethod, lFlags, pIContext, pIInParams, &pIOutParams, NULL);
  1017. if (SUCCEEDED(hr))
  1018. {
  1019. if (pIOutParams)
  1020. {
  1021. if (ppOutParams)
  1022. {
  1023. CSWbemObject *pObject = new CSWbemObject (this, pIOutParams);
  1024. if (!pObject)
  1025. hr = WBEM_E_OUT_OF_MEMORY;
  1026. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  1027. (PPVOID) ppOutParams)))
  1028. delete pObject;
  1029. }
  1030. pIOutParams->Release ();
  1031. }
  1032. }
  1033. // Restore original privileges on this thread
  1034. if (needToResetSecurity)
  1035. m_SecurityInfo->ResetSecurity (hThreadToken);
  1036. SetWbemError (this);
  1037. if (pIContext)
  1038. pIContext->Release ();
  1039. if (pIInParams)
  1040. pIInParams->Release ();
  1041. pIWbemServices->Release ();
  1042. }
  1043. }
  1044. if (FAILED(hr))
  1045. m_Dispatch.RaiseException (hr);
  1046. return hr;
  1047. }
  1048. //***************************************************************************
  1049. //
  1050. // SCODE CSWbemServices::SubclassesOf
  1051. //
  1052. // DESCRIPTION:
  1053. //
  1054. // Create an enumerator for classes
  1055. //
  1056. // PARAMETERS:
  1057. //
  1058. // bsSuperClass Underlying class basis for enumeration
  1059. // lFlags Flags
  1060. // pContext Any context info
  1061. // ppEnum On successful return holds the enumerator
  1062. //
  1063. // RETURN VALUES:
  1064. //
  1065. // WBEM_S_NO_ERROR success
  1066. // WBEM_E_INVALID_PARAMETER bad input parameters
  1067. // WBEM_E_FAILED otherwise
  1068. //
  1069. //***************************************************************************
  1070. HRESULT CSWbemServices::SubclassesOf (
  1071. BSTR bsSuperClass,
  1072. long lFlags,
  1073. /*ISWbemValueBag*/ IDispatch *pContext,
  1074. ISWbemObjectSet **ppEnum
  1075. )
  1076. {
  1077. HRESULT hr = WBEM_E_FAILED;
  1078. ResetLastErrors ();
  1079. if (NULL == ppEnum)
  1080. hr = WBEM_E_INVALID_PARAMETER;
  1081. else if (m_SecurityInfo)
  1082. {
  1083. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  1084. if (pIWbemServices)
  1085. {
  1086. IEnumWbemClassObject *pIEnum = NULL;
  1087. // Get the context
  1088. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  1089. bool needToResetSecurity = false;
  1090. HANDLE hThreadToken = NULL;
  1091. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  1092. hr = pIWbemServices->CreateClassEnum
  1093. (bsSuperClass, lFlags, pIContext, &pIEnum);
  1094. if (SUCCEEDED(hr))
  1095. {
  1096. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  1097. if (!pEnum)
  1098. hr = WBEM_E_OUT_OF_MEMORY;
  1099. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  1100. delete pEnum;
  1101. pIEnum->Release ();
  1102. }
  1103. // Restore original privileges on this thread
  1104. if (needToResetSecurity)
  1105. m_SecurityInfo->ResetSecurity (hThreadToken);
  1106. SetWbemError (this);
  1107. if (pIContext)
  1108. pIContext->Release ();
  1109. pIWbemServices->Release ();
  1110. }
  1111. }
  1112. if (FAILED(hr))
  1113. m_Dispatch.RaiseException (hr);
  1114. return hr;
  1115. }
  1116. //***************************************************************************
  1117. //
  1118. // SCODE CSWbemServices::get_Security_
  1119. //
  1120. // DESCRIPTION:
  1121. //
  1122. // Return the security configurator
  1123. //
  1124. // WBEM_S_NO_ERROR success
  1125. // WBEM_E_INVALID_PARAMETER bad input parameters
  1126. // WBEM_E_FAILED otherwise
  1127. //
  1128. //***************************************************************************
  1129. HRESULT CSWbemServices::get_Security_ (
  1130. ISWbemSecurity **ppSecurity
  1131. )
  1132. {
  1133. HRESULT hr = WBEM_E_FAILED;
  1134. ResetLastErrors ();
  1135. if (NULL == ppSecurity)
  1136. hr = WBEM_E_INVALID_PARAMETER;
  1137. {
  1138. *ppSecurity = NULL;
  1139. if (m_SecurityInfo)
  1140. {
  1141. *ppSecurity = m_SecurityInfo;
  1142. (*ppSecurity)->AddRef ();
  1143. hr = WBEM_S_NO_ERROR;
  1144. }
  1145. }
  1146. if (FAILED(hr))
  1147. m_Dispatch.RaiseException (hr);
  1148. return hr;
  1149. }
  1150. //***************************************************************************
  1151. //
  1152. // SCODE CSWbemServices::Put
  1153. //
  1154. // DESCRIPTION:
  1155. //
  1156. // Save/commit a class or instance into this namespace
  1157. //
  1158. // PARAMETERS:
  1159. //
  1160. // objWbemObject Class/Instance to be saved
  1161. // lFlags Flags
  1162. // pContext Context
  1163. // ppObjectPath Object Path
  1164. //
  1165. // RETURN VALUES:
  1166. //
  1167. // WBEM_S_NO_ERROR success
  1168. // WBEM_E_INVALID_PARAMETER bad input parameters
  1169. // WBEM_E_FAILED otherwise
  1170. //
  1171. //***************************************************************************
  1172. HRESULT CSWbemServices::Put (
  1173. ISWbemObjectEx *objWbemObject,
  1174. long lFlags,
  1175. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  1176. ISWbemObjectPath **ppObjectPath
  1177. )
  1178. {
  1179. HRESULT hr = WBEM_E_FAILED;
  1180. ResetLastErrors ();
  1181. if (NULL == objWbemObject)
  1182. hr = WBEM_E_INVALID_PARAMETER;
  1183. else if (m_SecurityInfo)
  1184. {
  1185. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  1186. if (pIWbemServices)
  1187. {
  1188. IWbemClassObject *pObject = CSWbemObject::GetIWbemClassObject (objWbemObject);
  1189. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  1190. if (NULL != pObject)
  1191. {
  1192. // Figure out whether this is a class or instance
  1193. VARIANT var;
  1194. VariantInit (&var);
  1195. if (WBEM_S_NO_ERROR == pObject->Get (WBEMS_SP_GENUS, 0, &var, NULL, NULL))
  1196. {
  1197. IWbemCallResult *pResult = NULL;
  1198. HRESULT hrCallResult = WBEM_E_FAILED;
  1199. bool needToResetSecurity = false;
  1200. HANDLE hThreadToken = NULL;
  1201. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  1202. {
  1203. if (WBEM_GENUS_CLASS == var.lVal)
  1204. hrCallResult = pIWbemServices->PutClass
  1205. (pObject, lFlags | WBEM_FLAG_RETURN_IMMEDIATELY, pIContext, &pResult);
  1206. else
  1207. hrCallResult = pIWbemServices->PutInstance
  1208. (pObject, lFlags | WBEM_FLAG_RETURN_IMMEDIATELY, pIContext, &pResult);
  1209. if (needToResetSecurity)
  1210. m_SecurityInfo->ResetSecurity (hThreadToken);
  1211. }
  1212. if (WBEM_S_NO_ERROR == hrCallResult)
  1213. {
  1214. //Secure the IWbemCallResult interface
  1215. m_SecurityInfo->SecureInterface (pResult);
  1216. if ((WBEM_S_NO_ERROR == (hrCallResult = pResult->GetCallStatus (INFINITE, &hr))) &&
  1217. (WBEM_S_NO_ERROR == hr))
  1218. {
  1219. if (ppObjectPath)
  1220. {
  1221. ISWbemObjectPath *pObjectPath = new CSWbemObjectPath (m_SecurityInfo, GetLocale());
  1222. if (!pObjectPath)
  1223. hr = WBEM_E_OUT_OF_MEMORY;
  1224. else
  1225. {
  1226. pObjectPath->AddRef ();
  1227. pObjectPath->put_Path (GetPath ());
  1228. if (WBEM_GENUS_CLASS == var.lVal)
  1229. {
  1230. VARIANT nameVar;
  1231. VariantInit (&nameVar);
  1232. /*
  1233. * Note we must check that returned value is a BSTR - it could be a VT_NULL if
  1234. * the __CLASS property has not yet been set.
  1235. */
  1236. if ((WBEM_S_NO_ERROR == pObject->Get (WBEMS_SP_CLASS, 0, &nameVar, NULL, NULL))
  1237. && (VT_BSTR == V_VT(&nameVar)))
  1238. {
  1239. pObjectPath->put_Class (nameVar.bstrVal);
  1240. *ppObjectPath = pObjectPath;
  1241. }
  1242. VariantClear (&nameVar);
  1243. }
  1244. else
  1245. {
  1246. // Now get the relpath string from the call result
  1247. BSTR resultString = NULL;
  1248. if (WBEM_S_NO_ERROR == pResult->GetResultString (INFINITE, &resultString))
  1249. {
  1250. pObjectPath->put_RelPath (resultString);
  1251. *ppObjectPath = pObjectPath;
  1252. SysFreeString (resultString);
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else
  1260. hr = hrCallResult;
  1261. if (pResult)
  1262. pResult->Release ();
  1263. }
  1264. if (pIContext)
  1265. pIContext->Release ();
  1266. pObject->Release ();
  1267. VariantClear (&var);
  1268. }
  1269. SetWbemError (this);
  1270. pIWbemServices->Release ();
  1271. }
  1272. }
  1273. if (FAILED(hr))
  1274. m_Dispatch.RaiseException (hr);
  1275. return hr;
  1276. }
  1277. //***************************************************************************
  1278. //
  1279. // CSWbemServices::GetIWbemServices
  1280. //
  1281. // DESCRIPTION:
  1282. //
  1283. // Return the IWbemServices interface corresponding to this
  1284. // scriptable wrapper.
  1285. //
  1286. // PARAMETERS:
  1287. // ppServices holds the IWbemServices pointer on return
  1288. //
  1289. // RETURN VALUES:
  1290. // S_OK success
  1291. // E_FAIL otherwise
  1292. //
  1293. // NOTES:
  1294. // If successful, the returned interface is AddRef'd; the caller is
  1295. // responsible for release.
  1296. //
  1297. //***************************************************************************
  1298. STDMETHODIMP CSWbemServices::GetIWbemServices (IWbemServices **ppServices)
  1299. {
  1300. HRESULT hr = E_FAIL;
  1301. if (ppServices)
  1302. {
  1303. *ppServices = GetIWbemServices ();
  1304. hr = S_OK;
  1305. }
  1306. return hr;
  1307. }
  1308. //***************************************************************************
  1309. //
  1310. // CSWbemServices::GetIWbemServices
  1311. //
  1312. // DESCRIPTION:
  1313. //
  1314. // Given an IDispatch interface which we hope is also an ISWbemServicesEx
  1315. // interface, return the underlying IWbemServices interface.
  1316. //
  1317. // PARAMETERS:
  1318. // pDispatch the IDispatch in question
  1319. //
  1320. // RETURN VALUES:
  1321. // The underlying IWbemServices interface, or NULL.
  1322. //
  1323. // NOTES:
  1324. // If successful, the returned interface is AddRef'd; the caller is
  1325. // responsible for release.
  1326. //
  1327. //***************************************************************************
  1328. IWbemServices *CSWbemServices::GetIWbemServices (
  1329. IDispatch *pDispatch
  1330. )
  1331. {
  1332. IWbemServices *pServices = NULL;
  1333. ISWbemInternalServices *pIServices = NULL;
  1334. if (pDispatch)
  1335. {
  1336. if (SUCCEEDED (pDispatch->QueryInterface
  1337. (IID_ISWbemInternalServices, (PPVOID) &pIServices)))
  1338. {
  1339. pIServices->GetIWbemServices (&pServices);
  1340. pIServices->Release ();
  1341. }
  1342. }
  1343. return pServices;
  1344. }