// // Copyright © Nick Lowe 2009 // // Nick Lowe // nick@int-r.net // http://processprivileges.codeplex.com/ namespace ProcessPrivileges { using System; using System.Diagnostics.CodeAnalysis; /// /// Privilege attributes that augment a with state information. /// /// /// Use the following checks to interpret privilege attributes: /// /// // Privilege is disabled.
if (attributes == PrivilegeAttributes.Disabled) { /* ... */ }
///
/// /// // Privilege is enabled.
if ((attributes & PrivilegeAttributes.Enabled) == PrivilegeAttributes.Enabled) { /* ... */ }
///
/// /// // Privilege is removed.
if ((attributes & PrivilegeAttributes.Removed) == PrivilegeAttributes.Removed) { /* ... */ }
///
/// To avoid having to work with a flags based enumerated type, use on attributes. ///
[Flags, SuppressMessage( "Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Justification = "Native enum."), SuppressMessage( "Microsoft.Usage", "CA2217:DoNotMarkEnumsWithFlags", Justification = "Native enum.")] public enum PrivilegeAttributes { /// Privilege is disabled. Disabled = 0, /// Privilege is enabled by default. EnabledByDefault = 1, /// Privilege is enabled. Enabled = 2, /// Privilege is removed. Removed = 4, /// Privilege used to gain access to an object or service. UsedForAccess = -2147483648 } /// Access rights for access tokens. [Flags, SuppressMessage( "Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Justification = "Native enum."), SuppressMessage("Microsoft.Usage", "CA2217:DoNotMarkEnumsWithFlags", Justification = "Native enum.")] public enum TokenAccessRights { /// Right to attach a primary token to a process. AssignPrimary = 0, /// Right to duplicate an access token. Duplicate = 1, /// Right to attach an impersonation access token to a process. Impersonate = 4, /// Right to query an access token. Query = 8, /// Right to query the source of an access token. QuerySource = 16, /// Right to enable or disable the privileges in an access token. AdjustPrivileges = 32, /// Right to adjust the attributes of the groups in an access token. AdjustGroups = 64, /// Right to change the default owner, primary group, or DACL of an access token. AdjustDefault = 128, /// Right to adjust the session ID of an access token. AdjustSessionId = 256, /// Combines all possible access rights for a token. AllAccess = AccessTypeMasks.StandardRightsRequired | AssignPrimary | Duplicate | Impersonate | Query | QuerySource | AdjustPrivileges | AdjustGroups | AdjustDefault | AdjustSessionId, /// Combines the standard rights required to read with . Read = AccessTypeMasks.StandardRightsRead | Query, /// Combines the standard rights required to write with , and . Write = AccessTypeMasks.StandardRightsWrite | AdjustPrivileges | AdjustGroups | AdjustDefault, /// Combines the standard rights required to execute with . Execute = AccessTypeMasks.StandardRightsExecute | Impersonate } [Flags] internal enum AccessTypeMasks { Delete = 65536, ReadControl = 131072, WriteDAC = 262144, WriteOwner = 524288, Synchronize = 1048576, StandardRightsRequired = 983040, StandardRightsRead = ReadControl, StandardRightsWrite = ReadControl, StandardRightsExecute = ReadControl, StandardRightsAll = 2031616, SpecificRightsAll = 65535 } internal enum TokenInformationClass { None, TokenUser, TokenGroups, TokenPrivileges, TokenOwner, TokenPrimaryGroup, TokenDefaultDacl, TokenSource, TokenType, TokenImpersonationLevel, TokenStatistics, TokenRestrictedSids, TokenSessionId, TokenGroupsAndPrivileges, TokenSessionReference, TokenSandBoxInert, TokenAuditPolicy, TokenOrigin, TokenElevationType, TokenLinkedToken, TokenElevation, TokenHasRestrictions, TokenAccessInformation, TokenVirtualizationAllowed, TokenVirtualizationEnabled, TokenIntegrityLevel, TokenUIAccess, TokenMandatoryPolicy, TokenLogonSid, MaxTokenInfoClass } }