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.

817 lines
23 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-2000 Microsoft Corporation
  4. //
  5. // SERVICES.CPP
  6. //
  7. // rogerbo 26-May-98 Created.
  8. //
  9. // Defines the implementation of ISWbemServicesEx
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include "objsink.h"
  14. //***************************************************************************
  15. //
  16. // SCODE CSWbemServices::ExecQueryAsync
  17. //
  18. // DESCRIPTION:
  19. //
  20. // Execute an asynchronous query
  21. //
  22. // PARAMETERS:
  23. //
  24. // bsQuery The query strimg
  25. // pAsyncNotify The notification sink
  26. // bsQueryLanguage The query language descriptor (e.g."WQL")
  27. // lFlags Flags
  28. // pContext Any context information
  29. // pAsyncContext asynchronous context information
  30. // ppEnum Returns the sink
  31. //
  32. // RETURN VALUES:
  33. //
  34. // WBEM_S_NO_ERROR success
  35. // WBEM_E_INVALID_PARAMETER bad input parameters
  36. // WBEM_E_FAILED otherwise
  37. //
  38. //***************************************************************************
  39. HRESULT STDMETHODCALLTYPE CSWbemServices::ExecQueryAsync
  40. (
  41. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  42. /* [in] */ BSTR Query,
  43. /* [defaultvalue][optional][in] */ BSTR QueryLanguage,
  44. /* [defaultvalue][optional][in] */ long lFlags,
  45. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pContext,
  46. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  47. )
  48. {
  49. HRESULT hr = WBEM_E_FAILED;
  50. ResetLastErrors ();
  51. if (m_SecurityInfo)
  52. {
  53. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  54. if (pIWbemServices)
  55. {
  56. // Create the sink
  57. CWbemObjectSink *pWbemObjectSink;
  58. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  59. this, pAsyncNotify, pAsyncContext);
  60. if (pSink)
  61. {
  62. // Get the context
  63. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (pContext,
  64. m_pIServiceProvider);
  65. bool needToResetSecurity = false;
  66. HANDLE hThreadToken = NULL;
  67. /*
  68. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  69. * guarantee that the returned objects have the __RELPATH
  70. * property included. This is in case anyone calls a
  71. * method subsequently on such an object, as the "."
  72. * notation requires that the __RELPATH property be present.
  73. */
  74. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  75. hr = pIWbemServices->ExecQueryAsync
  76. (QueryLanguage, Query,
  77. lFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  78. pIContext,
  79. pSink);
  80. // Check to see if we need to release the stub (either we failed locally
  81. // or via a re-entrant call to SetStatus
  82. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  83. // Restore original privileges on this thread
  84. if (needToResetSecurity)
  85. m_SecurityInfo->ResetSecurity (hThreadToken);
  86. SetWbemError (this);
  87. if (pIContext)
  88. pIContext->Release ();
  89. } else
  90. hr = wbemErrInvalidParameter;
  91. pIWbemServices->Release ();
  92. }
  93. }
  94. if (FAILED(hr))
  95. m_Dispatch.RaiseException (hr);
  96. return hr;
  97. }
  98. HRESULT STDMETHODCALLTYPE CSWbemServices::GetAsync
  99. (
  100. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  101. /* [defaultvalue][optional][in] */ BSTR strObjectPath,
  102. /* [defaultvalue][optional][in] */ long iFlags,
  103. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  104. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  105. )
  106. {
  107. HRESULT hr = WBEM_E_FAILED;
  108. ResetLastErrors ();
  109. if (m_SecurityInfo)
  110. {
  111. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  112. if (pIWbemServices)
  113. {
  114. // Create the sink
  115. CWbemObjectSink *pWbemObjectSink;
  116. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  117. this, pAsyncNotify, pAsyncContext);
  118. if (pSink)
  119. {
  120. // Get the context
  121. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  122. m_pIServiceProvider);
  123. bool needToResetSecurity = false;
  124. HANDLE hThreadToken = NULL;
  125. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  126. hr = pIWbemServices->GetObjectAsync (
  127. (strObjectPath && (0 < wcslen(strObjectPath))) ? strObjectPath : NULL,
  128. iFlags,
  129. pIContext,
  130. pSink);
  131. // Check to see if we need to release the stub (either we failed locally
  132. // or via a re-entrant call to SetStatus
  133. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  134. // Restore original privileges on this thread
  135. if (needToResetSecurity)
  136. m_SecurityInfo->ResetSecurity (hThreadToken);
  137. SetWbemError (this);
  138. if (pIContext)
  139. pIContext->Release ();
  140. } else
  141. hr = wbemErrInvalidParameter;
  142. pIWbemServices->Release ();
  143. }
  144. }
  145. if (FAILED(hr))
  146. m_Dispatch.RaiseException (hr);
  147. return hr;
  148. }
  149. HRESULT STDMETHODCALLTYPE CSWbemServices::DeleteAsync
  150. (
  151. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  152. /* [in] */ BSTR strObjectPath,
  153. /* [defaultvalue][optional][in] */ long iFlags,
  154. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  155. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  156. )
  157. {
  158. HRESULT hr = WBEM_E_FAILED;
  159. ResetLastErrors ();
  160. if (m_SecurityInfo)
  161. {
  162. CComPtr<IWbemServices> pIWbemServices = GetIWbemServices ();
  163. if (pIWbemServices)
  164. {
  165. CWbemPathCracker pathCracker (strObjectPath);
  166. if ((pathCracker.GetType () != CWbemPathCracker::WbemPathType::wbemPathTypeError) &&
  167. pathCracker.IsClassOrInstance ())
  168. {
  169. // Create the sink
  170. CWbemObjectSink *pWbemObjectSink;
  171. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  172. this, pAsyncNotify, pAsyncContext);
  173. if (pSink)
  174. {
  175. // Get the context
  176. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  177. m_pIServiceProvider);
  178. bool needToResetSecurity = false;
  179. HANDLE hThreadToken = NULL;
  180. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  181. {
  182. if (pathCracker.IsInstance ())
  183. hr = pIWbemServices->DeleteInstanceAsync (strObjectPath, iFlags, pIContext, pSink);
  184. else
  185. hr = pIWbemServices->DeleteClassAsync (strObjectPath, iFlags, pIContext, pSink);
  186. }
  187. // Check to see if we need to release the stub (either we failed locally
  188. // or via a re-entrant call to SetStatus
  189. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  190. // Restore original privileges on this thread
  191. if (needToResetSecurity)
  192. m_SecurityInfo->ResetSecurity (hThreadToken);
  193. SetWbemError (this);
  194. if (pIContext)
  195. pIContext->Release ();
  196. } else
  197. hr = wbemErrInvalidParameter;
  198. }
  199. else
  200. hr = wbemErrInvalidParameter;
  201. }
  202. }
  203. if (FAILED(hr))
  204. m_Dispatch.RaiseException (hr);
  205. return hr;
  206. }
  207. HRESULT STDMETHODCALLTYPE CSWbemServices::InstancesOfAsync
  208. (
  209. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  210. /* [in] */ BSTR strClass,
  211. /* [defaultvalue][optional][in] */ long iFlags,
  212. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  213. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  214. )
  215. {
  216. HRESULT hr = WBEM_E_FAILED;
  217. ResetLastErrors ();
  218. if (m_SecurityInfo)
  219. {
  220. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  221. if (pIWbemServices)
  222. {
  223. // Create the sink
  224. CWbemObjectSink *pWbemObjectSink;
  225. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  226. this, pAsyncNotify, pAsyncContext);
  227. if (pSink)
  228. {
  229. // Get the context
  230. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  231. m_pIServiceProvider);
  232. bool needToResetSecurity = false;
  233. HANDLE hThreadToken = NULL;
  234. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  235. hr = pIWbemServices->CreateInstanceEnumAsync
  236. (strClass, iFlags, pIContext, pSink);
  237. // Check to see if we need to release the stub (either we failed locally
  238. // or via a re-entrant call to SetStatus
  239. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  240. // Restore original privileges on this thread
  241. if (needToResetSecurity)
  242. m_SecurityInfo->ResetSecurity (hThreadToken);
  243. SetWbemError (this);
  244. if (pIContext)
  245. pIContext->Release ();
  246. } else
  247. hr = wbemErrInvalidParameter;
  248. pIWbemServices->Release ();
  249. }
  250. }
  251. if (FAILED(hr))
  252. m_Dispatch.RaiseException (hr);
  253. return hr;
  254. }
  255. HRESULT STDMETHODCALLTYPE CSWbemServices::SubclassesOfAsync
  256. (
  257. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  258. /* [defaultvalue][optional][in] */ BSTR strSuperclass,
  259. /* [defaultvalue][optional][in] */ long iFlags,
  260. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  261. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  262. )
  263. {
  264. HRESULT hr = WBEM_E_FAILED;
  265. ResetLastErrors ();
  266. if (m_SecurityInfo)
  267. {
  268. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  269. if (pIWbemServices)
  270. {
  271. // Create the sink
  272. CWbemObjectSink *pWbemObjectSink;
  273. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  274. this, pAsyncNotify, pAsyncContext);
  275. if (pSink)
  276. {
  277. // Get the context
  278. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  279. m_pIServiceProvider);
  280. bool needToResetSecurity = false;
  281. HANDLE hThreadToken = NULL;
  282. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  283. hr = pIWbemServices->CreateClassEnumAsync
  284. (strSuperclass, iFlags, pIContext, pSink);
  285. // Check to see if we need to release the stub (either we failed locally
  286. // or via a re-entrant call to SetStatus
  287. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  288. // Restore original privileges on this thread
  289. if (needToResetSecurity)
  290. m_SecurityInfo->ResetSecurity (hThreadToken);
  291. SetWbemError (this);
  292. if (pIContext)
  293. pIContext->Release ();
  294. } else
  295. hr = wbemErrInvalidParameter;
  296. pIWbemServices->Release ();
  297. }
  298. }
  299. if (FAILED(hr))
  300. m_Dispatch.RaiseException (hr);
  301. return hr;
  302. }
  303. HRESULT STDMETHODCALLTYPE CSWbemServices::AssociatorsOfAsync
  304. (
  305. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  306. /* [in] */ BSTR strObjectPath,
  307. /* [defaultvalue][optional][in] */ BSTR strAssocClass,
  308. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  309. /* [defaultvalue][optional][in] */ BSTR strResultRole,
  310. /* [defaultvalue][optional][in] */ BSTR strRole,
  311. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  312. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  313. /* [defaultvalue][optional][in] */ BSTR strRequiredAssocQualifier,
  314. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  315. /* [defaultvalue][optional][in] */ long iFlags,
  316. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  317. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  318. )
  319. {
  320. HRESULT hr = WBEM_E_FAILED;
  321. ResetLastErrors ();
  322. if (NULL == strObjectPath)
  323. hr = WBEM_E_INVALID_PARAMETER;
  324. else if (m_SecurityInfo)
  325. {
  326. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  327. if (pIWbemServices)
  328. {
  329. // Create the sink
  330. CWbemObjectSink *pWbemObjectSink;
  331. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  332. this, pAsyncNotify, pAsyncContext);
  333. if (pSink)
  334. {
  335. // Get the context
  336. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  337. m_pIServiceProvider);
  338. // Format the query string
  339. BSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  340. BSTR bsQuery = FormatAssociatorsQuery (strObjectPath, strAssocClass, strResultClass, strResultRole,
  341. strRole, bClassesOnly, bSchemaOnly, strRequiredAssocQualifier, strRequiredQualifier);
  342. bool needToResetSecurity = false;
  343. HANDLE hThreadToken = NULL;
  344. /*
  345. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  346. * guarantee that the returned objects have the __RELPATH
  347. * property included. This is in case anyone calls a
  348. * method subsequently on such an object, as the "."
  349. * notation requires that the __RELPATH property be present.
  350. */
  351. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  352. hr = pIWbemServices->ExecQueryAsync
  353. (bsQueryLanguage, bsQuery,
  354. iFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  355. pIContext,
  356. pSink);
  357. // Check to see if we need to release the stub (either we failed locally
  358. // or via a re-entrant call to SetStatus
  359. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  360. if (needToResetSecurity)
  361. m_SecurityInfo->ResetSecurity (hThreadToken);
  362. SetWbemError (this);
  363. SysFreeString (bsQuery);
  364. SysFreeString (bsQueryLanguage);
  365. if (pIContext)
  366. pIContext->Release ();
  367. } else
  368. hr = wbemErrInvalidParameter;
  369. pIWbemServices->Release ();
  370. }
  371. }
  372. if (FAILED(hr))
  373. m_Dispatch.RaiseException (hr);
  374. return hr;
  375. }
  376. HRESULT STDMETHODCALLTYPE CSWbemServices::ReferencesToAsync
  377. (
  378. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  379. /* [in] */ BSTR strObjectPath,
  380. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  381. /* [defaultvalue][optional][in] */ BSTR strRole,
  382. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  383. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  384. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  385. /* [defaultvalue][optional][in] */ long iFlags,
  386. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  387. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  388. )
  389. {
  390. HRESULT hr = WBEM_E_FAILED;
  391. ResetLastErrors ();
  392. if (NULL == strObjectPath)
  393. hr = WBEM_E_INVALID_PARAMETER;
  394. else if (m_SecurityInfo)
  395. {
  396. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  397. if (pIWbemServices)
  398. {
  399. // Create the sink
  400. CWbemObjectSink *pWbemObjectSink;
  401. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  402. this, pAsyncNotify, pAsyncContext);
  403. if (pSink)
  404. {
  405. // Get the context
  406. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  407. m_pIServiceProvider);
  408. // Format the query string
  409. CComBSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  410. CComBSTR bsQuery = FormatReferencesQuery (strObjectPath, strResultClass, strRole,
  411. bClassesOnly, bSchemaOnly, strRequiredQualifier);
  412. bool needToResetSecurity = false;
  413. HANDLE hThreadToken = NULL;
  414. /*
  415. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  416. * guarantee that the returned objects have the __RELPATH
  417. * property included. This is in case anyone calls a
  418. * method subsequently on such an object, as the "."
  419. * notation requires that the __RELPATH property be present.
  420. */
  421. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  422. hr = pIWbemServices->ExecQueryAsync
  423. (bsQueryLanguage, bsQuery,
  424. iFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  425. pIContext,
  426. pSink);
  427. // Check to see if we need to release the stub (either we failed locally
  428. // or via a re-entrant call to SetStatus
  429. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  430. if (needToResetSecurity)
  431. m_SecurityInfo->ResetSecurity (hThreadToken);
  432. SetWbemError (this);
  433. if (pIContext)
  434. pIContext->Release ();
  435. } else
  436. hr = wbemErrInvalidParameter;
  437. pIWbemServices->Release ();
  438. }
  439. }
  440. if (FAILED(hr))
  441. m_Dispatch.RaiseException (hr);
  442. return hr;
  443. }
  444. HRESULT STDMETHODCALLTYPE CSWbemServices::ExecNotificationQueryAsync
  445. (
  446. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  447. /* [in] */ BSTR Query,
  448. /* [defaultvalue][optional][in] */ BSTR strQueryLanguage,
  449. /* [defaultvalue][optional][in] */ long iFlags,
  450. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  451. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  452. )
  453. {
  454. HRESULT hr = WBEM_E_FAILED;
  455. ResetLastErrors ();
  456. if (m_SecurityInfo)
  457. {
  458. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  459. if (pIWbemServices)
  460. {
  461. // Create the sink
  462. CWbemObjectSink *pWbemObjectSink;
  463. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  464. this, pAsyncNotify, pAsyncContext);
  465. if (pSink)
  466. {
  467. // Get the context
  468. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  469. m_pIServiceProvider);
  470. bool needToResetSecurity = false;
  471. HANDLE hThreadToken = NULL;
  472. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  473. hr = pIWbemServices->ExecNotificationQueryAsync
  474. (strQueryLanguage, Query, iFlags, pIContext, pSink);
  475. // Check to see if we need to release the stub (either we failed locally
  476. // or via a re-entrant call to SetStatus
  477. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  478. if (needToResetSecurity)
  479. m_SecurityInfo->ResetSecurity (hThreadToken);
  480. SetWbemError (this);
  481. if (pIContext)
  482. pIContext->Release ();
  483. } else
  484. hr = wbemErrInvalidParameter;
  485. pIWbemServices->Release ();
  486. }
  487. }
  488. if (FAILED(hr))
  489. m_Dispatch.RaiseException (hr);
  490. return hr;
  491. }
  492. HRESULT STDMETHODCALLTYPE CSWbemServices::ExecMethodAsync
  493. (
  494. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  495. /* [in] */ BSTR strObjectPath,
  496. /* [in] */ BSTR strMethodName,
  497. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objInParams,
  498. /* [defaultvalue][optional][in] */ long iFlags,
  499. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  500. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  501. )
  502. {
  503. HRESULT hr = WBEM_E_FAILED;
  504. ResetLastErrors ();
  505. if (m_SecurityInfo)
  506. {
  507. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  508. if (pIWbemServices)
  509. {
  510. // Create the sink
  511. CWbemObjectSink *pWbemObjectSink;
  512. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  513. this, pAsyncNotify, pAsyncContext);
  514. if (pSink)
  515. {
  516. IWbemClassObject *pIInParams = CSWbemObject::GetIWbemClassObject (objInParams);
  517. // Get the context
  518. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  519. m_pIServiceProvider);
  520. bool needToResetSecurity = false;
  521. HANDLE hThreadToken = NULL;
  522. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  523. hr = pIWbemServices->ExecMethodAsync
  524. (strObjectPath, strMethodName, iFlags, pIContext, pIInParams, pSink);
  525. // Check to see if we need to release the stub (either we failed locally
  526. // or via a re-entrant call to SetStatus
  527. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  528. if (needToResetSecurity)
  529. m_SecurityInfo->ResetSecurity (hThreadToken);
  530. SetWbemError (this);
  531. if (pIContext)
  532. pIContext->Release ();
  533. if (pIInParams)
  534. pIInParams->Release ();
  535. } else
  536. hr = wbemErrInvalidParameter;
  537. pIWbemServices->Release ();
  538. }
  539. }
  540. if (FAILED(hr))
  541. m_Dispatch.RaiseException (hr);
  542. return hr;
  543. }
  544. HRESULT STDMETHODCALLTYPE CSWbemServices::PutAsync
  545. (
  546. /* [in] */ ISWbemSink *pAsyncNotify,
  547. /* [in] */ ISWbemObjectEx *objObject,
  548. /* [in] */ long iFlags,
  549. /* [in] */ /*ISWbemNamedValueSet*/ IDispatch *objContext,
  550. /* [in] */ /*ISWbemNamedValueSet*/ IDispatch *pAsyncContext
  551. )
  552. {
  553. HRESULT hr = WBEM_E_FAILED;
  554. ResetLastErrors ();
  555. if (m_SecurityInfo)
  556. {
  557. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  558. if (pIWbemServices)
  559. {
  560. if (pAsyncNotify)
  561. {
  562. IWbemClassObject *pWbemClassObject = CSWbemObject::GetIWbemClassObject (objObject);
  563. if (pWbemClassObject)
  564. {
  565. // Figure out whether this is a class or instance
  566. VARIANT var;
  567. VariantInit (&var);
  568. if (WBEM_S_NO_ERROR == pWbemClassObject->Get (WBEMS_SP_GENUS, 0, &var, NULL, NULL))
  569. {
  570. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  571. m_pIServiceProvider);
  572. if (WBEM_GENUS_CLASS == var.lVal)
  573. {
  574. // Save the class name for later
  575. VARIANT nameVar;
  576. VariantInit (&nameVar);
  577. /*
  578. * Note we must check that returned value is a BSTR - it could be a VT_NULL if
  579. * the __CLASS property has not yet been set.
  580. */
  581. if ((WBEM_S_NO_ERROR == pWbemClassObject->Get (WBEMS_SP_CLASS, 0, &nameVar, NULL, NULL))
  582. && (VT_BSTR == V_VT(&nameVar)))
  583. {
  584. // Create the sink
  585. CWbemObjectSink *pWbemObjectSink;
  586. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  587. this, pAsyncNotify, pAsyncContext, true, nameVar.bstrVal);
  588. if (pSink)
  589. {
  590. bool needToResetSecurity = false;
  591. HANDLE hThreadToken = NULL;
  592. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  593. hr = pIWbemServices->PutClassAsync (pWbemClassObject, iFlags,
  594. pIContext, pSink);
  595. // Check to see if we need to release the stub (either we failed locally
  596. // or via a re-entrant call to SetStatus
  597. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  598. if (needToResetSecurity)
  599. m_SecurityInfo->ResetSecurity (hThreadToken);
  600. }
  601. }
  602. VariantClear (&nameVar);
  603. }
  604. else
  605. {
  606. // Create the sink
  607. CWbemObjectSink *pWbemObjectSink;
  608. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  609. this, pAsyncNotify, pAsyncContext, true);
  610. if (pSink)
  611. {
  612. bool needToResetSecurity = false;
  613. HANDLE hThreadToken = NULL;
  614. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  615. hr = pIWbemServices->PutInstanceAsync (pWbemClassObject, iFlags, pIContext, pSink);
  616. // Check to see if we need to release the stub (either we failed locally
  617. // or via a re-entrant call to SetStatus
  618. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  619. // Restore original privileges on this thread
  620. if (needToResetSecurity)
  621. m_SecurityInfo->ResetSecurity (hThreadToken);
  622. }
  623. }
  624. SetWbemError (this);
  625. if (pIContext)
  626. pIContext->Release ();
  627. }
  628. pWbemClassObject->Release ();
  629. VariantClear (&var);
  630. }
  631. } else
  632. hr = wbemErrInvalidParameter;
  633. pIWbemServices->Release ();
  634. }
  635. }
  636. if (FAILED(hr))
  637. m_Dispatch.RaiseException (hr);
  638. return hr;
  639. }
  640. HRESULT CSWbemServices::CancelAsyncCall(IWbemObjectSink *pSink)
  641. {
  642. HRESULT hr = WBEM_E_FAILED;
  643. ResetLastErrors ();
  644. if (m_SecurityInfo)
  645. {
  646. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  647. if (pIWbemServices)
  648. {
  649. bool needToResetSecurity = false;
  650. HANDLE hThreadToken = NULL;
  651. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  652. hr = pIWbemServices->CancelAsyncCall(pSink);
  653. pIWbemServices->Release ();
  654. // Restore original privileges on this thread
  655. if (needToResetSecurity)
  656. m_SecurityInfo->ResetSecurity (hThreadToken);
  657. }
  658. }
  659. return hr;
  660. }