Merge pull request #3394 from mono/netstandard
[mono.git] / mcs / class / corlib / System.Security.AccessControl / SystemAcl.cs
1 //
2 // System.Security.AccessControl.SystemAcl implementation
3 //
4 // Authors:
5 //      Dick Porter  <dick@ximian.com>
6 //      Atsushi Enomoto  <atsushi@ximian.com>
7 //      James Bellinger  <jfb@zer7.com>
8 //
9 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
10 // Copyright (C) 2012      James Bellinger
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System.Security.Principal;
33
34 namespace System.Security.AccessControl
35 {
36         public sealed class SystemAcl : CommonAcl
37         {
38                 public SystemAcl (bool isContainer, bool isDS, int capacity)
39                         : base (isContainer, isDS, capacity)
40                 {
41                 }
42                 
43                 public SystemAcl (bool isContainer, bool isDS, RawAcl rawAcl)
44                         : base (isContainer, isDS, rawAcl)
45                 {
46                 }
47                 
48                 public SystemAcl (bool isContainer, bool isDS, byte revision, int capacity)
49                         : base (isContainer, isDS, revision, capacity)
50                 {
51                 }
52
53                 public void AddAudit (AuditFlags auditFlags,
54                                       SecurityIdentifier sid, int accessMask,
55                                       InheritanceFlags inheritanceFlags,
56                                       PropagationFlags propagationFlags)
57                 {
58                         AddAce (AceQualifier.SystemAudit, sid, accessMask,
59                                 inheritanceFlags, propagationFlags, auditFlags);
60                 }
61                 
62                 public void AddAudit (AuditFlags auditFlags,
63                                       SecurityIdentifier sid, int accessMask,
64                                       InheritanceFlags inheritanceFlags,
65                                       PropagationFlags propagationFlags,
66                                       ObjectAceFlags objectFlags,
67                                       Guid objectType,
68                                       Guid inheritedObjectType)
69                 {
70                         AddAce (AceQualifier.SystemAudit, sid, accessMask,
71                                 inheritanceFlags, propagationFlags, auditFlags,
72                                 objectFlags, objectType, inheritedObjectType);
73                 }
74
75                 public void AddAudit (SecurityIdentifier sid, ObjectAuditRule rule)
76                 {
77                         AddAudit (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
78                 }
79
80                 [MonoTODO]
81                 public bool RemoveAudit (AuditFlags auditFlags,
82                                          SecurityIdentifier sid,
83                                          int accessMask,
84                                          InheritanceFlags inheritanceFlags,
85                                          PropagationFlags propagationFlags)
86                 {
87                         throw new NotImplementedException ();
88                 }
89                 
90                 [MonoTODO]
91                 public bool RemoveAudit (AuditFlags auditFlags,
92                                          SecurityIdentifier sid,
93                                          int accessMask,
94                                          InheritanceFlags inheritanceFlags,
95                                          PropagationFlags propagationFlags,
96                                          ObjectAceFlags objectFlags,
97                                          Guid objectType,
98                                          Guid inheritedObjectType)
99                 {
100                         throw new NotImplementedException ();
101                 }
102
103                 public bool RemoveAudit (SecurityIdentifier sid, ObjectAuditRule rule)
104                 {
105                         return RemoveAudit (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
106                 }
107
108                 public void RemoveAuditSpecific (AuditFlags auditFlags,
109                                                  SecurityIdentifier sid,
110                                                  int accessMask,
111                                                  InheritanceFlags inheritanceFlags,
112                                                  PropagationFlags propagationFlags)
113                 {
114                         RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
115                                            inheritanceFlags, propagationFlags, auditFlags);
116
117                 }
118                 
119                 public void RemoveAuditSpecific (AuditFlags auditFlags,
120                                                  SecurityIdentifier sid,
121                                                  int accessMask,
122                                                  InheritanceFlags inheritanceFlags,
123                                                  PropagationFlags propagationFlags,
124                                                  ObjectAceFlags objectFlags,
125                                                  Guid objectType,
126                                                  Guid inheritedObjectType)
127                 {
128                         RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
129                                            inheritanceFlags, propagationFlags, auditFlags,
130                                            objectFlags, objectType, inheritedObjectType);
131
132                 }
133
134                 public void RemoveAuditSpecific (SecurityIdentifier sid, ObjectAuditRule rule)
135                 {
136                         RemoveAuditSpecific (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
137                 }
138
139                 public void SetAudit (AuditFlags auditFlags,
140                                       SecurityIdentifier sid,
141                                       int accessMask,
142                                       InheritanceFlags inheritanceFlags,
143                                       PropagationFlags propagationFlags)
144                 {
145                         SetAce (AceQualifier.SystemAudit, sid, accessMask,
146                                 inheritanceFlags, propagationFlags, auditFlags);
147                 }
148                 
149                 public void SetAudit (AuditFlags auditFlags,
150                                       SecurityIdentifier sid,
151                                       int accessMask,
152                                       InheritanceFlags inheritanceFlags,
153                                       PropagationFlags propagationFlags,
154                                       ObjectAceFlags objectFlags,
155                                       Guid objectType,
156                                       Guid inheritedObjectType)
157                 {
158                         SetAce (AceQualifier.SystemAudit, sid, accessMask,
159                                 inheritanceFlags, propagationFlags, auditFlags,
160                                 objectFlags, objectType, inheritedObjectType);
161                 }
162
163                 public void SetAudit (SecurityIdentifier sid, ObjectAuditRule rule)
164                 {
165                         SetAudit (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
166                 }
167
168                 internal override void ApplyCanonicalSortToExplicitAces ()
169                 {
170                         int explicitCount = GetCanonicalExplicitAceCount ();
171                         ApplyCanonicalSortToExplicitAces (0, explicitCount);
172                 }
173                 
174                 internal override int GetAceInsertPosition (AceQualifier aceQualifier)
175                 {
176                         return 0;
177                 }
178                 
179                 internal override bool IsAceMeaningless (GenericAce ace)
180                 {
181                         if (base.IsAceMeaningless (ace)) return true;
182                         if (!IsValidAuditFlags (ace.AuditFlags)) return true;
183                         
184                         QualifiedAce qace = ace as QualifiedAce;
185                         if (null != qace) {
186                                 if (!(AceQualifier.SystemAudit == qace.AceQualifier ||
187                                       AceQualifier.SystemAlarm == qace.AceQualifier)) return true;
188                         }
189                         
190                         return false;
191                 }
192                 
193                 static bool IsValidAuditFlags (AuditFlags auditFlags)
194                 {
195                         return auditFlags != AuditFlags.None &&
196                                auditFlags == ((AuditFlags.Success|AuditFlags.Failure) & auditFlags);
197                 }
198         }
199 }
200