Example #1
0
 public static void EnablePrivilege(this Process process, SystemPrivilege privilege)
 {
     using (var hObj = SafeTokenHandle.FromProcess(process.Handle, AccessTypes.TOKEN_ADJUST_PRIVILEGES | AccessTypes.TOKEN_QUERY))
     {
         hObj.AdjustPrivilege(privilege, PrivilegeAttributes.SE_PRIVILEGE_ENABLED);
     }
 }
Example #2
0
 /// <summary>
 /// 默认构造函数
 /// </summary>
 public SystemPrivilegeParameterBase()
 {
     _privilegeparameterid = 0;
     _roleid       = null;
     _privilegeid  = null;
     _bizparameter = String.Empty;
 }
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public SystemPrivilegeParameterBase()
		{
			_privilegeparameterid = 0; 
			_roleid =  null; 
			_privilegeid =  null; 
			_bizparameter = String.Empty; 
		}
Example #4
0
 public static void DisablePrivilege(this Process process, SystemPrivilege privilege)
 {
     using (var hObj = SafeHTOKEN.FromProcess(process, TokenAccess.TOKEN_ADJUST_PRIVILEGES | TokenAccess.TOKEN_QUERY))
     {
         hObj.AdjustPrivilege(privilege, PrivilegeAttributes.SE_PRIVILEGE_DISABLED);
     }
 }
Example #5
0
 public static void RemovePrivilege(this Process process, SystemPrivilege privilege)
 {
     using (var hObj = SafeTokenHandle.FromProcess(process.Handle, TokenAccess.TOKEN_ADJUST_PRIVILEGES | TokenAccess.TOKEN_QUERY))
     {
         hObj.AdjustPrivilege(privilege, PrivilegeAttributes.SE_PRIVILEGE_REMOVED);
     }
 }
        public bool Contains(SystemPrivilege privilege)
        {
            if (_currentUser.Privileges.Contains(SystemPrivilege.All))
            {
                return(true);
            }

            return(_currentUser.Privileges.Contains(privilege));
        }
        private void Revoke(String privilege, String user)
        {
            SystemPrivilegeBuilder builder = new SystemPrivilegeBuilder();
            SystemPrivilege        pri     = builder.Grantee(new GranteeClauseBuilder().Grantee(user))
                                             .Privilege(new List <string>
            {
                privilege
            }).Build();

            this.privilegeBLL.RevokeSystemPrivilege(pri);
        }
Example #8
0
 public bool CanShow(SystemPrivilege privilegeNecessary)
 {
     if (privilegeNecessary == SystemPrivilege.None)
     {
         return(true);
     }
     else
     {
         return(GlobalServices.UAC.Contains(privilegeNecessary));
     }
 }
Example #9
0
        public static SafeCoTaskMemHandle AdjustPrivilege(this SafeHTOKEN hObj, SystemPrivilege priv, PrivilegeAttributes attr)
        {
            var newState  = new PTOKEN_PRIVILEGES(priv.GetLUID(), attr);
            var prevState = PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance();

            if (!AdjustTokenPrivileges(hObj, false, newState, (uint)prevState.Size, prevState, out var retLen))
            {
                throw new Win32Exception();
            }
            prevState.Size = (int)retLen;
            return(prevState);
        }
 /// <summary>
 /// 默认构造函数
 /// </summary>
 public SystemPrivilegeInRolesBase()
 {
     _privilegeroleid    = 0;
     _role_id            = null;
     _privilege_id       = null;
     _privilegerolevalue = String.Empty;
     _enabletype         = String.Empty;
     _createtime         = null;
     _updatetime         = null;
     _expirytime         = null;
     _enableparameter    = false;
 }
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public SystemPrivilegeInRolesBase()
		{
			_privilegeroleid = 0; 
			_role_id =  null; 
			_privilege_id =  null; 
			_privilegerolevalue = String.Empty; 
			_enabletype = String.Empty; 
			_createtime =  null;  
			_updatetime =  null;  
			_expirytime =  null;  
			_enableparameter = false; 
		}
 private void ExecuteGrant(List <String> privileges, String grantee, Boolean isAdmin)
 {
     if (privileges.Count > 0)
     {
         SystemPrivilegeBuilder builder   = new SystemPrivilegeBuilder();
         SystemPrivilege        privilege = builder
                                            .Privilege(privileges)
                                            .Grantee(new GranteeClauseBuilder().Grantee(grantee))
                                            .AdminOption(isAdmin).Build();
         this.privilegeBLL.GrantSystemPrivilege(privilege);
     }
 }
