EventWaitHandleSecurity 类

定义

表示应用于命名的系统等待句柄的 Windows 访问控制安全性。 此类不能被继承。

public ref class EventWaitHandleSecurity sealed : System::Security::AccessControl::NativeObjectSecurity
public sealed class EventWaitHandleSecurity : System.Security.AccessControl.NativeObjectSecurity
[System.Security.SecurityCritical]
public sealed class EventWaitHandleSecurity : System.Security.AccessControl.NativeObjectSecurity
type EventWaitHandleSecurity = class
    inherit NativeObjectSecurity
[<System.Security.SecurityCritical>]
type EventWaitHandleSecurity = class
    inherit NativeObjectSecurity
Public NotInheritable Class EventWaitHandleSecurity
Inherits NativeObjectSecurity
继承
属性

示例

下面的代码示例演示了规则和Deny规则之间的Allow分离,并演示了兼容规则中权限的组合。 该示例创建一个 EventWaitHandleSecurity 对象,添加允许和拒绝当前用户的各种权限的规则,并显示生成的规则对。 然后,该示例允许当前用户的新权限并显示结果,显示新权限与现有 Allow 规则合并。

备注

此示例不将安全对象 EventWaitHandle 附加到对象。 可在其中找到EventWaitHandle.GetAccessControlEventWaitHandle.SetAccessControl附加安全对象的示例。

using System;
using System.Threading;
using System.Security.AccessControl;
using System.Security.Principal;

public class Example
{
    public static void Main()
    {
        // Create a string representing the current user.
        string user = Environment.UserDomainName + "\\" + 
            Environment.UserName;

        // Create a security object that grants no access.
        EventWaitHandleSecurity mSec = new EventWaitHandleSecurity();

        // Add a rule that grants the current user the 
        // right to wait on or signal the event.
        EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        // Add a rule that denies the current user the 
        // right to change permissions on the event.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.ChangePermissions, 
            AccessControlType.Deny);
        mSec.AddAccessRule(rule);

        // Display the rules in the security object.
        ShowSecurity(mSec);

        // Add a rule that allows the current user the 
        // right to read permissions on the event. This rule
        // is merged with the existing Allow rule.
        rule = new EventWaitHandleAccessRule(user, 
            EventWaitHandleRights.ReadPermissions, 
            AccessControlType.Allow);
        mSec.AddAccessRule(rule);

        ShowSecurity(mSec);
    }

    private static void ShowSecurity(EventWaitHandleSecurity security)
    {
        Console.WriteLine("\r\nCurrent access rules:\r\n");

        foreach(EventWaitHandleAccessRule ar in 
            security.GetAccessRules(true, true, typeof(NTAccount)))
        {
            Console.WriteLine("        User: {0}", ar.IdentityReference);
            Console.WriteLine("        Type: {0}", ar.AccessControlType);
            Console.WriteLine("      Rights: {0}", ar.EventWaitHandleRights);
            Console.WriteLine();
        }
    }
}

/*This code example produces output similar to following:

Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, Synchronize


Current access rules:

        User: TestDomain\TestUser
        Type: Deny
      Rights: ChangePermissions

        User: TestDomain\TestUser
        Type: Allow
      Rights: Modify, ReadPermissions, Synchronize
 */
Imports System.Threading
Imports System.Security.AccessControl
Imports System.Security.Principal

Public Class Example

    Public Shared Sub Main()

        ' Create a string representing the current user.
        Dim user As String = Environment.UserDomainName _ 
            & "\" & Environment.UserName

        ' Create a security object that grants no access.
        Dim mSec As New EventWaitHandleSecurity()

        ' Add a rule that grants the current user the 
        ' right to wait on or signal the event.
        Dim rule As New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.Synchronize _
            Or EventWaitHandleRights.Modify, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ' Add a rule that denies the current user the 
        ' right to change permissions on the event.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.ChangePermissions, _
            AccessControlType.Deny)
        mSec.AddAccessRule(rule)

        ' Display the rules in the security object.
        ShowSecurity(mSec)

        ' Add a rule that allows the current user the 
        ' right to read permissions on the event. This rule
        ' is merged with the existing Allow rule.
        rule = New EventWaitHandleAccessRule(user, _
            EventWaitHandleRights.ReadPermissions, _
            AccessControlType.Allow)
        mSec.AddAccessRule(rule)

        ShowSecurity(mSec)

    End Sub 

    Private Shared Sub ShowSecurity(ByVal security As EventWaitHandleSecurity)
        Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)

        For Each ar As EventWaitHandleAccessRule In _
            security.GetAccessRules(True, True, GetType(NTAccount))

            Console.WriteLine("        User: {0}", ar.IdentityReference)
            Console.WriteLine("        Type: {0}", ar.AccessControlType)
            Console.WriteLine("      Rights: {0}", ar.EventWaitHandleRights)
            Console.WriteLine()
        Next

    End Sub
