SystemAcl.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // System.Security.AccessControl.SystemAcl implementation
  3. //
  4. // Authors:
  5. // Dick Porter <[email protected]>
  6. // Atsushi Enomoto <[email protected]>
  7. // James Bellinger <[email protected]>
  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. using System.Security.Principal;
  32. namespace System.Security.AccessControl
  33. {
  34. public sealed class SystemAcl : CommonAcl
  35. {
  36. public SystemAcl (bool isContainer, bool isDS, int capacity)
  37. : base (isContainer, isDS, capacity)
  38. {
  39. }
  40. public SystemAcl (bool isContainer, bool isDS, RawAcl rawAcl)
  41. : base (isContainer, isDS, rawAcl)
  42. {
  43. }
  44. public SystemAcl (bool isContainer, bool isDS, byte revision, int capacity)
  45. : base (isContainer, isDS, revision, capacity)
  46. {
  47. }
  48. public void AddAudit (AuditFlags auditFlags,
  49. SecurityIdentifier sid, int accessMask,
  50. InheritanceFlags inheritanceFlags,
  51. PropagationFlags propagationFlags)
  52. {
  53. AddAce (AceQualifier.SystemAudit, sid, accessMask,
  54. inheritanceFlags, propagationFlags, auditFlags);
  55. }
  56. public void AddAudit (AuditFlags auditFlags,
  57. SecurityIdentifier sid, int accessMask,
  58. InheritanceFlags inheritanceFlags,
  59. PropagationFlags propagationFlags,
  60. ObjectAceFlags objectFlags,
  61. Guid objectType,
  62. Guid inheritedObjectType)
  63. {
  64. AddAce (AceQualifier.SystemAudit, sid, accessMask,
  65. inheritanceFlags, propagationFlags, auditFlags,
  66. objectFlags, objectType, inheritedObjectType);
  67. }
  68. public void AddAudit (SecurityIdentifier sid, ObjectAuditRule rule)
  69. {
  70. AddAudit (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
  71. }
  72. [MonoTODO]
  73. public bool RemoveAudit (AuditFlags auditFlags,
  74. SecurityIdentifier sid,
  75. int accessMask,
  76. InheritanceFlags inheritanceFlags,
  77. PropagationFlags propagationFlags)
  78. {
  79. throw new NotImplementedException ();
  80. }
  81. [MonoTODO]
  82. public bool RemoveAudit (AuditFlags auditFlags,
  83. SecurityIdentifier sid,
  84. int accessMask,
  85. InheritanceFlags inheritanceFlags,
  86. PropagationFlags propagationFlags,
  87. ObjectAceFlags objectFlags,
  88. Guid objectType,
  89. Guid inheritedObjectType)
  90. {
  91. throw new NotImplementedException ();
  92. }
  93. public bool RemoveAudit (SecurityIdentifier sid, ObjectAuditRule rule)
  94. {
  95. return RemoveAudit (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
  96. }
  97. public void RemoveAuditSpecific (AuditFlags auditFlags,
  98. SecurityIdentifier sid,
  99. int accessMask,
  100. InheritanceFlags inheritanceFlags,
  101. PropagationFlags propagationFlags)
  102. {
  103. RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
  104. inheritanceFlags, propagationFlags, auditFlags);
  105. }
  106. public void RemoveAuditSpecific (AuditFlags auditFlags,
  107. SecurityIdentifier sid,
  108. int accessMask,
  109. InheritanceFlags inheritanceFlags,
  110. PropagationFlags propagationFlags,
  111. ObjectAceFlags objectFlags,
  112. Guid objectType,
  113. Guid inheritedObjectType)
  114. {
  115. RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
  116. inheritanceFlags, propagationFlags, auditFlags,
  117. objectFlags, objectType, inheritedObjectType);
  118. }
  119. public void RemoveAuditSpecific (SecurityIdentifier sid, ObjectAuditRule rule)
  120. {
  121. RemoveAuditSpecific (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
  122. }
  123. public void SetAudit (AuditFlags auditFlags,
  124. SecurityIdentifier sid,
  125. int accessMask,
  126. InheritanceFlags inheritanceFlags,
  127. PropagationFlags propagationFlags)
  128. {
  129. SetAce (AceQualifier.SystemAudit, sid, accessMask,
  130. inheritanceFlags, propagationFlags, auditFlags);
  131. }
  132. public void SetAudit (AuditFlags auditFlags,
  133. SecurityIdentifier sid,
  134. int accessMask,
  135. InheritanceFlags inheritanceFlags,
  136. PropagationFlags propagationFlags,
  137. ObjectAceFlags objectFlags,
  138. Guid objectType,
  139. Guid inheritedObjectType)
  140. {
  141. SetAce (AceQualifier.SystemAudit, sid, accessMask,
  142. inheritanceFlags, propagationFlags, auditFlags,
  143. objectFlags, objectType, inheritedObjectType);
  144. }
  145. public void SetAudit (SecurityIdentifier sid, ObjectAuditRule rule)
  146. {
  147. SetAudit (rule.AuditFlags, sid, rule.AccessMask, rule.InheritanceFlags, rule.PropagationFlags, rule.ObjectFlags, rule.ObjectType, rule.InheritedObjectType);
  148. }
  149. internal override void ApplyCanonicalSortToExplicitAces ()
  150. {
  151. int explicitCount = GetCanonicalExplicitAceCount ();
  152. ApplyCanonicalSortToExplicitAces (0, explicitCount);
  153. }
  154. internal override int GetAceInsertPosition (AceQualifier aceQualifier)
  155. {
  156. return 0;
  157. }
  158. internal override bool IsAceMeaningless (GenericAce ace)
  159. {
  160. if (base.IsAceMeaningless (ace)) return true;
  161. if (!IsValidAuditFlags (ace.AuditFlags)) return true;
  162. QualifiedAce qace = ace as QualifiedAce;
  163. if (null != qace) {
  164. if (!(AceQualifier.SystemAudit == qace.AceQualifier ||
  165. AceQualifier.SystemAlarm == qace.AceQualifier)) return true;
  166. }
  167. return false;
  168. }
  169. static bool IsValidAuditFlags (AuditFlags auditFlags)
  170. {
  171. return auditFlags != AuditFlags.None &&
  172. auditFlags == ((AuditFlags.Success|AuditFlags.Failure) & auditFlags);
  173. }
  174. }
  175. }