1 // 2 // System.Security.AccessControl.MutexSecurity implementation 3 // 4 // Authors: 5 // Dick Porter <dick@ximian.com> 6 // Atsushi Enomoto <atsushi@ximian.com> 7 // James Bellinger <jfb@zer7.com> 8 // 9 // Copyright (C) 2005-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 32 using System.Runtime.InteropServices; 33 using System.Security.Principal; 34 using System.Threading; 35 36 namespace System.Security.AccessControl 37 { 38 public sealed class MutexSecurity : NativeObjectSecurity 39 { MutexSecurity()40 public MutexSecurity () 41 : base (false, ResourceType.KernelObject) 42 { 43 } 44 MutexSecurity(string name, AccessControlSections includeSections)45 public MutexSecurity (string name, 46 AccessControlSections includeSections) 47 : base (false, ResourceType.KernelObject, name, includeSections, 48 MutexExceptionFromErrorCode, null) 49 { 50 } 51 MutexSecurity(SafeHandle handle, AccessControlSections includeSections)52 internal MutexSecurity (SafeHandle handle, 53 AccessControlSections includeSections) 54 : base (false, ResourceType.KernelObject, handle, includeSections, 55 MutexExceptionFromErrorCode, null) 56 { 57 } 58 59 public override Type AccessRightType { 60 get { return typeof (MutexRights); } 61 } 62 63 public override Type AccessRuleType { 64 get { return typeof (MutexAccessRule); } 65 } 66 67 public override Type AuditRuleType { 68 get { return typeof (MutexAuditRule); } 69 } 70 AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)71 public override AccessRule AccessRuleFactory (IdentityReference identityReference, int accessMask, 72 bool isInherited, InheritanceFlags inheritanceFlags, 73 PropagationFlags propagationFlags, AccessControlType type) 74 { 75 return new MutexAccessRule (identityReference, (MutexRights) accessMask, type); 76 } 77 AddAccessRule(MutexAccessRule rule)78 public void AddAccessRule (MutexAccessRule rule) 79 { 80 AddAccessRule ((AccessRule)rule); 81 } 82 RemoveAccessRule(MutexAccessRule rule)83 public bool RemoveAccessRule (MutexAccessRule rule) 84 { 85 return RemoveAccessRule ((AccessRule)rule); 86 } 87 RemoveAccessRuleAll(MutexAccessRule rule)88 public void RemoveAccessRuleAll (MutexAccessRule rule) 89 { 90 RemoveAccessRuleAll ((AccessRule)rule); 91 } 92 RemoveAccessRuleSpecific(MutexAccessRule rule)93 public void RemoveAccessRuleSpecific (MutexAccessRule rule) 94 { 95 RemoveAccessRuleSpecific ((AccessRule)rule); 96 } 97 ResetAccessRule(MutexAccessRule rule)98 public void ResetAccessRule (MutexAccessRule rule) 99 { 100 ResetAccessRule ((AccessRule)rule); 101 } 102 SetAccessRule(MutexAccessRule rule)103 public void SetAccessRule (MutexAccessRule rule) 104 { 105 SetAccessRule ((AccessRule)rule); 106 } 107 AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)108 public override AuditRule AuditRuleFactory (IdentityReference identityReference, int accessMask, 109 bool isInherited, InheritanceFlags inheritanceFlags, 110 PropagationFlags propagationFlags, AuditFlags flags) 111 { 112 return new MutexAuditRule (identityReference, (MutexRights) accessMask, flags); 113 } 114 AddAuditRule(MutexAuditRule rule)115 public void AddAuditRule (MutexAuditRule rule) 116 { 117 AddAuditRule ((AuditRule)rule); 118 } 119 RemoveAuditRule(MutexAuditRule rule)120 public bool RemoveAuditRule (MutexAuditRule rule) 121 { 122 return RemoveAuditRule((AuditRule)rule); 123 } 124 RemoveAuditRuleAll(MutexAuditRule rule)125 public void RemoveAuditRuleAll (MutexAuditRule rule) 126 { 127 RemoveAuditRuleAll((AuditRule)rule); 128 } 129 RemoveAuditRuleSpecific(MutexAuditRule rule)130 public void RemoveAuditRuleSpecific (MutexAuditRule rule) 131 { 132 RemoveAuditRuleSpecific((AuditRule)rule); 133 } 134 SetAuditRule(MutexAuditRule rule)135 public void SetAuditRule (MutexAuditRule rule) 136 { 137 SetAuditRule((AuditRule)rule); 138 } 139 MutexExceptionFromErrorCode(int errorCode, string name, SafeHandle handle, object context)140 static Exception MutexExceptionFromErrorCode (int errorCode, 141 string name, SafeHandle handle, 142 object context) 143 { 144 switch (errorCode) { 145 case 2: return new WaitHandleCannotBeOpenedException (); 146 default: return DefaultExceptionFromErrorCode (errorCode, name, handle, context); 147 } 148 } 149 } 150 } 151 152