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);
75 public bool RemoveAccess (AccessControlType accessType,
76 SecurityIdentifier sid,
78 InheritanceFlags inheritanceFlags,
79 PropagationFlags propagationFlags)
81 throw new NotImplementedException ();
84 public bool RemoveAccess (AccessControlType accessType,
85 SecurityIdentifier sid,
87 InheritanceFlags inheritanceFlags,
88 PropagationFlags propagationFlags,
89 ObjectAceFlags objectFlags,
91 Guid inheritedObjectType)
93 throw new NotImplementedException ();
96 public void RemoveAccessSpecific (AccessControlType accessType,
97 SecurityIdentifier sid,
99 InheritanceFlags inheritanceFlags,
100 PropagationFlags propagationFlags)
102 RemoveAceSpecific (GetAceQualifier (accessType), sid, accessMask,
103 inheritanceFlags, propagationFlags, AuditFlags.None);
106 public void RemoveAccessSpecific (AccessControlType accessType,
107 SecurityIdentifier sid,
109 InheritanceFlags inheritanceFlags,
110 PropagationFlags propagationFlags,
111 ObjectAceFlags objectFlags,
113 Guid inheritedObjectType)
115 RemoveAceSpecific (GetAceQualifier (accessType), sid, accessMask,
116 inheritanceFlags, propagationFlags, AuditFlags.None,
117 objectFlags, objectType, inheritedObjectType);
120 public void SetAccess (AccessControlType accessType,
121 SecurityIdentifier sid,
123 InheritanceFlags inheritanceFlags,
124 PropagationFlags propagationFlags)
126 SetAce (GetAceQualifier (accessType), sid, accessMask,
127 inheritanceFlags, propagationFlags, AuditFlags.None);
130 public void SetAccess (AccessControlType accessType,
131 SecurityIdentifier sid,
133 InheritanceFlags inheritanceFlags,
134 PropagationFlags propagationFlags,
135 ObjectAceFlags objectFlags,
137 Guid inheritedObjectType)
139 SetAce (GetAceQualifier (accessType), sid, accessMask,
140 inheritanceFlags, propagationFlags, AuditFlags.None,
141 objectFlags, objectType, inheritedObjectType);
144 internal override void ApplyCanonicalSortToExplicitAces ()
146 int explicitCount = GetCanonicalExplicitAceCount ();
147 int explicitDenys = GetCanonicalExplicitDenyAceCount ();
149 ApplyCanonicalSortToExplicitAces (0, explicitDenys);
150 ApplyCanonicalSortToExplicitAces (explicitDenys, explicitCount - explicitDenys);
153 internal override int GetAceInsertPosition (AceQualifier aceQualifier)
155 // Canonical order for DACLs is explicit deny, explicit allow, inherited.
156 if (AceQualifier.AccessAllowed == aceQualifier)
157 return GetCanonicalExplicitDenyAceCount ();
162 static AceQualifier GetAceQualifier (AccessControlType accessType)
164 if (AccessControlType.Allow == accessType)
165 return AceQualifier.AccessAllowed;
166 else if (AccessControlType.Deny == accessType)
167 return AceQualifier.AccessDenied;
169 throw new ArgumentOutOfRangeException ("accessType");
172 internal override bool IsAceMeaningless (GenericAce ace)
174 if (base.IsAceMeaningless (ace)) return true;
175 if (AuditFlags.None != ace.AuditFlags) return true;
177 QualifiedAce qace = ace as QualifiedAce;
179 if (!(AceQualifier.AccessAllowed == qace.AceQualifier ||
180 AceQualifier.AccessDenied == qace.AceQualifier)) return true;