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.

424 lines
8.0 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 "ProvInSk.h"
  13. #include "guids.h"
  14. /******************************************************************************
  15. *
  16. * Name:
  17. *
  18. *
  19. * Description:
  20. *
  21. *
  22. *****************************************************************************/
  23. CServerObject_ProviderInitSink :: CServerObject_ProviderInitSink (
  24. SECURITY_DESCRIPTOR *a_SecurityDescriptor
  25. ) : m_ReferenceCount ( 0 ) ,
  26. m_Event ( NULL ) ,
  27. m_StatusCalled ( FALSE ) ,
  28. m_Result ( S_OK ) ,
  29. m_SecurityDescriptor ( NULL )
  30. {
  31. }
  32. /******************************************************************************
  33. *
  34. * Name:
  35. *
  36. *
  37. * Description:
  38. *
  39. *
  40. *****************************************************************************/
  41. CServerObject_ProviderInitSink :: ~CServerObject_ProviderInitSink ()
  42. {
  43. if ( m_Event )
  44. {
  45. CloseHandle ( m_Event ) ;
  46. }
  47. if ( m_SecurityDescriptor )
  48. {
  49. delete [] ( BYTE * ) m_SecurityDescriptor ;
  50. }
  51. }
  52. /******************************************************************************
  53. *
  54. * Name:
  55. *
  56. *
  57. * Description:
  58. *
  59. *
  60. *****************************************************************************/
  61. HRESULT CServerObject_ProviderInitSink :: SinkInitialize ( SECURITY_DESCRIPTOR *a_SecurityDescriptor )
  62. {
  63. HRESULT t_Result = S_OK ;
  64. m_Event = CreateEvent ( NULL , FALSE , FALSE , NULL ) ;
  65. if ( m_Event )
  66. {
  67. if ( a_SecurityDescriptor )
  68. {
  69. t_Result = ProviderSubSystem_Common_Globals :: SinkAccessInitialize ( a_SecurityDescriptor , m_SecurityDescriptor ) ;
  70. }
  71. }
  72. else
  73. {
  74. t_Result = WBEM_E_OUT_OF_MEMORY ;
  75. }
  76. return t_Result ;
  77. }
  78. /******************************************************************************
  79. *
  80. * Name:
  81. *
  82. *
  83. * Description:
  84. *
  85. *
  86. *****************************************************************************/
  87. STDMETHODIMP CServerObject_ProviderInitSink :: QueryInterface (
  88. REFIID iid ,
  89. LPVOID FAR *iplpv
  90. )
  91. {
  92. *iplpv = NULL ;
  93. if ( iid == IID_IUnknown )
  94. {
  95. *iplpv = ( LPVOID ) this ;
  96. }
  97. else if ( iid == IID_IWbemProviderInitSink )
  98. {
  99. *iplpv = ( LPVOID ) this ;
  100. }
  101. if ( *iplpv )
  102. {
  103. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  104. return ResultFromScode ( S_OK ) ;
  105. }
  106. else
  107. {
  108. return ResultFromScode ( E_NOINTERFACE ) ;
  109. }
  110. }
  111. /******************************************************************************
  112. *
  113. * Name:
  114. *
  115. *
  116. * Description:
  117. *
  118. *
  119. *****************************************************************************/
  120. STDMETHODIMP_( ULONG ) CServerObject_ProviderInitSink :: AddRef ()
  121. {
  122. return InterlockedIncrement ( & m_ReferenceCount ) ;
  123. }
  124. /******************************************************************************
  125. *
  126. * Name:
  127. *
  128. *
  129. * Description:
  130. *
  131. *
  132. *****************************************************************************/
  133. STDMETHODIMP_(ULONG) CServerObject_ProviderInitSink :: Release ()
  134. {
  135. LONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  136. if ( t_ReferenceCount == 0 )
  137. {
  138. delete this ;
  139. }
  140. return t_ReferenceCount ;
  141. }
  142. /******************************************************************************
  143. *
  144. * Name:
  145. *
  146. *
  147. * Description:
  148. *
  149. *
  150. *****************************************************************************/
  151. HRESULT CServerObject_ProviderInitSink :: SetStatus (
  152. LONG a_Status,
  153. LONG a_Flags
  154. )
  155. {
  156. HRESULT t_Result = S_OK ;
  157. if ( m_SecurityDescriptor )
  158. {
  159. t_Result = CoImpersonateClient () ;
  160. if ( SUCCEEDED ( t_Result ) )
  161. {
  162. t_Result = ProviderSubSystem_Common_Globals :: Check_SecurityDescriptor_CallIdentity (
  163. m_SecurityDescriptor ,
  164. MASK_PROVIDER_BINDING_BIND ,
  165. & g_ProviderBindingMapping
  166. ) ;
  167. CoRevertToSelf () ;
  168. }
  169. }
  170. if ( SUCCEEDED ( t_Result ) )
  171. {
  172. m_Result = a_Status ;
  173. }
  174. else
  175. {
  176. m_Result = t_Result ;
  177. }
  178. SetEvent ( m_Event ) ;
  179. return t_Result ;
  180. }
  181. /******************************************************************************
  182. *
  183. * Name:
  184. *
  185. *
  186. * Description:
  187. *
  188. *
  189. *****************************************************************************/
  190. CInterceptor_IWbemProviderInitSink :: CInterceptor_IWbemProviderInitSink (
  191. IWbemProviderInitSink *a_InterceptedSink
  192. ) : m_ReferenceCount ( 0 ) ,
  193. m_InterceptedSink ( a_InterceptedSink ) ,
  194. m_GateClosed ( FALSE ) ,
  195. m_InProgress ( 0 ) ,
  196. m_StatusCalled ( FALSE )
  197. {
  198. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_CInterceptor_IWbemProviderInitSink_ObjectsInProgress ) ;
  199. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  200. if ( m_InterceptedSink )
  201. {
  202. m_InterceptedSink->AddRef () ;
  203. }
  204. }
  205. /******************************************************************************
  206. *
  207. * Name:
  208. *
  209. *
  210. * Description:
  211. *
  212. *
  213. *****************************************************************************/
  214. CInterceptor_IWbemProviderInitSink::~CInterceptor_IWbemProviderInitSink ()
  215. {
  216. if ( ! m_StatusCalled )
  217. {
  218. m_InterceptedSink->SetStatus ( WBEM_E_UNEXPECTED , 0 ) ;
  219. }
  220. if ( m_InterceptedSink )
  221. {
  222. m_InterceptedSink->Release () ;
  223. }
  224. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_CInterceptor_IWbemProviderInitSink_ObjectsInProgress ) ;
  225. ProviderSubSystem_Globals :: Decrement_Global_Object_Count () ;
  226. }
  227. /******************************************************************************
  228. *
  229. * Name:
  230. *
  231. *
  232. * Description:
  233. *
  234. *
  235. *****************************************************************************/
  236. STDMETHODIMP CInterceptor_IWbemProviderInitSink::QueryInterface (
  237. REFIID iid ,
  238. LPVOID FAR *iplpv
  239. )
  240. {
  241. *iplpv = NULL ;
  242. if ( iid == IID_IUnknown )
  243. {
  244. *iplpv = ( LPVOID ) this ;
  245. }
  246. else if ( iid == IID_IWbemProviderInitSink )
  247. {
  248. *iplpv = ( LPVOID ) ( IWbemProviderInitSink * ) this ;
  249. }
  250. if ( *iplpv )
  251. {
  252. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  253. return ResultFromScode ( S_OK ) ;
  254. }
  255. else
  256. {
  257. return ResultFromScode ( E_NOINTERFACE ) ;
  258. }
  259. }
  260. /******************************************************************************
  261. *
  262. * Name:
  263. *
  264. *
  265. * Description:
  266. *
  267. *
  268. *****************************************************************************/
  269. STDMETHODIMP_( ULONG ) CInterceptor_IWbemProviderInitSink :: AddRef ()
  270. {
  271. return InterlockedIncrement ( & m_ReferenceCount ) ;
  272. }
  273. /******************************************************************************
  274. *
  275. * Name:
  276. *
  277. *
  278. * Description:
  279. *
  280. *
  281. *****************************************************************************/
  282. STDMETHODIMP_(ULONG) CInterceptor_IWbemProviderInitSink :: Release ()
  283. {
  284. LONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  285. if ( t_ReferenceCount == 0 )
  286. {
  287. delete this ;
  288. }
  289. return t_ReferenceCount ;
  290. }
  291. /******************************************************************************
  292. *
  293. * Name:
  294. *
  295. *
  296. * Description:
  297. *
  298. *
  299. *****************************************************************************/
  300. HRESULT CInterceptor_IWbemProviderInitSink :: SetStatus (
  301. LONG a_Status,
  302. LONG a_Flags
  303. )
  304. {
  305. HRESULT t_Result = S_OK ;
  306. m_StatusCalled = TRUE ;
  307. m_InProgress ++ ;
  308. if ( m_GateClosed == 1 )
  309. {
  310. t_Result = WBEM_E_SHUTTING_DOWN ;
  311. }
  312. else
  313. {
  314. t_Result = m_InterceptedSink->SetStatus (
  315. a_Status,
  316. a_Flags
  317. ) ;
  318. }
  319. m_InProgress -- ;
  320. return t_Result ;
  321. }
  322. /******************************************************************************
  323. *
  324. * Name:
  325. *
  326. *
  327. * Description:
  328. *
  329. *
  330. *****************************************************************************/
  331. HRESULT CInterceptor_IWbemProviderInitSink :: Shutdown ()
  332. {
  333. HRESULT t_Result = S_OK ;
  334. m_GateClosed ++ ;
  335. bool t_Acquired = false ;
  336. while ( ! t_Acquired )
  337. {
  338. if ( m_InProgress == 0 )
  339. {
  340. t_Acquired = true ;
  341. break ;
  342. }
  343. if ( SwitchToThread () == FALSE )
  344. {
  345. }
  346. }
  347. return t_Result ;
  348. }