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.

818 lines
24 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;
  163. pIWbemServices.Attach(GetIWbemServices());
  164. if (pIWbemServices)
  165. {
  166. CWbemPathCracker pathCracker (strObjectPath);
  167. if ((pathCracker.GetType () != CWbemPathCracker::WbemPathType::wbemPathTypeError) &&
  168. pathCracker.IsClassOrInstance ())
  169. {
  170. // Create the sink
  171. CWbemObjectSink *pWbemObjectSink;
  172. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  173. this, pAsyncNotify, pAsyncContext);
  174. if (pSink)
  175. {
  176. // Get the context
  177. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  178. m_pIServiceProvider);
  179. bool needToResetSecurity = false;
  180. HANDLE hThreadToken = NULL;
  181. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  182. {
  183. if (pathCracker.IsInstance ())
  184. hr = pIWbemServices->DeleteInstanceAsync (strObjectPath, iFlags, pIContext, pSink);
  185. else
  186. hr = pIWbemServices->DeleteClassAsync (strObjectPath, iFlags, pIContext, pSink);
  187. }
  188. // Check to see if we need to release the stub (either we failed locally
  189. // or via a re-entrant call to SetStatus
  190. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  191. // Restore original privileges on this thread
  192. if (needToResetSecurity)
  193. m_SecurityInfo->ResetSecurity (hThreadToken);
  194. SetWbemError (this);
  195. if (pIContext)
  196. pIContext->Release ();
  197. } else
  198. hr = wbemErrInvalidParameter;
  199. }
  200. else
  201. hr = wbemErrInvalidParameter;
  202. }
  203. }
  204. if (FAILED(hr))
  205. m_Dispatch.RaiseException (hr);
  206. return hr;
  207. }
  208. HRESULT STDMETHODCALLTYPE CSWbemServices::InstancesOfAsync
  209. (
  210. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  211. /* [in] */ BSTR strClass,
  212. /* [defaultvalue][optional][in] */ long iFlags,
  213. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  214. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  215. )
  216. {
  217. HRESULT hr = WBEM_E_FAILED;
  218. ResetLastErrors ();
  219. if (m_SecurityInfo)
  220. {
  221. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  222. if (pIWbemServices)
  223. {
  224. // Create the sink
  225. CWbemObjectSink *pWbemObjectSink;
  226. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  227. this, pAsyncNotify, pAsyncContext);
  228. if (pSink)
  229. {
  230. // Get the context
  231. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  232. m_pIServiceProvider);
  233. bool needToResetSecurity = false;
  234. HANDLE hThreadToken = NULL;
  235. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  236. hr = pIWbemServices->CreateInstanceEnumAsync
  237. (strClass, iFlags, pIContext, pSink);
  238. // Check to see if we need to release the stub (either we failed locally
  239. // or via a re-entrant call to SetStatus
  240. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  241. // Restore original privileges on this thread
  242. if (needToResetSecurity)
  243. m_SecurityInfo->ResetSecurity (hThreadToken);
  244. SetWbemError (this);
  245. if (pIContext)
  246. pIContext->Release ();
  247. } else
  248. hr = wbemErrInvalidParameter;
  249. pIWbemServices->Release ();
  250. }
  251. }
  252. if (FAILED(hr))
  253. m_Dispatch.RaiseException (hr);
  254. return hr;
  255. }
  256. HRESULT STDMETHODCALLTYPE CSWbemServices::SubclassesOfAsync
  257. (
  258. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  259. /* [defaultvalue][optional][in] */ BSTR strSuperclass,
  260. /* [defaultvalue][optional][in] */ long iFlags,
  261. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  262. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  263. )
  264. {
  265. HRESULT hr = WBEM_E_FAILED;
  266. ResetLastErrors ();
  267. if (m_SecurityInfo)
  268. {
  269. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  270. if (pIWbemServices)
  271. {
  272. // Create the sink
  273. CWbemObjectSink *pWbemObjectSink;
  274. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  275. this, pAsyncNotify, pAsyncContext);
  276. if (pSink)
  277. {
  278. // Get the context
  279. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  280. m_pIServiceProvider);
  281. bool needToResetSecurity = false;
  282. HANDLE hThreadToken = NULL;
  283. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  284. hr = pIWbemServices->CreateClassEnumAsync
  285. (strSuperclass, iFlags, pIContext, pSink);
  286. // Check to see if we need to release the stub (either we failed locally
  287. // or via a re-entrant call to SetStatus
  288. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  289. // Restore original privileges on this thread
  290. if (needToResetSecurity)
  291. m_SecurityInfo->ResetSecurity (hThreadToken);
  292. SetWbemError (this);
  293. if (pIContext)
  294. pIContext->Release ();
  295. } else
  296. hr = wbemErrInvalidParameter;
  297. pIWbemServices->Release ();
  298. }
  299. }
  300. if (FAILED(hr))
  301. m_Dispatch.RaiseException (hr);
  302. return hr;
  303. }
  304. HRESULT STDMETHODCALLTYPE CSWbemServices::AssociatorsOfAsync
  305. (
  306. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  307. /* [in] */ BSTR strObjectPath,
  308. /* [defaultvalue][optional][in] */ BSTR strAssocClass,
  309. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  310. /* [defaultvalue][optional][in] */ BSTR strResultRole,
  311. /* [defaultvalue][optional][in] */ BSTR strRole,
  312. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  313. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  314. /* [defaultvalue][optional][in] */ BSTR strRequiredAssocQualifier,
  315. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  316. /* [defaultvalue][optional][in] */ long iFlags,
  317. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  318. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  319. )
  320. {
  321. HRESULT hr = WBEM_E_FAILED;
  322. ResetLastErrors ();
  323. if (NULL == strObjectPath)
  324. hr = WBEM_E_INVALID_PARAMETER;
  325. else if (m_SecurityInfo)
  326. {
  327. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  328. if (pIWbemServices)
  329. {
  330. // Create the sink
  331. CWbemObjectSink *pWbemObjectSink;
  332. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  333. this, pAsyncNotify, pAsyncContext);
  334. if (pSink)
  335. {
  336. // Get the context
  337. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  338. m_pIServiceProvider);
  339. // Format the query string
  340. BSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  341. BSTR bsQuery = FormatAssociatorsQuery (strObjectPath, strAssocClass, strResultClass, strResultRole,
  342. strRole, bClassesOnly, bSchemaOnly, strRequiredAssocQualifier, strRequiredQualifier);
  343. bool needToResetSecurity = false;
  344. HANDLE hThreadToken = NULL;
  345. /*
  346. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  347. * guarantee that the returned objects have the __RELPATH
  348. * property included. This is in case anyone calls a
  349. * method subsequently on such an object, as the "."
  350. * notation requires that the __RELPATH property be present.
  351. */
  352. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  353. hr = pIWbemServices->ExecQueryAsync
  354. (bsQueryLanguage, bsQuery,
  355. iFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  356. pIContext,
  357. pSink);
  358. // Check to see if we need to release the stub (either we failed locally
  359. // or via a re-entrant call to SetStatus
  360. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  361. if (needToResetSecurity)
  362. m_SecurityInfo->ResetSecurity (hThreadToken);
  363. SetWbemError (this);
  364. SysFreeString (bsQuery);
  365. SysFreeString (bsQueryLanguage);
  366. if (pIContext)
  367. pIContext->Release ();
  368. } else
  369. hr = wbemErrInvalidParameter;
  370. pIWbemServices->Release ();
  371. }
  372. }
  373. if (FAILED(hr))
  374. m_Dispatch.RaiseException (hr);
  375. return hr;
  376. }
  377. HRESULT STDMETHODCALLTYPE CSWbemServices::ReferencesToAsync
  378. (
  379. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  380. /* [in] */ BSTR strObjectPath,
  381. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  382. /* [defaultvalue][optional][in] */ BSTR strRole,
  383. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  384. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  385. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  386. /* [defaultvalue][optional][in] */ long iFlags,
  387. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  388. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  389. )
  390. {
  391. HRESULT hr = WBEM_E_FAILED;
  392. ResetLastErrors ();
  393. if (NULL == strObjectPath)
  394. hr = WBEM_E_INVALID_PARAMETER;
  395. else if (m_SecurityInfo)
  396. {
  397. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  398. if (pIWbemServices)
  399. {
  400. // Create the sink
  401. CWbemObjectSink *pWbemObjectSink;
  402. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  403. this, pAsyncNotify, pAsyncContext);
  404. if (pSink)
  405. {
  406. // Get the context
  407. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  408. m_pIServiceProvider);
  409. // Format the query string
  410. CComBSTR bsQueryLanguage = SysAllocString (OLESTR("WQL"));
  411. CComBSTR bsQuery = FormatReferencesQuery (strObjectPath, strResultClass, strRole,
  412. bClassesOnly, bSchemaOnly, strRequiredQualifier);
  413. bool needToResetSecurity = false;
  414. HANDLE hThreadToken = NULL;
  415. /*
  416. * We OR in the WBEM_FLAG_ENSURE_LOCATABLE flag to
  417. * guarantee that the returned objects have the __RELPATH
  418. * property included. This is in case anyone calls a
  419. * method subsequently on such an object, as the "."
  420. * notation requires that the __RELPATH property be present.
  421. */
  422. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  423. hr = pIWbemServices->ExecQueryAsync
  424. (bsQueryLanguage, bsQuery,
  425. iFlags | WBEM_FLAG_ENSURE_LOCATABLE,
  426. pIContext,
  427. pSink);
  428. // Check to see if we need to release the stub (either we failed locally
  429. // or via a re-entrant call to SetStatus
  430. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  431. if (needToResetSecurity)
  432. m_SecurityInfo->ResetSecurity (hThreadToken);
  433. SetWbemError (this);
  434. if (pIContext)
  435. pIContext->Release ();
  436. } else
  437. hr = wbemErrInvalidParameter;
  438. pIWbemServices->Release ();
  439. }
  440. }
  441. if (FAILED(hr))
  442. m_Dispatch.RaiseException (hr);
  443. return hr;
  444. }
  445. HRESULT STDMETHODCALLTYPE CSWbemServices::ExecNotificationQueryAsync
  446. (
  447. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  448. /* [in] */ BSTR Query,
  449. /* [defaultvalue][optional][in] */ BSTR strQueryLanguage,
  450. /* [defaultvalue][optional][in] */ long iFlags,
  451. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  452. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  453. )
  454. {
  455. HRESULT hr = WBEM_E_FAILED;
  456. ResetLastErrors ();
  457. if (m_SecurityInfo)
  458. {
  459. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  460. if (pIWbemServices)
  461. {
  462. // Create the sink
  463. CWbemObjectSink *pWbemObjectSink;
  464. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  465. this, pAsyncNotify, pAsyncContext);
  466. if (pSink)
  467. {
  468. // Get the context
  469. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  470. m_pIServiceProvider);
  471. bool needToResetSecurity = false;
  472. HANDLE hThreadToken = NULL;
  473. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  474. hr = pIWbemServices->ExecNotificationQueryAsync
  475. (strQueryLanguage, Query, iFlags, pIContext, pSink);
  476. // Check to see if we need to release the stub (either we failed locally
  477. // or via a re-entrant call to SetStatus
  478. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  479. if (needToResetSecurity)
  480. m_SecurityInfo->ResetSecurity (hThreadToken);
  481. SetWbemError (this);
  482. if (pIContext)
  483. pIContext->Release ();
  484. } else
  485. hr = wbemErrInvalidParameter;
  486. pIWbemServices->Release ();
  487. }
  488. }
  489. if (FAILED(hr))
  490. m_Dispatch.RaiseException (hr);
  491. return hr;
  492. }
  493. HRESULT STDMETHODCALLTYPE CSWbemServices::ExecMethodAsync
  494. (
  495. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  496. /* [in] */ BSTR strObjectPath,
  497. /* [in] */ BSTR strMethodName,
  498. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objInParams,
  499. /* [defaultvalue][optional][in] */ long iFlags,
  500. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  501. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext
  502. )
  503. {
  504. HRESULT hr = WBEM_E_FAILED;
  505. ResetLastErrors ();
  506. if (m_SecurityInfo)
  507. {
  508. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  509. if (pIWbemServices)
  510. {
  511. // Create the sink
  512. CWbemObjectSink *pWbemObjectSink;
  513. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  514. this, pAsyncNotify, pAsyncContext);
  515. if (pSink)
  516. {
  517. IWbemClassObject *pIInParams = CSWbemObject::GetIWbemClassObject (objInParams);
  518. // Get the context
  519. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  520. m_pIServiceProvider);
  521. bool needToResetSecurity = false;
  522. HANDLE hThreadToken = NULL;
  523. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  524. hr = pIWbemServices->ExecMethodAsync
  525. (strObjectPath, strMethodName, iFlags, pIContext, pIInParams, pSink);
  526. // Check to see if we need to release the stub (either we failed locally
  527. // or via a re-entrant call to SetStatus
  528. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  529. if (needToResetSecurity)
  530. m_SecurityInfo->ResetSecurity (hThreadToken);
  531. SetWbemError (this);
  532. if (pIContext)
  533. pIContext->Release ();
  534. if (pIInParams)
  535. pIInParams->Release ();
  536. } else
  537. hr = wbemErrInvalidParameter;
  538. pIWbemServices->Release ();
  539. }
  540. }
  541. if (FAILED(hr))
  542. m_Dispatch.RaiseException (hr);
  543. return hr;
  544. }
  545. HRESULT STDMETHODCALLTYPE CSWbemServices::PutAsync
  546. (
  547. /* [in] */ ISWbemSink *pAsyncNotify,
  548. /* [in] */ ISWbemObjectEx *objObject,
  549. /* [in] */ long iFlags,
  550. /* [in] */ /*ISWbemNamedValueSet*/ IDispatch *objContext,
  551. /* [in] */ /*ISWbemNamedValueSet*/ IDispatch *pAsyncContext
  552. )
  553. {
  554. HRESULT hr = WBEM_E_FAILED;
  555. ResetLastErrors ();
  556. if (m_SecurityInfo)
  557. {
  558. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  559. if (pIWbemServices)
  560. {
  561. if (pAsyncNotify)
  562. {
  563. IWbemClassObject *pWbemClassObject = CSWbemObject::GetIWbemClassObject (objObject);
  564. if (pWbemClassObject)
  565. {
  566. // Figure out whether this is a class or instance
  567. VARIANT var;
  568. VariantInit (&var);
  569. if (WBEM_S_NO_ERROR == pWbemClassObject->Get (WBEMS_SP_GENUS, 0, &var, NULL, NULL))
  570. {
  571. IWbemContext *pIContext = CSWbemNamedValueSet::GetIWbemContext (objContext,
  572. m_pIServiceProvider);
  573. if (WBEM_GENUS_CLASS == var.lVal)
  574. {
  575. // Save the class name for later
  576. VARIANT nameVar;
  577. VariantInit (&nameVar);
  578. /*
  579. * Note we must check that returned value is a BSTR - it could be a VT_NULL if
  580. * the __CLASS property has not yet been set.
  581. */
  582. if ((WBEM_S_NO_ERROR == pWbemClassObject->Get (WBEMS_SP_CLASS, 0, &nameVar, NULL, NULL))
  583. && (VT_BSTR == V_VT(&nameVar)))
  584. {
  585. // Create the sink
  586. CWbemObjectSink *pWbemObjectSink;
  587. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  588. this, pAsyncNotify, pAsyncContext, true, nameVar.bstrVal);
  589. if (pSink)
  590. {
  591. bool needToResetSecurity = false;
  592. HANDLE hThreadToken = NULL;
  593. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  594. hr = pIWbemServices->PutClassAsync (pWbemClassObject, iFlags,
  595. pIContext, pSink);
  596. // Check to see if we need to release the stub (either we failed locally
  597. // or via a re-entrant call to SetStatus
  598. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  599. if (needToResetSecurity)
  600. m_SecurityInfo->ResetSecurity (hThreadToken);
  601. }
  602. }
  603. VariantClear (&nameVar);
  604. }
  605. else
  606. {
  607. // Create the sink
  608. CWbemObjectSink *pWbemObjectSink;
  609. IWbemObjectSink *pSink = CWbemObjectSink::CreateObjectSink(&pWbemObjectSink,
  610. this, pAsyncNotify, pAsyncContext, true);
  611. if (pSink)
  612. {
  613. bool needToResetSecurity = false;
  614. HANDLE hThreadToken = NULL;
  615. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  616. hr = pIWbemServices->PutInstanceAsync (pWbemClassObject, iFlags, pIContext, pSink);
  617. // Check to see if we need to release the stub (either we failed locally
  618. // or via a re-entrant call to SetStatus
  619. pWbemObjectSink->ReleaseTheStubIfNecessary(hr);
  620. // Restore original privileges on this thread
  621. if (needToResetSecurity)
  622. m_SecurityInfo->ResetSecurity (hThreadToken);
  623. }
  624. }
  625. SetWbemError (this);
  626. if (pIContext)
  627. pIContext->Release ();
  628. }
  629. pWbemClassObject->Release ();
  630. VariantClear (&var);
  631. }
  632. } else
  633. hr = wbemErrInvalidParameter;
  634. pIWbemServices->Release ();
  635. }
  636. }
  637. if (FAILED(hr))
  638. m_Dispatch.RaiseException (hr);
  639. return hr;
  640. }
  641. HRESULT CSWbemServices::CancelAsyncCall(IWbemObjectSink *pSink)
  642. {
  643. HRESULT hr = WBEM_E_FAILED;
  644. ResetLastErrors ();
  645. if (m_SecurityInfo)
  646. {
  647. IWbemServices *pIWbemServices = (IWbemServices *) m_SecurityInfo->GetProxy ();
  648. if (pIWbemServices)
  649. {
  650. bool needToResetSecurity = false;
  651. HANDLE hThreadToken = NULL;
  652. if (m_SecurityInfo->SetSecurity (needToResetSecurity, hThreadToken))
  653. hr = pIWbemServices->CancelAsyncCall(pSink);
  654. pIWbemServices->Release ();
  655. // Restore original privileges on this thread
  656. if (needToResetSecurity)
  657. m_SecurityInfo->ResetSecurity (hThreadToken);
  658. }
  659. }
  660. return hr;
  661. }