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.

278 lines
6.9 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvFact.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include "PreComp.h"
  9. #include <wbemint.h>
  10. #include "Globals.h"
  11. #include "CGlobals.h"
  12. #include "ProvSubS.h"
  13. #include "Guids.h"
  14. #include "StrobeThread.h"
  15. #include "ProvCache.h"
  16. #include "ProvHost.h"
  17. #include "ProvWsv.h"
  18. StrobeThread :: StrobeThread (WmiAllocator &a_Allocator , DWORD timeout) :
  19. m_Allocator ( a_Allocator ), timeout_(timeout)
  20. {
  21. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_StrobeThread_ObjectsInProgress ) ;
  22. }
  23. StrobeThread::~StrobeThread ()
  24. {
  25. CWbemGlobal_IWmiProvSubSysController *t_ProvSubSysController = ProviderSubSystem_Globals :: GetProvSubSysController () ;
  26. t_ProvSubSysController->Shutdown () ;
  27. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_StrobeThread_ObjectsInProgress ) ;
  28. }
  29. int StrobeThread :: handleTimeout ()
  30. {
  31. CoInitializeEx ( NULL , COINIT_MULTITHREADED ) ;
  32. ULONG t_NextStrobeDelta = 0xFFFFFFFF ;
  33. try
  34. {
  35. CWbemGlobal_IWbemRefresherMgrController *t_RefresherManagerController = ProviderSubSystem_Globals :: GetRefresherManagerController () ;
  36. t_RefresherManagerController->Strobe ( t_NextStrobeDelta ) ;
  37. CWbemGlobal_IWmiHostController *t_HostController = ProviderSubSystem_Globals :: GetHostController () ;
  38. t_HostController->Strobe ( t_NextStrobeDelta ) ;
  39. CWbemGlobal_IWmiProvSubSysController *t_ProvSubSysController = ProviderSubSystem_Globals :: GetProvSubSysController () ;
  40. CWbemGlobal_IWmiProvSubSysController_Container *t_Container = NULL ;
  41. WmiStatusCode t_StatusCode = t_ProvSubSysController->GetContainer ( t_Container ) ;
  42. t_ProvSubSysController->Lock () ;
  43. CWbemGlobal_IWmiFactoryController **t_ShutdownElements = new CWbemGlobal_IWmiFactoryController * [ t_Container->Size () ] ;
  44. if ( t_ShutdownElements )
  45. {
  46. CWbemGlobal_IWmiProvSubSysController_Container_Iterator t_Iterator = t_Container->Begin () ;
  47. ULONG t_Count = 0 ;
  48. while ( ! t_Iterator.Null () )
  49. {
  50. CWbemGlobal_IWmiFactoryController *t_FactoryController = NULL ;
  51. ProvSubSysContainerElement *t_Element = t_Iterator.GetElement () ;
  52. HRESULT t_Result = t_Element->QueryInterface ( IID_CWbemGlobal_IWmiFactoryController , ( void ** ) & t_ShutdownElements [ t_Count ] ) ;
  53. t_Iterator.Increment () ;
  54. t_Count ++ ;
  55. }
  56. t_ProvSubSysController->UnLock () ;
  57. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  58. {
  59. if ( t_ShutdownElements [ t_Index ] )
  60. {
  61. t_ShutdownElements [ t_Index ]->Strobe ( t_NextStrobeDelta ) ;
  62. t_ShutdownElements [ t_Index ]->Release () ;
  63. }
  64. }
  65. delete [] t_ShutdownElements ;
  66. }
  67. else
  68. {
  69. t_ProvSubSysController->UnLock () ;
  70. }
  71. }
  72. catch ( ... )
  73. {
  74. }
  75. Dispatcher::changeTimer(*this, t_NextStrobeDelta);
  76. CoUninitialize () ;
  77. return 0 ;
  78. }
  79. Task_ProcessTermination :: Task_ProcessTermination (
  80. WmiAllocator &a_Allocator ,
  81. HANDLE a_Process ,
  82. DWORD a_ProcessIdentifier
  83. ): m_ProcessIdentifier ( a_ProcessIdentifier ),
  84. processHandle_(a_Process)
  85. {
  86. }
  87. Task_ProcessTermination::~Task_ProcessTermination()
  88. {
  89. CloseHandle(processHandle_);
  90. }
  91. HANDLE Task_ProcessTermination::getHandle()
  92. {
  93. return processHandle_;
  94. }
  95. int Task_ProcessTermination::handleEvent()
  96. {
  97. try
  98. {
  99. // Discard entities in host.
  100. CWbemGlobal_HostedProviderController *t_Controller = ProviderSubSystem_Globals :: GetHostedProviderController () ;
  101. t_Controller->Lock () ;
  102. CWbemGlobal_HostedProviderController_Container_Iterator t_Iterator ;
  103. WmiStatusCode t_StatusCode = t_Controller->Find ( m_ProcessIdentifier , t_Iterator ) ;
  104. switch ( t_StatusCode )
  105. {
  106. case e_StatusCode_Success:
  107. {
  108. HostedProviderContainerElement *t_Element = t_Iterator.GetElement () ;
  109. t_StatusCode = t_Controller->Delete ( m_ProcessIdentifier ) ;
  110. t_Controller->UnLock () ;
  111. ProviderController *t_ProviderController = NULL ;
  112. HRESULT t_Result = t_Element->QueryInterface ( IID_ProviderController , ( void ** ) & t_ProviderController ) ;
  113. if ( SUCCEEDED ( t_Result ) )
  114. {
  115. t_ProviderController->Lock () ;
  116. ProviderController :: Container *t_Container = NULL ;
  117. t_StatusCode = t_ProviderController->GetContainer ( t_Container ) ;
  118. CInterceptor_IWbemProvider **t_InterceptorElements = new CInterceptor_IWbemProvider * [ t_Container->Size () ] ;
  119. if ( t_InterceptorElements )
  120. {
  121. ProviderController :: Container_Iterator t_Iterator = t_Container->Begin () ;
  122. ULONG t_Count = 0 ;
  123. while ( ! t_Iterator.Null () )
  124. {
  125. t_InterceptorElements [ t_Count ] = t_Iterator.GetElement ();
  126. t_ProviderController->Delete ( t_Iterator.GetKey () ) ;
  127. t_Iterator = t_Container->Begin () ;
  128. t_Count ++ ;
  129. }
  130. t_ProviderController->UnLock () ;
  131. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  132. {
  133. if ( t_InterceptorElements [ t_Index ] )
  134. {
  135. t_Result = t_InterceptorElements [ t_Index ]->AbnormalShutdown () ;
  136. t_InterceptorElements [ t_Index ]->NonCyclicRelease () ;
  137. }
  138. }
  139. delete [] t_InterceptorElements ;
  140. }
  141. else
  142. {
  143. t_ProviderController->UnLock () ;
  144. }
  145. t_ProviderController->Release () ;
  146. }
  147. t_Element->Release () ;
  148. }
  149. break ;
  150. default:
  151. {
  152. t_Controller->UnLock () ;
  153. }
  154. break ;
  155. }
  156. // Discard of host.
  157. CWbemGlobal_IWmiHostController_Cache *t_Cache = NULL ;
  158. ProviderSubSystem_Globals :: GetHostController ()->GetCache ( t_Cache ) ;
  159. ProviderSubSystem_Globals :: GetHostController ()->Lock () ;
  160. ULONG t_Count = 0 ;
  161. CServerObject_HostInterceptor **t_InterceptorElements = new CServerObject_HostInterceptor * [ t_Cache->Size () ] ;
  162. if ( t_InterceptorElements )
  163. {
  164. CWbemGlobal_IWmiHostController_Cache_Iterator t_HostIterator = t_Cache->Begin () ;
  165. while ( ! t_HostIterator.Null () )
  166. {
  167. HostCacheElement *t_Element = t_HostIterator.GetElement () ;
  168. t_InterceptorElements [ t_Count ] = NULL ;
  169. HRESULT t_Result = t_Element->QueryInterface (
  170. IID_CServerObject_HostInterceptor ,
  171. ( void ** ) & t_InterceptorElements [ t_Count ]
  172. ) ;
  173. t_HostIterator.Increment () ;
  174. t_Count ++ ;
  175. }
  176. }
  177. ProviderSubSystem_Globals :: GetHostController ()->UnLock () ;
  178. if ( t_InterceptorElements )
  179. {
  180. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  181. {
  182. if ( t_InterceptorElements [ t_Index ] )
  183. {
  184. if ( t_InterceptorElements [ t_Index ]->GetProcessIdentifier () == m_ProcessIdentifier )
  185. {
  186. ProviderSubSystem_Globals :: GetHostController ()->Shutdown ( t_InterceptorElements [ t_Index ]->GetKey () ) ;
  187. }
  188. t_InterceptorElements [ t_Index ]->Release () ;
  189. }
  190. }
  191. delete [] t_InterceptorElements ;
  192. }
  193. }
  194. catch ( ... )
  195. {
  196. }
  197. return -1; // remove from queue
  198. }