Source code of Windows XP (NT5)
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.

433 lines
13 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. authz.h
  5. Abstract:
  6. This module contains the authorization framework APIs and any public data
  7. structures needed to call these APIs.
  8. Author:
  9. Kedar Dubhashi - March 2000
  10. Revision History:
  11. Created - March 2000
  12. --*/
  13. #ifndef __AUTHZ_H__
  14. #define __AUTHZ_H__
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #if !defined(_AUTHZ_)
  19. #define AUTHZAPI DECLSPEC_IMPORT
  20. #else
  21. #define AUTHZAPI
  22. #endif
  23. #include <windows.h>
  24. #include <adtgen.h>
  25. //
  26. // Flags which may be used at the time of client context creation using a sid.
  27. //
  28. #define AUTHZ_SKIP_TOKEN_GROUPS 0x2
  29. DECLARE_HANDLE(AUTHZ_ACCESS_CHECK_RESULTS_HANDLE);
  30. DECLARE_HANDLE(AUTHZ_CLIENT_CONTEXT_HANDLE);
  31. DECLARE_HANDLE(AUTHZ_RESOURCE_MANAGER_HANDLE);
  32. DECLARE_HANDLE(AUTHZ_AUDIT_EVENT_HANDLE);
  33. DECLARE_HANDLE(AUTHZ_AUDIT_EVENT_TYPE_HANDLE);
  34. typedef AUTHZ_ACCESS_CHECK_RESULTS_HANDLE *PAUTHZ_ACCESS_CHECK_RESULTS_HANDLE;
  35. typedef AUTHZ_CLIENT_CONTEXT_HANDLE *PAUTHZ_CLIENT_CONTEXT_HANDLE;
  36. typedef AUTHZ_RESOURCE_MANAGER_HANDLE *PAUTHZ_RESOURCE_MANAGER_HANDLE;
  37. typedef AUTHZ_AUDIT_EVENT_HANDLE *PAUTHZ_AUDIT_EVENT_HANDLE;
  38. typedef AUTHZ_AUDIT_EVENT_TYPE_HANDLE *PAUTHZ_AUDIT_EVENT_TYPE_HANDLE;
  39. //
  40. // Structure defining the access check request.
  41. //
  42. typedef struct _AUTHZ_ACCESS_REQUEST
  43. {
  44. ACCESS_MASK DesiredAccess;
  45. //
  46. // To replace the principal self sid in the acl.
  47. //
  48. PSID PrincipalSelfSid;
  49. //
  50. // Object type list represented by an array of (level, guid) pair and the
  51. // number of elements in the array. This is a post-fix representation of the
  52. // object tree.
  53. // These fields should be set to NULL and 0 respectively except when per
  54. // property access is desired.
  55. //
  56. POBJECT_TYPE_LIST ObjectTypeList;
  57. DWORD ObjectTypeListLength;
  58. //
  59. // To support completely business rules based access. This will be passed as
  60. // input to the callback access check function. Access check algorithm does
  61. // not interpret these.
  62. //
  63. PVOID OptionalArguments;
  64. } AUTHZ_ACCESS_REQUEST, *PAUTHZ_ACCESS_REQUEST;
  65. //
  66. // Structure to return the results of the access check call.
  67. //
  68. typedef struct _AUTHZ_ACCESS_REPLY
  69. {
  70. //
  71. // The length of the array representing the object type list structure. If
  72. // no object type is used to represent the object, then the length must be
  73. // set to 1.
  74. //
  75. // Note: This parameter must be filled!
  76. //
  77. DWORD ResultListLength;
  78. //
  79. // Array of granted access masks. This memory is allocated by the RM. Access
  80. // check routines just fill in the values.
  81. //
  82. PACCESS_MASK GrantedAccessMask;
  83. //
  84. // Array of SACL evaluation results. This memory is allocated by the RM, if SACL
  85. // evaluation results are desired. Access check routines just fill in the values.
  86. // Sacl evaluation will only be performed if auditing is requested.
  87. //
  88. #define AUTHZ_GENERATE_SUCCESS_AUDIT 0x1
  89. #define AUTHZ_GENERATE_FAILURE_AUDIT 0x2
  90. PDWORD SaclEvaluationResults OPTIONAL;
  91. //
  92. // Array of results for each element of the array. This memory is allocated
  93. // by the RM. Access check routines just fill in the values.
  94. //
  95. PDWORD Error;
  96. } AUTHZ_ACCESS_REPLY, *PAUTHZ_ACCESS_REPLY;
  97. //
  98. // Typedefs for callback functions to be provided by the resource manager.
  99. //
  100. //
  101. // Callback access check function takes in
  102. // AuthzClientContext - a client context
  103. // pAce - pointer to a callback ace
  104. // pArgs - Optional arguments that were passed to AuthzAccessCheck thru
  105. // AuthzAccessRequest->OptionalArguments are passed back here.
  106. // pbAceApplicable - The resource manager must supply whether the ace should
  107. // be used in the computation of access evaluation
  108. //
  109. // Returns
  110. // TRUE if the API succeeded.
  111. // FALSE on any intermediate errors (like failed memory allocation)
  112. // In case of failure, the caller must use SetLastError(ErrorValue).
  113. //
  114. typedef BOOL (CALLBACK *PFN_AUTHZ_DYNAMIC_ACCESS_CHECK) (
  115. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  116. IN PACE_HEADER pAce,
  117. IN PVOID pArgs OPTIONAL,
  118. IN OUT PBOOL pbAceApplicable
  119. );
  120. //
  121. // Callback compute dynamic groups function takes in
  122. // AuthzClientContext - a client context
  123. // pArgs - Optional arguments that supplied to AuthzInitializeClientContext*
  124. // thru DynamicGroupArgs are passed back here..
  125. // pSidAttrArray - To allocate and return an array of (sids, attribute)
  126. // pairs to be added to the normal part of the client context.
  127. // pSidCount - Number of elements in pSidAttrArray
  128. // pRestrictedSidAttrArray - To allocate and return an array of (sids, attribute)
  129. // pairs to be added to the restricted part of the client context.
  130. // pRestrictedSidCount - Number of elements in pRestrictedSidAttrArray
  131. //
  132. // Note:
  133. // Memory returned thru both these array will be freed by the callback
  134. // free function defined by the resource manager.
  135. //
  136. // Returns
  137. // TRUE if the API succeeded.
  138. // FALSE on any intermediate errors (like failed memory allocation)
  139. // In case of failure, the caller must use SetLastError(ErrorValue).
  140. //
  141. typedef BOOL (CALLBACK *PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS) (
  142. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  143. IN PVOID Args,
  144. OUT PSID_AND_ATTRIBUTES *pSidAttrArray,
  145. OUT PDWORD pSidCount,
  146. OUT PSID_AND_ATTRIBUTES *pRestrictedSidAttrArray,
  147. OUT PDWORD pRestrictedSidCount
  148. );
  149. //
  150. // Callback free function takes in
  151. // pSidAttrArray - To be freed. This has been allocated by the compute
  152. // dynamic groups function.
  153. //
  154. typedef VOID (CALLBACK *PFN_AUTHZ_FREE_DYNAMIC_GROUPS) (
  155. IN PSID_AND_ATTRIBUTES pSidAttrArray
  156. );
  157. //
  158. // Valid flags for AuthzAccessCheck
  159. //
  160. #define AUTHZ_ACCESS_CHECK_NO_DEEP_COPY_SD 0x00000001
  161. AUTHZAPI
  162. BOOL
  163. WINAPI
  164. AuthzAccessCheck(
  165. IN DWORD Flags,
  166. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  167. IN PAUTHZ_ACCESS_REQUEST pRequest,
  168. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent OPTIONAL,
  169. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  170. IN PSECURITY_DESCRIPTOR *OptionalSecurityDescriptorArray OPTIONAL,
  171. IN DWORD OptionalSecurityDescriptorCount,
  172. IN OUT PAUTHZ_ACCESS_REPLY pReply,
  173. OUT PAUTHZ_ACCESS_CHECK_RESULTS_HANDLE phAccessCheckResults OPTIONAL
  174. );
  175. AUTHZAPI
  176. BOOL
  177. WINAPI
  178. AuthzCachedAccessCheck(
  179. IN DWORD Flags,
  180. IN AUTHZ_ACCESS_CHECK_RESULTS_HANDLE hAccessCheckResults,
  181. IN PAUTHZ_ACCESS_REQUEST pRequest,
  182. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent OPTIONAL,
  183. IN OUT PAUTHZ_ACCESS_REPLY pReply
  184. );
  185. AUTHZAPI
  186. BOOL
  187. WINAPI
  188. AuthzOpenObjectAudit(
  189. IN DWORD Flags,
  190. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  191. IN PAUTHZ_ACCESS_REQUEST pRequest,
  192. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent,
  193. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  194. IN PSECURITY_DESCRIPTOR *OptionalSecurityDescriptorArray OPTIONAL,
  195. IN DWORD OptionalSecurityDescriptorCount,
  196. IN PAUTHZ_ACCESS_REPLY pReply
  197. );
  198. AUTHZAPI
  199. BOOL
  200. WINAPI
  201. AuthzFreeHandle(
  202. IN OUT AUTHZ_ACCESS_CHECK_RESULTS_HANDLE hAccessCheckResults
  203. );
  204. //
  205. // Flags for AuthzInitializeResourceManager
  206. //
  207. #define AUTHZ_RM_FLAG_NO_AUDIT 0x1
  208. #define AUTHZ_VALID_RM_INIT_FLAGS (AUTHZ_RM_FLAG_NO_AUDIT)
  209. AUTHZAPI
  210. BOOL
  211. WINAPI
  212. AuthzInitializeResourceManager(
  213. IN DWORD Flags,
  214. IN PFN_AUTHZ_DYNAMIC_ACCESS_CHECK pfnDynamicAccessCheck OPTIONAL,
  215. IN PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS pfnComputeDynamicGroups OPTIONAL,
  216. IN PFN_AUTHZ_FREE_DYNAMIC_GROUPS pfnFreeDynamicGroups OPTIONAL,
  217. IN PCWSTR szResourceManagerName,
  218. OUT PAUTHZ_RESOURCE_MANAGER_HANDLE phAuthzResourceManager
  219. );
  220. AUTHZAPI
  221. BOOL
  222. WINAPI
  223. AuthzFreeResourceManager(
  224. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager
  225. );
  226. AUTHZAPI
  227. BOOL
  228. WINAPI
  229. AuthzInitializeContextFromToken(
  230. IN DWORD Flags,
  231. IN HANDLE TokenHandle,
  232. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager,
  233. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  234. IN LUID Identifier,
  235. IN PVOID DynamicGroupArgs OPTIONAL,
  236. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phAuthzClientContext
  237. );
  238. AUTHZAPI
  239. BOOL
  240. WINAPI
  241. AuthzInitializeContextFromSid(
  242. IN DWORD Flags,
  243. IN PSID UserSid,
  244. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager,
  245. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  246. IN LUID Identifier,
  247. IN PVOID DynamicGroupArgs OPTIONAL,
  248. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phAuthzClientContext
  249. );
  250. AUTHZAPI
  251. BOOL
  252. WINAPI
  253. AuthzInitializeContextFromAuthzContext(
  254. IN DWORD Flags,
  255. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  256. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  257. IN LUID Identifier,
  258. IN PVOID DynamicGroupArgs,
  259. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phNewAuthzClientContext
  260. );
  261. AUTHZAPI
  262. BOOL
  263. WINAPI
  264. AuthzAddSidsToContext(
  265. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  266. IN PSID_AND_ATTRIBUTES Sids OPTIONAL,
  267. IN DWORD SidCount,
  268. IN PSID_AND_ATTRIBUTES RestrictedSids OPTIONAL,
  269. IN DWORD RestrictedSidCount,
  270. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phNewAuthzClientContext
  271. );
  272. //
  273. // Enumeration type to be used to specify the type of information to be
  274. // retrieved from an existing AuthzClientContext.
  275. //
  276. typedef enum _AUTHZ_CONTEXT_INFORMATION_CLASS
  277. {
  278. AuthzContextInfoUserSid = 1,
  279. AuthzContextInfoGroupsSids,
  280. AuthzContextInfoRestrictedSids,
  281. AuthzContextInfoPrivileges,
  282. AuthzContextInfoExpirationTime,
  283. AuthzContextInfoServerContext,
  284. AuthzContextInfoIdentifier,
  285. AuthzContextInfoSource,
  286. AuthzContextInfoAll
  287. } AUTHZ_CONTEXT_INFORMATION_CLASS;
  288. AUTHZAPI
  289. BOOL
  290. WINAPI
  291. AuthzGetInformationFromContext(
  292. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  293. IN AUTHZ_CONTEXT_INFORMATION_CLASS InfoClass,
  294. IN DWORD BufferSize,
  295. OUT PDWORD pSizeRequired,
  296. OUT PVOID Buffer
  297. );
  298. AUTHZAPI
  299. BOOL
  300. WINAPI
  301. AuthzFreeContext(
  302. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext
  303. );
  304. //
  305. // Valid flags that may be used in AuthzInitializeObjectAccessAuditEvent().
  306. //
  307. #define AUTHZ_NO_SUCCESS_AUDIT 0x00000001
  308. #define AUTHZ_NO_FAILURE_AUDIT 0x00000002
  309. #define AUTHZ_NO_ALLOC_STRINGS 0x00000004
  310. #define AUTHZ_VALID_OBJECT_ACCESS_AUDIT_FLAGS (AUTHZ_NO_SUCCESS_AUDIT | \
  311. AUTHZ_NO_FAILURE_AUDIT | \
  312. AUTHZ_NO_ALLOC_STRINGS)
  313. AUTHZAPI
  314. BOOL
  315. WINAPI
  316. AuthzInitializeObjectAccessAuditEvent(
  317. IN DWORD Flags,
  318. IN AUTHZ_AUDIT_EVENT_TYPE_HANDLE hAuditEventType,
  319. IN PWSTR szOperationType,
  320. IN PWSTR szObjectType,
  321. IN PWSTR szObjectName,
  322. IN PWSTR szAdditionalInfo,
  323. OUT PAUTHZ_AUDIT_EVENT_HANDLE phAuditEvent,
  324. IN DWORD dwAdditionalParameterCount,
  325. ...
  326. );
  327. //
  328. // Enumeration type to be used to specify the type of information to be
  329. // retrieved from an existing AUTHZ_AUDIT_EVENT_HANDLE.
  330. //
  331. typedef enum _AUTHZ_AUDIT_EVENT_INFORMATION_CLASS
  332. {
  333. AuthzAuditEventInfoFlags = 1,
  334. AuthzAuditEventInfoOperationType,
  335. AuthzAuditEventInfoObjectType,
  336. AuthzAuditEventInfoObjectName,
  337. AuthzAuditEventInfoAdditionalInfo,
  338. } AUTHZ_AUDIT_EVENT_INFORMATION_CLASS;
  339. AUTHZAPI
  340. BOOL
  341. WINAPI
  342. AuthzGetInformationFromAuditEvent(
  343. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent,
  344. IN AUTHZ_AUDIT_EVENT_INFORMATION_CLASS InfoClass,
  345. IN DWORD BufferSize,
  346. OUT PDWORD pSizeRequired,
  347. OUT PVOID Buffer
  348. );
  349. AUTHZAPI
  350. BOOL
  351. WINAPI
  352. AuthzFreeAuditEvent(
  353. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent
  354. );
  355. #ifdef __cplusplus
  356. }
  357. #endif
  358. #endif