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.

789 lines
16 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvResv.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include "PreComp.h"
  9. #include <wbemint.h>
  10. #include "Globals.h"
  11. #include "CGlobals.h"
  12. #include "ProvResv.h"
  13. #include "ProvFact.h"
  14. #include "ProvSubS.h"
  15. #include "guids.h"
  16. /******************************************************************************
  17. *
  18. * Name:
  19. *
  20. *
  21. * Description:
  22. *
  23. *
  24. *****************************************************************************/
  25. CServerObject_DynamicPropertyProviderResolver :: CServerObject_DynamicPropertyProviderResolver (
  26. WmiAllocator &a_Allocator ,
  27. _IWmiProviderFactory *a_Factory ,
  28. IWbemServices *a_CoreStub
  29. ) : m_ReferenceCount ( 0 ) ,
  30. m_Allocator ( a_Allocator ) ,
  31. m_Factory ( a_Factory ) ,
  32. m_CoreStub ( a_CoreStub ) ,
  33. m_User ( NULL ) ,
  34. m_Locale ( NULL )
  35. {
  36. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_CServerObject_DynamicPropertyProviderResolver_ObjectsInProgress ) ;
  37. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  38. if ( m_Factory )
  39. {
  40. m_Factory->AddRef () ;
  41. }
  42. if ( m_CoreStub )
  43. {
  44. m_CoreStub->AddRef () ;
  45. }
  46. }
  47. /******************************************************************************
  48. *
  49. * Name:
  50. *
  51. *
  52. * Description:
  53. *
  54. *
  55. *****************************************************************************/
  56. CServerObject_DynamicPropertyProviderResolver::~CServerObject_DynamicPropertyProviderResolver ()
  57. {
  58. if ( m_User )
  59. {
  60. SysFreeString ( m_User ) ;
  61. }
  62. if ( m_Locale )
  63. {
  64. SysFreeString ( m_Locale ) ;
  65. }
  66. if ( m_Factory )
  67. {
  68. m_Factory->Release () ;
  69. }
  70. if ( m_CoreStub )
  71. {
  72. m_CoreStub->Release () ;
  73. }
  74. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_CServerObject_DynamicPropertyProviderResolver_ObjectsInProgress ) ;
  75. ProviderSubSystem_Globals :: Decrement_Global_Object_Count () ;
  76. }
  77. /******************************************************************************
  78. *
  79. * Name:
  80. *
  81. *
  82. * Description:
  83. *
  84. *
  85. *****************************************************************************/
  86. STDMETHODIMP CServerObject_DynamicPropertyProviderResolver::QueryInterface (
  87. REFIID iid ,
  88. LPVOID FAR *iplpv
  89. )
  90. {
  91. *iplpv = NULL ;
  92. if ( iid == IID_IUnknown )
  93. {
  94. *iplpv = ( LPVOID ) this ;
  95. }
  96. else if ( iid == IID__IWmiDynamicPropertyResolver )
  97. {
  98. *iplpv = ( LPVOID ) ( _IWmiDynamicPropertyResolver * ) this ;
  99. }
  100. else if ( iid == IID_IWbemProviderInit )
  101. {
  102. *iplpv = ( LPVOID ) ( IWbemProviderInit * ) this ;
  103. }
  104. else if ( iid == IID_IWbemShutdown )
  105. {
  106. *iplpv = ( LPVOID ) ( IWbemShutdown * )this ;
  107. }
  108. if ( *iplpv )
  109. {
  110. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  111. return ResultFromScode ( S_OK ) ;
  112. }
  113. else
  114. {
  115. return ResultFromScode ( E_NOINTERFACE ) ;
  116. }
  117. }
  118. /******************************************************************************
  119. *
  120. * Name:
  121. *
  122. *
  123. * Description:
  124. *
  125. *
  126. *****************************************************************************/
  127. STDMETHODIMP_( ULONG ) CServerObject_DynamicPropertyProviderResolver :: AddRef ()
  128. {
  129. return InterlockedIncrement ( & m_ReferenceCount ) ;
  130. }
  131. /******************************************************************************
  132. *
  133. * Name:
  134. *
  135. *
  136. * Description:
  137. *
  138. *
  139. *****************************************************************************/
  140. STDMETHODIMP_(ULONG) CServerObject_DynamicPropertyProviderResolver :: Release ()
  141. {
  142. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  143. if ( t_ReferenceCount == 0 )
  144. {
  145. delete this ;
  146. }
  147. return t_ReferenceCount ;
  148. }
  149. /******************************************************************************
  150. *
  151. * Name:
  152. *
  153. *
  154. * Description:
  155. *
  156. *
  157. *****************************************************************************/
  158. HRESULT CServerObject_DynamicPropertyProviderResolver :: GetClassAndInstanceContext (
  159. IWbemClassObject *a_Class ,
  160. IWbemClassObject *a_Instance ,
  161. BSTR &a_ClassContext ,
  162. BSTR &a_InstanceContext ,
  163. BOOL &a_Dynamic
  164. )
  165. {
  166. HRESULT t_Result = S_OK ;
  167. a_Dynamic = FALSE ;
  168. a_ClassContext = NULL ;
  169. a_InstanceContext = NULL ;
  170. IWbemQualifierSet *t_InstanceQualifierObject = NULL ;
  171. t_Result = a_Instance->GetQualifierSet ( & t_InstanceQualifierObject ) ;
  172. if ( SUCCEEDED ( t_Result ) )
  173. {
  174. VARIANT t_Variant ;
  175. VariantInit ( & t_Variant ) ;
  176. LONG t_Flavour = 0 ;
  177. t_Result = t_InstanceQualifierObject->Get (
  178. ProviderSubSystem_Globals :: s_DynProps ,
  179. 0 ,
  180. & t_Variant ,
  181. & t_Flavour
  182. ) ;
  183. if ( SUCCEEDED ( t_Result ) )
  184. {
  185. if ( t_Variant.vt == VT_BOOL )
  186. {
  187. if ( t_Variant.boolVal == VARIANT_TRUE )
  188. {
  189. a_Dynamic = TRUE ;
  190. VARIANT t_Variant ;
  191. VariantInit ( & t_Variant ) ;
  192. t_Flavour = 0 ;
  193. HRESULT t_TempResult = t_InstanceQualifierObject->Get (
  194. ProviderSubSystem_Globals :: s_InstanceContext ,
  195. 0 ,
  196. & t_Variant ,
  197. & t_Flavour
  198. ) ;
  199. if ( SUCCEEDED ( t_TempResult ) )
  200. {
  201. if ( t_Variant.vt == VT_BSTR )
  202. {
  203. a_InstanceContext = SysAllocString ( t_Variant.bstrVal ) ;
  204. if ( a_InstanceContext == NULL )
  205. {
  206. t_Result = WBEM_E_OUT_OF_MEMORY ;
  207. }
  208. }
  209. else
  210. {
  211. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  212. }
  213. VariantClear ( & t_Variant ) ;
  214. }
  215. else
  216. {
  217. if ( t_TempResult != WBEM_E_NOT_FOUND )
  218. {
  219. t_Result = t_TempResult ;
  220. }
  221. }
  222. if ( SUCCEEDED ( t_Result ) )
  223. {
  224. VARIANT t_ClassContextVariant ;
  225. VariantInit ( & t_ClassContextVariant ) ;
  226. t_TempResult = t_InstanceQualifierObject->Get (
  227. ProviderSubSystem_Globals :: s_ClassContext ,
  228. 0 ,
  229. & t_ClassContextVariant ,
  230. & t_Flavour
  231. ) ;
  232. if ( SUCCEEDED ( t_TempResult ) )
  233. {
  234. if ( t_ClassContextVariant.vt == VT_BSTR )
  235. {
  236. a_ClassContext = SysAllocString ( t_ClassContextVariant.bstrVal ) ;
  237. if ( a_ClassContext == NULL )
  238. {
  239. t_Result = WBEM_E_OUT_OF_MEMORY ;
  240. }
  241. }
  242. else
  243. {
  244. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  245. }
  246. VariantClear ( & t_ClassContextVariant ) ;
  247. }
  248. else
  249. {
  250. if ( t_TempResult != WBEM_E_NOT_FOUND )
  251. {
  252. t_Result = t_TempResult ;
  253. }
  254. }
  255. if ( SUCCEEDED ( t_Result ) )
  256. {
  257. if ( a_ClassContext == NULL )
  258. {
  259. IWbemQualifierSet *t_ClassQualifierObject = NULL ;
  260. t_Result = a_Class->GetQualifierSet ( & t_ClassQualifierObject ) ;
  261. if ( SUCCEEDED ( t_Result ) )
  262. {
  263. VARIANT t_Variant ;
  264. VariantInit ( & t_Variant ) ;
  265. LONG t_Flavour = 0 ;
  266. HRESULT t_TempResult = t_ClassQualifierObject->Get (
  267. ProviderSubSystem_Globals :: s_ClassContext ,
  268. 0 ,
  269. & t_Variant ,
  270. & t_Flavour
  271. ) ;
  272. if ( SUCCEEDED ( t_TempResult ) )
  273. {
  274. if ( t_Variant.vt == VT_BSTR )
  275. {
  276. a_ClassContext = SysAllocString ( t_Variant.bstrVal ) ;
  277. }
  278. else
  279. {
  280. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  281. }
  282. VariantClear ( & t_Variant ) ;
  283. }
  284. else
  285. {
  286. if ( t_TempResult != WBEM_E_NOT_FOUND )
  287. {
  288. t_Result = t_TempResult ;
  289. }
  290. }
  291. t_ClassQualifierObject->Release () ;
  292. }
  293. else
  294. {
  295. t_Result = WBEM_E_CRITICAL_ERROR ;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. else
  303. {
  304. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  305. }
  306. VariantClear ( & t_Variant ) ;
  307. }
  308. else
  309. {
  310. if ( t_Result != WBEM_E_NOT_FOUND )
  311. {
  312. }
  313. else
  314. {
  315. t_Result = S_OK ;
  316. }
  317. }
  318. t_InstanceQualifierObject->Release () ;
  319. }
  320. else
  321. {
  322. t_Result = WBEM_E_CRITICAL_ERROR ;
  323. }
  324. return t_Result ;
  325. }
  326. /******************************************************************************
  327. *
  328. * Name:
  329. *
  330. *
  331. * Description:
  332. *
  333. *
  334. *****************************************************************************/
  335. HRESULT CServerObject_DynamicPropertyProviderResolver :: ReadOrWrite (
  336. IWbemContext *a_Context ,
  337. IWbemClassObject *a_Instance ,
  338. BSTR a_ClassContext ,
  339. BSTR a_InstanceContext ,
  340. BSTR a_PropertyContext ,
  341. BSTR a_Provider ,
  342. BSTR a_Property ,
  343. BOOL a_Read
  344. )
  345. {
  346. IWbemPropertyProvider *t_Provider = NULL ;
  347. WmiInternalContext t_InternalContext ;
  348. ZeroMemory ( & t_InternalContext , sizeof ( t_InternalContext ) ) ;
  349. HRESULT t_Result = m_Factory->GetProvider (
  350. t_InternalContext ,
  351. 0 ,
  352. a_Context ,
  353. NULL ,
  354. m_User ,
  355. m_Locale ,
  356. NULL ,
  357. a_Provider ,
  358. IID_IWbemPropertyProvider ,
  359. ( void ** ) & t_Provider
  360. ) ;
  361. if ( SUCCEEDED ( t_Result ) )
  362. {
  363. VARIANT t_Variant ;
  364. VariantInit ( & t_Variant ) ;
  365. if ( a_Read )
  366. {
  367. t_Result = t_Provider->GetProperty (
  368. 0 ,
  369. m_Locale ,
  370. a_ClassContext ,
  371. a_InstanceContext ,
  372. a_PropertyContext ,
  373. & t_Variant
  374. ) ;
  375. if ( SUCCEEDED ( t_Result ) )
  376. {
  377. t_Result = a_Instance->Put ( a_Property , 0 , & t_Variant , 0 ) ;
  378. VariantClear ( & t_Variant ) ;
  379. }
  380. }
  381. else
  382. {
  383. LONG t_VarType = 0 ;
  384. LONG t_Flavour = 0 ;
  385. t_Result = a_Instance->Get ( a_Property , 0 , & t_Variant , & t_VarType , & t_Flavour ) ;
  386. if ( SUCCEEDED ( t_Result ) )
  387. {
  388. t_Result = t_Provider->PutProperty (
  389. 0 ,
  390. m_Locale ,
  391. a_ClassContext ,
  392. a_InstanceContext ,
  393. a_PropertyContext ,
  394. & t_Variant
  395. ) ;
  396. if ( SUCCEEDED ( t_Result ) )
  397. {
  398. t_Result = a_Instance->Put ( a_Property , 0 , NULL , 0 ) ;
  399. }
  400. VariantClear ( & t_Variant ) ;
  401. }
  402. }
  403. t_Provider->Release () ;
  404. }
  405. return t_Result ;
  406. }
  407. /******************************************************************************
  408. *
  409. * Name:
  410. *
  411. *
  412. * Description:
  413. *
  414. *
  415. *****************************************************************************/
  416. HRESULT CServerObject_DynamicPropertyProviderResolver :: ReadOrWrite (
  417. IWbemContext *a_Context ,
  418. IWbemClassObject *a_Class ,
  419. IWbemClassObject *a_Instance ,
  420. BOOL a_Read
  421. )
  422. {
  423. HRESULT t_Result = S_OK ;
  424. BSTR t_ClassContext = NULL ;
  425. BSTR t_InstanceContext = NULL ;
  426. BOOL t_Dynamic = FALSE ;
  427. t_Result = GetClassAndInstanceContext (
  428. a_Class ,
  429. a_Instance ,
  430. t_ClassContext ,
  431. t_InstanceContext ,
  432. t_Dynamic
  433. ) ;
  434. if ( SUCCEEDED ( t_Result ) )
  435. {
  436. if ( t_Dynamic )
  437. {
  438. IWbemQualifierSet *t_InstanceQualifierObject = NULL ;
  439. t_Result = a_Instance->GetQualifierSet ( & t_InstanceQualifierObject ) ;
  440. if ( SUCCEEDED ( t_Result ) )
  441. {
  442. VARIANT t_Variant ;
  443. VariantInit ( & t_Variant ) ;
  444. BSTR t_Property = NULL ;
  445. CIMTYPE t_Type = CIM_EMPTY ;
  446. a_Instance->BeginEnumeration ( WBEM_FLAG_NONSYSTEM_ONLY ) ;
  447. while ( SUCCEEDED ( t_Result ) && ( a_Instance->Next ( 0 , & t_Property , &t_Variant , &t_Type , NULL ) == WBEM_NO_ERROR ) )
  448. {
  449. BSTR t_PropertyContext = NULL ;
  450. BSTR t_Provider = NULL ;
  451. IWbemQualifierSet *t_PropertyQualifierSet = NULL ;
  452. if ( ( a_Instance->GetPropertyQualifierSet ( t_Property , &t_PropertyQualifierSet ) ) == WBEM_NO_ERROR )
  453. {
  454. VARIANT t_DynamicVariant ;
  455. VariantInit ( & t_DynamicVariant ) ;
  456. LONG t_Flag = 0 ;
  457. if ( SUCCEEDED ( t_PropertyQualifierSet->Get ( ProviderSubSystem_Globals :: s_Dynamic , 0 , & t_DynamicVariant , &t_Flag ) ) )
  458. {
  459. if ( t_DynamicVariant.vt == VT_BOOL )
  460. {
  461. if ( t_DynamicVariant.boolVal == VARIANT_TRUE )
  462. {
  463. VARIANT t_ProviderVariant ;
  464. VariantInit ( & t_ProviderVariant ) ;
  465. t_Flag = 0 ;
  466. if ( SUCCEEDED ( t_PropertyQualifierSet->Get ( ProviderSubSystem_Globals :: s_Provider , 0 , & t_ProviderVariant , &t_Flag ) ) )
  467. {
  468. if ( t_ProviderVariant.vt == VT_BSTR )
  469. {
  470. t_Provider = SysAllocString ( t_ProviderVariant.bstrVal ) ;
  471. }
  472. else
  473. {
  474. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  475. }
  476. VariantClear ( & t_ProviderVariant ) ;
  477. }
  478. else
  479. {
  480. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  481. }
  482. VARIANT t_PropertyContextVariant ;
  483. VariantInit ( & t_PropertyContextVariant ) ;
  484. t_Flag = 0 ;
  485. if ( SUCCEEDED ( t_PropertyQualifierSet->Get ( ProviderSubSystem_Globals :: s_PropertyContext , 0 , & t_PropertyContextVariant , &t_Flag ) ) )
  486. {
  487. if ( t_PropertyContextVariant.vt == VT_BSTR )
  488. {
  489. t_PropertyContext = SysAllocString ( t_PropertyContextVariant.bstrVal ) ;
  490. }
  491. else
  492. {
  493. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  494. }
  495. VariantClear ( & t_PropertyContextVariant ) ;
  496. }
  497. }
  498. }
  499. else
  500. {
  501. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  502. }
  503. VariantClear ( & t_DynamicVariant ) ;
  504. }
  505. t_PropertyQualifierSet->Release();
  506. }
  507. if ( SUCCEEDED ( t_Result ) && t_Provider )
  508. {
  509. //
  510. // discard the error here, as we did in W2K
  511. //
  512. HRESULT t_ResultInner = ReadOrWrite (
  513. a_Context ,
  514. a_Instance ,
  515. t_ClassContext ,
  516. t_InstanceContext ,
  517. t_PropertyContext ,
  518. t_Provider ,
  519. t_Property ,
  520. a_Read
  521. ) ;
  522. }
  523. if ( t_PropertyContext )
  524. {
  525. SysFreeString ( t_PropertyContext ) ;
  526. }
  527. if ( t_Provider )
  528. {
  529. SysFreeString ( t_Provider ) ;
  530. }
  531. VariantClear ( & t_Variant ) ;
  532. SysFreeString ( t_Property ) ;
  533. }
  534. t_InstanceQualifierObject->Release () ;
  535. }
  536. else
  537. {
  538. t_Result = WBEM_E_CRITICAL_ERROR ;
  539. }
  540. }
  541. if ( t_ClassContext )
  542. {
  543. SysFreeString ( t_ClassContext ) ;
  544. }
  545. if ( t_InstanceContext )
  546. {
  547. SysFreeString ( t_InstanceContext ) ;
  548. }
  549. }
  550. return t_Result ;
  551. }
  552. /******************************************************************************
  553. *
  554. * Name:
  555. *
  556. *
  557. * Description:
  558. *
  559. *
  560. *****************************************************************************/
  561. HRESULT CServerObject_DynamicPropertyProviderResolver :: Read (
  562. IWbemContext *a_Context ,
  563. IWbemClassObject *a_Class ,
  564. IWbemClassObject **a_Instance
  565. )
  566. {
  567. IWbemClassObject *t_Object = *a_Instance ;
  568. HRESULT t_Result = ReadOrWrite (
  569. a_Context ,
  570. a_Class ,
  571. t_Object ,
  572. TRUE
  573. ) ;
  574. return t_Result ;
  575. }
  576. /******************************************************************************
  577. *
  578. * Name:
  579. *
  580. *
  581. * Description:
  582. *
  583. *
  584. *****************************************************************************/
  585. HRESULT CServerObject_DynamicPropertyProviderResolver :: Write (
  586. IWbemContext *a_Context ,
  587. IWbemClassObject *a_Class ,
  588. IWbemClassObject *a_Instance
  589. )
  590. {
  591. HRESULT t_Result = ReadOrWrite (
  592. a_Context ,
  593. a_Class ,
  594. a_Instance ,
  595. FALSE
  596. ) ;
  597. return t_Result ;
  598. }
  599. /******************************************************************************
  600. *
  601. * Name:
  602. *
  603. *
  604. * Description:
  605. *
  606. *
  607. *****************************************************************************/
  608. HRESULT CServerObject_DynamicPropertyProviderResolver :: Initialize (
  609. LPWSTR a_User,
  610. LONG a_Flags,
  611. LPWSTR a_Namespace,
  612. LPWSTR a_Locale,
  613. IWbemServices *a_Core , // For anybody
  614. IWbemContext *a_Context ,
  615. IWbemProviderInitSink *a_Sink // For init signals
  616. )
  617. {
  618. HRESULT t_Result = S_OK ;
  619. if ( a_User )
  620. {
  621. m_User = SysAllocString ( a_User ) ;
  622. if ( ! m_User )
  623. {
  624. t_Result = WBEM_E_OUT_OF_MEMORY ;
  625. }
  626. }
  627. if ( SUCCEEDED ( t_Result ) )
  628. {
  629. if ( a_Locale )
  630. {
  631. m_Locale = SysAllocString ( a_Locale ) ;
  632. if ( ! m_Locale )
  633. {
  634. t_Result = WBEM_E_OUT_OF_MEMORY ;
  635. }
  636. }
  637. }
  638. a_Sink->SetStatus ( t_Result , 0 ) ;
  639. return t_Result ;
  640. }
  641. /******************************************************************************
  642. *
  643. * Name:
  644. *
  645. *
  646. * Description:
  647. *
  648. *
  649. *****************************************************************************/
  650. HRESULT CServerObject_DynamicPropertyProviderResolver :: Shutdown (
  651. LONG a_Flags ,
  652. ULONG a_MaxMilliSeconds ,
  653. IWbemContext *a_Context
  654. )
  655. {
  656. return S_OK ;
  657. }