1
0

GenericSecurity.cs 2.7 KB

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