2 // System.Security.AccessControl.DiscretionaryAcl implementation
5 // Dick Porter <dick@ximian.com>
6 // Atsushi Enomoto <atsushi@ximian.com>
7 // James Bellinger <jfb@zer7.com>
9 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
10 // Copyright (C) 2012 James Bellinger
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
32 using System.Security.Principal;
34 namespace System.Security.AccessControl
36 public sealed class DiscretionaryAcl : CommonAcl
38 public DiscretionaryAcl (bool isContainer, bool isDS, int capacity)
39 : base (isContainer, isDS, capacity)
43 public DiscretionaryAcl (bool isContainer, bool isDS, RawAcl rawAcl)
44 : base (isContainer, isDS, rawAcl)
48 public DiscretionaryAcl (bool isContainer, bool isDS, byte revision, int capacity)
49 : base (isContainer, isDS, revision, capacity)
53 public void AddAccess (AccessControlType accessType,
54 SecurityIdentifier sid, int accessMask,
55 InheritanceFlags inheritanceFlags,
56 PropagationFlags propagationFlags)
58 AddAce (GetAceQualifier (accessType), sid, accessMask,
59 inheritanceFlags, propagationFlags, AuditFlags.None);
62 public void AddAccess (AccessControlType accessType,
63 SecurityIdentifier sid, int accessMask,
64 InheritanceFlags inheritanceFlags,
65 PropagationFlags propagationFlags,
66 ObjectAceFlags objectFlags,
68 Guid inheritedObjectType)
70 AddAce (GetAceQualifier (accessType), sid, accessMask,
71 inheritanceFlags, propagationFlags, AuditFlags.None,
72 objectFlags, objectType, inheritedObjectType);
76 public bool RemoveAccess (AccessControlType accessType,
77 SecurityIdentifier sid,
79 InheritanceFlags inheritanceFlags,
80 PropagationFlags propagationFlags)
82 throw new NotImplementedException ();
86 public bool RemoveAccess (AccessControlType accessType,
87 SecurityIdentifier sid,
89 InheritanceFlags inheritanceFlags,
90 PropagationFlags propagationFlags,
91 ObjectAceFlags objectFlags,
93 Guid inheritedObjectType)
95 throw new NotImplementedException ();
98 public void RemoveAccessSpecific (AccessControlType accessType,
99 SecurityIdentifier sid,
101 InheritanceFlags inheritanceFlags,
102 PropagationFlags propagationFlags)
104 RemoveAceSpecific (GetAceQualifier (accessType), sid, accessMask,
105 inheritanceFlags, propagationFlags, AuditFlags.None);
108 public void RemoveAccessSpecific (AccessControlType accessType,
109 SecurityIdentifier sid,
111 InheritanceFlags inheritanceFlags,
112 PropagationFlags propagationFlags,
113 ObjectAceFlags objectFlags,
115 Guid inheritedObjectType)
117 RemoveAceSpecific (GetAceQualifier (accessType), sid, accessMask,
118 inheritanceFlags, propagationFlags, AuditFlags.None,
119 objectFlags, objectType, inheritedObjectType);
122 public void SetAccess (AccessControlType accessType,
123 SecurityIdentifier sid,
125 InheritanceFlags inheritanceFlags,
126 PropagationFlags propagationFlags)
128 SetAce (GetAceQualifier (accessType), sid, accessMask,
129 inheritanceFlags, propagationFlags, AuditFlags.None);
132 public void SetAccess (AccessControlType accessType,
133 SecurityIdentifier sid,
135 InheritanceFlags inheritanceFlags,
136 PropagationFlags propagationFlags,
137 ObjectAceFlags objectFlags,
139 Guid inheritedObjectType)
141 SetAce (GetAceQualifier (accessType), sid, accessMask,
142 inheritanceFlags, propagationFlags, AuditFlags.None,
143 objectFlags, objectType, inheritedObjectType);
146 internal override void ApplyCanonicalSortToExplicitAces ()
148 int explicitCount = GetCanonicalExplicitAceCount ();
149 int explicitDenys = GetCanonicalExplicitDenyAceCount ();
151 ApplyCanonicalSortToExplicitAces (0, explicitDenys);
152 ApplyCanonicalSortToExplicitAces (explicitDenys, explicitCount - explicitDenys);
155 internal override int GetAceInsertPosition (AceQualifier aceQualifier)
157 // Canonical order for DACLs is explicit deny, explicit allow, inherited.
158 if (AceQualifier.AccessAllowed == aceQualifier)
159 return GetCanonicalExplicitDenyAceCount ();
164 static AceQualifier GetAceQualifier (AccessControlType accessType)
166 if (AccessControlType.Allow == accessType)
167 return AceQualifier.AccessAllowed;
168 else if (AccessControlType.Deny == accessType)
169 return AceQualifier.AccessDenied;
171 throw new ArgumentOutOfRangeException ("accessType");
174 internal override bool IsAceMeaningless (GenericAce ace)
176 if (base.IsAceMeaningless (ace)) return true;
177 if (AuditFlags.None != ace.AuditFlags) return true;
179 QualifiedAce qace = ace as QualifiedAce;
181 if (!(AceQualifier.AccessAllowed == qace.AceQualifier ||
182 AceQualifier.AccessDenied == qace.AceQualifier)) return true;