Merge pull request #4045 from lambdageek/bug-47867
[mono.git] / mcs / class / System.Core / System.IO.Pipes / PipeSecurity.cs
1 //
2 // PipeSecurity.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //      James Bellinger <jfb@zer7.com>
7 //
8 // Copyright (C) 2009 Novell, Inc.  http://www.novell.com
9 // Copyright (C) 2012 James Bellinger
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30 using System;
31 using System.IO;
32 using System.Linq;
33 using System.Runtime.InteropServices;
34 using System.Security.AccessControl;
35 using System.Security.Permissions;
36 using System.Security.Principal;
37
38 namespace System.IO.Pipes
39 {
40         [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort = true)]
41         public class PipeSecurity : NativeObjectSecurity
42         {
43                 public PipeSecurity ()
44                         : base (false, ResourceType.FileObject)
45                 {
46                 }
47                 
48                 internal PipeSecurity (SafeHandle handle, AccessControlSections includeSections)
49                         : base (false, ResourceType.FileObject, handle, includeSections)
50                 {
51                 }
52                 
53                 public override Type AccessRightType {
54                         get { return typeof (PipeAccessRights); }
55                 }
56
57                 public override Type AccessRuleType {
58                         get { return typeof (PipeAccessRule); }
59                 }
60
61                 public override Type AuditRuleType {
62                         get { return typeof (PipeAuditRule); }
63                 }
64
65                 public override AccessRule AccessRuleFactory (IdentityReference identityReference,
66                                                               int accessMask, bool isInherited,
67                                                               InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
68                                                               AccessControlType type)
69                 {
70                         return new PipeAccessRule (identityReference, (PipeAccessRights)accessMask, type);
71                 }
72
73                 public void AddAccessRule (PipeAccessRule rule)
74                 {
75                         AddAccessRule ((AccessRule)rule);
76                 }
77
78                 public void AddAuditRule (PipeAuditRule rule)
79                 {
80                         AddAuditRule ((AuditRule) rule);
81                 }
82
83                 public override sealed AuditRule AuditRuleFactory (IdentityReference identityReference,
84                                                                    int accessMask, bool isInherited,
85                                                                    InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
86                                                                    AuditFlags flags)
87                 {
88                         return new PipeAuditRule (identityReference, (PipeAccessRights)accessMask, flags);
89                 }
90
91                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
92                 protected internal void Persist (SafeHandle handle)
93                 {
94                         WriteLock();
95                         try {
96                                 Persist (handle, AccessControlSectionsModified, null);
97                         } finally {
98                                 WriteUnlock ();
99                         }
100                 }
101
102                 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
103                 protected internal void Persist (string name)
104                 {
105                         WriteLock();
106                         try {
107                                 Persist (name, AccessControlSectionsModified, null);
108                         } finally {
109                                 WriteUnlock ();
110                         }
111                 }
112
113                 public bool RemoveAccessRule (PipeAccessRule rule)
114                 {
115                         return RemoveAccessRule ((AccessRule)rule);
116                 }
117
118                 public void RemoveAccessRuleSpecific (PipeAccessRule rule)
119                 {
120                         RemoveAccessRuleSpecific ((AccessRule)rule);
121                 }
122
123                 public bool RemoveAuditRule (PipeAuditRule rule)
124                 {
125                         return RemoveAuditRule ((AuditRule)rule);
126                 }
127
128                 public void RemoveAuditRuleAll (PipeAuditRule rule)
129                 {
130                         RemoveAuditRuleAll ((AuditRule)rule);
131                 }
132
133                 public void RemoveAuditRuleSpecific (PipeAuditRule rule)
134                 {
135                         RemoveAuditRuleSpecific ((AuditRule)rule);
136                 }
137
138                 public void ResetAccessRule (PipeAccessRule rule)
139                 {
140                         ResetAccessRule ((AccessRule)rule);
141                 }
142
143                 public void SetAccessRule (PipeAccessRule rule)
144                 {
145                         SetAccessRule ((AccessRule)rule);
146                 }
147
148                 public void SetAuditRule (PipeAuditRule rule)
149                 {
150                         SetAuditRule ((AuditRule)rule);
151                 }
152         }
153 }