mscorlib(4.0.0.0) API with additions
SemaphoreSecurity.cs
1 using Microsoft.Win32.SafeHandles;
4 using System.Threading;
5 
7 {
9  [ComVisible(false)]
11  {
14  public override Type AccessRightType => typeof(SemaphoreRights);
15 
18  public override Type AccessRuleType => typeof(SemaphoreAccessRule);
19 
22  public override Type AuditRuleType => typeof(SemaphoreAuditRule);
23 
27  : base(isContainer: true, ResourceType.KernelObject)
28  {
29  }
30 
35  public SemaphoreSecurity(string name, AccessControlSections includeSections)
36  : base(isContainer: true, ResourceType.KernelObject, name, includeSections, _HandleErrorCode, null)
37  {
38  }
39 
40  internal SemaphoreSecurity(SafeWaitHandle handle, AccessControlSections includeSections)
41  : base(isContainer: true, ResourceType.KernelObject, handle, includeSections, _HandleErrorCode, null)
42  {
43  }
44 
45  private static Exception _HandleErrorCode(int errorCode, string name, SafeHandle handle, object context)
46  {
47  Exception result = null;
48  if (errorCode == 2 || errorCode == 6 || errorCode == 123)
49  {
50  result = ((name == null || name.Length == 0) ? new WaitHandleCannotBeOpenedException() : new WaitHandleCannotBeOpenedException(SR.GetString("WaitHandleCannotBeOpenedException_InvalidHandle", name)));
51  }
52  return result;
53  }
54 
70  public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
71  {
72  return new SemaphoreAccessRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type);
73  }
74 
90  public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
91  {
92  return new SemaphoreAuditRule(identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags);
93  }
94 
95  internal AccessControlSections GetAccessControlSectionsFromChanges()
96  {
97  AccessControlSections accessControlSections = AccessControlSections.None;
98  if (base.AccessRulesModified)
99  {
100  accessControlSections = AccessControlSections.Access;
101  }
102  if (base.AuditRulesModified)
103  {
104  accessControlSections |= AccessControlSections.Audit;
105  }
106  if (base.OwnerModified)
107  {
108  accessControlSections |= AccessControlSections.Owner;
109  }
110  if (base.GroupModified)
111  {
112  accessControlSections |= AccessControlSections.Group;
113  }
114  return accessControlSections;
115  }
116 
117  internal void Persist(SafeWaitHandle handle)
118  {
119  WriteLock();
120  try
121  {
122  AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
123  if (accessControlSectionsFromChanges != 0)
124  {
125  Persist(handle, accessControlSectionsFromChanges);
126  bool flag2 = base.AccessRulesModified = false;
127  bool flag4 = base.AuditRulesModified = flag2;
128  bool ownerModified = base.GroupModified = flag4;
129  base.OwnerModified = ownerModified;
130  }
131  }
132  finally
133  {
134  WriteUnlock();
135  }
136  }
137 
143  {
144  AddAccessRule((AccessRule)rule);
145  }
146 
152  {
153  SetAccessRule((AccessRule)rule);
154  }
155 
161  {
163  }
164 
172  {
173  return RemoveAccessRule((AccessRule)rule);
174  }
175 
181  {
183  }
184 
190  {
192  }
193 
197  {
198  AddAuditRule((AuditRule)rule);
199  }
200 
206  {
207  SetAuditRule((AuditRule)rule);
208  }
209 
217  {
218  return RemoveAuditRule((AuditRule)rule);
219  }
220 
226  {
228  }
229 
235  {
237  }
238  }
239 }
void ResetAccessRule(SemaphoreAccessRule rule)
Removes all access control rules with the same user as the specified rule, regardless of T:System....
Represents a set of access rights to be audited for a user or group. This class cannot be inherited.
PropagationFlags
Specifies how Access Control Entries (ACEs) are propagated to child objects. These flags are signific...
void RemoveAuditRuleAll(SemaphoreAuditRule rule)
Searches for all audit rules with the same user as the specified rule and, if found,...
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 AddAuditRule(SemaphoreAuditRule rule)
Searches for an audit rule with which the new rule can be merged. If none are found,...
Represents a combination of a user's identity, an access mask, and an access control type (allow or d...
Definition: AccessRule.cs:7
Definition: __Canon.cs:3
void RemoveAuditRuleSpecific(SemaphoreAuditRule rule)
Searches for an audit rule that exactly matches the specified rule and, if found, removes it.
void RemoveAccessRuleAll(SemaphoreAccessRule rule)
Searches for all access control rules with the same user and T:System.Security.AccessControl....
void RemoveAccessRuleSpecific(SemaphoreAccessRule rule)
Searches for an access control rule that exactly matches the specified rule and, if found,...
Represents a set of access rights allowed or denied for a user or group. This class cannot be inherit...
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,...
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,...
Represents a wrapper class for operating system handles. This class must be inherited.
Definition: SafeHandle.cs:12
void SetAccessRule(SemaphoreAccessRule rule)
Removes all access control rules with the same user and T:System.Security.AccessControl....
Provides the ability to control access to native objects without direct manipulation of Access Contro...
bool RemoveAccessRule(SemaphoreAccessRule rule)
Searches for an access control rule with the same user and T:System.Security.AccessControl....
Represents a combination of a user’s identity and an access mask.
Definition: AuditRule.cs:7
SemaphoreRights
Specifies the access control rights that can be applied to named system semaphore objects.
void AddAccessRule(SemaphoreAccessRule rule)
Searches for a matching rule with which the new rule can be merged. If none are found,...
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
ResourceType
Specifies the defined native object types.
Definition: ResourceType.cs:4
Represents the Windows access control security for a named semaphore. This class cannot be inherited.
AccessControlType
Specifies whether an T:System.Security.AccessControl.AccessRule object is used to allow or deny acces...
SemaphoreSecurity(string name, AccessControlSections includeSections)
Initializes a new instance of the T:System.Security.AccessControl.SemaphoreSecurity class with the sp...
override Type AccessRuleType
Gets the type that the T:System.Security.AccessControl.SemaphoreSecurity class uses to represent acce...
override Type AccessRightType
Gets the enumeration that the T:System.Security.AccessControl.SemaphoreSecurity class uses to represe...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
bool RemoveAuditRule(SemaphoreAuditRule rule)
Searches for an audit control rule with the same user as the specified rule, and with compatible inhe...
void SetAuditRule(SemaphoreAuditRule rule)
Removes all audit rules with the same user as the specified rule, regardless of the T:System....
SemaphoreSecurity()
Initializes a new instance of the T:System.Security.AccessControl.SemaphoreSecurity class with defaul...
InheritanceFlags
Inheritance flags specify the semantics of inheritance for access control entries (ACEs).
override Type AuditRuleType
Gets the type that the T:System.Security.AccessControl.SemaphoreSecurity class uses to represent audi...
AccessControlSections
Specifies which sections of a security descriptor to save or load.
AuditFlags
Specifies the conditions for auditing attempts to access a securable object.
Definition: AuditFlags.cs:5