PipeSecurity.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // PipeSecurity.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. // James Bellinger <[email protected]>
  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. using System;
  31. using System.IO;
  32. using System.Linq;
  33. using System.Runtime.InteropServices;
  34. using System.Security.AccessControl;
  35. using System.Security.Permissions;
  36. using System.Security.Principal;
  37. namespace System.IO.Pipes
  38. {
  39. [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort = true)]
  40. public class PipeSecurity : NativeObjectSecurity
  41. {
  42. public PipeSecurity ()
  43. : base (false, ResourceType.FileObject)
  44. {
  45. }
  46. internal PipeSecurity (SafeHandle handle, AccessControlSections includeSections)
  47. : base (false, ResourceType.FileObject, handle, includeSections)
  48. {
  49. }
  50. public override Type AccessRightType {
  51. get { return typeof (PipeAccessRights); }
  52. }
  53. public override Type AccessRuleType {
  54. get { return typeof (PipeAccessRule); }
  55. }
  56. public override Type AuditRuleType {
  57. get { return typeof (PipeAuditRule); }
  58. }
  59. public override AccessRule AccessRuleFactory (IdentityReference identityReference,
  60. int accessMask, bool isInherited,
  61. InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
  62. AccessControlType type)
  63. {
  64. return new PipeAccessRule (identityReference, (PipeAccessRights)accessMask, type);
  65. }
  66. public void AddAccessRule (PipeAccessRule rule)
  67. {
  68. AddAccessRule ((AccessRule)rule);
  69. }
  70. public void AddAuditRule (PipeAuditRule rule)
  71. {
  72. AddAuditRule ((AuditRule) rule);
  73. }
  74. public override sealed AuditRule AuditRuleFactory (IdentityReference identityReference,
  75. int accessMask, bool isInherited,
  76. InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags,
  77. AuditFlags flags)
  78. {
  79. return new PipeAuditRule (identityReference, (PipeAccessRights)accessMask, flags);
  80. }
  81. [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
  82. protected internal void Persist (SafeHandle handle)
  83. {
  84. WriteLock();
  85. try {
  86. Persist (handle, AccessControlSectionsModified, null);
  87. } finally {
  88. WriteUnlock ();
  89. }
  90. }
  91. [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
  92. protected internal void Persist (string name)
  93. {
  94. WriteLock();
  95. try {
  96. Persist (name, AccessControlSectionsModified, null);
  97. } finally {
  98. WriteUnlock ();
  99. }
  100. }
  101. #if BOOTSTRAP_BASIC
  102. AccessControlSections AccessControlSectionsModified {
  103. get {
  104. return (AccessRulesModified ? AccessControlSections.Access : 0) |
  105. (AuditRulesModified ? AccessControlSections.Audit : 0) |
  106. (OwnerModified ? AccessControlSections.Owner : 0) |
  107. (GroupModified ? AccessControlSections.Group : 0);
  108. }
  109. }
  110. #endif
  111. public bool RemoveAccessRule (PipeAccessRule rule)
  112. {
  113. return RemoveAccessRule ((AccessRule)rule);
  114. }
  115. public void RemoveAccessRuleSpecific (PipeAccessRule rule)
  116. {
  117. RemoveAccessRuleSpecific ((AccessRule)rule);
  118. }
  119. public bool RemoveAuditRule (PipeAuditRule rule)
  120. {
  121. return RemoveAuditRule ((AuditRule)rule);
  122. }
  123. public void RemoveAuditRuleAll (PipeAuditRule rule)
  124. {
  125. RemoveAuditRuleAll ((AuditRule)rule);
  126. }
  127. public void RemoveAuditRuleSpecific (PipeAuditRule rule)
  128. {
  129. RemoveAuditRuleSpecific ((AuditRule)rule);
  130. }
  131. public void ResetAccessRule (PipeAccessRule rule)
  132. {
  133. ResetAccessRule ((AccessRule)rule);
  134. }
  135. public void SetAccessRule (PipeAccessRule rule)
  136. {
  137. SetAccessRule ((AccessRule)rule);
  138. }
  139. public void SetAuditRule (PipeAuditRule rule)
  140. {
  141. SetAuditRule ((AuditRule)rule);
  142. }
  143. }
  144. }