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.

316 lines
9.2 KiB

  1. /*++ BUILD Version: 0002 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. seopaque.h
  5. Abstract:
  6. This module contains definitions of opaque Security data structures.
  7. These structures are available to user and kernel security routines
  8. only.
  9. This file is not included by including "ntos.h".
  10. Author:
  11. Jim Kelly (Jimk) 23-Mar-1990
  12. Revision History:
  13. --*/
  14. #ifndef _SEOPAQUE_
  15. #define _SEOPAQUE_
  16. ///////////////////////////////////////////////////////////////////////////
  17. // //
  18. // Private Structures //
  19. // //
  20. ///////////////////////////////////////////////////////////////////////////
  21. //
  22. // Generic ACE structures, to be used for casting ACE's of known types
  23. //
  24. typedef struct _KNOWN_ACE {
  25. ACE_HEADER Header;
  26. ACCESS_MASK Mask;
  27. ULONG SidStart;
  28. } KNOWN_ACE, *PKNOWN_ACE;
  29. typedef struct _KNOWN_OBJECT_ACE {
  30. ACE_HEADER Header;
  31. ACCESS_MASK Mask;
  32. ULONG Flags;
  33. // GUID ObjectType; // Optionally present
  34. // GUID InheritedObjectType; // Optionally present
  35. ULONG SidStart;
  36. } KNOWN_OBJECT_ACE, *PKNOWN_OBJECT_ACE;
  37. typedef struct _KNOWN_COMPOUND_ACE {
  38. ACE_HEADER Header;
  39. ACCESS_MASK Mask;
  40. USHORT CompoundAceType;
  41. USHORT Reserved;
  42. ULONG SidStart;
  43. } KNOWN_COMPOUND_ACE, *PKNOWN_COMPOUND_ACE;
  44. //typedef struct _KNOWN_IMPERSONATION_ACE {
  45. // ACE_HEADER Header;
  46. // ACCESS_MASK Mask;
  47. // USHORT DataType;
  48. // USHORT Argument;
  49. // ULONG Operands;
  50. //} KNOWN_IMPERSONATION_ACE, *PKNOWN_IMPERSONATION_ACE;
  51. ///////////////////////////////////////////////////////////////////////////
  52. // //
  53. // Miscellaneous support macros //
  54. // //
  55. ///////////////////////////////////////////////////////////////////////////
  56. //
  57. // Given a pointer return its word aligned equivalent value
  58. //
  59. #define WordAlign(Ptr) ( \
  60. (PVOID)((((ULONG_PTR)(Ptr)) + 1) & -2) \
  61. )
  62. //
  63. // Given a pointer return its longword aligned equivalent value
  64. //
  65. #define LongAlign(Ptr) ( \
  66. (PVOID)((((ULONG_PTR)(Ptr)) + 3) & -4) \
  67. )
  68. //
  69. // Given a size return its longword aligned equivalent value
  70. //
  71. #define LongAlignSize(Size) (((ULONG)(Size) + 3) & -4)
  72. //
  73. // Given a size return its sizeof(PVOID) aligned equivalent value
  74. //
  75. #define PtrAlignSize(Size) \
  76. (((ULONG)(Size) + sizeof(PVOID) - 1) & ~(sizeof(PVOID)-1))
  77. //
  78. // Given a pointer return its quadword aligned equivalent value
  79. //
  80. #define QuadAlign(Ptr) ( \
  81. (PVOID)((((ULONG_PTR)(Ptr)) + 7) & -8) \
  82. )
  83. //
  84. // This macro returns TRUE if a flag in a set of flags is on and FALSE
  85. // otherwise
  86. //
  87. #define FlagOn(Flags,SingleFlag) ( \
  88. ((Flags) & (SingleFlag)) != 0 ? TRUE : FALSE \
  89. )
  90. //
  91. // This macro clears a single flag in a set of flags
  92. //
  93. #define ClearFlag(Flags,SingleFlag) { \
  94. (Flags) &= ~(SingleFlag); \
  95. }
  96. //
  97. // Get a pointer to the first ace in an acl
  98. //
  99. #define FirstAce(Acl) ((PVOID)((PUCHAR)(Acl) + sizeof(ACL)))
  100. //
  101. // Get a pointer to the following ace
  102. //
  103. #define NextAce(Ace) ((PVOID)((PUCHAR)(Ace) + ((PACE_HEADER)(Ace))->AceSize))
  104. //
  105. // A "known" ACE is one of the types that existed before the introduction of
  106. // compound ACEs. While the name is no longer as accurate as it used to be,
  107. // it's convenient.
  108. //
  109. #define IsKnownAceType(Ace) ( \
  110. (((PACE_HEADER)(Ace))->AceType >= ACCESS_MIN_MS_ACE_TYPE) && \
  111. (((PACE_HEADER)(Ace))->AceType <= ACCESS_MAX_MS_V2_ACE_TYPE) \
  112. )
  113. //
  114. // Test if the ACE is a valid version 3 ACE.
  115. //
  116. #define IsV3AceType(Ace) ( \
  117. (((PACE_HEADER)(Ace))->AceType >= ACCESS_MIN_MS_ACE_TYPE) && \
  118. (((PACE_HEADER)(Ace))->AceType <= ACCESS_MAX_MS_V3_ACE_TYPE) \
  119. )
  120. //
  121. // Test if the ACE is a valid version 4 ACE.
  122. //
  123. #define IsV4AceType(Ace) ( \
  124. (((PACE_HEADER)(Ace))->AceType >= ACCESS_MIN_MS_ACE_TYPE) && \
  125. (((PACE_HEADER)(Ace))->AceType <= ACCESS_MAX_MS_V4_ACE_TYPE) \
  126. )
  127. //
  128. // Test if the ACE is a valid ACE.
  129. //
  130. #define IsMSAceType(Ace) ( \
  131. (((PACE_HEADER)(Ace))->AceType >= ACCESS_MIN_MS_ACE_TYPE) && \
  132. (((PACE_HEADER)(Ace))->AceType <= ACCESS_MAX_MS_ACE_TYPE) \
  133. )
  134. //
  135. // Determine if an ace is a standard ace
  136. //
  137. #define IsCompoundAceType(Ace) ( \
  138. (((PACE_HEADER)(Ace))->AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE))
  139. //
  140. // Test if the ACE is an object ACE.
  141. //
  142. #define IsObjectAceType(Ace) ( \
  143. (((PACE_HEADER)(Ace))->AceType >= ACCESS_MIN_MS_OBJECT_ACE_TYPE) && \
  144. (((PACE_HEADER)(Ace))->AceType <= ACCESS_MAX_MS_OBJECT_ACE_TYPE) \
  145. )
  146. //
  147. // Update this macro as new ACL revisions are defined.
  148. //
  149. #define ValidAclRevision(Acl) ((Acl)->AclRevision >= MIN_ACL_REVISION && \
  150. (Acl)->AclRevision <= MAX_ACL_REVISION )
  151. //
  152. // Macro to determine if an ace is to be inherited by a subdirectory
  153. //
  154. #define ContainerInherit(Ace) ( \
  155. FlagOn((Ace)->AceFlags, CONTAINER_INHERIT_ACE) \
  156. )
  157. //
  158. // Macro to determine if an ace is to be proprogate to a subdirectory.
  159. // It will if it is inheritable by either a container or non-container
  160. // and is not explicitly marked for no-propagation.
  161. //
  162. #define Propagate(Ace) ( \
  163. !FlagOn((Ace)->AceFlags, NO_PROPAGATE_INHERIT_ACE) && \
  164. (FlagOn(( Ace )->AceFlags, OBJECT_INHERIT_ACE) || \
  165. FlagOn(( Ace )->AceFlags, CONTAINER_INHERIT_ACE) ) \
  166. )
  167. //
  168. // Macro to determine if an ACE is to be inherited by a sub-object
  169. //
  170. #define ObjectInherit(Ace) ( \
  171. FlagOn(( Ace )->AceFlags, OBJECT_INHERIT_ACE) \
  172. )
  173. //
  174. // Macro to determine if an ACE was inherited.
  175. //
  176. #define AceInherited(Ace) ( \
  177. FlagOn(( Ace )->AceFlags, INHERITED_ACE) \
  178. )
  179. //
  180. // Extract the SID from a object ACE
  181. //
  182. #define RtlObjectAceObjectTypePresent( Ace ) \
  183. ((((PKNOWN_OBJECT_ACE)(Ace))->Flags & ACE_OBJECT_TYPE_PRESENT) != 0 )
  184. #define RtlObjectAceInheritedObjectTypePresent( Ace ) \
  185. ((((PKNOWN_OBJECT_ACE)(Ace))->Flags & ACE_INHERITED_OBJECT_TYPE_PRESENT) != 0 )
  186. #define RtlObjectAceSid( Ace ) \
  187. ((PSID)(((PUCHAR)&(((PKNOWN_OBJECT_ACE)(Ace))->SidStart)) + \
  188. (RtlObjectAceObjectTypePresent(Ace) ? sizeof(GUID) : 0 ) + \
  189. (RtlObjectAceInheritedObjectTypePresent(Ace) ? sizeof(GUID) : 0 )))
  190. #define RtlObjectAceObjectType( Ace ) \
  191. ((GUID *)(RtlObjectAceObjectTypePresent(Ace) ? \
  192. &((PKNOWN_OBJECT_ACE)(Ace))->SidStart : \
  193. NULL ))
  194. #define RtlObjectAceInheritedObjectType( Ace ) \
  195. ((GUID *)(RtlObjectAceInheritedObjectTypePresent(Ace) ? \
  196. ( RtlObjectAceObjectTypePresent(Ace) ? \
  197. (PULONG)(((PUCHAR)(&((PKNOWN_OBJECT_ACE)(Ace))->SidStart)) + sizeof(GUID)) : \
  198. &((PKNOWN_OBJECT_ACE)(Ace))->SidStart ) : \
  199. NULL ))
  200. //
  201. // Comparison routine for two GUIDs.
  202. //
  203. #define RtlpIsEqualGuid(rguid1, rguid2) \
  204. (((PLONG) rguid1)[0] == ((PLONG) rguid2)[0] && \
  205. ((PLONG) rguid1)[1] == ((PLONG) rguid2)[1] && \
  206. ((PLONG) rguid1)[2] == ((PLONG) rguid2)[2] && \
  207. ((PLONG) rguid1)[3] == ((PLONG) rguid2)[3])
  208. //
  209. // Macros for mapping DACL/SACL specific security descriptor control bits
  210. // to generic control bits.
  211. //
  212. // This mapping allows common routines to manipulate control bits generically
  213. // and have the appropriate bits set in the security descriptor based
  214. // on whether to ACL is a DACL or a SACL.
  215. //
  216. #define SEP_ACL_PRESENT SE_DACL_PRESENT
  217. #define SEP_ACL_DEFAULTED SE_DACL_DEFAULTED
  218. #define SEP_ACL_AUTO_INHERITED SE_DACL_AUTO_INHERITED
  219. #define SEP_ACL_PROTECTED SE_DACL_PROTECTED
  220. #define SEP_ACL_ALL ( \
  221. SEP_ACL_PRESENT | \
  222. SEP_ACL_DEFAULTED | \
  223. SEP_ACL_AUTO_INHERITED | \
  224. SEP_ACL_PROTECTED )
  225. #define SeControlDaclToGeneric( _Dacl ) \
  226. ((_Dacl) & SEP_ACL_ALL )
  227. #define SeControlGenericToDacl( _Generic ) \
  228. ((_Generic) & SEP_ACL_ALL )
  229. #define SeControlSaclToGeneric( _Sacl ) ( \
  230. (((_Sacl) & SE_SACL_PRESENT) ? SEP_ACL_PRESENT : 0 ) | \
  231. (((_Sacl) & SE_SACL_DEFAULTED) ? SEP_ACL_DEFAULTED : 0 ) | \
  232. (((_Sacl) & SE_SACL_AUTO_INHERITED) ? SEP_ACL_AUTO_INHERITED : 0 ) | \
  233. (((_Sacl) & SE_SACL_PROTECTED) ? SEP_ACL_PROTECTED : 0 ) )
  234. #define SeControlGenericToSacl( _Generic ) ( \
  235. (((_Generic) & SEP_ACL_PRESENT) ? SE_SACL_PRESENT : 0 ) | \
  236. (((_Generic) & SEP_ACL_DEFAULTED) ? SE_SACL_DEFAULTED : 0 ) | \
  237. (((_Generic) & SEP_ACL_AUTO_INHERITED) ? SE_SACL_AUTO_INHERITED : 0 ) | \
  238. (((_Generic) & SEP_ACL_PROTECTED) ? SE_SACL_PROTECTED : 0 ) )
  239. #endif // _SEOPAQUE_