GenericSecurity.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #if !NETSTANDARD
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Security.AccessControl;
  5. using System.Security.Principal;
  6. namespace WinSCP
  7. {
  8. // All the code to manipulate security object is available in .NET framework,
  9. // but its API tries to be type-safe and handle-safe, enforcing special implemnentation
  10. // (to otherwise a generic WinAPI) for each handle type. This is to make sure
  11. // only correct set of permissions can be set for corresponding object types and
  12. // mainly that handles do not leak.
  13. // Hence the AccessRule and NativeObjectSecurity clases are abstract.
  14. // This is the simplest possible implementation that yet allows us to make use
  15. // of the existing .NET implementation, sparing necessity to P/Invoke the underlying WinAPI.
  16. internal class GenericAccessRule : AccessRule
  17. {
  18. public GenericAccessRule(IdentityReference identity, int accessMask, AccessControlType type) :
  19. base(identity, accessMask, false, InheritanceFlags.None, PropagationFlags.None, type)
  20. {
  21. }
  22. }
  23. internal class GenericSecurity : NativeObjectSecurity
  24. {
  25. public GenericSecurity(bool isContainer, ResourceType resType, SafeHandle objectHandle, AccessControlSections sectionsRequested)
  26. : base(isContainer, resType, objectHandle, sectionsRequested)
  27. {
  28. }
  29. new public void Persist(SafeHandle handle, AccessControlSections includeSections)
  30. {
  31. base.Persist(handle, includeSections);
  32. }
  33. new public void AddAccessRule(AccessRule rule)
  34. {
  35. base.AddAccessRule(rule);
  36. }
  37. #region NativeObjectSecurity Abstract Method Overrides
  38. public override Type AccessRightType
  39. {
  40. get { throw new NotImplementedException(); }
  41. }
  42. public override AccessRule AccessRuleFactory(System.Security.Principal.IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)
  43. {
  44. throw new NotImplementedException();
  45. }
  46. public override Type AccessRuleType
  47. {
  48. get { return typeof(AccessRule); }
  49. }
  50. public override AuditRule AuditRuleFactory(System.Security.Principal.IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)
  51. {
  52. throw new NotImplementedException();
  53. }
  54. public override Type AuditRuleType
  55. {
  56. get { return typeof(AuditRule); }
  57. }
  58. #endregion
  59. }
  60. }
  61. #endif