Example #13
0
 internal static AdvApi32.LUID GetLUID(SystemPrivilege systemPrivilege, string systemName = null)
 {
     AdvApi32.LUID val;
     lock (luidLookup)
     {
         if (!luidLookup.TryGetValue(systemPrivilege, out val))
         {
             val = AdvApi32.LUID.FromName(SystemPrivilegeTypeConverter.PrivLookup[systemPrivilege], systemName);
             luidLookup.Add(systemPrivilege, val);
         }
     }
     return(val);
 }
Example #14
0
        internal static LUID GetLUID(SystemPrivilege systemPrivilege, string systemName = null)
        {
            LUID val;

            lock (luidLookup)
            {
                if (!luidLookup.TryGetValue(systemPrivilege, out val))
                {
                    val = LUID.FromName(PrivLookup[systemPrivilege], systemName);
                    luidLookup.Add(systemPrivilege, val);
                }
            }
            return(val);
        }
Example #15
0
 public static LUID GetLUID(this SystemPrivilege systemPrivilege, string systemName = null) => SystemPrivilegeTypeConverter.GetLUID(systemPrivilege, systemName);
Example #16
0
 public static bool HasPrivilege(this SafeTokenHandle hObj, SystemPrivilege priv) => HasPrivileges(hObj, true, priv);
Example #17
0
 public bool RevokeSystemPrivilege(SystemPrivilege privilege)
 {
     return(this.systemPrivilegeRepository.Execute(privilege.QueryRevoke));
 }
Example #18
0
 /// <summary>Determines whether the specified privilege is had by the process.</summary>
 /// <param name="process">The process.</param>
 /// <param name="priv">The privilege.</param>
 /// <returns><c>true</c> if the process has the specified privilege; otherwise, <c>false</c>.</returns>
 public static bool HasPrivilege(this Process process, SystemPrivilege priv) => HasPrivileges(process, true, priv);
Example #19
0
 public bool GrantSystemPrivilege(SystemPrivilege privilege)
 {
     return(this.systemPrivilegeRepository.Execute(privilege.QueryGrant));
 }
Example #20
0
 /// <summary>
 /// Enumerates the accounts with the specified privilege. Requires the <see cref="DesiredAccess.LookupNames"/> and
 /// <see cref="DesiredAccess.ViewLocalInformation"/> rights.
 /// </summary>
 /// <param name="privilege">The privilege.</param>
 /// <returns>An array of <see cref="SecurityIdentifier"/> objects representing all accounts with the specified privilege.</returns>
 public IEnumerable <SecurityIdentifier> EnumerateAccountsWithRight(SystemPrivilege privilege) => EnumerateAccountsWithRight(FromPriv(privilege));
Example #21
0
        public static SafeCoTaskMemHandle AdjustPrivilege(this AdvApi32.SafeTokenHandle hObj, SystemPrivilege priv, AdvApi32.PrivilegeAttributes attr)
        {
            var newState  = new AdvApi32.PTOKEN_PRIVILEGES(priv.GetLUID(), attr);
            var prevState = AdvApi32.PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance();
            var retLen    = (uint)prevState.Size;

            if (!AdvApi32.AdjustTokenPrivileges(hObj, false, newState, newState.SizeInBytes, prevState, ref retLen))
            {
                throw new Win32Exception();
            }
            prevState.Resize((int)retLen);
            return(prevState);
        }
Example #22
0
 public static bool HasPrivilege(this SafeHTOKEN hObj, SystemPrivilege priv) => HasPrivileges(hObj, true, priv);
Example #23
0
 internal PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a)
 {
     Privilege = p; Attributes = a;
 }
Example #24
0
 /// <summary>Initializes a new instance of the <see cref="PrivilegeAndAttributes"/> class.</summary>
 /// <param name="p">The privilege.</param>
 /// <param name="a">The attribute.</param>
 public PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a)
 {
     Privilege  = p;
     Attributes = a;
 }
Example #25
0
 private static string FromPriv(SystemPrivilege priv) => SystemPrivilegeTypeConverter.PrivLookup[priv];
Example #26
0
 /// <summary>Adjusts a specified privilege on a security token to have the supplied attributes.</summary>
 /// <param name="hObj">The security token object.</param>
 /// <param name="priv">The privilege to adjust.</param>
 /// <param name="attr">The attribute to change.</param>
 /// <returns>The privious privileges.</returns>
 public static TOKEN_PRIVILEGES AdjustPrivilege(this SafeHTOKEN hObj, SystemPrivilege priv, PrivilegeAttributes attr) => AdjustPrivileges(hObj, new TOKEN_PRIVILEGES(priv.GetLUID(), attr));