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.

542 lines
17 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. Revision History:
  9. Created - March 2000
  10. --*/
  11. #ifndef __AUTHZ_H__
  12. #define __AUTHZ_H__
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #if !defined(_AUTHZ_)
  17. #define AUTHZAPI DECLSPEC_IMPORT
  18. #else
  19. #define AUTHZAPI
  20. #endif
  21. #include <windows.h>
  22. #include <adtgen.h>
  23. //
  24. // Flags which may be used at the time of client context creation using a sid.
  25. //
  26. #define AUTHZ_SKIP_TOKEN_GROUPS 0x2
  27. #define AUTHZ_REQUIRE_S4U_LOGON 0x4
  28. DECLARE_HANDLE(AUTHZ_ACCESS_CHECK_RESULTS_HANDLE);
  29. DECLARE_HANDLE(AUTHZ_CLIENT_CONTEXT_HANDLE);
  30. DECLARE_HANDLE(AUTHZ_RESOURCE_MANAGER_HANDLE);
  31. DECLARE_HANDLE(AUTHZ_AUDIT_EVENT_HANDLE);
  32. DECLARE_HANDLE(AUTHZ_AUDIT_EVENT_TYPE_HANDLE);
  33. DECLARE_HANDLE(AUTHZ_SECURITY_EVENT_PROVIDER_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. typedef AUTHZ_SECURITY_EVENT_PROVIDER_HANDLE *PAUTHZ_SECURITY_EVENT_PROVIDER_HANDLE;
  40. //
  41. // Structure defining the access check request.
  42. //
  43. typedef struct _AUTHZ_ACCESS_REQUEST
  44. {
  45. ACCESS_MASK DesiredAccess;
  46. //
  47. // To replace the principal self sid in the acl.
  48. //
  49. PSID PrincipalSelfSid;
  50. //
  51. // Object type list represented by an array of (level, guid) pair and the
  52. // number of elements in the array. This is a post-fix representation of the
  53. // object tree.
  54. // These fields should be set to NULL and 0 respectively except when per
  55. // property access is desired.
  56. //
  57. POBJECT_TYPE_LIST ObjectTypeList;
  58. DWORD ObjectTypeListLength;
  59. //
  60. // To support completely business rules based access. This will be passed as
  61. // input to the callback access check function. Access check algorithm does
  62. // not interpret these.
  63. //
  64. PVOID OptionalArguments;
  65. } AUTHZ_ACCESS_REQUEST, *PAUTHZ_ACCESS_REQUEST;
  66. //
  67. // Structure to return the results of the access check call.
  68. //
  69. typedef struct _AUTHZ_ACCESS_REPLY
  70. {
  71. //
  72. // The length of the array representing the object type list structure. If
  73. // no object type is used to represent the object, then the length must be
  74. // set to 1.
  75. //
  76. // Note: This parameter must be filled!
  77. //
  78. DWORD ResultListLength;
  79. //
  80. // Array of granted access masks. This memory is allocated by the RM. Access
  81. // check routines just fill in the values.
  82. //
  83. PACCESS_MASK GrantedAccessMask;
  84. //
  85. // Array of SACL evaluation results. This memory is allocated by the RM, if SACL
  86. // evaluation results are desired. Access check routines just fill in the values.
  87. // Sacl evaluation will only be performed if auditing is requested.
  88. //
  89. #define AUTHZ_GENERATE_SUCCESS_AUDIT 0x1
  90. #define AUTHZ_GENERATE_FAILURE_AUDIT 0x2
  91. PDWORD SaclEvaluationResults OPTIONAL;
  92. //
  93. // Array of results for each element of the array. This memory is allocated
  94. // by the RM. Access check routines just fill in the values.
  95. //
  96. PDWORD Error;
  97. } AUTHZ_ACCESS_REPLY, *PAUTHZ_ACCESS_REPLY;
  98. //
  99. // Typedefs for callback functions to be provided by the resource manager.
  100. //
  101. //
  102. // Callback access check function takes in
  103. // AuthzClientContext - a client context
  104. // pAce - pointer to a callback ace
  105. // pArgs - Optional arguments that were passed to AuthzAccessCheck thru
  106. // AuthzAccessRequest->OptionalArguments are passed back here.
  107. // pbAceApplicable - The resource manager must supply whether the ace should
  108. // be used in the computation of access evaluation
  109. //
  110. // Returns
  111. // TRUE if the API succeeded.
  112. // FALSE on any intermediate errors (like failed memory allocation)
  113. // In case of failure, the caller must use SetLastError(ErrorValue).
  114. //
  115. typedef BOOL (CALLBACK *PFN_AUTHZ_DYNAMIC_ACCESS_CHECK) (
  116. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  117. IN PACE_HEADER pAce,
  118. IN PVOID pArgs OPTIONAL,
  119. IN OUT PBOOL pbAceApplicable
  120. );
  121. //
  122. // Callback compute dynamic groups function takes in
  123. // AuthzClientContext - a client context
  124. // pArgs - Optional arguments that supplied to AuthzInitializeClientContext*
  125. // thru DynamicGroupArgs are passed back here..
  126. // pSidAttrArray - To allocate and return an array of (sids, attribute)
  127. // pairs to be added to the normal part of the client context.
  128. // pSidCount - Number of elements in pSidAttrArray
  129. // pRestrictedSidAttrArray - To allocate and return an array of (sids, attribute)
  130. // pairs to be added to the restricted part of the client context.
  131. // pRestrictedSidCount - Number of elements in pRestrictedSidAttrArray
  132. //
  133. // Note:
  134. // Memory returned thru both these array will be freed by the callback
  135. // free function defined by the resource manager.
  136. //
  137. // Returns
  138. // TRUE if the API succeeded.
  139. // FALSE on any intermediate errors (like failed memory allocation)
  140. // In case of failure, the caller must use SetLastError(ErrorValue).
  141. //
  142. typedef BOOL (CALLBACK *PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS) (
  143. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  144. IN PVOID Args,
  145. OUT PSID_AND_ATTRIBUTES *pSidAttrArray,
  146. OUT PDWORD pSidCount,
  147. OUT PSID_AND_ATTRIBUTES *pRestrictedSidAttrArray,
  148. OUT PDWORD pRestrictedSidCount
  149. );
  150. //
  151. // Callback free function takes in
  152. // pSidAttrArray - To be freed. This has been allocated by the compute
  153. // dynamic groups function.
  154. //
  155. typedef VOID (CALLBACK *PFN_AUTHZ_FREE_DYNAMIC_GROUPS) (
  156. IN PSID_AND_ATTRIBUTES pSidAttrArray
  157. );
  158. //
  159. // Valid flags for AuthzAccessCheck
  160. //
  161. #define AUTHZ_ACCESS_CHECK_NO_DEEP_COPY_SD 0x00000001
  162. AUTHZAPI
  163. BOOL
  164. WINAPI
  165. AuthzAccessCheck(
  166. IN DWORD Flags,
  167. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  168. IN PAUTHZ_ACCESS_REQUEST pRequest,
  169. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent OPTIONAL,
  170. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  171. IN PSECURITY_DESCRIPTOR *OptionalSecurityDescriptorArray OPTIONAL,
  172. IN DWORD OptionalSecurityDescriptorCount,
  173. IN OUT PAUTHZ_ACCESS_REPLY pReply,
  174. OUT PAUTHZ_ACCESS_CHECK_RESULTS_HANDLE phAccessCheckResults OPTIONAL
  175. );
  176. AUTHZAPI
  177. BOOL
  178. WINAPI
  179. AuthzCachedAccessCheck(
  180. IN DWORD Flags,
  181. IN AUTHZ_ACCESS_CHECK_RESULTS_HANDLE hAccessCheckResults,
  182. IN PAUTHZ_ACCESS_REQUEST pRequest,
  183. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent OPTIONAL,
  184. IN OUT PAUTHZ_ACCESS_REPLY pReply
  185. );
  186. AUTHZAPI
  187. BOOL
  188. WINAPI
  189. AuthzOpenObjectAudit(
  190. IN DWORD Flags,
  191. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  192. IN PAUTHZ_ACCESS_REQUEST pRequest,
  193. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent,
  194. IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
  195. IN PSECURITY_DESCRIPTOR *OptionalSecurityDescriptorArray OPTIONAL,
  196. IN DWORD OptionalSecurityDescriptorCount,
  197. IN PAUTHZ_ACCESS_REPLY pReply
  198. );
  199. AUTHZAPI
  200. BOOL
  201. WINAPI
  202. AuthzFreeHandle(
  203. IN OUT AUTHZ_ACCESS_CHECK_RESULTS_HANDLE hAccessCheckResults
  204. );
  205. //
  206. // Flags for AuthzInitializeResourceManager
  207. //
  208. #define AUTHZ_RM_FLAG_NO_AUDIT 0x1
  209. #define AUTHZ_RM_FLAG_INITIALIZE_UNDER_IMPERSONATION 0x2
  210. #define AUTHZ_VALID_RM_INIT_FLAGS (AUTHZ_RM_FLAG_NO_AUDIT | AUTHZ_RM_FLAG_INITIALIZE_UNDER_IMPERSONATION)
  211. AUTHZAPI
  212. BOOL
  213. WINAPI
  214. AuthzInitializeResourceManager(
  215. IN DWORD Flags,
  216. IN PFN_AUTHZ_DYNAMIC_ACCESS_CHECK pfnDynamicAccessCheck OPTIONAL,
  217. IN PFN_AUTHZ_COMPUTE_DYNAMIC_GROUPS pfnComputeDynamicGroups OPTIONAL,
  218. IN PFN_AUTHZ_FREE_DYNAMIC_GROUPS pfnFreeDynamicGroups OPTIONAL,
  219. IN PCWSTR szResourceManagerName,
  220. OUT PAUTHZ_RESOURCE_MANAGER_HANDLE phAuthzResourceManager
  221. );
  222. AUTHZAPI
  223. BOOL
  224. WINAPI
  225. AuthzFreeResourceManager(
  226. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager
  227. );
  228. AUTHZAPI
  229. BOOL
  230. WINAPI
  231. AuthzInitializeContextFromToken(
  232. IN DWORD Flags,
  233. IN HANDLE TokenHandle,
  234. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager,
  235. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  236. IN LUID Identifier,
  237. IN PVOID DynamicGroupArgs OPTIONAL,
  238. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phAuthzClientContext
  239. );
  240. AUTHZAPI
  241. BOOL
  242. WINAPI
  243. AuthzInitializeContextFromSid(
  244. IN DWORD Flags,
  245. IN PSID UserSid,
  246. IN AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager,
  247. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  248. IN LUID Identifier,
  249. IN PVOID DynamicGroupArgs OPTIONAL,
  250. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phAuthzClientContext
  251. );
  252. AUTHZAPI
  253. BOOL
  254. WINAPI
  255. AuthzInitializeContextFromAuthzContext(
  256. IN DWORD Flags,
  257. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  258. IN PLARGE_INTEGER pExpirationTime OPTIONAL,
  259. IN LUID Identifier,
  260. IN PVOID DynamicGroupArgs,
  261. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phNewAuthzClientContext
  262. );
  263. AUTHZAPI
  264. BOOL
  265. WINAPI
  266. AuthzAddSidsToContext(
  267. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  268. IN PSID_AND_ATTRIBUTES Sids OPTIONAL,
  269. IN DWORD SidCount,
  270. IN PSID_AND_ATTRIBUTES RestrictedSids OPTIONAL,
  271. IN DWORD RestrictedSidCount,
  272. OUT PAUTHZ_CLIENT_CONTEXT_HANDLE phNewAuthzClientContext
  273. );
  274. //
  275. // Enumeration type to be used to specify the type of information to be
  276. // retrieved from an existing AuthzClientContext.
  277. //
  278. typedef enum _AUTHZ_CONTEXT_INFORMATION_CLASS
  279. {
  280. AuthzContextInfoUserSid = 1,
  281. AuthzContextInfoGroupsSids,
  282. AuthzContextInfoRestrictedSids,
  283. AuthzContextInfoPrivileges,
  284. AuthzContextInfoExpirationTime,
  285. AuthzContextInfoServerContext,
  286. AuthzContextInfoIdentifier,
  287. AuthzContextInfoSource,
  288. AuthzContextInfoAll,
  289. AuthzContextInfoAuthenticationId
  290. } AUTHZ_CONTEXT_INFORMATION_CLASS;
  291. AUTHZAPI
  292. BOOL
  293. WINAPI
  294. AuthzGetInformationFromContext(
  295. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
  296. IN AUTHZ_CONTEXT_INFORMATION_CLASS InfoClass,
  297. IN DWORD BufferSize,
  298. OUT PDWORD pSizeRequired,
  299. OUT PVOID Buffer
  300. );
  301. AUTHZAPI
  302. BOOL
  303. WINAPI
  304. AuthzFreeContext(
  305. IN AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext
  306. );
  307. //
  308. // Valid flags that may be used in AuthzInitializeObjectAccessAuditEvent().
  309. //
  310. #define AUTHZ_NO_SUCCESS_AUDIT 0x00000001
  311. #define AUTHZ_NO_FAILURE_AUDIT 0x00000002
  312. #define AUTHZ_NO_ALLOC_STRINGS 0x00000004
  313. #define AUTHZ_VALID_OBJECT_ACCESS_AUDIT_FLAGS (AUTHZ_NO_SUCCESS_AUDIT | \
  314. AUTHZ_NO_FAILURE_AUDIT | \
  315. AUTHZ_NO_ALLOC_STRINGS)
  316. AUTHZAPI
  317. BOOL
  318. WINAPI
  319. AuthzInitializeObjectAccessAuditEvent(
  320. IN DWORD Flags,
  321. IN AUTHZ_AUDIT_EVENT_TYPE_HANDLE hAuditEventType OPTIONAL,
  322. IN PWSTR szOperationType,
  323. IN PWSTR szObjectType,
  324. IN PWSTR szObjectName,
  325. IN PWSTR szAdditionalInfo,
  326. OUT PAUTHZ_AUDIT_EVENT_HANDLE phAuditEvent,
  327. IN DWORD dwAdditionalParameterCount,
  328. ...
  329. );
  330. AUTHZAPI
  331. BOOL
  332. WINAPI
  333. AuthzInitializeObjectAccessAuditEvent2(
  334. IN DWORD Flags,
  335. IN AUTHZ_AUDIT_EVENT_TYPE_HANDLE hAuditEventType,
  336. IN PWSTR szOperationType,
  337. IN PWSTR szObjectType,
  338. IN PWSTR szObjectName,
  339. IN PWSTR szAdditionalInfo,
  340. IN PWSTR szAdditionalInfo2,
  341. OUT PAUTHZ_AUDIT_EVENT_HANDLE phAuditEvent,
  342. IN DWORD dwAdditionalParameterCount,
  343. ...
  344. );
  345. //
  346. // Enumeration type to be used to specify the type of information to be
  347. // retrieved from an existing AUTHZ_AUDIT_EVENT_HANDLE.
  348. //
  349. typedef enum _AUTHZ_AUDIT_EVENT_INFORMATION_CLASS
  350. {
  351. AuthzAuditEventInfoFlags = 1,
  352. AuthzAuditEventInfoOperationType,
  353. AuthzAuditEventInfoObjectType,
  354. AuthzAuditEventInfoObjectName,
  355. AuthzAuditEventInfoAdditionalInfo,
  356. } AUTHZ_AUDIT_EVENT_INFORMATION_CLASS;
  357. AUTHZAPI
  358. BOOL
  359. WINAPI
  360. AuthzGetInformationFromAuditEvent(
  361. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent,
  362. IN AUTHZ_AUDIT_EVENT_INFORMATION_CLASS InfoClass,
  363. IN DWORD BufferSize,
  364. OUT PDWORD pSizeRequired,
  365. OUT PVOID Buffer
  366. );
  367. AUTHZAPI
  368. BOOL
  369. WINAPI
  370. AuthzFreeAuditEvent(
  371. IN AUTHZ_AUDIT_EVENT_HANDLE hAuditEvent
  372. );
  373. //
  374. // Support for generic auditing.
  375. //
  376. typedef struct _AUTHZ_REGISTRATION_OBJECT_TYPE_NAME_OFFSET
  377. {
  378. PWSTR szObjectTypeName;
  379. DWORD dwOffset;
  380. } AUTHZ_REGISTRATION_OBJECT_TYPE_NAME_OFFSET, *PAUTHZ_REGISTRATION_OBJECT_TYPE_NAME_OFFSET;
  381. typedef struct _AUTHZ_SOURCE_SCHEMA_REGISTRATION
  382. {
  383. DWORD dwFlags;
  384. PWSTR szEventSourceName;
  385. PWSTR szEventMessageFile;
  386. PWSTR szEventSourceXmlSchemaFile;
  387. PWSTR szEventAccessStringsFile;
  388. PWSTR szExecutableImagePath;
  389. PVOID pReserved;
  390. DWORD dwObjectTypeNameCount;
  391. AUTHZ_REGISTRATION_OBJECT_TYPE_NAME_OFFSET ObjectTypeNames[ANYSIZE_ARRAY];
  392. } AUTHZ_SOURCE_SCHEMA_REGISTRATION, *PAUTHZ_SOURCE_SCHEMA_REGISTRATION;
  393. #define AUTHZ_FLAG_ALLOW_MULTIPLE_SOURCE_INSTANCES 0x1
  394. AUTHZAPI
  395. BOOL
  396. WINAPI
  397. AuthzInstallSecurityEventSource(
  398. IN DWORD dwFlags,
  399. IN PAUTHZ_SOURCE_SCHEMA_REGISTRATION pRegistration
  400. );
  401. AUTHZAPI
  402. BOOL
  403. WINAPI
  404. AuthzUninstallSecurityEventSource(
  405. IN DWORD dwFlags,
  406. IN PCWSTR szEventSourceName
  407. );
  408. AUTHZAPI
  409. BOOL
  410. WINAPI
  411. AuthzEnumerateSecurityEventSources(
  412. IN DWORD dwFlags,
  413. OUT PAUTHZ_SOURCE_SCHEMA_REGISTRATION Buffer,
  414. OUT PDWORD pdwCount,
  415. IN OUT PDWORD pdwLength
  416. );
  417. AUTHZAPI
  418. BOOL
  419. WINAPI
  420. AuthzRegisterSecurityEventSource(
  421. IN DWORD dwFlags,
  422. IN PCWSTR szEventSourceName,
  423. OUT PAUTHZ_SECURITY_EVENT_PROVIDER_HANDLE phEventProvider
  424. );
  425. AUTHZAPI
  426. BOOL
  427. WINAPI
  428. AuthzUnregisterSecurityEventSource(
  429. IN DWORD dwFlags,
  430. IN OUT PAUTHZ_SECURITY_EVENT_PROVIDER_HANDLE phEventProvider
  431. );
  432. AUTHZAPI
  433. BOOL
  434. WINAPI
  435. AuthzReportSecurityEvent(
  436. IN DWORD dwFlags,
  437. IN OUT AUTHZ_SECURITY_EVENT_PROVIDER_HANDLE hEventProvider,
  438. IN DWORD dwAuditId,
  439. IN PSID pUserSid OPTIONAL,
  440. IN DWORD dwCount,
  441. ...
  442. );
  443. AUTHZAPI
  444. BOOL
  445. WINAPI
  446. AuthzReportSecurityEventFromParams(
  447. IN DWORD dwFlags,
  448. IN OUT AUTHZ_SECURITY_EVENT_PROVIDER_HANDLE hEventProvider,
  449. IN DWORD dwAuditId,
  450. IN PSID pUserSid OPTIONAL,
  451. IN PAUDIT_PARAMS pParams
  452. );
  453. #ifdef __cplusplus
  454. }
  455. #endif
  456. #endif