mscorlib(4.0.0.0) API with additions
MutexSecurity.cs
1 using Microsoft.Win32.SafeHandles;
4 using System.Threading;
5 
7 {
9  public sealed class MutexSecurity : NativeObjectSecurity
10  {
13  public override Type AccessRightType => typeof(MutexRights);
14 
17  public override Type AccessRuleType => typeof(MutexAccessRule);
18 
21  public override Type AuditRuleType => typeof(MutexAuditRule);
22 
25  public MutexSecurity()
26  : base(isContainer: true, ResourceType.KernelObject)
27  {
28  }
29 
35  [SecuritySafeCritical]
36  public MutexSecurity(string name, AccessControlSections includeSections)
37  : base(isContainer: true, ResourceType.KernelObject, name, includeSections, _HandleErrorCode, null)
38  {
39  }
40 
41  [SecurityCritical]
42  internal MutexSecurity(SafeWaitHandle handle, AccessControlSections includeSections)
43  : base(isContainer: true, ResourceType.KernelObject, handle, includeSections, _HandleErrorCode, null)
44  {
45  }
46 
47  [SecurityCritical]
48  private static Exception _HandleErrorCode(int errorCode, string name, SafeHandle handle, object context)
49  {
50  Exception result = null;
51  if (errorCode == 2 || errorCode == 6 || errorCode == 123)
52  {
53  result = ((name == null || name.Length == 0) ? new WaitHandleCannotBeOpenedException() : new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name)));
54  }
55  return result;
56  }
57 
73  public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
74  {
75  return new MutexAccessRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
76  }
77 
93  public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
94  {
95  return new MutexAuditRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
96  }
97 
98  internal AccessControlSections GetAccessControlSectionsFromChanges()
99  {
100  AccessControlSections accessControlSections = AccessControlSections.None;
101  if (base.AccessRulesModified)
102  {
103  accessControlSections = AccessControlSections.Access;
104  }
105  if (base.AuditRulesModified)
106  {
107  accessControlSections |= AccessControlSections.Audit;
108  }
109  if (base.OwnerModified)
110  {
111  accessControlSections |= AccessControlSections.Owner;
112  }
113  if (base.GroupModified)
114  {
115  accessControlSections |= AccessControlSections.Group;
116  }
117  return accessControlSections;
118  }
119 
120  [SecurityCritical]
121  internal void Persist(SafeWaitHandle handle)
122  {
123  WriteLock();
124  try
125  {
126  AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
127  if (accessControlSectionsFromChanges != 0)
128  {
129  Persist(handle, accessControlSectionsFromChanges);
130  bool flag2 = base.AccessRulesModified = false;
131  bool flag4 = base.AuditRulesModified = flag2;
132  bool ownerModified = base.GroupModified = flag4;
133  base.OwnerModified = ownerModified;
134  }
135  }
136  finally
137  {
138  WriteUnlock();
139  }
140  }
141 
148  public void AddAccessRule(MutexAccessRule rule)
149  {
150  AddAccessRule((AccessRule)rule);
151  }
152 
157  public void SetAccessRule(MutexAccessRule rule)
158  {
159  SetAccessRule((AccessRule)rule);
160  }
161 
167  {
169  }
170 
178  {
179  return RemoveAccessRule((AccessRule)rule);
180  }
181 
187  {
189  }
190 
196  {
198  }
199 
202  public void AddAuditRule(MutexAuditRule rule)
203  {
204  AddAuditRule((AuditRule)rule);
205  }
206 
211  public void SetAuditRule(MutexAuditRule rule)
212  {
213  SetAuditRule((AuditRule)rule);
214  }
215 
222  public bool RemoveAuditRule(MutexAuditRule rule)
223  {
224  return RemoveAuditRule((AuditRule)rule);
225  }
226 
232  {
234  }
235 
241  {
243  }
244  }
245 }
void AddAuditRule(MutexAuditRule rule)
Searches for an audit rule with which the new rule can be merged. If none are found,...
override Type AuditRuleType
Gets the type that the T:System.Security.AccessControl.MutexSecurity class uses to represent audit ru...
PropagationFlags
Specifies how Access Control Entries (ACEs) are propagated to child objects. These flags are signific...
The exception that is thrown when an attempt is made to open a system mutex, semaphore,...
Represents an identity and is the base class for the T:System.Security.Principal.NTAccount and T:Syst...
void SetAccessRule(MutexAccessRule rule)
Removes all access control rules with the same user and T:System.Security.AccessControl....
Represents a combination of a user's identity, an access mask, and an access control type (allow or d...
Definition: AccessRule.cs:7
void RemoveAccessRuleSpecific(MutexAccessRule rule)
Searches for an access control rule that exactly matches the specified rule and, if found,...
Definition: __Canon.cs:3
override Type AccessRightType
Gets the enumeration that the T:System.Security.AccessControl.MutexSecurity class uses to represent a...
void SetAuditRule(MutexAuditRule rule)
Removes all audit rules with the same user as the specified rule, regardless of the T:System....
bool RemoveAuditRule(MutexAuditRule rule)
Searches for an audit control rule with the same user as the specified rule, and with compatible inhe...
void AddAccessRule(MutexAccessRule rule)
Searches for a matching access control rule with which the new rule can be merged....
Represents a wrapper class for operating system handles. This class must be inherited.
Definition: SafeHandle.cs:12
override Type AccessRuleType
Gets the type that the T:System.Security.AccessControl.MutexSecurity class uses to represent access r...
Provides the ability to control access to native objects without direct manipulation of Access Contro...
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a combination of a user’s identity and an access mask.
Definition: AuditRule.cs:7
bool RemoveAccessRule(MutexAccessRule rule)
Searches for an access control rule with the same user and T:System.Security.AccessControl....
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Represents the Windows access control security for a named mutex. This class cannot be inherited.
Definition: MutexSecurity.cs:9
ResourceType
Specifies the defined native object types.
Definition: ResourceType.cs:4
Represents a set of access rights allowed or denied for a user or group. This class cannot be inherit...
AccessControlType
Specifies whether an T:System.Security.AccessControl.AccessRule object is used to allow or deny acces...
MutexRights
Specifies the access control rights that can be applied to named system mutex objects.
Definition: MutexRights.cs:5
Represents a set of access rights to be audited for a user or group. This class cannot be inherited.
void ResetAccessRule(MutexAccessRule rule)
Removes all access control rules with the same user as the specified rule, regardless of T:System....
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
MutexSecurity(string name, AccessControlSections includeSections)
Initializes a new instance of the T:System.Security.AccessControl.MutexSecurity class with the specif...
override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
Creates a new audit rule, specifying the user the rule applies to, the access rights to audit,...
void RemoveAccessRuleAll(MutexAccessRule rule)
Searches for all access control rules with the same user and T:System.Security.AccessControl....
MutexSecurity()
Initializes a new instance of the T:System.Security.AccessControl.MutexSecurity class with default va...
InheritanceFlags
Inheritance flags specify the semantics of inheritance for access control entries (ACEs).
AccessControlSections
Specifies which sections of a security descriptor to save or load.
void RemoveAuditRuleAll(MutexAuditRule rule)
Searches for all audit rules with the same user as the specified rule and, if found,...
void RemoveAuditRuleSpecific(MutexAuditRule rule)
Searches for an audit rule that exactly matches the specified rule and, if found, removes it.
override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
Creates a new access control rule for the specified user, with the specified access rights,...
AuditFlags
Specifies the conditions for auditing attempts to access a securable object.
Definition: AuditFlags.cs:5