mscorlib(4.0.0.0) API with additions
PipeSecurity.cs
1 using Microsoft.Win32.SafeHandles;
3 using System.Security;
7 
8 namespace System.IO.Pipes
9 {
11  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
13  {
16  public override Type AccessRightType => typeof(PipeAccessRights);
17 
20  public override Type AccessRuleType => typeof(PipeAccessRule);
21 
24  public override Type AuditRuleType => typeof(PipeAuditRule);
25 
27  public PipeSecurity()
28  : base(isContainer: false, ResourceType.KernelObject)
29  {
30  }
31 
32  [SecuritySafeCritical]
33  internal PipeSecurity(SafePipeHandle safeHandle, AccessControlSections includeSections)
34  : base(isContainer: false, ResourceType.KernelObject, safeHandle, includeSections)
35  {
36  }
37 
41  public void AddAccessRule(PipeAccessRule rule)
42  {
43  if (rule == null)
44  {
45  throw new ArgumentNullException("rule");
46  }
48  }
49 
53  public void SetAccessRule(PipeAccessRule rule)
54  {
55  if (rule == null)
56  {
57  throw new ArgumentNullException("rule");
58  }
60  }
61 
65  public void ResetAccessRule(PipeAccessRule rule)
66  {
67  if (rule == null)
68  {
69  throw new ArgumentNullException("rule");
70  }
72  }
73 
79  public bool RemoveAccessRule(PipeAccessRule rule)
80  {
81  if (rule == null)
82  {
83  throw new ArgumentNullException("rule");
84  }
85  AuthorizationRuleCollection accessRules = GetAccessRules(includeExplicit: true, includeInherited: true, rule.IdentityReference.GetType());
86  for (int i = 0; i < accessRules.Count; i++)
87  {
88  PipeAccessRule pipeAccessRule = accessRules[i] as PipeAccessRule;
89  if (pipeAccessRule != null && pipeAccessRule.PipeAccessRights == rule.PipeAccessRights && pipeAccessRule.IdentityReference == rule.IdentityReference && pipeAccessRule.AccessControlType == rule.AccessControlType)
90  {
91  return RemoveAccessRule((AccessRule)rule);
92  }
93  }
94  if (rule.PipeAccessRights != PipeAccessRights.FullControl)
95  {
96  return RemoveAccessRule((AccessRule)new PipeAccessRule(rule.IdentityReference, PipeAccessRule.AccessMaskFromRights(rule.PipeAccessRights, AccessControlType.Deny), isInherited: false, rule.AccessControlType));
97  }
98  return RemoveAccessRule((AccessRule)rule);
99  }
100 
105  {
106  if (rule == null)
107  {
108  throw new ArgumentNullException("rule");
109  }
110  AuthorizationRuleCollection accessRules = GetAccessRules(includeExplicit: true, includeInherited: true, rule.IdentityReference.GetType());
111  for (int i = 0; i < accessRules.Count; i++)
112  {
113  PipeAccessRule pipeAccessRule = accessRules[i] as PipeAccessRule;
114  if (pipeAccessRule != null && pipeAccessRule.PipeAccessRights == rule.PipeAccessRights && pipeAccessRule.IdentityReference == rule.IdentityReference && pipeAccessRule.AccessControlType == rule.AccessControlType)
115  {
117  return;
118  }
119  }
120  if (rule.PipeAccessRights != PipeAccessRights.FullControl)
121  {
122  RemoveAccessRuleSpecific((AccessRule)new PipeAccessRule(rule.IdentityReference, PipeAccessRule.AccessMaskFromRights(rule.PipeAccessRights, AccessControlType.Deny), isInherited: false, rule.AccessControlType));
123  }
124  else
125  {
127  }
128  }
129 
133  public void AddAuditRule(PipeAuditRule rule)
134  {
135  AddAuditRule((AuditRule)rule);
136  }
137 
141  public void SetAuditRule(PipeAuditRule rule)
142  {
143  SetAuditRule((AuditRule)rule);
144  }
145 
151  public bool RemoveAuditRule(PipeAuditRule rule)
152  {
153  return RemoveAuditRule((AuditRule)rule);
154  }
155 
160  {
162  }
163 
168  {
170  }
171 
188  public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
189  {
190  if (inheritanceFlags != 0)
191  {
192  throw new ArgumentException(System.SR.GetString("Argument_NonContainerInvalidAnyFlag"), "inheritanceFlags");
193  }
194  if (propagationFlags != 0)
195  {
196  throw new ArgumentException(System.SR.GetString("Argument_NonContainerInvalidAnyFlag"), "propagationFlags");
197  }
198  return new PipeAccessRule(identityReference, accessMask, isInherited, type);
199  }
200 
213  public sealed override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
214  {
215  if (inheritanceFlags != 0)
216  {
217  throw new ArgumentException(System.SR.GetString("Argument_NonContainerInvalidAnyFlag"), "inheritanceFlags");
218  }
219  if (propagationFlags != 0)
220  {
221  throw new ArgumentException(System.SR.GetString("Argument_NonContainerInvalidAnyFlag"), "propagationFlags");
222  }
223  return new PipeAuditRule(identityReference, accessMask, isInherited, flags);
224  }
225 
226  private AccessControlSections GetAccessControlSectionsFromChanges()
227  {
228  AccessControlSections accessControlSections = AccessControlSections.None;
229  if (base.AccessRulesModified)
230  {
231  accessControlSections = AccessControlSections.Access;
232  }
233  if (base.AuditRulesModified)
234  {
235  accessControlSections |= AccessControlSections.Audit;
236  }
237  if (base.OwnerModified)
238  {
239  accessControlSections |= AccessControlSections.Owner;
240  }
241  if (base.GroupModified)
242  {
243  accessControlSections |= AccessControlSections.Group;
244  }
245  return accessControlSections;
246  }
247 
250  [SecurityCritical]
251  [SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
252  protected internal void Persist(SafeHandle handle)
253  {
254  WriteLock();
255  try
256  {
257  AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
258  Persist(handle, accessControlSectionsFromChanges);
259  bool flag2 = base.AccessRulesModified = false;
260  bool flag4 = base.AuditRulesModified = flag2;
261  bool ownerModified = base.GroupModified = flag4;
262  base.OwnerModified = ownerModified;
263  }
264  finally
265  {
266  WriteUnlock();
267  }
268  }
269 
272  [SecurityCritical]
273  [SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
274  protected internal void Persist(string name)
275  {
276  WriteLock();
277  try
278  {
279  AccessControlSections accessControlSectionsFromChanges = GetAccessControlSectionsFromChanges();
280  Persist(name, accessControlSectionsFromChanges);
281  bool flag2 = base.AccessRulesModified = false;
282  bool flag4 = base.AuditRulesModified = flag2;
283  bool ownerModified = base.GroupModified = flag4;
284  base.OwnerModified = ownerModified;
285  }
286  finally
287  {
288  WriteUnlock();
289  }
290  }
291  }
292 }
Represents an abstraction of an access control entry (ACE) that defines an audit rule for a pipe.
Definition: PipeAuditRule.cs:9
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
PropagationFlags
Specifies how Access Control Entries (ACEs) are propagated to child objects. These flags are signific...
Describes a set of security permissions applied to code. This class cannot be inherited.
Represents an identity and is the base class for the T:System.Security.Principal.NTAccount and T:Syst...
void SetAccessRule(PipeAccessRule rule)
Sets an access rule in the Discretionary Access Control List (DACL) that is associated with the curre...
Definition: PipeSecurity.cs:53
Represents a combination of a user's identity, an access mask, and an access control type (allow or d...
Definition: AccessRule.cs:7
IdentityReference IdentityReference
Gets the T:System.Security.Principal.IdentityReference to which this rule applies.
Definition: __Canon.cs:3
PipeAccessRights PipeAccessRights
Gets the T:System.IO.Pipes.PipeAccessRights flags that are associated with the current T:System....
bool RemoveAccessRule(PipeAccessRule rule)
Removes an access rule from the Discretionary Access Control List (DACL) that is associated with the ...
Definition: PipeSecurity.cs:79
Represents a wrapper class for operating system handles. This class must be inherited.
Definition: SafeHandle.cs:12
void AddAccessRule(PipeAccessRule rule)
Adds an access rule to the Discretionary Access Control List (DACL) that is associated with the curre...
Definition: PipeSecurity.cs:41
Provides the ability to control access to native objects without direct manipulation of Access Contro...
internal void Persist(SafeHandle handle)
Saves the specified sections of the security descriptor that is associated with the current T:System....
SecurityAction
Specifies the security actions that can be performed using declarative security.
Represents a combination of a user’s identity and an access mask.
Definition: AuditRule.cs:7
override Type AuditRuleType
Gets the T:System.Type object associated with the audit rules of the current T:System....
Definition: PipeSecurity.cs:24
sealed override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
Initializes a new instance of the T:System.Security.AccessControl.AuditRule class with the specified ...
void RemoveAuditRuleAll(PipeAuditRule rule)
Removes all audit rules that have the same security identifier as the specified audit rule from the S...
Definition: SR.cs:7
virtual int Count
Gets the number of elements contained in the T:System.Collections.ReadOnlyCollectionBase instance.
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
bool RemoveAuditRule(PipeAuditRule rule)
Removes an audit rule from the System Access Control List (SACL) that is associated with the current ...
void RemoveAccessRuleSpecific(PipeAccessRule rule)
Removes the specified access rule from the Discretionary Access Control List (DACL) that is associate...
ResourceType
Specifies the defined native object types.
Definition: ResourceType.cs:4
internal void Persist(string name)
Saves the specified sections of the security descriptor that is associated with the current T:System....
void AddAuditRule(PipeAuditRule rule)
Adds an audit rule to the System Access Control List (SACL)that is associated with the current T:Syst...
void ResetAccessRule(PipeAccessRule rule)
Removes all access rules in the Discretionary Access Control List (DACL) that is associated with the ...
Definition: PipeSecurity.cs:65
AccessControlType
Specifies whether an T:System.Security.AccessControl.AccessRule object is used to allow or deny acces...
override Type AccessRuleType
Gets the T:System.Type of the object that is associated with the access rules of the current T:System...
Definition: PipeSecurity.cs:20
Represents a collection of T:System.Security.AccessControl.AuthorizationRule objects.
override Type AccessRightType
Gets the T:System.Type of the securable object that is associated with the current T:System....
Definition: PipeSecurity.cs:16
The exception that is thrown when one of the arguments provided to a method is not valid.
void SetAuditRule(PipeAuditRule rule)
Sets an audit rule in the System Access Control List (SACL) that is associated with the current T:Sys...
PipeAccessRights
Defines the access rights to use when you create access and audit rules.
Represents the access control and audit security for a pipe.
Definition: PipeSecurity.cs:12
PipeSecurity()
Initializes a new instance of the T:System.IO.Pipes.PipeSecurity class.
Definition: PipeSecurity.cs:27
void RemoveAuditRuleSpecific(PipeAuditRule rule)
Removes the specified audit rule from the System Access Control List (SACL) that is associated with t...
AuthorizationRuleCollection GetAccessRules(bool includeExplicit, bool includeInherited, Type targetType)
Gets a collection of the access rules associated with the specified security identifier.
AccessControlType AccessControlType
Gets the T:System.Security.AccessControl.AccessControlType value associated with this T:System....
Definition: AccessRule.cs:65
Represents an abstraction of an access control entry (ACE) that defines an access rule for a pipe.
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.
override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
Initializes a new instance of the T:System.Security.AccessControl.AccessRule class with the specified...
AuditFlags
Specifies the conditions for auditing attempts to access a securable object.
Definition: AuditFlags.cs:5