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.

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