End Class 

'This code example produces output similar to following:
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, Synchronize
'
'
'Current access rules:
'
'        User: TestDomain\TestUser
'        Type: Deny
'      Rights: ChangePermissions
'
'        User: TestDomain\TestUser
'        Type: Allow
'      Rights: Modify, ReadPermissions, Synchronize

注解

对象 EventWaitHandleSecurity 指定命名系统等待句柄的访问权限,并指定审核访问尝试的方式。 对等待句柄的访问权限以规则表示,每个访问规则都由对象 EventWaitHandleAccessRule 表示。 每个审核规则都由一个 EventWaitHandleAuditRule 对象表示。

这反映了基础Windows安全系统,其中每个安全对象最多都有一个可自由裁量访问控制列表 (DACL) 控制对受保护对象的访问,最多一个系统访问控制列表 (SACL) ,用于指定审核哪些访问尝试。 DACL 和 SACL 是 ACE (ACE) 的访问控制项的有序列表,用于指定用户和组的访问和审核。 EventWaitHandleAuditRuleEventWaitHandleAccessRule对象可能表示多个 ACE。

备注

对象 EventWaitHandle 可以表示本地等待句柄或命名的系统等待句柄。 Windows访问控制安全性仅对命名系统等待句柄有意义。

EventWaitHandleAccessRuleEventWaitHandleAuditRuleEventWaitHandleSecurity类隐藏 ACL 和 ACE 的实现详细信息。 它们允许忽略 17 种不同的 ACE 类型以及正确维护访问权限继承和传播的复杂性。 这些对象还设计为防止以下常见访问控制错误:

  • 使用 null DACL 创建安全描述符。 对 DACL 的空引用允许任何用户向对象添加访问规则,从而可能会造成拒绝服务攻击。 新 EventWaitHandleSecurity 对象始终以空 DACL 开头,拒绝所有用户的所有访问。

  • 违反 ACE 的规范排序。 如果 DACL 中的 ACE 列表未按规范顺序保留,则用户可能会无意中获得对受保护对象的访问。 例如,拒绝的访问权限必须始终显示在允许的访问权限之前。 EventWaitHandleSecurity 对象在内部维护正确的顺序。

  • 操作安全描述符标志,该标志应仅在资源管理器控制下。

  • 创建 ACE 标志的无效组合。

  • 操作继承的 ACE。 继承和传播由资源管理器处理,以响应对访问和审核规则所做的更改。

  • 将无意义的 ACE 插入 ACL。

.NET 安全对象不支持的唯一功能是大多数应用程序开发人员应避免的危险活动,例如:

  • 通常由资源管理器执行的低级别任务。

  • 以不维护规范顺序的方式添加或删除访问控制条目。

若要修改命名等待句柄的Windows访问控制安全性,请使用EventWaitHandle.GetAccessControl该方法获取EventWaitHandleSecurity对象。 通过添加和删除规则来修改安全对象,然后使用 EventWaitHandle.SetAccessControl 该方法重新附加它。

重要

EventWaitHandleSecurity 对象的更改不会影响命名等待句柄的访问级别,直到调用 EventWaitHandle.SetAccessControl 方法将更改的安全对象分配给命名的等待句柄。

若要将访问控制安全性从一个等待句柄复制到另一EventWaitHandleSecurity个等待句柄,请使用EventWaitHandle.GetAccessControl该方法获取表示第一个等待句柄的访问和审核规则的对象,然后使用EventWaitHandle.SetAccessControl接受EventWaitHandleSecurity对象的方法或构造函数将这些规则分配给第二个等待句柄。

