CommonObjectSecurity.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // System.Security.AccessControl.CommonObjectSecurity implementation
  3. //
  4. // Authors:
  5. // Dick Porter <[email protected]>
  6. // Atsushi Enomoto <[email protected]>
  7. //
  8. // Copyright (C) 2005-2007 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Collections.Generic;
  30. namespace System.Security.AccessControl {
  31. [MonoTODO ("required for NativeObjectSecurity - implementation is missing")]
  32. public abstract class CommonObjectSecurity : ObjectSecurity {
  33. protected CommonObjectSecurity (bool isContainer)
  34. : base (isContainer, false)
  35. {
  36. }
  37. List<AccessRule> access_rules = new List<AccessRule> ();
  38. List<AuditRule> audit_rules = new List<AuditRule> ();
  39. public AuthorizationRuleCollection GetAccessRules (bool includeExplicit, bool includeInherited, Type targetType)
  40. {
  41. throw new NotImplementedException ();
  42. }
  43. public AuthorizationRuleCollection GetAuditRules (bool includeExplicit, bool includeInherited, Type targetType)
  44. {
  45. throw new NotImplementedException ();
  46. }
  47. // Access
  48. protected void AddAccessRule (AccessRule rule)
  49. {
  50. access_rules.Add (rule);
  51. AccessRulesModified = true;
  52. }
  53. protected bool RemoveAccessRule (AccessRule rule)
  54. {
  55. throw new NotImplementedException ();
  56. }
  57. protected void RemoveAccessRuleAll (AccessRule rule)
  58. {
  59. throw new NotImplementedException ();
  60. }
  61. protected void RemoveAccessRuleSpecific (AccessRule rule)
  62. {
  63. throw new NotImplementedException ();
  64. }
  65. protected void ResetAccessRule (AccessRule rule)
  66. {
  67. throw new NotImplementedException ();
  68. }
  69. protected void SetAccessRule (AccessRule rule)
  70. {
  71. throw new NotImplementedException ();
  72. }
  73. protected override bool ModifyAccess (AccessControlModification modification, AccessRule rule, out bool modified)
  74. {
  75. foreach (AccessRule r in access_rules) {
  76. if (rule != r)
  77. continue;
  78. switch (modification) {
  79. case AccessControlModification.Add:
  80. AddAccessRule (rule);
  81. break;
  82. case AccessControlModification.Set:
  83. SetAccessRule (rule);
  84. break;
  85. case AccessControlModification.Reset:
  86. ResetAccessRule (rule);
  87. break;
  88. case AccessControlModification.Remove:
  89. RemoveAccessRule (rule);
  90. break;
  91. case AccessControlModification.RemoveAll:
  92. RemoveAccessRuleAll (rule);
  93. break;
  94. case AccessControlModification.RemoveSpecific:
  95. RemoveAccessRuleSpecific (rule);
  96. break;
  97. }
  98. modified = true;
  99. return true;
  100. }
  101. modified = false;
  102. return false;
  103. }
  104. // Audit
  105. protected void AddAuditRule (AuditRule rule)
  106. {
  107. audit_rules.Add (rule);
  108. AuditRulesModified = true;
  109. }
  110. protected bool RemoveAuditRule (AuditRule rule)
  111. {
  112. throw new NotImplementedException ();
  113. }
  114. protected void RemoveAuditRuleAll (AuditRule rule)
  115. {
  116. throw new NotImplementedException ();
  117. }
  118. protected void RemoveAuditRuleSpecific (AuditRule rule)
  119. {
  120. throw new NotImplementedException ();
  121. }
  122. protected void SetAuditRule (AuditRule rule)
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. protected override bool ModifyAudit (AccessControlModification modification, AuditRule rule, out bool modified)
  127. {
  128. foreach (AuditRule r in audit_rules) {
  129. if (rule != r)
  130. continue;
  131. switch (modification) {
  132. case AccessControlModification.Add:
  133. AddAuditRule (rule);
  134. break;
  135. case AccessControlModification.Set:
  136. SetAuditRule (rule);
  137. break;
  138. //case AccessControlModification.Reset:
  139. // ResetAuditRule (rule);
  140. // break;
  141. case AccessControlModification.Remove:
  142. RemoveAuditRule (rule);
  143. break;
  144. case AccessControlModification.RemoveAll:
  145. RemoveAuditRuleAll (rule);
  146. break;
  147. case AccessControlModification.RemoveSpecific:
  148. RemoveAuditRuleSpecific (rule);
  149. break;
  150. }
  151. AuditRulesModified = true;
  152. modified = true;
  153. return true;
  154. }
  155. modified = false;
  156. return false;
  157. }
  158. }
  159. }