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.

448 lines
13 KiB

  1. //=================================================================
  2. //
  3. // AdvApi32Api.h
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #ifndef _ADVAPI32API_H_
  9. #define _ADVAPI32API_H_
  10. #include <lmaccess.h>
  11. #include <lmapibuf.h>
  12. #include <lmserver.h>
  13. #include <lmerr.h>
  14. #include <ntsecapi.h>
  15. #include <stack>
  16. #include <comdef.h>
  17. #include <dsrole.h>
  18. #include <dsgetdc.h>
  19. #include <aclapi.h>
  20. #include "DllUtils.h"
  21. /******************************************************************************
  22. * #includes to Register this class with the CResourceManager.
  23. *****************************************************************************/
  24. #include "DllWrapperBase.h"
  25. extern const GUID g_guidAdvApi32Api;
  26. extern const TCHAR g_tstrAdvApi32[];
  27. /******************************************************************************
  28. * Function pointer typedefs. Add new functions here as required.
  29. *****************************************************************************/
  30. typedef NTSTATUS (STDAPICALLTYPE *PFN_LSA_ENUMERATE_TRUSTED_DOMAINS)
  31. (
  32. IN LSA_HANDLE PolicyHandle,
  33. IN OUT PLSA_ENUMERATION_HANDLE EnumerationContext,
  34. OUT PVOID *Buffer,
  35. IN ULONG PreferedMaximumLength,
  36. OUT PULONG CountReturned
  37. );
  38. typedef NTSTATUS (STDAPICALLTYPE *PFN_LSA_QUERY_INFORMATION_POLICY)
  39. (
  40. IN LSA_HANDLE PolicyHandle,
  41. IN POLICY_INFORMATION_CLASS InformationClass,
  42. OUT PVOID *Buffer
  43. );
  44. typedef NTSTATUS (STDAPICALLTYPE *PFN_LSA_NT_STATUS_TO_WIN_ERROR)
  45. (
  46. IN NTSTATUS Status
  47. );
  48. typedef NTSTATUS (STDAPICALLTYPE *PFN_LSA_FREE_MEMORY)
  49. (
  50. IN PVOID Buffer
  51. );
  52. typedef NTSTATUS (STDAPICALLTYPE *PFN_LSA_OPEN_POLICY)
  53. (
  54. IN PLSA_UNICODE_STRING SystemName OPTIONAL,
  55. IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
  56. IN ACCESS_MASK DesiredAccess,
  57. OUT PLSA_HANDLE PolicyHandle
  58. );
  59. typedef NTSTATUS (STDAPICALLTYPE *PFN_LSA_CLOSE)
  60. (
  61. IN LSA_HANDLE ObjectHandle
  62. );
  63. typedef DWORD (WINAPI *PFN_SET_NAMED_SECURITY_INFO_W)
  64. (
  65. IN LPWSTR pObjectName,
  66. IN SE_OBJECT_TYPE ObjectType,
  67. IN SECURITY_INFORMATION SecurityInfo,
  68. IN PSID psidOowner,
  69. IN PSID psidGroup,
  70. IN PACL pDacl,
  71. IN PACL pSacl
  72. );
  73. typedef DWORD (WINAPI *PFN_GET_NAMED_SECURITY_INFO_W)
  74. (
  75. LPWSTR pObjectName,
  76. SE_OBJECT_TYPE ObjectType,
  77. SECURITY_INFORMATION SecurityInfo,
  78. PSID *ppsidOowner,
  79. PSID *ppsidGroup,
  80. PACL *ppDacl,
  81. PACL *ppSacl,
  82. PSECURITY_DESCRIPTOR *ppSecurityDescriptor
  83. );
  84. typedef BOOL (WINAPI *PFN_QUERY_SERVICE_STATUS_EX)
  85. (
  86. SC_HANDLE hService,
  87. SC_STATUS_TYPE InfoLevel,
  88. LPBYTE lpBuffer,
  89. DWORD cbBufSize,
  90. LPDWORD pcbBytesNeeded
  91. );
  92. typedef BOOL (WINAPI *PFN_DUPLICATE_TOKEN_EX )
  93. (
  94. HANDLE , // handle to token to duplicate
  95. DWORD , // access rights of new token
  96. LPSECURITY_ATTRIBUTES , // security attributes of the new token
  97. SECURITY_IMPERSONATION_LEVEL , // impersonation level of new token
  98. TOKEN_TYPE , // primary or impersonation token
  99. PHANDLE // handle to duplicated token
  100. );
  101. typedef BOOL (WINAPI *PFN_SET_SECURITY_DESCRIPTOR_CONTROL)
  102. (
  103. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  104. IN SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
  105. IN SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
  106. );
  107. typedef BOOL (WINAPI *PFN_CONVERT_TO_AUTO_INHERIT_PRIVATE_OBJECT_SECURITY)
  108. (
  109. IN PSECURITY_DESCRIPTOR ParentDescriptor,
  110. IN PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
  111. OUT PSECURITY_DESCRIPTOR *NewSecurityDescriptor,
  112. IN GUID *ObjectType,
  113. IN BOOLEAN IsDirectoryObject,
  114. IN PGENERIC_MAPPING GenericMapping
  115. );
  116. typedef BOOL (WINAPI *PFN_DESTROY_PRIVATE_OBJECT_SECURITY)
  117. (
  118. IN OUT PSECURITY_DESCRIPTOR * ObjectDescriptor
  119. );
  120. typedef DWORD (WINAPI *PFN_SET_NAMED_SECURITY_INFO_EX)
  121. (
  122. IN LPCTSTR lpObject,
  123. IN SE_OBJECT_TYPE ObjectType,
  124. IN SECURITY_INFORMATION SecurityInfo,
  125. IN LPCTSTR lpProvider,
  126. IN PACTRL_ACCESS pAccessList,
  127. IN PACTRL_AUDIT pAuditList,
  128. IN LPTSTR lpOwner,
  129. IN LPTSTR lpGroup,
  130. IN PACTRL_OVERLAPPED pOverlapped
  131. );
  132. typedef DWORD (WINAPI *PFN_GET_EXPLICIT_ENTRIES_FROM_ACL)
  133. (
  134. IN PACL pacl,
  135. OUT PULONG pcCountOfExplicitEntries,
  136. OUT PEXPLICIT_ACCESS * pListOfExplicitEntries
  137. );
  138. typedef BOOL (APIENTRY *PFN_CHECK_TOKEN_MEMBERSHIP)
  139. (
  140. IN HANDLE TokenHandle OPTIONAL,
  141. IN PSID SidToCheck,
  142. OUT PBOOL IsMember
  143. );
  144. typedef BOOL (WINAPI *PFN_ADD_ACCESS_ALLOWED_OBJECT_ACE)
  145. (
  146. IN OUT PACL pAcl,
  147. IN DWORD dwAceRevision,
  148. IN DWORD AceFlags,
  149. IN DWORD AccessMask,
  150. IN GUID *ObjectTypeGuid,
  151. IN GUID *InheritedObjectTypeGuid,
  152. IN PSID pSid
  153. );
  154. typedef BOOL (WINAPI *PFN_ADD_ACCESS_DENIED_OBJECT_ACE)
  155. (
  156. IN OUT PACL pAcl,
  157. IN DWORD dwAceRevision,
  158. IN DWORD AceFlags,
  159. IN DWORD AccessMask,
  160. IN GUID *ObjectTypeGuid,
  161. IN GUID *InheritedObjectTypeGuid,
  162. IN PSID pSid
  163. );
  164. typedef BOOL (WINAPI *PFN_ADD_AUDIT_ACCESS_OBJECT_ACE)
  165. (
  166. IN OUT PACL pAcl,
  167. IN DWORD dwAceRevision,
  168. IN DWORD AceFlags,
  169. IN DWORD AccessMask,
  170. IN GUID *ObjectTypeGuid,
  171. IN GUID *InheritedObjectTypeGuid,
  172. IN PSID pSid,
  173. IN BOOL bAuditSuccess,
  174. IN BOOL bAuditFailure
  175. );
  176. typedef DWORD (WINAPI *PFN_GET_EFFECTIVE_RIGHTS_FROM_ACL_W)
  177. (
  178. IN PACL pacl,
  179. IN PTRUSTEE_W pTrustee,
  180. OUT PACCESS_MASK pAccessRights
  181. );
  182. /******************************************************************************
  183. * Wrapper class for AdvApi32 load/unload, for registration with CResourceManager.
  184. ******************************************************************************/
  185. class CAdvApi32Api : public CDllWrapperBase
  186. {
  187. private:
  188. // Member variables (function pointers) pointing to kernel32 functions.
  189. // Add new functions here as required.
  190. PFN_LSA_ENUMERATE_TRUSTED_DOMAINS m_pfnLsaEnumerateTrustedDomains;
  191. PFN_LSA_QUERY_INFORMATION_POLICY m_pfnLsaQueryInformationPolicy;
  192. PFN_LSA_NT_STATUS_TO_WIN_ERROR m_pfnLsaNtStatusToWinError;
  193. PFN_LSA_FREE_MEMORY m_pfnLsaFreeMemory;
  194. PFN_LSA_OPEN_POLICY m_pfnLsaOpenPolicy;
  195. PFN_LSA_CLOSE m_pfnLsaClose;
  196. PFN_SET_NAMED_SECURITY_INFO_W m_pfnSetNamedSecurityInfoW;
  197. PFN_GET_NAMED_SECURITY_INFO_W m_pfnGetNamedSecurityInfoW;
  198. PFN_QUERY_SERVICE_STATUS_EX m_pfnQueryServiceStatusEx;
  199. PFN_DUPLICATE_TOKEN_EX m_pfnDuplicateTokenEx;
  200. PFN_SET_SECURITY_DESCRIPTOR_CONTROL m_pfnSetSecurityDescriptorControl;
  201. PFN_CONVERT_TO_AUTO_INHERIT_PRIVATE_OBJECT_SECURITY m_pfnConvertToAutoInheritPrivateObjectSecurity;
  202. PFN_DESTROY_PRIVATE_OBJECT_SECURITY m_pfnDestroyPrivateObjectSecurity;
  203. PFN_SET_NAMED_SECURITY_INFO_EX m_pfnSetNamedSecurityInfoEx;
  204. PFN_GET_EXPLICIT_ENTRIES_FROM_ACL m_pfnGetExplicitEntriesFromAcl;
  205. PFN_CHECK_TOKEN_MEMBERSHIP m_pfnCheckTokenMembership;
  206. PFN_ADD_ACCESS_ALLOWED_OBJECT_ACE m_pfnAddAccessAllowedObjectAce;
  207. PFN_ADD_ACCESS_DENIED_OBJECT_ACE m_pfnAddAccessDeniedObjectAce;
  208. PFN_ADD_AUDIT_ACCESS_OBJECT_ACE m_pfnAddAuditAccessObjectAce;
  209. PFN_GET_EFFECTIVE_RIGHTS_FROM_ACL_W m_pfnGetEffectiveRightsFromAclW;
  210. public:
  211. // Constructor and destructor:
  212. CAdvApi32Api(LPCTSTR a_tstrWrappedDllName);
  213. ~CAdvApi32Api();
  214. // Inherrited initialization function.
  215. virtual bool Init();
  216. // Member functions wrapping kernel32 functions.
  217. // Add new functions here as required:
  218. NTSTATUS LsaEnumerateTrustedDomains
  219. (
  220. LSA_HANDLE a_PolicyHandle,
  221. PLSA_ENUMERATION_HANDLE a_EnumerationContext,
  222. PVOID *a_Buffer,
  223. ULONG a_PreferedMaximumLength,
  224. PULONG a_CountReturned
  225. );
  226. NTSTATUS LsaQueryInformationPolicy
  227. (
  228. LSA_HANDLE a_PolicyHandle,
  229. POLICY_INFORMATION_CLASS a_InformationClass,
  230. PVOID *a_Buffer
  231. );
  232. NTSTATUS LsaNtStatusToWinError
  233. (
  234. NTSTATUS a_Status
  235. );
  236. NTSTATUS LsaFreeMemory
  237. (
  238. PVOID a_Buffer
  239. );
  240. NTSTATUS LsaOpenPolicy
  241. (
  242. PLSA_UNICODE_STRING a_SystemName,
  243. PLSA_OBJECT_ATTRIBUTES a_ObjectAttributes,
  244. ACCESS_MASK a_DesiredAccess,
  245. PLSA_HANDLE a_PolicyHandle
  246. );
  247. NTSTATUS LsaClose
  248. (
  249. LSA_HANDLE a_ObjectHandle
  250. );
  251. bool SetNamedSecurityInfoW
  252. (
  253. LPWSTR a_pObjectName,
  254. SE_OBJECT_TYPE a_ObjectType,
  255. SECURITY_INFORMATION a_SecurityInfo,
  256. PSID a_psidOowner,
  257. PSID a_psidGroup,
  258. PACL a_pDacl,
  259. PACL a_pSacl,
  260. DWORD *a_dwRetval
  261. );
  262. bool GetNamedSecurityInfoW
  263. (
  264. LPWSTR a_pObjectName,
  265. SE_OBJECT_TYPE a_ObjectType,
  266. SECURITY_INFORMATION a_SecurityInfo,
  267. PSID *a_ppsidOowner,
  268. PSID *a_ppsidGroup,
  269. PACL *a_ppDacl,
  270. PACL *a_ppSacl,
  271. PSECURITY_DESCRIPTOR *a_ppSecurityDescriptor,
  272. DWORD *a_dwRetval
  273. );
  274. bool QueryServiceStatusEx
  275. (
  276. SC_HANDLE a_hService,
  277. SC_STATUS_TYPE a_InfoLevel,
  278. LPBYTE a_lpBuffer,
  279. DWORD a_cbBufSize,
  280. LPDWORD a_pcbBytesNeeded,
  281. BOOL *a_fRetval
  282. );
  283. bool DuplicateTokenEx
  284. (
  285. HANDLE a_h, // handle to token to duplicate
  286. DWORD a_dw, // access rights of new token
  287. LPSECURITY_ATTRIBUTES a_lpsa, // security attributes of the new token
  288. SECURITY_IMPERSONATION_LEVEL a_sil, // impersonation level of new token
  289. TOKEN_TYPE a_tt, // primary or impersonation token
  290. PHANDLE a_ph, // handle to duplicated token
  291. BOOL *a_fRetval // encapsulated function return value
  292. );
  293. bool SetSecurityDescriptorControl
  294. (
  295. PSECURITY_DESCRIPTOR pSecurityDescriptor,
  296. SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
  297. SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet,
  298. BOOL *a_fRetval
  299. );
  300. bool ConvertToAutoInheritPrivateObjectSecurity
  301. (
  302. PSECURITY_DESCRIPTOR a_ParentDescriptor,
  303. PSECURITY_DESCRIPTOR a_CurrentSecurityDescriptor,
  304. PSECURITY_DESCRIPTOR *a_NewSecurityDescriptor,
  305. GUID *a_ObjectType,
  306. BOOLEAN a_IsDirectoryObject,
  307. PGENERIC_MAPPING a_GenericMapping,
  308. BOOL *a_fRetval
  309. );
  310. bool DestroyPrivateObjectSecurity
  311. (
  312. PSECURITY_DESCRIPTOR *a_ObjectDescriptor,
  313. BOOL *a_fRetval
  314. );
  315. bool SetNamedSecurityInfoEx
  316. (
  317. LPCTSTR a_lpObject,
  318. SE_OBJECT_TYPE a_ObjectType,
  319. SECURITY_INFORMATION a_SecurityInfo,
  320. LPCTSTR a_lpProvider,
  321. PACTRL_ACCESS a_pAccessList,
  322. PACTRL_AUDIT a_pAuditList,
  323. LPTSTR a_lpOwner,
  324. LPTSTR a_lpGroup,
  325. PACTRL_OVERLAPPED a_pOverlapped,
  326. DWORD *a_dwRetval
  327. );
  328. bool GetExplicitEntriesFromAcl
  329. (
  330. PACL a_pacl,
  331. PULONG a_pcCountOfExplicitEntries,
  332. PEXPLICIT_ACCESS *a_pListOfExplicitEntries,
  333. DWORD *a_dwRetval
  334. );
  335. bool CheckTokenMembership
  336. (
  337. HANDLE a_hTokenHandle OPTIONAL,
  338. PSID a_pSidToCheck,
  339. PBOOL a_pfIsMember,
  340. BOOL *a_fRetval
  341. );
  342. bool AddAccessAllowedObjectAce
  343. (
  344. PACL a_pAcl,
  345. DWORD a_dwAceRevision,
  346. DWORD a_AceFlags,
  347. DWORD a_AccessMask,
  348. GUID *a_ObjectTypeGuid,
  349. GUID *a_InheritedObjectTypeGuid,
  350. PSID a_pSid,
  351. BOOL *a_fRetval
  352. );
  353. bool AddAccessDeniedObjectAce
  354. (
  355. PACL a_pAcl,
  356. DWORD a_dwAceRevision,
  357. DWORD a_AceFlags,
  358. DWORD a_AccessMask,
  359. GUID *a_ObjectTypeGuid,
  360. GUID *a_InheritedObjectTypeGuid,
  361. PSID a_pSid,
  362. BOOL *a_fRetval
  363. );
  364. bool AddAuditAccessObjectAce
  365. (
  366. PACL a_pAcl,
  367. DWORD a_dwAceRevision,
  368. DWORD a_AceFlags,
  369. DWORD a_AccessMask,
  370. GUID *a_ObjectTypeGuid,
  371. GUID *a_InheritedObjectTypeGuid,
  372. PSID a_pSid,
  373. BOOL a_bAuditSuccess,
  374. BOOL a_bAuditFailure,
  375. BOOL *a_fRetval
  376. );
  377. bool GetEffectiveRightsFromAclW
  378. (
  379. PACL a_pacl,
  380. PTRUSTEE_W a_pTrustee,
  381. PACCESS_MASK a_pAccessRights,
  382. DWORD *a_dwRetval
  383. );
  384. };
  385. #endif