对安全描述符定义语言进行投资的用户 (SDDL) 可以使用 SetSecurityDescriptorSddlForm 该方法为命名等待句柄设置访问规则,并 GetSecurityDescriptorSddlForm 获取表示 SDDL 格式的访问规则的字符串。 不建议用于新开发。

构造函数

EventWaitHandleSecurity()

使用默认值初始化 EventWaitHandleSecurity 类的新实例。

属性

AccessRightType

获取 EventWaitHandleSecurity 类用于表示访问权限的枚举类型。

AccessRulesModified

获取或设置一个布尔值,该值指定是否已修改与此 ObjectSecurity 对象关联的访问规则。

(继承自 ObjectSecurity)
AccessRuleType

获取 EventWaitHandleSecurity 类用于表示访问规则的类型。

AreAccessRulesCanonical

获取一个布尔值,该值指定与此 ObjectSecurity 对象关联的访问规则是否处于规范顺序。

(继承自 ObjectSecurity)
AreAccessRulesProtected

获取一个布尔值,用于指定与 ObjectSecurity 对象关联的自定义访问控制列表 (DACL) 是否受到保护。

(继承自 ObjectSecurity)
AreAuditRulesCanonical

获取一个布尔值,该值指定与此 ObjectSecurity 对象关联的审核规则是否处于规范顺序。

(继承自 ObjectSecurity)
AreAuditRulesProtected

获取一个布尔值,该值指定与此 ObjectSecurity 对象关联的系统访问控制列表 (SACL) 是否受保护。

(继承自 ObjectSecurity)
AuditRulesModified

获取或设置一个布尔值,该值指定是否已修改与此 ObjectSecurity 对象关联的审核规则。

(继承自 ObjectSecurity)
AuditRuleType

获取 EventWaitHandleSecurity 类用于表示审核规则的类型。

GroupModified

获取或设置一个布尔值,该值指定是否已修改与安全对象相关联的组。

(继承自 ObjectSecurity)
IsContainer

获取一个指定此 ObjectSecurity 对象是否是容器对象的布尔值。

(继承自 ObjectSecurity)
IsDS

获取一个布尔值,该值指定此 ObjectSecurity 对象是否是目录对象。

(继承自 ObjectSecurity)
OwnerModified

获取或设置一个布尔值,该值指定是否已修改安全对象的所有者。

(继承自 ObjectSecurity)
SecurityDescriptor

获取此实例的安全说明符。

(继承自 ObjectSecurity)

方法

AccessRuleFactory(IdentityReference, Int32, Boolean, InheritanceFlags, PropagationFlags, AccessControlType)

使用指定的访问权限、访问控制和标志为指定用户创建新的访问控制规则。

AddAccessRule(AccessRule)

将指定的访问规则添加到与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL)。

(继承自 CommonObjectSecurity)
AddAccessRule(EventWaitHandleAccessRule)

搜索可以将新规则与之合并的匹配访问控制规则。 如果未找到符合条件的规则,则添加新规则。

AddAuditRule(AuditRule)

将指定的审核规则添加到与该 CommonObjectSecurity 对象关联的系统访问控制列表 (SACL)。

(继承自 CommonObjectSecurity)
AddAuditRule(EventWaitHandleAuditRule)

搜索可以将新规则与之合并的审核规则。 如果未找到符合条件的规则,则添加新规则。

AuditRuleFactory(IdentityReference, Int32, Boolean, InheritanceFlags, PropagationFlags, AuditFlags)

新建审核规则,指定规则应用到的用户、要审核的访问权限以及触发审核规则的结果。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetAccessRules(Boolean, Boolean, Type)

获取与指定的安全性标识符关联的访问规则的集合。

(继承自 CommonObjectSecurity)
GetAuditRules(Boolean, Boolean, Type)

获取与指定的安全性标识符关联的审核规则的集合。

(继承自 CommonObjectSecurity)
GetGroup(Type)

获取与指定所有者关联的主要组。

(继承自 ObjectSecurity)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetOwner(Type)

获取与指定主要组关联的所有者。

(继承自 ObjectSecurity)
GetSecurityDescriptorBinaryForm()

返回表示此 ObjectSecurity 对象的安全描述符信息的字节值数组。

(继承自 ObjectSecurity)
GetSecurityDescriptorSddlForm(AccessControlSections)

