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); } }
/// <summary> /// 默认构造函数 /// </summary> public SystemPrivilegeParameterBase() { _privilegeparameterid = 0; _roleid = null; _privilegeid = null; _bizparameter = String.Empty; }
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); } }
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); }
public bool CanShow(SystemPrivilege privilegeNecessary) { if (privilegeNecessary == SystemPrivilege.None) { return(true); } else { return(GlobalServices.UAC.Contains(privilegeNecessary)); } }
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; }
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); } }
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); }
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); }
public static LUID GetLUID(this SystemPrivilege systemPrivilege, string systemName = null) => SystemPrivilegeTypeConverter.GetLUID(systemPrivilege, systemName);
public static bool HasPrivilege(this SafeTokenHandle hObj, SystemPrivilege priv) => HasPrivileges(hObj, true, priv);
public bool RevokeSystemPrivilege(SystemPrivilege privilege) { return(this.systemPrivilegeRepository.Execute(privilege.QueryRevoke)); }
/// <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);
public bool GrantSystemPrivilege(SystemPrivilege privilege) { return(this.systemPrivilegeRepository.Execute(privilege.QueryGrant)); }
/// <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));
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); }
public static bool HasPrivilege(this SafeHTOKEN hObj, SystemPrivilege priv) => HasPrivileges(hObj, true, priv);
internal PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a) { Privilege = p; Attributes = a; }
/// <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; }
private static string FromPriv(SystemPrivilege priv) => SystemPrivilegeTypeConverter.PrivLookup[priv];
/// <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));