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.

706 lines
16 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Globals.h
  5. Abstract:
  6. History:
  7. --*/
  8. #ifndef _CommonGlobals_H
  9. #define _CommonGlobals_H
  10. #include <pssException.h>
  11. #include <HelperFuncs.h>
  12. #include <Allocator.h>
  13. #include <BasicTree.h>
  14. #include <Queue.h>
  15. #include <Cache.h>
  16. #include <locks.h>
  17. /******************************************************************************
  18. *
  19. * Name:
  20. *
  21. *
  22. * Description:
  23. *
  24. *
  25. *****************************************************************************/
  26. #define SYNCPROV_BATCH_TRANSMIT_SIZE 0x40000
  27. /******************************************************************************
  28. *
  29. * Name:
  30. *
  31. *
  32. * Description:
  33. *
  34. *
  35. *****************************************************************************/
  36. typedef WmiContainerController <void *> CWbemGlobal_VoidPointerController ;
  37. typedef CWbemGlobal_VoidPointerController :: Container CWbemGlobal_VoidPointerController_Container ;
  38. typedef CWbemGlobal_VoidPointerController :: Container_Iterator CWbemGlobal_VoidPointerController_Container_Iterator ;
  39. typedef CWbemGlobal_VoidPointerController :: WmiContainerElement VoidPointerContainerElement ;
  40. /******************************************************************************
  41. *
  42. * Name:
  43. *
  44. *
  45. * Description:
  46. *
  47. *
  48. *****************************************************************************/
  49. #define CWbemGlobal_IWmiObjectSinkController CWbemGlobal_VoidPointerController
  50. #define CWbemGlobal_IWmiObjectSinkController_Container CWbemGlobal_VoidPointerController_Container
  51. #define CWbemGlobal_IWmiObjectSinkController_Container_Iterator CWbemGlobal_VoidPointerController_Container_Iterator
  52. #define ObjectSinkContainerElement VoidPointerContainerElement
  53. /******************************************************************************
  54. *
  55. * Name:
  56. *
  57. *
  58. * Description:
  59. *
  60. *
  61. *****************************************************************************/
  62. #define MASK_PROVIDER_BINDING_BIND 1
  63. /******************************************************************************
  64. *
  65. * Name:
  66. *
  67. *
  68. * Description:
  69. *
  70. *
  71. *****************************************************************************/
  72. #define HRESULT_ERROR_MASK (0x0000FFFF)
  73. #define HRESULT_ERROR_FUNC(X) (X&HRESULT_ERROR_MASK)
  74. #define HRESULT_FACILITY_MASK (0x0FFF0000)
  75. #define HRESULT_FACILITY_FUNC(X) ((X&HRESULT_FACILITY_MASK)>>16)
  76. #define HRESULT_SEVERITY_MASK (0xC0000000)
  77. #define HRESULT_SEVERITY_FUNC(X) ((X&HRESULT_SEVERITY_MASK)>>30)
  78. #define HRESULT_ERROR_SERVER_UNAVAILABLE 1722L
  79. #define HRESULT_ERROR_CALL_FAILED_DNE 1727L
  80. /******************************************************************************
  81. *
  82. * Name:
  83. *
  84. *
  85. * Description:
  86. *
  87. *
  88. *****************************************************************************/
  89. #define MAX_PROXIES 512
  90. class ProxyContainer
  91. {
  92. private:
  93. WmiAllocator &m_Allocator ;
  94. #if 1
  95. WmiStack <IUnknown *,8> **m_ContainerArray ;
  96. #else
  97. WmiQueue <IUnknown *,8> **m_ContainerArray ;
  98. #endif
  99. CriticalSection m_CriticalSection ;
  100. ULONG m_TopSize ;
  101. ULONG m_CurrentSize ;
  102. ULONG m_ProxyCount ;
  103. BOOL m_Initialized ;
  104. public:
  105. ProxyContainer (
  106. WmiAllocator &a_Allocator ,
  107. ULONG a_ProxyCount ,
  108. ULONG a_TopSize
  109. ) : m_Allocator ( a_Allocator ) ,
  110. m_ContainerArray ( NULL ) ,
  111. m_TopSize ( a_TopSize ) ,
  112. m_CurrentSize ( 0 ) ,
  113. m_ProxyCount ( a_ProxyCount ) ,
  114. m_Initialized ( FALSE ) ,
  115. m_CriticalSection(NOTHROW_LOCK)
  116. {
  117. }
  118. ~ProxyContainer ()
  119. {
  120. UnInitialize () ;
  121. }
  122. WmiStatusCode Initialize ()
  123. {
  124. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  125. #if 1
  126. m_ContainerArray = new WmiStack <IUnknown *,8> * [ m_ProxyCount ] ;
  127. #else
  128. m_ContainerArray = new WmiQueue <IUnknown *,8> * [ m_ProxyCount ] ;
  129. #endif
  130. if ( m_ContainerArray )
  131. {
  132. t_StatusCode = WmiHelper :: InitializeCriticalSection ( & m_CriticalSection ) ;
  133. if ( t_StatusCode == e_StatusCode_Success )
  134. {
  135. m_Initialized = TRUE ;
  136. for ( ULONG t_Index = 0 ; t_Index < m_ProxyCount ; t_Index ++ )
  137. {
  138. m_ContainerArray [ t_Index ] = NULL ;
  139. }
  140. for ( t_Index = 0 ; t_Index < m_ProxyCount ; t_Index ++ )
  141. {
  142. #if 1
  143. WmiStack <IUnknown *,8> *t_Container = m_ContainerArray [ t_Index ] = new WmiStack <IUnknown *,8> ( m_Allocator ) ;
  144. #else
  145. WmiQueue <IUnknown *,8> *t_Container = m_ContainerArray [ t_Index ] = new WmiQueue <IUnknown *,8> ( m_Allocator ) ;
  146. #endif
  147. if ( t_Container )
  148. {
  149. t_StatusCode = t_Container->Initialize () ;
  150. if ( t_StatusCode != e_StatusCode_Success )
  151. {
  152. break ;
  153. }
  154. }
  155. else
  156. {
  157. t_StatusCode = e_StatusCode_OutOfMemory ;
  158. break ;
  159. }
  160. }
  161. }
  162. }
  163. else
  164. {
  165. t_StatusCode = e_StatusCode_OutOfMemory ;
  166. }
  167. return t_StatusCode ;
  168. }
  169. WmiStatusCode UnInitialize ()
  170. {
  171. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  172. if ( m_ContainerArray )
  173. {
  174. for ( ULONG t_Index = 0 ; t_Index < m_ProxyCount ; t_Index ++ )
  175. {
  176. #if 1
  177. WmiStack <IUnknown *,8> *t_Container = m_ContainerArray [ t_Index ] ;
  178. #else
  179. WmiQueue <IUnknown *,8> *t_Container = m_ContainerArray [ t_Index ] ;
  180. #endif
  181. if ( t_Container )
  182. {
  183. IUnknown *t_Top = NULL ;
  184. WmiStatusCode t_StatusCode ;
  185. while ( ( t_StatusCode = t_Container->Top ( t_Top ) ) == e_StatusCode_Success )
  186. {
  187. t_Top->Release () ;
  188. #if 1
  189. t_StatusCode = t_Container->Pop () ;
  190. #else
  191. t_StatusCode = t_Container->DeQueue () ;
  192. #endif
  193. }
  194. t_StatusCode = t_Container->UnInitialize () ;
  195. delete t_Container ;
  196. }
  197. }
  198. delete [] m_ContainerArray ;
  199. m_ContainerArray = NULL ;
  200. }
  201. if ( m_Initialized )
  202. {
  203. WmiHelper :: DeleteCriticalSection ( & m_CriticalSection ) ;
  204. m_Initialized = FALSE ;
  205. }
  206. return t_StatusCode ;
  207. }
  208. WmiStatusCode Return (
  209. IUnknown *a_Element ,
  210. ULONG a_Index
  211. )
  212. {
  213. #if 1
  214. WmiStack <IUnknown *,8> *t_Container = m_ContainerArray [ a_Index ] ;
  215. return t_Container->Push ( a_Element ) ;
  216. #else
  217. WmiQueue <IUnknown *,8> *t_Container = m_ContainerArray [ a_Index ] ;
  218. return t_Container->EnQueue ( a_Element ) ;
  219. #endif
  220. }
  221. WmiStatusCode Top (
  222. IUnknown *&a_Element ,
  223. ULONG a_Index
  224. )
  225. {
  226. #if 1
  227. WmiStack <IUnknown *,8> *t_Container = m_ContainerArray [ a_Index ] ;
  228. return t_Container->Top ( a_Element ) ;
  229. #else
  230. WmiQueue <IUnknown *,8> *t_Container = m_ContainerArray [ a_Index ] ;
  231. return t_Container->Top ( a_Element ) ;
  232. #endif
  233. }
  234. WmiStatusCode Reserve ( ULONG a_Index )
  235. {
  236. #if 1
  237. WmiStack <IUnknown *,8> *t_Container = m_ContainerArray [ a_Index ] ;
  238. return t_Container->Pop () ;
  239. #else
  240. WmiQueue <IUnknown *,8> *t_Container = m_ContainerArray [ a_Index ] ;
  241. return t_Container->DeQueue () ;
  242. #endif
  243. }
  244. ULONG GetTopSize () { return m_TopSize ; } ;
  245. ULONG GetCurrentSize () { return m_CurrentSize ; } ;
  246. BOOL GetInitialized () { return m_Initialized ; }
  247. void SetCurrentSize ( ULONG a_CurrentSize ) { m_CurrentSize = a_CurrentSize ; }
  248. CriticalSection &GetCriticalSection () { return m_CriticalSection ; }
  249. } ;
  250. /******************************************************************************
  251. *
  252. * Name:
  253. *
  254. *
  255. * Description:
  256. *
  257. *
  258. *****************************************************************************/
  259. class ProviderSubSystem_Common_Globals
  260. {
  261. public:
  262. static LPCWSTR s_Wql ;
  263. static LPCWSTR s_Provider ;
  264. static WORD s_System_ACESize ;
  265. static WORD s_LocalService_ACESize ;
  266. static WORD s_NetworkService_ACESize ;
  267. static WORD s_LocalAdmins_ACESize ;
  268. static ACCESS_ALLOWED_ACE *s_Provider_System_ACE ;
  269. static ACCESS_ALLOWED_ACE *s_Provider_LocalService_ACE ;
  270. static ACCESS_ALLOWED_ACE *s_Provider_NetworkService_ACE ;
  271. static ACCESS_ALLOWED_ACE *s_Provider_LocalAdmins_ACE ;
  272. static ACCESS_ALLOWED_ACE *s_Token_All_Access_System_ACE ;
  273. static ACCESS_ALLOWED_ACE *s_Token_All_Access_LocalService_ACE ;
  274. static ACCESS_ALLOWED_ACE *s_Token_All_Access_NetworkService_ACE ;
  275. static ACCESS_ALLOWED_ACE *s_Token_All_Access_LocalAdmins_ACE ;
  276. static SECURITY_DESCRIPTOR *s_MethodSecurityDescriptor ;
  277. static SECURITY_DESCRIPTOR *s_DefaultDecoupledSD;
  278. static ULONG s_TransmitBufferSize ;
  279. static ULONG s_DefaultStackSize ;
  280. public:
  281. static HRESULT CreateInstance (
  282. const CLSID &a_ReferenceClsid ,
  283. LPUNKNOWN a_OuterUnknown ,
  284. const DWORD &a_ClassContext ,
  285. const UUID &a_ReferenceInterfaceId ,
  286. void **a_ObjectInterface
  287. ) ;
  288. static HRESULT CreateRemoteInstance (
  289. LPCWSTR a_Server ,
  290. const CLSID &a_ReferenceClsid ,
  291. LPUNKNOWN a_OuterUnknown ,
  292. const DWORD &a_ClassContext ,
  293. const UUID &a_ReferenceInterfaceId ,
  294. void **a_ObjectInterface
  295. ) ;
  296. static HRESULT GetNamespaceServerPath (
  297. IWbemPath *a_Namespace ,
  298. wchar_t *&a_ServerNamespacePath
  299. ) ;
  300. static HRESULT GetNamespacePath (
  301. IWbemPath *a_Namespace ,
  302. wchar_t *&a_NamespacePath
  303. ) ;
  304. static HRESULT GetPathText (
  305. IWbemPath *a_Path ,
  306. wchar_t *&a_ObjectPath
  307. ) ;
  308. static HRESULT Set_Uint32 (
  309. _IWmiObject *a_Instance ,
  310. wchar_t *a_Name ,
  311. const DWORD &a_Uint32
  312. );
  313. static HRESULT Set_String (
  314. IWbemClassObject *a_Instance ,
  315. wchar_t *a_Name ,
  316. wchar_t *a_String
  317. );
  318. static HRESULT BeginCallbackImpersonation (
  319. IUnknown *&a_OldContext ,
  320. IServerSecurity *&a_OldSecurity ,
  321. BOOL &a_Impersonating
  322. ) ;
  323. static HRESULT BeginImpersonation (
  324. IUnknown *&a_OldContext ,
  325. IServerSecurity *&a_OldSecurity ,
  326. BOOL &a_Impersonating ,
  327. DWORD *a_AuthenticationLevel = NULL
  328. ) ;
  329. static HRESULT EndImpersonation (
  330. IUnknown *a_OldContext ,
  331. IServerSecurity *a_OldSecurity ,
  332. BOOL a_Impersonating
  333. ) ;
  334. static HRESULT GetProxy (
  335. REFIID a_InterfaceId ,
  336. IUnknown *a_Interface ,
  337. IUnknown *&a_Proxy
  338. ) ;
  339. static HRESULT GetProxy (
  340. ProxyContainer &a_Container ,
  341. ULONG a_ProxyIndex ,
  342. REFIID a_InterfaceId ,
  343. IUnknown *a_Interface ,
  344. IUnknown *&a_Proxy
  345. ) ;
  346. static HRESULT SetCloaking (
  347. IUnknown *a_Unknown
  348. ) ;
  349. static HRESULT SetCloaking (
  350. IUnknown *a_Unknown ,
  351. DWORD a_AuthenticationLevel ,
  352. DWORD a_ImpersonationLevel
  353. ) ;
  354. static DWORD GetCurrentImpersonationLevel () ;
  355. static HRESULT EnableAllPrivileges () ;
  356. static HRESULT EnableAllPrivileges ( HANDLE a_Token ) ;
  357. static HRESULT SetProxyState_NoImpersonation (
  358. ProxyContainer &a_Container ,
  359. ULONG a_ProxyIndex ,
  360. REFIID a_InterfaceId ,
  361. IUnknown *a_Interface ,
  362. IUnknown *&a_Proxy ,
  363. BOOL &a_Revert
  364. ) ;
  365. static HRESULT SetProxyState (
  366. ProxyContainer &a_Container ,
  367. ULONG a_ProxyIndex ,
  368. REFIID a_InterfaceId ,
  369. IUnknown *a_Interface ,
  370. IUnknown *&a_Proxy ,
  371. BOOL &a_Revert
  372. ) ;
  373. static HRESULT RevertProxyState (
  374. ProxyContainer &a_Container ,
  375. ULONG a_ProxyIndex ,
  376. IUnknown *a_Proxy ,
  377. BOOL a_Revert
  378. ) ;
  379. static HRESULT SetProxyState_SvcHost (
  380. ProxyContainer &a_Container ,
  381. ULONG a_ProxyIndex ,
  382. REFIID a_InterfaceId ,
  383. IUnknown *a_Interface ,
  384. IUnknown *&a_Proxy ,
  385. BOOL &a_Revert ,
  386. DWORD a_ProcessIdentifier ,
  387. HANDLE &a_IdentifyToken ,
  388. ACCESS_ALLOWED_ACE *a_Ace ,
  389. WORD a_AceSize
  390. ) ;
  391. static HRESULT RevertProxyState_SvcHost (
  392. ProxyContainer &a_Container ,
  393. ULONG a_ProxyIndex ,
  394. IUnknown *a_Proxy ,
  395. BOOL a_Revert ,
  396. DWORD a_ProcessIdentifier ,
  397. HANDLE a_IdentifyToken
  398. ) ;
  399. static HRESULT SetProxyState_PrvHost (
  400. ProxyContainer &a_Container ,
  401. ULONG a_ProxyIndex ,
  402. REFIID a_InterfaceId ,
  403. IUnknown *a_Interface ,
  404. IUnknown *&a_Proxy ,
  405. BOOL &a_Revert ,
  406. DWORD a_ProcessIdentifier ,
  407. HANDLE &a_IdentifyToken
  408. ) ;
  409. static HRESULT RevertProxyState_PrvHost (
  410. ProxyContainer &a_Container ,
  411. ULONG a_ProxyIndex ,
  412. IUnknown *a_Proxy ,
  413. BOOL a_Revert ,
  414. DWORD a_ProcessIdentifier ,
  415. HANDLE a_IdentifyToken
  416. ) ;
  417. static HRESULT SetProxyState_SvcHost (
  418. REFIID a_InterfaceId ,
  419. IUnknown *a_Interface ,
  420. IUnknown *&a_Proxy ,
  421. BOOL &a_Revert ,
  422. DWORD a_ProcessIdentifier ,
  423. HANDLE &a_IdentifyToken ,
  424. ACCESS_ALLOWED_ACE *a_Ace ,
  425. WORD a_AceSize
  426. ) ;
  427. static HRESULT RevertProxyState_SvcHost (
  428. IUnknown *a_Proxy ,
  429. BOOL a_Revert ,
  430. DWORD a_ProcessIdentifier ,
  431. HANDLE a_IdentifyToken
  432. ) ;
  433. static HRESULT SetProxyState_PrvHost (
  434. REFIID a_InterfaceId ,
  435. IUnknown *a_Interface ,
  436. IUnknown *&a_Proxy ,
  437. BOOL &a_Revert ,
  438. DWORD a_ProcessIdentifier ,
  439. HANDLE &a_IdentifyToken
  440. ) ;
  441. static HRESULT RevertProxyState_PrvHost (
  442. IUnknown *a_Proxy ,
  443. BOOL a_Revert ,
  444. DWORD a_ProcessIdentifier ,
  445. HANDLE a_IdentifyToken
  446. ) ;
  447. static HRESULT SetProxyState (
  448. REFIID a_InterfaceId ,
  449. IUnknown *a_Interface ,
  450. IUnknown *&a_Proxy ,
  451. BOOL &a_Revert
  452. ) ;
  453. static HRESULT SetProxyState_NoImpersonation (
  454. REFIID a_InterfaceId ,
  455. IUnknown *a_Interface ,
  456. IUnknown *&a_Proxy ,
  457. BOOL &a_Revert
  458. ) ;
  459. static HRESULT RevertProxyState (
  460. IUnknown *a_Proxy ,
  461. BOOL a_Revert
  462. ) ;
  463. static HRESULT Load_DWORD ( HKEY a_Key , LPCWSTR a_Name , DWORD &a_Value ) ;
  464. static HRESULT Load_String ( HKEY a_Key , LPCWSTR a_Name , BSTR &a_Value ) ;
  465. static HRESULT Load_ByteArray ( HKEY a_Key , LPCWSTR a_Name , BYTE *&a_Value , DWORD &a_ValueLength ) ;
  466. static HRESULT Save_DWORD ( HKEY a_Key , LPCWSTR a_Name , DWORD a_Value ) ;
  467. static HRESULT Save_String ( HKEY a_Key , LPCWSTR a_Name , BSTR a_Value ) ;
  468. static HRESULT Save_ByteArray ( HKEY a_Key , LPCWSTR a_Name , BYTE *a_Value , DWORD a_ValueLength ) ;
  469. static HRESULT UnMarshalRegistration (
  470. IUnknown **a_Unknown ,
  471. BYTE *a_MarshaledProxy ,
  472. DWORD a_MarshaledProxyLength
  473. ) ;
  474. static HRESULT MarshalRegistration (
  475. IUnknown *a_Unknown ,
  476. BYTE *&a_MarshaledProxy ,
  477. DWORD &a_MarshaledProxyLength
  478. ) ;
  479. static HRESULT ReleaseRegistration (
  480. BYTE *a_MarshaledProxy ,
  481. DWORD a_MarshaledProxyLength
  482. ) ;
  483. static HRESULT IsDependantCall ( IWbemContext *a_Parent , IWbemContext *a_ChildContext , BOOL &a_DependantCall ) ;
  484. static HRESULT Check_SecurityDescriptor_CallIdentity (
  485. SECURITY_DESCRIPTOR *a_SecurityDescriptor ,
  486. DWORD a_Access ,
  487. GENERIC_MAPPING *a_Mapping,
  488. SECURITY_DESCRIPTOR *defaultSD = GetMethodSecurityDescriptor()
  489. ) ;
  490. static HRESULT AdjustSecurityDescriptorWithSid (
  491. SID *a_OwnerSid ,
  492. SID *a_GroupSid ,
  493. DWORD a_Access ,
  494. SECURITY_DESCRIPTOR *&a_SecurityDescriptor ,
  495. SECURITY_DESCRIPTOR *&a_AlteredSecurityDescriptor
  496. ) ;
  497. static HRESULT CreateSystemAces () ;
  498. static HRESULT DeleteSystemAces () ;
  499. static HRESULT ConstructIdentifyToken_SvcHost (
  500. BOOL &a_Revert ,
  501. DWORD a_ProcessIdentifier ,
  502. HANDLE &a_IdentifyToken ,
  503. ACCESS_ALLOWED_ACE *a_Ace ,
  504. WORD a_AceSize
  505. ) ;
  506. static HRESULT ConstructIdentifyToken_PrvHost (
  507. BOOL &a_Revert ,
  508. DWORD a_ProcessIdentifier ,
  509. HANDLE &a_IdentifyToken ,
  510. ACCESS_ALLOWED_ACE *a_Ace ,
  511. WORD a_AceSize
  512. ) ;
  513. static HRESULT CheckAccess (
  514. SECURITY_DESCRIPTOR *a_SecurityDescriptor ,
  515. DWORD a_Access ,
  516. GENERIC_MAPPING *a_Mapping
  517. ) ;
  518. static HRESULT GetUserSid (
  519. HANDLE a_Token ,
  520. ULONG *a_Size ,
  521. PSID &a_Sid
  522. ) ;
  523. static HRESULT GetGroupSid (
  524. HANDLE a_Token ,
  525. ULONG *a_Size ,
  526. PSID &a_Sid
  527. ) ;
  528. static HRESULT GetAceWithProcessTokenUser (
  529. DWORD a_ProcessIdentifier ,
  530. WORD &a_AceSize ,
  531. ACCESS_ALLOWED_ACE *&a_Ace
  532. ) ;
  533. static HRESULT SinkAccessInitialize (
  534. SECURITY_DESCRIPTOR *a_RegistrationSecurityDescriptor ,
  535. SECURITY_DESCRIPTOR *&a_SinkSecurityDescriptor
  536. ) ;
  537. static HRESULT CreateMethodSecurityDescriptor () ;
  538. static HRESULT DeleteMethodSecurityDescriptor () ;
  539. static SECURITY_DESCRIPTOR *GetMethodSecurityDescriptor ()
  540. {
  541. return s_MethodSecurityDescriptor ;
  542. }
  543. static SECURITY_DESCRIPTOR *GetDefaultDecoupledSD()
  544. {
  545. return s_DefaultDecoupledSD ;
  546. }
  547. static DWORD InitializeTransmitSize () ;
  548. static DWORD GetTransmitSize () { return s_TransmitBufferSize ; }
  549. static DWORD InitializeDefaultStackSize () ;
  550. static DWORD GetDefaultStackSize () { return s_DefaultStackSize ; }
  551. } ;
  552. wchar_t * DupString(const wchar_t * src);
  553. #endif // _CommonGlobals_H