SystemAcl.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 bool RemoveAudit (AuditFlags auditFlags,
  69. SecurityIdentifier sid,
  70. int accessMask,
  71. InheritanceFlags inheritanceFlags,
  72. PropagationFlags propagationFlags)
  73. {
  74. throw new NotImplementedException ();
  75. }
  76. public bool RemoveAudit (AuditFlags auditFlags,
  77. SecurityIdentifier sid,
  78. int accessMask,
  79. InheritanceFlags inheritanceFlags,
  80. PropagationFlags propagationFlags,
  81. ObjectAceFlags objectFlags,
  82. Guid objectType,
  83. Guid inheritedObjectType)
  84. {
  85. throw new NotImplementedException ();
  86. }
  87. public void RemoveAuditSpecific (AuditFlags auditFlags,
  88. SecurityIdentifier sid,
  89. int accessMask,
  90. InheritanceFlags inheritanceFlags,
  91. PropagationFlags propagationFlags)
  92. {
  93. RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
  94. inheritanceFlags, propagationFlags, auditFlags);
  95. }
  96. public void RemoveAuditSpecific (AuditFlags auditFlags,
  97. SecurityIdentifier sid,
  98. int accessMask,
  99. InheritanceFlags inheritanceFlags,
  100. PropagationFlags propagationFlags,
  101. ObjectAceFlags objectFlags,
  102. Guid objectType,
  103. Guid inheritedObjectType)
  104. {
  105. RemoveAceSpecific (AceQualifier.SystemAudit, sid, accessMask,
  106. inheritanceFlags, propagationFlags, auditFlags,
  107. objectFlags, objectType, inheritedObjectType);
  108. }
  109. public void SetAudit (AuditFlags auditFlags,
  110. SecurityIdentifier sid,
  111. int accessMask,
  112. InheritanceFlags inheritanceFlags,
  113. PropagationFlags propagationFlags)
  114. {
  115. SetAce (AceQualifier.SystemAudit, sid, accessMask,
  116. inheritanceFlags, propagationFlags, auditFlags);
  117. }
  118. public void SetAudit (AuditFlags auditFlags,
  119. SecurityIdentifier sid,
  120. int accessMask,
  121. InheritanceFlags inheritanceFlags,
  122. PropagationFlags propagationFlags,
  123. ObjectAceFlags objectFlags,
  124. Guid objectType,
  125. Guid inheritedObjectType)
  126. {
  127. SetAce (AceQualifier.SystemAudit, sid, accessMask,
  128. inheritanceFlags, propagationFlags, auditFlags,
  129. objectFlags, objectType, inheritedObjectType);
  130. }
  131. internal override void ApplyCanonicalSortToExplicitAces ()
  132. {
  133. int explicitCount = GetCanonicalExplicitAceCount ();
  134. ApplyCanonicalSortToExplicitAces (0, explicitCount);
  135. }
  136. internal override int GetAceInsertPosition (AceQualifier aceQualifier)
  137. {
  138. return 0;
  139. }
  140. internal override bool IsAceMeaningless (GenericAce ace)
  141. {
  142. if (base.IsAceMeaningless (ace)) return true;
  143. if (!IsValidAuditFlags (ace.AuditFlags)) return true;
  144. QualifiedAce qace = ace as QualifiedAce;
  145. if (null != qace) {
  146. if (!(AceQualifier.SystemAudit == qace.AceQualifier ||
  147. AceQualifier.SystemAlarm == qace.AceQualifier)) return true;
  148. }
  149. return false;
  150. }
  151. static bool IsValidAuditFlags (AuditFlags auditFlags)
  152. {
  153. return auditFlags != AuditFlags.None &&
  154. auditFlags == ((AuditFlags.Success|AuditFlags.Failure) & auditFlags);
  155. }
  156. }
  157. }