security_enums.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import win32security, ntsecuritycon, winnt
  2. class Enum:
  3. def __init__(self, *const_names):
  4. """Accepts variable number of constant names that can be found in either
  5. win32security, ntsecuritycon, or winnt."""
  6. for const_name in const_names:
  7. try:
  8. const_val=getattr(win32security,const_name)
  9. except AttributeError:
  10. try:
  11. const_val=getattr(ntsecuritycon, const_name)
  12. except AttributeError:
  13. try:
  14. const_val=getattr(winnt, const_name)
  15. except AttributeError:
  16. raise AttributeError('Constant "%s" not found in win32security, ntsecuritycon, or winnt.' %const_name)
  17. setattr(self, const_name, const_val)
  18. def lookup_name(self, const_val):
  19. """Looks up the name of a particular value."""
  20. for k,v in self.__dict__.items():
  21. if v==const_val:
  22. return k
  23. raise AttributeError('Value %s not found in enum' %const_val)
  24. def lookup_flags(self, flags):
  25. """Returns the names of all recognized flags in input, and any flags not found in the enum."""
  26. flag_names=[]
  27. unknown_flags=flags
  28. for k,v in self.__dict__.items():
  29. if flags & v == v:
  30. flag_names.append(k)
  31. unknown_flags = unknown_flags & ~v
  32. return flag_names, unknown_flags
  33. TOKEN_INFORMATION_CLASS = Enum(
  34. 'TokenUser',
  35. 'TokenGroups',
  36. 'TokenPrivileges',
  37. 'TokenOwner',
  38. 'TokenPrimaryGroup',
  39. 'TokenDefaultDacl',
  40. 'TokenSource',
  41. 'TokenType',
  42. 'TokenImpersonationLevel',
  43. 'TokenStatistics',
  44. 'TokenRestrictedSids',
  45. 'TokenSessionId',
  46. 'TokenGroupsAndPrivileges',
  47. 'TokenSessionReference',
  48. 'TokenSandBoxInert',
  49. 'TokenAuditPolicy',
  50. 'TokenOrigin',
  51. 'TokenElevationType',
  52. 'TokenLinkedToken',
  53. 'TokenElevation',
  54. 'TokenHasRestrictions',
  55. 'TokenAccessInformation',
  56. 'TokenVirtualizationAllowed',
  57. 'TokenVirtualizationEnabled',
  58. 'TokenIntegrityLevel',
  59. 'TokenUIAccess',
  60. 'TokenMandatoryPolicy',
  61. 'TokenLogonSid')
  62. TOKEN_TYPE = Enum(
  63. 'TokenPrimary',
  64. 'TokenImpersonation')
  65. TOKEN_ELEVATION_TYPE = Enum(
  66. 'TokenElevationTypeDefault',
  67. 'TokenElevationTypeFull',
  68. 'TokenElevationTypeLimited')
  69. POLICY_AUDIT_EVENT_TYPE = Enum(
  70. 'AuditCategorySystem',
  71. 'AuditCategoryLogon',
  72. 'AuditCategoryObjectAccess',
  73. 'AuditCategoryPrivilegeUse',
  74. 'AuditCategoryDetailedTracking',
  75. 'AuditCategoryPolicyChange',
  76. 'AuditCategoryAccountManagement',
  77. 'AuditCategoryDirectoryServiceAccess',
  78. 'AuditCategoryAccountLogon')
  79. POLICY_INFORMATION_CLASS = Enum(
  80. 'PolicyAuditLogInformation',
  81. 'PolicyAuditEventsInformation',
  82. 'PolicyPrimaryDomainInformation',
  83. 'PolicyPdAccountInformation',
  84. 'PolicyAccountDomainInformation',
  85. 'PolicyLsaServerRoleInformation',
  86. 'PolicyReplicaSourceInformation',
  87. 'PolicyDefaultQuotaInformation',
  88. 'PolicyModificationInformation',
  89. 'PolicyAuditFullSetInformation',
  90. 'PolicyAuditFullQueryInformation',
  91. 'PolicyDnsDomainInformation')
  92. POLICY_LSA_SERVER_ROLE = Enum(
  93. 'PolicyServerRoleBackup',
  94. 'PolicyServerRolePrimary')
  95. ## access modes for opening a policy handle - this is not a real enum
  96. POLICY_ACCESS_MODES = Enum(
  97. 'POLICY_VIEW_LOCAL_INFORMATION',
  98. 'POLICY_VIEW_AUDIT_INFORMATION',
  99. 'POLICY_GET_PRIVATE_INFORMATION',
  100. 'POLICY_TRUST_ADMIN',
  101. 'POLICY_CREATE_ACCOUNT',
  102. 'POLICY_CREATE_SECRET',
  103. 'POLICY_CREATE_PRIVILEGE',
  104. 'POLICY_SET_DEFAULT_QUOTA_LIMITS',
  105. 'POLICY_SET_AUDIT_REQUIREMENTS',
  106. 'POLICY_AUDIT_LOG_ADMIN',
  107. 'POLICY_SERVER_ADMIN',
  108. 'POLICY_LOOKUP_NAMES',
  109. 'POLICY_NOTIFICATION',
  110. 'POLICY_ALL_ACCESS',
  111. 'POLICY_READ',
  112. 'POLICY_WRITE',
  113. 'POLICY_EXECUTE')
  114. ## EventAuditingOptions flags - not a real enum
  115. POLICY_AUDIT_EVENT_OPTIONS_FLAGS = Enum(
  116. 'POLICY_AUDIT_EVENT_UNCHANGED',
  117. 'POLICY_AUDIT_EVENT_SUCCESS',
  118. 'POLICY_AUDIT_EVENT_FAILURE',
  119. 'POLICY_AUDIT_EVENT_NONE')
  120. # AceType in ACE_HEADER - not a real enum
  121. ACE_TYPE = Enum(
  122. 'ACCESS_MIN_MS_ACE_TYPE',
  123. 'ACCESS_ALLOWED_ACE_TYPE',
  124. 'ACCESS_DENIED_ACE_TYPE',
  125. 'SYSTEM_AUDIT_ACE_TYPE',
  126. 'SYSTEM_ALARM_ACE_TYPE',
  127. 'ACCESS_MAX_MS_V2_ACE_TYPE',
  128. 'ACCESS_ALLOWED_COMPOUND_ACE_TYPE',
  129. 'ACCESS_MAX_MS_V3_ACE_TYPE',
  130. 'ACCESS_MIN_MS_OBJECT_ACE_TYPE',
  131. 'ACCESS_ALLOWED_OBJECT_ACE_TYPE',
  132. 'ACCESS_DENIED_OBJECT_ACE_TYPE',
  133. 'SYSTEM_AUDIT_OBJECT_ACE_TYPE',
  134. 'SYSTEM_ALARM_OBJECT_ACE_TYPE',
  135. 'ACCESS_MAX_MS_OBJECT_ACE_TYPE',
  136. 'ACCESS_MAX_MS_V4_ACE_TYPE',
  137. 'ACCESS_MAX_MS_ACE_TYPE',
  138. 'ACCESS_ALLOWED_CALLBACK_ACE_TYPE',
  139. 'ACCESS_DENIED_CALLBACK_ACE_TYPE',
  140. 'ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE',
  141. 'ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE',
  142. 'SYSTEM_AUDIT_CALLBACK_ACE_TYPE',
  143. 'SYSTEM_ALARM_CALLBACK_ACE_TYPE',
  144. 'SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE',
  145. 'SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE',
  146. 'SYSTEM_MANDATORY_LABEL_ACE_TYPE',
  147. 'ACCESS_MAX_MS_V5_ACE_TYPE')
  148. #bit flags for AceFlags - not a real enum
  149. ACE_FLAGS = Enum(
  150. 'CONTAINER_INHERIT_ACE',
  151. 'FAILED_ACCESS_ACE_FLAG',
  152. 'INHERIT_ONLY_ACE',
  153. 'INHERITED_ACE',
  154. 'NO_PROPAGATE_INHERIT_ACE',
  155. 'OBJECT_INHERIT_ACE',
  156. 'SUCCESSFUL_ACCESS_ACE_FLAG',
  157. 'NO_INHERITANCE',
  158. 'SUB_CONTAINERS_AND_OBJECTS_INHERIT',
  159. 'SUB_CONTAINERS_ONLY_INHERIT',
  160. 'SUB_OBJECTS_ONLY_INHERIT')
  161. # used in SetEntriesInAcl - very similar to ACE_TYPE
  162. ACCESS_MODE = Enum(
  163. 'NOT_USED_ACCESS',
  164. 'GRANT_ACCESS',
  165. 'SET_ACCESS',
  166. 'DENY_ACCESS',
  167. 'REVOKE_ACCESS',
  168. 'SET_AUDIT_SUCCESS',
  169. 'SET_AUDIT_FAILURE')
  170. # Bit flags in PSECURITY_DESCRIPTOR->Control - not a real enum
  171. SECURITY_DESCRIPTOR_CONTROL_FLAGS = Enum(
  172. 'SE_DACL_AUTO_INHERITED', ## win2k and up
  173. 'SE_SACL_AUTO_INHERITED', ## win2k and up
  174. 'SE_DACL_PROTECTED', ## win2k and up
  175. 'SE_SACL_PROTECTED', ## win2k and up
  176. 'SE_DACL_DEFAULTED',
  177. 'SE_DACL_PRESENT',
  178. 'SE_GROUP_DEFAULTED',
  179. 'SE_OWNER_DEFAULTED',
  180. 'SE_SACL_PRESENT',
  181. 'SE_SELF_RELATIVE',
  182. 'SE_SACL_DEFAULTED')
  183. # types of SID
  184. SID_NAME_USE = Enum(
  185. 'SidTypeUser',
  186. 'SidTypeGroup',
  187. 'SidTypeDomain',
  188. 'SidTypeAlias',
  189. 'SidTypeWellKnownGroup',
  190. 'SidTypeDeletedAccount',
  191. 'SidTypeInvalid',
  192. 'SidTypeUnknown',
  193. 'SidTypeComputer',
  194. 'SidTypeLabel')
  195. ## bit flags, not a real enum
  196. TOKEN_ACCESS_PRIVILEGES = Enum(
  197. 'TOKEN_ADJUST_DEFAULT',
  198. 'TOKEN_ADJUST_GROUPS',
  199. 'TOKEN_ADJUST_PRIVILEGES',
  200. 'TOKEN_ALL_ACCESS',
  201. 'TOKEN_ASSIGN_PRIMARY',
  202. 'TOKEN_DUPLICATE',
  203. 'TOKEN_EXECUTE',
  204. 'TOKEN_IMPERSONATE',
  205. 'TOKEN_QUERY',
  206. 'TOKEN_QUERY_SOURCE',
  207. 'TOKEN_READ',
  208. 'TOKEN_WRITE')
  209. SECURITY_IMPERSONATION_LEVEL = Enum(
  210. 'SecurityAnonymous',
  211. 'SecurityIdentification',
  212. 'SecurityImpersonation',
  213. 'SecurityDelegation')
  214. POLICY_SERVER_ENABLE_STATE = Enum(
  215. 'PolicyServerEnabled',
  216. 'PolicyServerDisabled')
  217. POLICY_NOTIFICATION_INFORMATION_CLASS = Enum(
  218. 'PolicyNotifyAuditEventsInformation',
  219. 'PolicyNotifyAccountDomainInformation',
  220. 'PolicyNotifyServerRoleInformation',
  221. 'PolicyNotifyDnsDomainInformation',
  222. 'PolicyNotifyDomainEfsInformation',
  223. 'PolicyNotifyDomainKerberosTicketInformation',
  224. 'PolicyNotifyMachineAccountPasswordInformation')
  225. TRUSTED_INFORMATION_CLASS = Enum(
  226. 'TrustedDomainNameInformation',
  227. 'TrustedControllersInformation',
  228. 'TrustedPosixOffsetInformation',
  229. 'TrustedPasswordInformation',
  230. 'TrustedDomainInformationBasic',
  231. 'TrustedDomainInformationEx',
  232. 'TrustedDomainAuthInformation',
  233. 'TrustedDomainFullInformation',
  234. 'TrustedDomainAuthInformationInternal',
  235. 'TrustedDomainFullInformationInternal',
  236. 'TrustedDomainInformationEx2Internal',
  237. 'TrustedDomainFullInformation2Internal')
  238. TRUSTEE_FORM = Enum(
  239. 'TRUSTEE_IS_SID',
  240. 'TRUSTEE_IS_NAME',
  241. 'TRUSTEE_BAD_FORM',
  242. 'TRUSTEE_IS_OBJECTS_AND_SID',
  243. 'TRUSTEE_IS_OBJECTS_AND_NAME')
  244. TRUSTEE_TYPE = Enum(
  245. 'TRUSTEE_IS_UNKNOWN',
  246. 'TRUSTEE_IS_USER',
  247. 'TRUSTEE_IS_GROUP',
  248. 'TRUSTEE_IS_DOMAIN',
  249. 'TRUSTEE_IS_ALIAS',
  250. 'TRUSTEE_IS_WELL_KNOWN_GROUP',
  251. 'TRUSTEE_IS_DELETED',
  252. 'TRUSTEE_IS_INVALID',
  253. 'TRUSTEE_IS_COMPUTER')
  254. ## SE_OBJECT_TYPE - securable objects
  255. SE_OBJECT_TYPE = Enum(
  256. 'SE_UNKNOWN_OBJECT_TYPE',
  257. 'SE_FILE_OBJECT',
  258. 'SE_SERVICE',
  259. 'SE_PRINTER',
  260. 'SE_REGISTRY_KEY',
  261. 'SE_LMSHARE',
  262. 'SE_KERNEL_OBJECT',
  263. 'SE_WINDOW_OBJECT',
  264. 'SE_DS_OBJECT',
  265. 'SE_DS_OBJECT_ALL',
  266. 'SE_PROVIDER_DEFINED_OBJECT',
  267. 'SE_WMIGUID_OBJECT',
  268. 'SE_REGISTRY_WOW64_32KEY')
  269. PRIVILEGE_FLAGS = Enum(
  270. 'SE_PRIVILEGE_ENABLED_BY_DEFAULT',
  271. 'SE_PRIVILEGE_ENABLED',
  272. 'SE_PRIVILEGE_USED_FOR_ACCESS')
  273. # Group flags used with TokenGroups
  274. TOKEN_GROUP_ATTRIBUTES = Enum(
  275. 'SE_GROUP_MANDATORY',
  276. 'SE_GROUP_ENABLED_BY_DEFAULT',
  277. 'SE_GROUP_ENABLED',
  278. 'SE_GROUP_OWNER',
  279. 'SE_GROUP_USE_FOR_DENY_ONLY',
  280. 'SE_GROUP_INTEGRITY',
  281. 'SE_GROUP_INTEGRITY_ENABLED',
  282. 'SE_GROUP_LOGON_ID',
  283. 'SE_GROUP_RESOURCE')
  284. # Privilege flags returned by TokenPrivileges
  285. TOKEN_PRIVILEGE_ATTRIBUTES = Enum(
  286. 'SE_PRIVILEGE_ENABLED_BY_DEFAULT',
  287. 'SE_PRIVILEGE_ENABLED',
  288. 'SE_PRIVILEGE_REMOVED',
  289. 'SE_PRIVILEGE_USED_FOR_ACCESS')