Merge pull request #2258 from protel-opensource/protelmaster
[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                 [MonoTODO]
76                 public bool RemoveAudit (AuditFlags auditFlags,
77                                          SecurityIdentifier sid,
78                                          int accessMask,
79                                          InheritanceFlags inheritanceFlags,
80                                          PropagationFlags propagationFlags)
81                 {
82                         throw new NotImplementedException ();
83                 }
84                 
85                 [MonoTODO]
86                 public bool RemoveAudit (AuditFlags auditFlags,
87                                          SecurityIdentifier sid,
88                                          int accessMask,
89                                          InheritanceFlags inheritanceFlags,
90                                          PropagationFlags propagationFlags,
91                                          ObjectAceFlags objectFlags,
92                                          Guid objectType,
93                                          Guid inheritedObjectType)
94                 {
95                         throw new NotImplementedException ();
96                 }
97                 
98                 public void RemoveAuditSpecific (AuditFlags auditFlags,
99                                                  SecurityIdentifier sid,
100                                                  int accessMask,
101                                                  InheritanceFlags inheritanceFlags,
102                                                  PropagationFlags propagationFlags)
103                 {
104                         RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
105                                            inheritanceFlags, propagationFlags, auditFlags);
106
107                 }
108                 
109                 public void RemoveAuditSpecific (AuditFlags auditFlags,
110                                                  SecurityIdentifier sid,
111                                                  int accessMask,
112                                                  InheritanceFlags inheritanceFlags,
113                                                  PropagationFlags propagationFlags,
114                                                  ObjectAceFlags objectFlags,
115                                                  Guid objectType,
116                                                  Guid inheritedObjectType)
117                 {
118                         RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
119                                            inheritanceFlags, propagationFlags, auditFlags,
120                                            objectFlags, objectType, inheritedObjectType);
121
122                 }
123                 
124                 public void SetAudit (AuditFlags auditFlags,
125                                       SecurityIdentifier sid,
126                                       int accessMask,
127                                       InheritanceFlags inheritanceFlags,
128                                       PropagationFlags propagationFlags)
129                 {
130                         SetAce (AceQualifier.SystemAudit, sid, accessMask,
131                                 inheritanceFlags, propagationFlags, auditFlags);
132                 }
133                 
134                 public void SetAudit (AuditFlags auditFlags,
135                                       SecurityIdentifier sid,
136                                       int accessMask,
137                                       InheritanceFlags inheritanceFlags,
138                                       PropagationFlags propagationFlags,
139                                       ObjectAceFlags objectFlags,
140                                       Guid objectType,
141                                       Guid inheritedObjectType)
142                 {
143                         SetAce (AceQualifier.SystemAudit, sid, accessMask,
144                                 inheritanceFlags, propagationFlags, auditFlags,
145                                 objectFlags, objectType, inheritedObjectType);
146                 }
147                 
148                 internal override void ApplyCanonicalSortToExplicitAces ()
149                 {
150                         int explicitCount = GetCanonicalExplicitAceCount ();
151                         ApplyCanonicalSortToExplicitAces (0, explicitCount);
152                 }
153                 
154                 internal override int GetAceInsertPosition (AceQualifier aceQualifier)
155                 {
156                         return 0;
157                 }
158                 
159                 internal override bool IsAceMeaningless (GenericAce ace)
160                 {
161                         if (base.IsAceMeaningless (ace)) return true;
162                         if (!IsValidAuditFlags (ace.AuditFlags)) return true;
163                         
164                         QualifiedAce qace = ace as QualifiedAce;
165                         if (null != qace) {
166                                 if (!(AceQualifier.SystemAudit == qace.AceQualifier ||
167                                       AceQualifier.SystemAlarm == qace.AceQualifier)) return true;
168                         }
169                         
170                         return false;
171                 }
172                 
173                 static bool IsValidAuditFlags (AuditFlags auditFlags)
174                 {
175                         return auditFlags != AuditFlags.None &&
176                                auditFlags == ((AuditFlags.Success|AuditFlags.Failure) & auditFlags);
177                 }
178         }
179 }
180