返回与此 ObjectSecurity 对象关联的安全描述符的指定部分的安全描述符定义语言 (SDDL) 表示形式。

(继承自 ObjectSecurity)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ModifyAccess(AccessControlModification, AccessRule, Boolean)

将指定的修改应用到与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL) 中。

(继承自 CommonObjectSecurity)
ModifyAccessRule(AccessControlModification, AccessRule, Boolean)

将指定的修改应用到与此 ObjectSecurity 对象关联的自由访问控制列表 (DACL) 中。

(继承自 ObjectSecurity)
ModifyAudit(AccessControlModification, AuditRule, Boolean)

将指定的修改应用到与此 CommonObjectSecurity 对象关联的系统访问控制列表 (SACL) 中。

(继承自 CommonObjectSecurity)
ModifyAuditRule(AccessControlModification, AuditRule, Boolean)

将指定的修改应用到与此 ObjectSecurity 对象关联的系统访问控制列表 (SACL) 中。

(继承自 ObjectSecurity)
Persist(Boolean, String, AccessControlSections)

将与此 ObjectSecurity 对象关联的安全描述符的指定部分保存到永久存储中。 我们建议传递给构造函数和 persist 方法的 includeSections 参数的值应完全相同。

(继承自 ObjectSecurity)
Persist(SafeHandle, AccessControlSections)

将与此 NativeObjectSecurity 对象关联的安全描述符的指定部分保存到永久存储中。 我们建议保持传递给构造函数和 persist 方法的 includeSections 参数的值完全相同。

(继承自 NativeObjectSecurity)
Persist(SafeHandle, AccessControlSections, Object)

将与此 NativeObjectSecurity 对象关联的安全描述符的指定部分保存到永久存储中。 我们建议传递给构造函数和 persist 方法的 includeSections 参数的值应完全相同。

(继承自 NativeObjectSecurity)
Persist(String, AccessControlSections)

将与此 NativeObjectSecurity 对象关联的安全描述符的指定部分保存到永久存储中。 我们建议传递给构造函数和 persist 方法的 includeSections 参数的值应完全相同。

(继承自 NativeObjectSecurity)
Persist(String, AccessControlSections, Object)

将与此 NativeObjectSecurity 对象关联的安全描述符的指定部分保存到永久存储中。 我们建议传递给构造函数和 persist 方法的 includeSections 参数的值应完全相同。

(继承自 NativeObjectSecurity)
PurgeAccessRules(IdentityReference)

删除与指定 IdentityReference 关联的所有访问规则。

(继承自 ObjectSecurity)
PurgeAuditRules(IdentityReference)

删除与指定 IdentityReference 关联的所有审核规则。

(继承自 ObjectSecurity)
ReadLock()

为读取访问锁定此 ObjectSecurity 对象。

(继承自 ObjectSecurity)
ReadUnlock()

解锁此 ObjectSecurity 对象以进行读取访问。

(继承自 ObjectSecurity)
RemoveAccessRule(AccessRule)

从与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL) 中移除与指定的访问规则具有相同安全性标识符和访问掩码的访问规则。

(继承自 CommonObjectSecurity)
RemoveAccessRule(EventWaitHandleAccessRule)

搜索如下的访问控制规则:与指定的访问规则具有相同的用户和 AccessControlType(允许或拒绝),并具有兼容的继承和传播标志;如果找到,则从中移除指定访问规则中包含的权限。

RemoveAccessRuleAll(AccessRule)

从与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL) 中移除与指定的访问规则具有相同安全性标识符的所有访问规则。

(继承自 CommonObjectSecurity)
RemoveAccessRuleAll(EventWaitHandleAccessRule)

搜索与指定的规则具有相同用户和 AccessControlType(允许或拒绝)的所有访问控制规则,如果找到则将其移除。

RemoveAccessRuleSpecific(AccessRule)

从与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL) 中移除与指定的访问规则完全匹配的所有访问规则。

(继承自 CommonObjectSecurity)
RemoveAccessRuleSpecific(EventWaitHandleAccessRule)

搜索与指定的规则完全匹配的访问控制规则,如果找到则将其移除。

RemoveAuditRule(AuditRule)

从与此 CommonObjectSecurity 对象关联的系统访问控制列表 (SACL) 中移除与指定的审核规则具有相同安全性标识符和访问掩码的审核规则。

