1 // 2 // System.Security.AccessControl.ObjectSecurity<T> 3 // 4 // Authors: 5 // ? 6 // James Bellinger <jfb@zer7.com> 7 // 8 // Copyright (C) 2009 Novell, Inc (http://www.novell.com) 9 // Copyright (C) 2012 James Bellinger 10 // 11 // Permission is hereby granted, free of charge, to any person obtaining 12 // a copy of this software and associated documentation files (the 13 // "Software"), to deal in the Software without restriction, including 14 // without limitation the rights to use, copy, modify, merge, publish, 15 // distribute, sublicense, and/or sell copies of the Software, and to 16 // permit persons to whom the Software is furnished to do so, subject to 17 // the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be 20 // included in all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 // 30 31 32 using System.Runtime.InteropServices; 33 using System.Security.Principal; 34 35 namespace System.Security.AccessControl 36 { 37 public abstract class ObjectSecurity<T> : NativeObjectSecurity where T : struct 38 { ObjectSecurity(bool isContainer, ResourceType resourceType)39 protected ObjectSecurity (bool isContainer, 40 ResourceType resourceType) 41 : base (isContainer, resourceType) 42 { 43 44 } 45 ObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle safeHandle, AccessControlSections includeSections)46 protected ObjectSecurity (bool isContainer, 47 ResourceType resourceType, 48 SafeHandle safeHandle, 49 AccessControlSections includeSections) 50 : base (isContainer, resourceType, safeHandle, includeSections) 51 { 52 53 } 54 ObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections)55 protected ObjectSecurity (bool isContainer, 56 ResourceType resourceType, 57 string name, 58 AccessControlSections includeSections) 59 : base (isContainer, resourceType, name, includeSections) 60 { 61 62 } 63 ObjectSecurity(bool isContainer, ResourceType resourceType, SafeHandle safeHandle, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext)64 protected ObjectSecurity (bool isContainer, 65 ResourceType resourceType, 66 SafeHandle safeHandle, 67 AccessControlSections includeSections, 68 ExceptionFromErrorCode exceptionFromErrorCode, 69 object exceptionContext) 70 : base (isContainer, resourceType, safeHandle, includeSections, 71 exceptionFromErrorCode, exceptionContext) 72 { 73 74 } 75 ObjectSecurity(bool isContainer, ResourceType resourceType, string name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, object exceptionContext)76 protected ObjectSecurity (bool isContainer, 77 ResourceType resourceType, 78 string name, 79 AccessControlSections includeSections, 80 ExceptionFromErrorCode exceptionFromErrorCode, 81 object exceptionContext) 82 : base (isContainer, resourceType, name, includeSections, 83 exceptionFromErrorCode, exceptionContext) 84 { 85 86 } 87 88 public override Type AccessRightType { 89 get { return typeof (T); } 90 } 91 92 public override Type AccessRuleType { 93 get { return typeof (AccessRule<T>); } 94 } 95 96 public override Type AuditRuleType { 97 get { return typeof (AuditRule<T>); } 98 } 99 AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)100 public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, 101 bool isInherited, InheritanceFlags inheritanceFlags, 102 PropagationFlags propagationFlags, AccessControlType type) 103 { 104 return new AccessRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, type); 105 } 106 AddAccessRule(AccessRule<T> rule)107 public virtual void AddAccessRule (AccessRule<T> rule) 108 { 109 AddAccessRule ((AccessRule)rule); 110 } 111 RemoveAccessRule(AccessRule<T> rule)112 public virtual bool RemoveAccessRule (AccessRule<T> rule) 113 { 114 return RemoveAccessRule ((AccessRule)rule); 115 } 116 RemoveAccessRuleAll(AccessRule<T> rule)117 public virtual void RemoveAccessRuleAll (AccessRule<T> rule) 118 { 119 RemoveAccessRuleAll ((AccessRule)rule); 120 } 121 RemoveAccessRuleSpecific(AccessRule<T> rule)122 public virtual void RemoveAccessRuleSpecific (AccessRule<T> rule) 123 { 124 RemoveAccessRuleSpecific ((AccessRule)rule); 125 } 126 ResetAccessRule(AccessRule<T> rule)127 public virtual void ResetAccessRule (AccessRule<T> rule) 128 { 129 ResetAccessRule ((AccessRule)rule); 130 } 131 SetAccessRule(AccessRule<T> rule)132 public virtual void SetAccessRule (AccessRule<T> rule) 133 { 134 SetAccessRule ((AccessRule)rule); 135 } 136 AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)137 public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, 138 bool isInherited, InheritanceFlags inheritanceFlags, 139 PropagationFlags propagationFlags, AuditFlags flags) 140 { 141 return new AuditRule<T> (identityReference, accessMask, isInherited, inheritanceFlags, propagationFlags, flags); 142 } 143 AddAuditRule(AuditRule<T> rule)144 public virtual void AddAuditRule (AuditRule<T> rule) 145 { 146 AddAuditRule ((AuditRule)rule); 147 } 148 RemoveAuditRule(AuditRule<T> rule)149 public virtual bool RemoveAuditRule (AuditRule<T> rule) 150 { 151 return RemoveAuditRule((AuditRule)rule); 152 } 153 RemoveAuditRuleAll(AuditRule<T> rule)154 public virtual void RemoveAuditRuleAll (AuditRule<T> rule) 155 { 156 RemoveAuditRuleAll((AuditRule)rule); 157 } 158 RemoveAuditRuleSpecific(AuditRule<T> rule)159 public virtual void RemoveAuditRuleSpecific (AuditRule<T> rule) 160 { 161 RemoveAuditRuleSpecific((AuditRule)rule); 162 } 163 SetAuditRule(AuditRule<T> rule)164 public virtual void SetAuditRule (AuditRule<T> rule) 165 { 166 SetAuditRule((AuditRule)rule); 167 } 168 Persist(SafeHandle handle)169 protected void Persist (SafeHandle handle) 170 { 171 WriteLock (); 172 try { 173 Persist (handle, AccessControlSectionsModified); 174 } finally { 175 WriteUnlock (); 176 } 177 } 178 Persist(string name)179 protected void Persist (string name) 180 { 181 WriteLock (); 182 try { 183 Persist (name, AccessControlSectionsModified); 184 } finally { 185 WriteUnlock (); 186 } 187 } 188 } 189 } 190 191 192