5 // Atsushi Enomoto <atsushi@ximian.com>
6 // James Bellinger <jfb@zer7.com>
8 // Copyright (C) 2009 Novell, Inc. http://www.novell.com
9 // Copyright (C) 2012 James Bellinger
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Runtime.InteropServices;
34 using System.Security.AccessControl;
35 using System.Security.Permissions;
36 using System.Security.Principal;
38 namespace System.IO.Pipes
40 [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort = true)]
41 public class PipeSecurity : NativeObjectSecurity
43 public PipeSecurity ()
44 : base (false, ResourceType.FileObject)
48 internal PipeSecurity (SafeHandle handle, AccessControlSections includeSections)
49 : base (false, ResourceType.FileObject, handle, includeSections)
53 public override Type AccessRightType {
54 get { return typeof (PipeAccessRights); }
57 public override Type AccessRuleType {
58 get { return typeof (PipeAccessRule); }
61 public override Type AuditRuleType {
62 get { return typeof (PipeAuditRule); }
65 public override AccessRule AccessRuleFactory (IdentityReference identityReference,
66 int accessMask, bool isInherited,
67 InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
68 AccessControlType type)
70 return new PipeAccessRule (identityReference, (PipeAccessRights)accessMask, type);
73 public void AddAccessRule (PipeAccessRule rule)
75 AddAccessRule ((AccessRule)rule);
78 public void AddAuditRule (PipeAuditRule rule)
80 AddAuditRule ((AuditRule) rule);
83 public override sealed AuditRule AuditRuleFactory (IdentityReference identityReference,
84 int accessMask, bool isInherited,
85 InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
88 return new PipeAuditRule (identityReference, (PipeAccessRights)accessMask, flags);
91 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
92 protected internal void Persist (SafeHandle handle)
96 Persist (handle, AccessControlSectionsModified, null);
102 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
103 protected internal void Persist (string name)
107 Persist (name, AccessControlSectionsModified, null);
114 AccessControlSections AccessControlSectionsModified {
116 return (AccessRulesModified ? AccessControlSections.Access : 0) |
117 (AuditRulesModified ? AccessControlSections.Audit : 0) |
118 (OwnerModified ? AccessControlSections.Owner : 0) |
119 (GroupModified ? AccessControlSections.Group : 0);
123 public bool RemoveAccessRule (PipeAccessRule rule)
125 return RemoveAccessRule ((AccessRule)rule);
128 public void RemoveAccessRuleSpecific (PipeAccessRule rule)
130 RemoveAccessRuleSpecific ((AccessRule)rule);
133 public bool RemoveAuditRule (PipeAuditRule rule)
135 return RemoveAuditRule ((AuditRule)rule);
138 public void RemoveAuditRuleAll (PipeAuditRule rule)
140 RemoveAuditRuleAll ((AuditRule)rule);
143 public void RemoveAuditRuleSpecific (PipeAuditRule rule)
145 RemoveAuditRuleSpecific ((AuditRule)rule);
148 public void ResetAccessRule (PipeAccessRule rule)
150 ResetAccessRule ((AccessRule)rule);
153 public void SetAccessRule (PipeAccessRule rule)
155 SetAccessRule ((AccessRule)rule);
158 public void SetAuditRule (PipeAuditRule rule)
160 SetAuditRule ((AuditRule)rule);