Leaked source code of windows server 2003
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.

1624 lines
41 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. LONG cRef = InterlockedDecrement(&m_cRef);
  301. if (0 != cRef)
  302. {
  303. _ASSERT(cRef > 0);
  304. return cRef;
  305. }
  306. delete this;
  307. return 0;
  308. }
  309. // IDispatch methods should be inline
  310. STDMETHODIMP CSWbemServices::GetTypeInfoCount(UINT* pctinfo)
  311. {
  312. _RD(static char *me = "CSWbemServices::GetTypeInfoCount()";)
  313. _RPrint(me, "Called", 0, "");
  314. return m_Dispatch.GetTypeInfoCount(pctinfo);}
  315. STDMETHODIMP CSWbemServices::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  316. {
  317. _RD(static char *me = "CSWbemServices::GetTypeInfo()";)
  318. _RPrint(me, "Called", 0, "");
  319. return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  320. STDMETHODIMP CSWbemServices::GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  321. UINT cNames, LCID lcid, DISPID* rgdispid)
  322. {
  323. _RD(static char *me = "CSWbemServices::GetIdsOfNames()";)
  324. _RPrint(me, "Called", 0, "");
  325. return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  326. lcid,
  327. rgdispid);}
  328. STDMETHODIMP CSWbemServices::Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  329. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  330. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  331. {
  332. _RD(static char *me = "CSWbemServices::Invoke()";)
  333. _RPrint(me, "Called", 0, "");
  334. return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  335. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  336. // IDispatchEx methods should be inline
  337. HRESULT STDMETHODCALLTYPE CSWbemServices::GetDispID(
  338. /* [in] */ BSTR bstrName,
  339. /* [in] */ DWORD grfdex,
  340. /* [out] */ DISPID __RPC_FAR *pid)
  341. {
  342. _RD(static char *me = "CSWbemServices::GetDispID()";)
  343. _RPrint(me, "Called", 0, "");
  344. return m_Dispatch.GetDispID(bstrName, grfdex, pid);
  345. }
  346. /* [local] */ HRESULT STDMETHODCALLTYPE CSWbemServices::InvokeEx(
  347. /* [in] */ DISPID id,
  348. /* [in] */ LCID lcid,
  349. /* [in] */ WORD wFlags,
  350. /* [in] */ DISPPARAMS __RPC_FAR *pdp,
  351. /* [out] */ VARIANT __RPC_FAR *pvarRes,
  352. /* [out] */ EXCEPINFO __RPC_FAR *pei,
  353. /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller)
  354. {
  355. HRESULT hr;
  356. _RD(static char *me = "CSWbemServices::InvokeEx()";)
  357. _RPrint(me, "Called", (long)id, "id");
  358. _RPrint(me, "Called", (long)wFlags, "wFlags");
  359. m_pIServiceProvider = pspCaller;
  360. hr = m_Dispatch.InvokeEx(id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
  361. m_pIServiceProvider = NULL;
  362. return hr;
  363. }
  364. HRESULT STDMETHODCALLTYPE CSWbemServices::DeleteMemberByName(
  365. /* [in] */ BSTR bstr,
  366. /* [in] */ DWORD grfdex)
  367. {
  368. _RD(static char *me = "CSWbemServices::DeleteMemberByName()";)
  369. _RPrint(me, "Called", 0, "");
  370. return m_Dispatch.DeleteMemberByName(bstr, grfdex);
  371. }
  372. HRESULT STDMETHODCALLTYPE CSWbemServices::DeleteMemberByDispID(
  373. /* [in] */ DISPID id)
  374. {
  375. _RD(static char *me = "CSWbemServices::DeletememberByDispId()";)
  376. _RPrint(me, "Called", 0, "");
  377. return m_Dispatch.DeleteMemberByDispID(id);
  378. }
  379. HRESULT STDMETHODCALLTYPE CSWbemServices::GetMemberProperties(
  380. /* [in] */ DISPID id,
  381. /* [in] */ DWORD grfdexFetch,
  382. /* [out] */ DWORD __RPC_FAR *pgrfdex)
  383. {
  384. _RD(static char *me = "CSWbemServices::GetMemberProperties()";)
  385. _RPrint(me, "Called", 0, "");
  386. return m_Dispatch.GetMemberProperties(id, grfdexFetch, pgrfdex);
  387. }
  388. HRESULT STDMETHODCALLTYPE CSWbemServices::GetMemberName(
  389. /* [in] */ DISPID id,
  390. /* [out] */ BSTR __RPC_FAR *pbstrName)
  391. {
  392. _RD(static char *me = "CSWbemServices::GetMemberName()";)
  393. _RPrint(me, "Called", 0, "");
  394. return m_Dispatch.GetMemberName(id, pbstrName);
  395. }
  396. /*
  397. * I don't think this needs implementing
  398. */
  399. HRESULT STDMETHODCALLTYPE CSWbemServices::GetNextDispID(
  400. /* [in] */ DWORD grfdex,
  401. /* [in] */ DISPID id,
  402. /* [out] */ DISPID __RPC_FAR *pid)
  403. {
  404. _RD(static char *me = "CSWbemServices::GetNextDispID()";)
  405. _RPrint(me, "Called", 0, "");
  406. return m_Dispatch.GetNextDispID(grfdex, id, pid);
  407. }
  408. HRESULT STDMETHODCALLTYPE CSWbemServices::GetNameSpaceParent(
  409. /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk)
  410. {
  411. _RD(static char *me = "CSWbemServices::GetNamespaceParent()";)
  412. _RPrint(me, "Called", 0, "");
  413. return m_Dispatch.GetNameSpaceParent(ppunk);
  414. }
  415. //***************************************************************************
  416. // HRESULT CSWbemServices::InterfaceSupportsErrorInfo
  417. //
  418. // DESCRIPTION:
  419. //
  420. // Standard Com ISupportErrorInfo functions.
  421. //
  422. //***************************************************************************
  423. STDMETHODIMP CSWbemServices::InterfaceSupportsErrorInfo (IN REFIID riid)
  424. {
  425. return ((IID_ISWbemServices == riid) ||
  426. (IID_ISWbemServicesEx == riid)) ? S_OK : S_FALSE;
  427. }
  428. //***************************************************************************
  429. //
  430. // SCODE CSWbemServices::Get
  431. //
  432. // DESCRIPTION:
  433. //
  434. // Get an instance or class from a namespace
  435. //
  436. // PARAMETERS:
  437. //
  438. // bsObjectPath Relative object path to class or instance
  439. // lFlags Flags
  440. // pContext If specified, additional context
  441. // ppObject On successful return addresses an
  442. // ISWbemObject
  443. //
  444. // RETURN VALUES:
  445. //
  446. // WBEM_S_NO_ERROR success
  447. // WBEM_E_INVALID_PARAMETER bad input parameters
  448. // WBEM_E_FAILED otherwise
  449. //
  450. //***************************************************************************
  451. HRESULT CSWbemServices::Get (
  452. BSTR objectPath,
  453. long lFlags,
  454. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  455. ISWbemObject **ppObject
  456. )
  457. {
  458. _RD(static char *me = "CSWbemServices::Get";)
  459. HRESULT hr = WBEM_E_FAILED;
  460. ResetLastErrors ();
  461. if (NULL == ppObject)
  462. hr = WBEM_E_INVALID_PARAMETER;
  463. else if (m_SecurityInfo)
  464. {
  465. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  466. if (pIWbemServices)
  467. {
  468. IWbemClassObject *pIWbemClassObject = NULL;
  469. // Get the context
  470. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  471. bool needToResetSecurity = false;
  472. HANDLE hThreadToken = NULL;
  473. _RPrint(me, "Called - context: ", (long)pIContext, "");
  474. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  475. hr = pIWbemServices->GetObject (
  476. (objectPath && (0 < wcslen(objectPath))) ? objectPath : NULL,
  477. lFlags,
  478. pIContext,
  479. &pIWbemClassObject,
  480. NULL);
  481. if (needToResetSecurity)
  482. m_SecurityInfo->ResetSecurity (hThreadToken);
  483. if (SUCCEEDED(hr))
  484. {
  485. // Create a new CSWbemObject using the IWbemClassObject interface
  486. // just returned.
  487. CSWbemObject *pObject = new CSWbemObject (this, pIWbemClassObject);
  488. if (!pObject)
  489. hr = WBEM_E_OUT_OF_MEMORY;
  490. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  491. (PPVOID) ppObject)))
  492. delete pObject;
  493. pIWbemClassObject->Release ();
  494. }
  495. SetWbemError (this);
  496. if (pIContext)
  497. pIContext->Release ();
  498. pIWbemServices->Release ();
  499. }
  500. }
  501. if (FAILED(hr))
  502. m_Dispatch.RaiseException (hr);
  503. return hr;
  504. }
  505. //***************************************************************************
  506. //
  507. // SCODE CSWbemServices::Delete
  508. //
  509. // DESCRIPTION:
  510. //
  511. // Delete an instance or class from a namespace
  512. //
  513. // PARAMETERS:
  514. //
  515. // bsObjectPath Relative path of class or instance
  516. // pKeyValue Single key value
  517. // lFlags Flags
  518. // pContext Any context info
  519. //
  520. // RETURN VALUES:
  521. //
  522. // WBEM_S_NO_ERROR success
  523. // WBEM_E_INVALID_PARAMETER bad input parameters
  524. // WBEM_E_FAILED otherwise
  525. //
  526. //***************************************************************************
  527. HRESULT CSWbemServices::Delete (
  528. BSTR bsObjectPath,
  529. long lFlags,
  530. /*ISWbemValueBag*/ IDispatch *pContext
  531. )
  532. {
  533. HRESULT hr = WBEM_E_FAILED;
  534. ResetLastErrors ();
  535. if (m_SecurityInfo)
  536. {
  537. CWbemPathCracker pathCracker (bsObjectPath);
  538. if ((CWbemPathCracker::WbemPathType::wbemPathTypeError != pathCracker.GetType ()) &&
  539. pathCracker.IsClassOrInstance ())
  540. {
  541. CComPtr<IWbemServices> pIWbemServices;
  542. pIWbemServices.Attach( GetIWbemServices ());
  543. if (pIWbemServices)
  544. {
  545. // Get the context
  546. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  547. bool needToResetSecurity = false;
  548. HANDLE hThreadToken = NULL;
  549. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  550. {
  551. if (pathCracker.IsInstance ())
  552. hr = pIWbemServices->DeleteInstance (bsObjectPath, lFlags, pIContext, NULL);
  553. else
  554. hr = pIWbemServices->DeleteClass (bsObjectPath, lFlags, pIContext, NULL);
  555. }
  556. if (needToResetSecurity)
  557. m_SecurityInfo->ResetSecurity (hThreadToken);
  558. SetWbemError (this);
  559. if (pIContext)
  560. pIContext->Release ();
  561. }
  562. }
  563. else
  564. hr = WBEM_E_INVALID_PARAMETER;
  565. }
  566. if (FAILED(hr))
  567. m_Dispatch.RaiseException (hr);
  568. return hr;
  569. }
  570. //***************************************************************************
  571. //
  572. // SCODE CSWbemServices::InstancesOf
  573. //
  574. // DESCRIPTION:
  575. //
  576. // Create an enumerator for instances
  577. //
  578. // PARAMETERS:
  579. //
  580. // bsClass Underlying class basis for enumeration
  581. // lFlags Flags
  582. // pContext Any context info
  583. // ppEnum On successful return holds the enumerator
  584. //
  585. // RETURN VALUES:
  586. //
  587. // WBEM_S_NO_ERROR success
  588. // WBEM_E_INVALID_PARAMETER bad input parameters
  589. // WBEM_E_FAILED otherwise
  590. //
  591. //***************************************************************************
  592. HRESULT CSWbemServices::InstancesOf (
  593. BSTR bsClass,
  594. long lFlags,
  595. /*ISWbemValueBag*/ IDispatch *pContext,
  596. ISWbemObjectSet **ppEnum
  597. )
  598. {
  599. HRESULT hr = WBEM_E_FAILED;
  600. ResetLastErrors ();
  601. if (NULL == ppEnum)
  602. hr = WBEM_E_INVALID_PARAMETER;
  603. else if (m_SecurityInfo)
  604. {
  605. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  606. if (pIWbemServices)
  607. {
  608. IEnumWbemClassObject *pIEnum = NULL;
  609. // Get the context
  610. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  611. bool needToResetSecurity = false;
  612. HANDLE hThreadToken = NULL;
  613. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  614. hr = pIWbemServices->CreateInstanceEnum (bsClass, lFlags, pIContext, &pIEnum);
  615. if (needToResetSecurity)
  616. m_SecurityInfo->ResetSecurity (hThreadToken);
  617. if (SUCCEEDED(hr))
  618. {
  619. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  620. if (!pEnum)
  621. hr = WBEM_E_OUT_OF_MEMORY;
  622. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  623. delete pEnum;
  624. pIEnum->Release ();
  625. }
  626. SetWbemError (this);
  627. if (pIContext)
  628. pIContext->Release ();
  629. pIWbemServices->Release ();
  630. }
  631. }
  632. if (FAILED(hr))
  633. m_Dispatch.RaiseException (hr);
  634. return hr;
  635. }
  636. //***************************************************************************
  637. //
  638. // SCODE CSWbemServices::ExecQuery
  639. //
  640. // DESCRIPTION:
  641. //
  642. // Execute a query
  643. //
  644. // PARAMETERS:
  645. //
  646. // bsQuery The query strimg
  647. // bsQueryLanguage The query language descriptor (e.g."WQL")
  648. // lFlags Flags
  649. // pContext Any context information
  650. // ppEnum Returns the enumerator
  651. //
  652. // RETURN VALUES:
  653. //
  654. // WBEM_S_NO_ERROR success
  655. // WBEM_E_INVALID_PARAMETER bad input parameters
  656. // WBEM_E_FAILED otherwise
  657. //
  658. //***************************************************************************
  659. HRESULT CSWbemServices::ExecQuery (
  660. BSTR bsQuery,
  661. BSTR bsQueryLanguage,
  662. long lFlags,
  663. /*ISWbemValueBag*/ IDispatch *pContext,
  664. ISWbemObjectSet **ppEnum)
  665. {
  666. HRESULT hr = WBEM_E_FAILED;
  667. ResetLastErrors ();
  668. #ifdef __RTEST_RPC_FAILURE
  669. extern int __Rx;
  670. extern bool __Rdone;
  671. __Rx = 0;
  672. __Rdone = false;
  673. #endif
  674. if (NULL == ppEnum)
  675. hr = WBEM_E_INVALID_PARAMETER;
  676. else if (m_SecurityInfo)
  677. {
  678. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  679. if (pIWbemServices)
  680. {
  681. IEnumWbemClassObject *pIEnum = NULL;
  682. // Get the context
  683. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  684. bool needToResetSecurity = false;
  685. HANDLE hThreadToken = NULL;
  686. /*
  687. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  688. * guarantee that the returned objects have the __RELPATH
  689. * property included. This is in case anyone calls a
  690. * method subsequently on such an object, as the "."
  691. * notation requires that the __RELPATH property be present.
  692. */
  693. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  694. hr = pIWbemServices->ExecQuery
  695. (bsQueryLanguage, bsQuery,
  696. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  697. pIContext,
  698. &pIEnum);
  699. if (needToResetSecurity)
  700. m_SecurityInfo->ResetSecurity (hThreadToken);
  701. if (SUCCEEDED(hr))
  702. {
  703. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  704. if (!pEnum)
  705. hr = WBEM_E_OUT_OF_MEMORY;
  706. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  707. delete pEnum;
  708. pIEnum->Release ();
  709. }
  710. SetWbemError (this);
  711. if (pIContext)
  712. pIContext->Release ();
  713. pIWbemServices->Release ();
  714. }
  715. }
  716. if (FAILED(hr))
  717. m_Dispatch.RaiseException (hr);
  718. return hr;
  719. }
  720. //***************************************************************************
  721. //
  722. // SCODE CSWbemServices::AssociatorsOf
  723. //
  724. // DESCRIPTION:
  725. //
  726. // Return the associators of a class or instance
  727. //
  728. // PARAMETERS:
  729. //
  730. // bsQuery The query strimg
  731. // bsQueryLanguage The query language descriptor (e.g."WQL")
  732. // lFlags Flags
  733. // pContext Any context information
  734. // ppEnum Returns the enumerator
  735. //
  736. // RETURN VALUES:
  737. //
  738. // WBEM_S_NO_ERROR success
  739. // WBEM_E_INVALID_PARAMETER bad input parameters
  740. // WBEM_E_FAILED otherwise
  741. //
  742. //***************************************************************************
  743. HRESULT CSWbemServices::AssociatorsOf (
  744. BSTR strObjectPath,
  745. BSTR strAssocClass,
  746. BSTR strResultClass,
  747. BSTR strResultRole,
  748. BSTR strRole,
  749. VARIANT_BOOL bClassesOnly,
  750. VARIANT_BOOL bSchemaOnly,
  751. BSTR strRequiredAssocQualifier,
  752. BSTR strRequiredQualifier,
  753. long lFlags,
  754. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  755. ISWbemObjectSet **ppEnum
  756. )
  757. {
  758. HRESULT hr = WBEM_E_FAILED;
  759. ResetLastErrors ();
  760. if ((NULL == ppEnum) || (NULL == strObjectPath))
  761. hr = WBEM_E_INVALID_PARAMETER;
  762. else if (m_SecurityInfo)
  763. {
  764. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  765. if (pIWbemServices)
  766. {
  767. IEnumWbemClassObject *pIEnum = NULL;
  768. // Get the context
  769. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  770. // Format the query string
  771. BSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  772. BSTR bsQuery = FormatAssociatorsQuery (strObjectPath, strAssocClass, strResultClass, strResultRole,
  773. strRole, bClassesOnly, bSchemaOnly, strRequiredAssocQualifier, strRequiredQualifier);
  774. bool needToResetSecurity = false;
  775. HANDLE hThreadToken = NULL;
  776. /*
  777. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  778. * guarantee that the returned objects have the __RELPATH
  779. * property included. This is in case anyone calls a
  780. * method subsequently on such an object, as the "."
  781. * notation requires that the __RELPATH property be present.
  782. */
  783. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  784. hr = pIWbemServices->ExecQuery
  785. (bsQueryLanguage, bsQuery,
  786. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  787. pIContext,
  788. &pIEnum);
  789. // Restore original privileges on this thread
  790. if (needToResetSecurity)
  791. m_SecurityInfo->ResetSecurity (hThreadToken);
  792. if (SUCCEEDED(hr))
  793. {
  794. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  795. if (!pEnum)
  796. hr = WBEM_E_OUT_OF_MEMORY;
  797. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  798. delete pEnum;
  799. pIEnum->Release ();
  800. }
  801. SetWbemError (this);
  802. SysFreeString (bsQuery);
  803. SysFreeString (bsQueryLanguage);
  804. if (pIContext)
  805. pIContext->Release ();
  806. pIWbemServices->Release ();
  807. }
  808. }
  809. if (FAILED(hr))
  810. m_Dispatch.RaiseException (hr);
  811. return hr;
  812. }
  813. //***************************************************************************
  814. //
  815. // SCODE CSWbemServices::ReferencesTo
  816. //
  817. // DESCRIPTION:
  818. //
  819. // Return the references to a class or instance
  820. //
  821. // PARAMETERS:
  822. //
  823. // bsQuery The query strimg
  824. // bsQueryLanguage The query language descriptor (e.g."WQL")
  825. // lFlags Flags
  826. // pContext Any context information
  827. // ppEnum Returns the enumerator
  828. //
  829. // RETURN VALUES:
  830. //
  831. // WBEM_S_NO_ERROR success
  832. // WBEM_E_INVALID_PARAMETER bad input parameters
  833. // WBEM_E_FAILED otherwise
  834. //
  835. //***************************************************************************
  836. HRESULT CSWbemServices::ReferencesTo (
  837. BSTR strObjectPath,
  838. BSTR strResultClass,
  839. BSTR strRole,
  840. VARIANT_BOOL bClassesOnly,
  841. VARIANT_BOOL bSchemaOnly,
  842. BSTR strRequiredQualifier,
  843. long lFlags,
  844. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  845. ISWbemObjectSet **ppEnum
  846. )
  847. {
  848. HRESULT hr = WBEM_E_FAILED;
  849. ResetLastErrors ();
  850. if ((NULL == ppEnum) || (NULL == strObjectPath))
  851. hr = WBEM_E_INVALID_PARAMETER;
  852. else if (m_SecurityInfo)
  853. {
  854. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  855. if (pIWbemServices)
  856. {
  857. IEnumWbemClassObject *pIEnum = NULL;
  858. // Get the context
  859. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  860. // Format the query string
  861. BSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  862. BSTR bsQuery = FormatReferencesQuery (strObjectPath, strResultClass, strRole,
  863. bClassesOnly, bSchemaOnly, strRequiredQualifier);
  864. bool needToResetSecurity = false;
  865. HANDLE hThreadToken = NULL;
  866. /*
  867. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  868. * guarantee that the returned objects have the __RELPATH
  869. * property included. This is in case anyone calls a
  870. * method subsequently on such an object, as the "."
  871. * notation requires that the __RELPATH property be present.
  872. */
  873. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  874. hr = pIWbemServices->ExecQuery
  875. (bsQueryLanguage, bsQuery,
  876. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  877. pIContext,
  878. &pIEnum);
  879. // Restore original privileges on this thread
  880. if (needToResetSecurity)
  881. m_SecurityInfo->ResetSecurity (hThreadToken);
  882. if (SUCCEEDED(hr))
  883. {
  884. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  885. if (!pEnum)
  886. hr = WBEM_E_OUT_OF_MEMORY;
  887. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  888. delete pEnum;
  889. pIEnum->Release ();
  890. }
  891. SetWbemError (this);
  892. SysFreeString (bsQuery);
  893. SysFreeString (bsQueryLanguage);
  894. if (pIContext)
  895. pIContext->Release ();
  896. pIWbemServices->Release ();
  897. }
  898. }
  899. if (FAILED(hr))
  900. m_Dispatch.RaiseException (hr);
  901. return hr;
  902. }
  903. //***************************************************************************
  904. //
  905. // SCODE CSWbemServices::ExecNotificationQuery
  906. //
  907. // DESCRIPTION:
  908. //
  909. // Execute a notification query
  910. //
  911. // PARAMETERS:
  912. //
  913. // bsQuery The query strimg
  914. // bsQueryLanguage The query language descriptor (e.g."WQL")
  915. // lFlags Flags
  916. // pContext Any context information
  917. // ppEvents Returns the events iterator
  918. //
  919. // RETURN VALUES:
  920. //
  921. // WBEM_S_NO_ERROR success
  922. // WBEM_E_INVALID_PARAMETER bad input parameters
  923. // WBEM_E_FAILED otherwise
  924. //
  925. //***************************************************************************
  926. HRESULT CSWbemServices::ExecNotificationQuery (
  927. BSTR bsQuery,
  928. BSTR bsQueryLanguage,
  929. long lFlags,
  930. /*ISWbemValueBag*/ IDispatch *pContext,
  931. ISWbemEventSource **ppEvents)
  932. {
  933. HRESULT hr = WBEM_E_FAILED;
  934. ResetLastErrors ();
  935. if (NULL == ppEvents)
  936. hr = WBEM_E_INVALID_PARAMETER;
  937. else if (m_SecurityInfo)
  938. {
  939. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  940. if (pIWbemServices)
  941. {
  942. IEnumWbemClassObject *pIEnum = NULL;
  943. // Get the context
  944. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  945. bool needToResetSecurity = false;
  946. HANDLE hThreadToken = NULL;
  947. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  948. hr = pIWbemServices->ExecNotificationQuery
  949. (bsQueryLanguage, bsQuery, lFlags, pIContext, &pIEnum);
  950. if (SUCCEEDED(hr))
  951. {
  952. CSWbemEventSource *pEvents = new CSWbemEventSource (this, pIEnum);
  953. if (!pEvents)
  954. hr = WBEM_E_OUT_OF_MEMORY;
  955. else if (FAILED(hr = pEvents->QueryInterface (IID_ISWbemEventSource, (PPVOID) ppEvents)))
  956. delete pEvents;
  957. pIEnum->Release ();
  958. }
  959. // Restore original privileges on this thread
  960. if (needToResetSecurity)
  961. m_SecurityInfo->ResetSecurity (hThreadToken);
  962. SetWbemError (this);
  963. if (pIContext)
  964. pIContext->Release ();
  965. pIWbemServices->Release ();
  966. }
  967. }
  968. if (FAILED(hr))
  969. m_Dispatch.RaiseException (hr);
  970. return hr;
  971. }
  972. //***************************************************************************
  973. //
  974. // SCODE CSWbemServices::ExecMethod
  975. //
  976. // DESCRIPTION:
  977. //
  978. // Execute a method
  979. //
  980. // PARAMETERS:
  981. //
  982. // bsObjectPath Relative path to object
  983. // bsMethod The name of the method to call
  984. // pInParams The in-parameters
  985. // lFlags Flags
  986. // pContext Any context information
  987. // ppOutParams The out-parameters
  988. //
  989. // RETURN VALUES:
  990. //
  991. // WBEM_S_NO_ERROR success
  992. // WBEM_E_INVALID_PARAMETER bad input parameters
  993. // WBEM_E_FAILED otherwise
  994. //
  995. //***************************************************************************
  996. HRESULT CSWbemServices::ExecMethod (
  997. BSTR bsObjectPath,
  998. BSTR bsMethod,
  999. /*ISWbemObject*/ IDispatch *pInParams,
  1000. long lFlags,
  1001. /*ISWbemValueBag*/ IDispatch *pContext,
  1002. ISWbemObject **ppOutParams
  1003. )
  1004. {
  1005. HRESULT hr = WBEM_E_FAILED;
  1006. ResetLastErrors ();
  1007. if (m_SecurityInfo)
  1008. {
  1009. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  1010. if (pIWbemServices)
  1011. {
  1012. IWbemClassObject *pIInParams = CSWbemObject::GetIWbemClassObject (pInParams);
  1013. IWbemClassObject *pIOutParams = NULL;
  1014. // Get the context
  1015. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  1016. bool needToResetSecurity = false;
  1017. HANDLE hThreadToken = NULL;
  1018. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  1019. hr = pIWbemServices->ExecMethod
  1020. (bsObjectPath, bsMethod, lFlags, pIContext, pIInParams, &pIOutParams, NULL);
  1021. if (SUCCEEDED(hr))
  1022. {
  1023. if (pIOutParams)
  1024. {
  1025. if (ppOutParams)
  1026. {
  1027. CSWbemObject *pObject = new CSWbemObject (this, pIOutParams);
  1028. if (!pObject)
  1029. hr = WBEM_E_OUT_OF_MEMORY;
  1030. else if (FAILED(hr = pObject->QueryInterface (IID_ISWbemObject,
  1031. (PPVOID) ppOutParams)))
  1032. delete pObject;
  1033. }
  1034. pIOutParams->Release ();
  1035. }
  1036. }
  1037. // Restore original privileges on this thread
  1038. if (needToResetSecurity)
  1039. m_SecurityInfo->ResetSecurity (hThreadToken);
  1040. SetWbemError (this);
  1041. if (pIContext)
  1042. pIContext->Release ();
  1043. if (pIInParams)
  1044. pIInParams->Release ();
  1045. pIWbemServices->Release ();
  1046. }
  1047. }
  1048. if (FAILED(hr))
  1049. m_Dispatch.RaiseException (hr);
  1050. return hr;
  1051. }
  1052. //***************************************************************************
  1053. //
  1054. // SCODE CSWbemServices::SubclassesOf
  1055. //
  1056. // DESCRIPTION:
  1057. //
  1058. // Create an enumerator for classes
  1059. //
  1060. // PARAMETERS:
  1061. //
  1062. // bsSuperClass Underlying class basis for enumeration
  1063. // lFlags Flags
  1064. // pContext Any context info
  1065. // ppEnum On successful return holds the enumerator
  1066. //
  1067. // RETURN VALUES:
  1068. //
  1069. // WBEM_S_NO_ERROR success
  1070. // WBEM_E_INVALID_PARAMETER bad input parameters
  1071. // WBEM_E_FAILED otherwise
  1072. //
  1073. //***************************************************************************
  1074. HRESULT CSWbemServices::SubclassesOf (
  1075. BSTR bsSuperClass,
  1076. long lFlags,
  1077. /*ISWbemValueBag*/ IDispatch *pContext,
  1078. ISWbemObjectSet **ppEnum
  1079. )
  1080. {
  1081. HRESULT hr = WBEM_E_FAILED;
  1082. ResetLastErrors ();
  1083. if (NULL == ppEnum)
  1084. hr = WBEM_E_INVALID_PARAMETER;
  1085. else if (m_SecurityInfo)
  1086. {
  1087. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  1088. if (pIWbemServices)
  1089. {
  1090. IEnumWbemClassObject *pIEnum = NULL;
  1091. // Get the context
  1092. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  1093. bool needToResetSecurity = false;
  1094. HANDLE hThreadToken = NULL;
  1095. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  1096. hr = pIWbemServices->CreateClassEnum
  1097. (bsSuperClass, lFlags, pIContext, &pIEnum);
  1098. if (SUCCEEDED(hr))
  1099. {
  1100. CSWbemObjectSet *pEnum = new CSWbemObjectSet (this, pIEnum);
  1101. if (!pEnum)
  1102. hr = WBEM_E_OUT_OF_MEMORY;
  1103. else if (FAILED(hr = pEnum->QueryInterface (IID_ISWbemObjectSet, (PPVOID) ppEnum)))
  1104. delete pEnum;
  1105. pIEnum->Release ();
  1106. }
  1107. // Restore original privileges on this thread
  1108. if (needToResetSecurity)
  1109. m_SecurityInfo->ResetSecurity (hThreadToken);
  1110. SetWbemError (this);
  1111. if (pIContext)
  1112. pIContext->Release ();
  1113. pIWbemServices->Release ();
  1114. }
  1115. }
  1116. if (FAILED(hr))
  1117. m_Dispatch.RaiseException (hr);
  1118. return hr;
  1119. }
  1120. //***************************************************************************
  1121. //
  1122. // SCODE CSWbemServices::get_Security_
  1123. //
  1124. // DESCRIPTION:
  1125. //
  1126. // Return the security configurator
  1127. //
  1128. // WBEM_S_NO_ERROR success
  1129. // WBEM_E_INVALID_PARAMETER bad input parameters
  1130. // WBEM_E_FAILED otherwise
  1131. //
  1132. //***************************************************************************
  1133. HRESULT CSWbemServices::get_Security_ (
  1134. ISWbemSecurity **ppSecurity
  1135. )
  1136. {
  1137. HRESULT hr = WBEM_E_FAILED;
  1138. ResetLastErrors ();
  1139. if (NULL == ppSecurity)
  1140. hr = WBEM_E_INVALID_PARAMETER;
  1141. else
  1142. {
  1143. *ppSecurity = NULL;
  1144. if (m_SecurityInfo)
  1145. {
  1146. *ppSecurity = m_SecurityInfo;
  1147. (*ppSecurity)->AddRef ();
  1148. hr = WBEM_S_NO_ERROR;
  1149. }
  1150. }
  1151. if (FAILED(hr))
  1152. m_Dispatch.RaiseException (hr);
  1153. return hr;
  1154. }
  1155. //***************************************************************************
  1156. //
  1157. // SCODE CSWbemServices::Put
  1158. //
  1159. // DESCRIPTION:
  1160. //
  1161. // Save/commit a class or instance into this namespace
  1162. //
  1163. // PARAMETERS:
  1164. //
  1165. // objWbemObject Class/Instance to be saved
  1166. // lFlags Flags
  1167. // pContext Context
  1168. // ppObjectPath Object Path
  1169. //
  1170. // RETURN VALUES:
  1171. //
  1172. // WBEM_S_NO_ERROR success
  1173. // WBEM_E_INVALID_PARAMETER bad input parameters
  1174. // WBEM_E_FAILED otherwise
  1175. //
  1176. //***************************************************************************
  1177. HRESULT CSWbemServices::Put (
  1178. ISWbemObjectEx *objWbemObject,
  1179. long lFlags,
  1180. /*ISWbemNamedValueSet*/ IDispatch *pContext,
  1181. ISWbemObjectPath **ppObjectPath
  1182. )
  1183. {
  1184. HRESULT hr = WBEM_E_FAILED;
  1185. ResetLastErrors ();
  1186. if (NULL == objWbemObject)
  1187. hr = WBEM_E_INVALID_PARAMETER;
  1188. else if (m_SecurityInfo)
  1189. {
  1190. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  1191. if (pIWbemServices)
  1192. {
  1193. IWbemClassObject *pObject = CSWbemObject::GetIWbemClassObject (objWbemObject);
  1194. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext, m_pIServiceProvider);
  1195. if (NULL != pObject)
  1196. {
  1197. // Figure out whether this is a class or instance
  1198. VARIANT var;
  1199. VariantInit (&var);
  1200. if (WBEM_S_NO_ERROR == pObject->Get (WBEMS_SP_GENUS, 0, &var, NULL, NULL))
  1201. {
  1202. IWbemCallResult *pResult = NULL;
  1203. HRESULT hrCallResult = WBEM_E_FAILED;
  1204. bool needToResetSecurity = false;
  1205. HANDLE hThreadToken = NULL;
  1206. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  1207. {
  1208. if (WBEM_GENUS_CLASS == var.lVal)
  1209. hrCallResult = pIWbemServices->PutClass
  1210. (pObject, lFlags | WBEM_FLAG_RETURN_IMMEDIATELY, pIContext, &pResult);
  1211. else
  1212. hrCallResult = pIWbemServices->PutInstance
  1213. (pObject, lFlags | WBEM_FLAG_RETURN_IMMEDIATELY, pIContext, &pResult);
  1214. if (needToResetSecurity)
  1215. m_SecurityInfo->ResetSecurity (hThreadToken);
  1216. }
  1217. if (WBEM_S_NO_ERROR == hrCallResult)
  1218. {
  1219. //Secure the IWbemCallResult interface
  1220. m_SecurityInfo->SecureInterface (pResult);
  1221. if ((WBEM_S_NO_ERROR == (hrCallResult = pResult->GetCallStatus (INFINITE, &hr))) &&
  1222. (WBEM_S_NO_ERROR == hr))
  1223. {
  1224. if (ppObjectPath)
  1225. {
  1226. ISWbemObjectPath *pObjectPath = new CSWbemObjectPath (m_SecurityInfo, GetLocale());
  1227. if (!pObjectPath)
  1228. hr = WBEM_E_OUT_OF_MEMORY;
  1229. else
  1230. {
  1231. pObjectPath->AddRef ();
  1232. pObjectPath->put_Path (GetPath ());
  1233. if (WBEM_GENUS_CLASS == var.lVal)
  1234. {
  1235. VARIANT nameVar;
  1236. VariantInit (&nameVar);
  1237. /*
  1238. * Note we must check that returned value is a BSTR - it could be a VT_NULL if
  1239. * the __CLASS property has not yet been set.
  1240. */
  1241. if ((WBEM_S_NO_ERROR == pObject->Get (WBEMS_SP_CLASS, 0, &nameVar, NULL, NULL))
  1242. && (VT_BSTR == V_VT(&nameVar)))
  1243. {
  1244. pObjectPath->put_Class (nameVar.bstrVal);
  1245. *ppObjectPath = pObjectPath;
  1246. } else {
  1247. pObjectPath->Release();
  1248. }
  1249. VariantClear (&nameVar);
  1250. }
  1251. else
  1252. {
  1253. // Now get the relpath string from the call result
  1254. BSTR resultString = NULL;
  1255. if (WBEM_S_NO_ERROR == pResult->GetResultString (INFINITE, &resultString))
  1256. {
  1257. pObjectPath->put_RelPath (resultString);
  1258. *ppObjectPath = pObjectPath;
  1259. SysFreeString (resultString);
  1260. } else {
  1261. pObjectPath->Release();
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. else
  1269. hr = hrCallResult;
  1270. if (pResult)
  1271. pResult->Release ();
  1272. }
  1273. if (pIContext)
  1274. pIContext->Release ();
  1275. pObject->Release ();
  1276. VariantClear (&var);
  1277. }
  1278. SetWbemError (this);
  1279. pIWbemServices->Release ();
  1280. }
  1281. }
  1282. if (FAILED(hr))
  1283. m_Dispatch.RaiseException (hr);
  1284. return hr;
  1285. }
  1286. //***************************************************************************
  1287. //
  1288. // CSWbemServices::GetIWbemServices
  1289. //
  1290. // DESCRIPTION:
  1291. //
  1292. // Return the IWbemServices interface corresponding to this
  1293. // scriptable wrapper.
  1294. //
  1295. // PARAMETERS:
  1296. // ppServices holds the IWbemServices pointer on return
  1297. //
  1298. // RETURN VALUES:
  1299. // S_OK success
  1300. // E_FAIL otherwise
  1301. //
  1302. // NOTES:
  1303. // If successful, the returned interface is AddRef'd; the caller is
  1304. // responsible for release.
  1305. //
  1306. //***************************************************************************
  1307. STDMETHODIMP CSWbemServices::GetIWbemServices (IWbemServices **ppServices)
  1308. {
  1309. HRESULT hr = E_FAIL;
  1310. if (ppServices)
  1311. {
  1312. *ppServices = GetIWbemServices ();
  1313. hr = S_OK;
  1314. }
  1315. return hr;
  1316. }
  1317. //***************************************************************************
  1318. //
  1319. // CSWbemServices::GetIWbemServices
  1320. //
  1321. // DESCRIPTION:
  1322. //
  1323. // Given an IDispatch interface which we hope is also an ISWbemServicesEx
  1324. // interface, return the underlying IWbemServices interface.
  1325. //
  1326. // PARAMETERS:
  1327. // pDispatch the IDispatch in question
  1328. //
  1329. // RETURN VALUES:
  1330. // The underlying IWbemServices interface, or NULL.
  1331. //
  1332. // NOTES:
  1333. // If successful, the returned interface is AddRef'd; the caller is
  1334. // responsible for release.
  1335. //
  1336. //***************************************************************************
  1337. IWbemServices *CSWbemServices::GetIWbemServices (
  1338. IDispatch *pDispatch
  1339. )
  1340. {
  1341. IWbemServices *pServices = NULL;
  1342. ISWbemInternalServices *pIServices = NULL;
  1343. if (pDispatch)
  1344. {
  1345. if (SUCCEEDED (pDispatch->QueryInterface
  1346. (IID_ISWbemInternalServices, (PPVOID) &pIServices)))
  1347. {
  1348. pIServices->GetIWbemServices (&pServices);
  1349. pIServices->Release ();
  1350. }
  1351. }
  1352. return pServices;
  1353. }