(继承自 CommonObjectSecurity)
RemoveAuditRule(EventWaitHandleAuditRule)

搜索以下的审核规则:与指定的规则具有相同的用户,并具有兼容的继承和传播标志;如果找到兼容规则,则从中移除指定的规则中包含的权限。

RemoveAuditRuleAll(AuditRule)

从与此 CommonObjectSecurity 对象关联的系统访问控制列表 (SACL) 中移除与指定的审核规则具有相同安全性标识符的所有审核规则。

(继承自 CommonObjectSecurity)
RemoveAuditRuleAll(EventWaitHandleAuditRule)

搜索所有使用相同用户作为指定规则的审核规则,如果找到符合条件的规则,则移除它们。

RemoveAuditRuleSpecific(AuditRule)

从与此 CommonObjectSecurity 对象关联的系统访问控制列表 (SACL) 中移除与指定的审核规则完全匹配的所有审核规则。

(继承自 CommonObjectSecurity)
RemoveAuditRuleSpecific(EventWaitHandleAuditRule)

搜索与指定的规则完全匹配的审核规则;如果找到,则移除这些规则。

ResetAccessRule(AccessRule)

从与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL) 中移除所有访问规则,然后添加指定的访问规则。

(继承自 CommonObjectSecurity)
ResetAccessRule(EventWaitHandleAccessRule)

不论 AccessControlType 如何,移除与指定的规则具有相同用户的所有访问控制规则,然后添加指定的规则。

SetAccessRule(AccessRule)

从与此 CommonObjectSecurity 对象关联的自由访问控制列表 (DACL) 中移除与指定的访问规则具有相同安全性标识符和限定符的所有访问规则,然后添加指定的访问规则。

(继承自 CommonObjectSecurity)
SetAccessRule(EventWaitHandleAccessRule)

移除与指定的规则具有相同用户和 AccessControlType(允许或拒绝)的所有控制规则,然后添加指定的规则。

SetAccessRuleProtection(Boolean, Boolean)

设置或删除与此 ObjectSecurity 对象相关联的访问规则保护。 父级对象不能通过继承来修改受保护的访问规则。

(继承自 ObjectSecurity)
SetAuditRule(AuditRule)

从与此 CommonObjectSecurity 对象关联的系统访问控制列表 (SACL) 中移除与指定的审核规则具有相同的安全性标识符和限定符所有审核规则,然后添加指定的审核规则。

(继承自 CommonObjectSecurity)
SetAuditRule(EventWaitHandleAuditRule)

不论 AuditFlags 的值如何,移除与指定的规则具有相同用户的所有审核规则,然后添加指定的规则。

SetAuditRuleProtection(Boolean, Boolean)

设置或删除与此 ObjectSecurity 对象相关联的审核规则保护。 不能由通过继承的父级对象修改受保护的审核规则。

(继承自 ObjectSecurity)
SetGroup(IdentityReference)

设置与此 ObjectSecurity 对象关联的安全描述符的主要组。

(继承自 ObjectSecurity)
SetOwner(IdentityReference)

设置与此 ObjectSecurity 对象关联的安全描述符的所有者。

(继承自 ObjectSecurity)
SetSecurityDescriptorBinaryForm(Byte[])

根据指定的字节值数组设置此 ObjectSecurity 对象的安全描述符。

(继承自 ObjectSecurity)
SetSecurityDescriptorBinaryForm(Byte[], AccessControlSections)

根据指定的字节值数组设置此 ObjectSecurity 对象的安全描述符的指定部分。

(继承自 ObjectSecurity)
SetSecurityDescriptorSddlForm(String)

根据指定的安全描述符定义语言 (SDDL) 字符串设置此 ObjectSecurity 对象的安全描述符。

(继承自 ObjectSecurity)
SetSecurityDescriptorSddlForm(String, AccessControlSections)

根据指定的安全描述符定义语言 (SDDL) 字符串设置此 ObjectSecurity 对象的安全描述符的指定部分。

(继承自 ObjectSecurity)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
WriteLock()

锁定此 ObjectSecurity 对象以进行写访问。

(继承自 ObjectSecurity)
WriteUnlock()

解锁此 ObjectSecurity 对象以进行写入访问。

(继承自 ObjectSecurity)

适用于

另请参阅