Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SimpleFileSystemAccessRule.cs 5.3 KiB

8 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Security.AccessControl;
  2. namespace Security2
  3. {
  4. public class SimpleFileSystemAccessRule
  5. {
  6. private string fullName;
  7. private IdentityReference2 identity;
  8. private FileSystemRights2 accessRights;
  9. private AccessControlType type;
  10. public AccessControlType AccessControlType
  11. {
  12. get { return type; }
  13. set { type = value; }
  14. }
  15. public string FullName
  16. {
  17. get { return fullName; }
  18. }
  19. public string Name
  20. {
  21. get
  22. {
  23. return System.IO.Path.GetFileName(fullName);
  24. }
  25. }
  26. public IdentityReference2 Identity
  27. {
  28. get { return identity; }
  29. }
  30. public SimpleFileSystemAccessRights AccessRights
  31. {
  32. get
  33. {
  34. SimpleFileSystemAccessRights result = SimpleFileSystemAccessRights.None;
  35. if ((accessRights & FileSystemRights2.Read) == FileSystemRights2.Read)
  36. { result |= SimpleFileSystemAccessRights.Read; }
  37. if ((accessRights & FileSystemRights2.CreateFiles) == FileSystemRights2.CreateFiles)
  38. { result |= SimpleFileSystemAccessRights.Write; }
  39. if ((accessRights & FileSystemRights2.AppendData) == FileSystemRights2.AppendData)
  40. { result |= SimpleFileSystemAccessRights.Write; }
  41. if ((accessRights & FileSystemRights2.ReadExtendedAttributes) == FileSystemRights2.ReadExtendedAttributes)
  42. { result |= SimpleFileSystemAccessRights.Read; }
  43. if ((accessRights & FileSystemRights2.WriteExtendedAttributes) == FileSystemRights2.WriteExtendedAttributes)
  44. { result |= SimpleFileSystemAccessRights.Write; }
  45. if ((accessRights & FileSystemRights2.ExecuteFile) == FileSystemRights2.ExecuteFile)
  46. { result |= SimpleFileSystemAccessRights.Read; }
  47. if ((accessRights & FileSystemRights2.DeleteSubdirectoriesAndFiles) == FileSystemRights2.DeleteSubdirectoriesAndFiles)
  48. { result |= SimpleFileSystemAccessRights.Delete; }
  49. if ((accessRights & FileSystemRights2.ReadAttributes) == FileSystemRights2.ReadAttributes)
  50. { result |= SimpleFileSystemAccessRights.Read; }
  51. if ((accessRights & FileSystemRights2.WriteAttributes) == FileSystemRights2.WriteAttributes)
  52. { result |= SimpleFileSystemAccessRights.Write; }
  53. if ((accessRights & FileSystemRights2.Delete) == FileSystemRights2.Delete)
  54. { result |= SimpleFileSystemAccessRights.Delete; }
  55. if ((accessRights & FileSystemRights2.ReadPermissions) == FileSystemRights2.ReadPermissions)
  56. { result |= SimpleFileSystemAccessRights.Read; }
  57. if ((accessRights & FileSystemRights2.ChangePermissions) == FileSystemRights2.ChangePermissions)
  58. { result |= SimpleFileSystemAccessRights.Write; }
  59. if ((accessRights & FileSystemRights2.TakeOwnership) == FileSystemRights2.TakeOwnership)
  60. { result |= SimpleFileSystemAccessRights.Write; }
  61. if ((accessRights & FileSystemRights2.Synchronize) == FileSystemRights2.Synchronize)
  62. { result |= SimpleFileSystemAccessRights.Read; }
  63. if ((accessRights & FileSystemRights2.FullControl) == FileSystemRights2.FullControl)
  64. { result = (SimpleFileSystemAccessRights.Write | SimpleFileSystemAccessRights.Read | SimpleFileSystemAccessRights.Delete); }
  65. if ((accessRights & FileSystemRights2.GenericRead) == FileSystemRights2.GenericRead)
  66. { result |= SimpleFileSystemAccessRights.Read; }
  67. if ((accessRights & FileSystemRights2.GenericWrite) == FileSystemRights2.GenericWrite)
  68. { result |= SimpleFileSystemAccessRights.Write; }
  69. if ((accessRights & FileSystemRights2.GenericExecute) == FileSystemRights2.GenericExecute)
  70. { result |= SimpleFileSystemAccessRights.Read; }
  71. if ((accessRights & FileSystemRights2.GenericAll) == FileSystemRights2.GenericAll)
  72. { result = (SimpleFileSystemAccessRights.Write | SimpleFileSystemAccessRights.Read | SimpleFileSystemAccessRights.Delete); }
  73. return result;
  74. }
  75. }
  76. public SimpleFileSystemAccessRule(string Path, IdentityReference2 account, FileSystemRights2 access)
  77. {
  78. this.fullName = Path;
  79. this.accessRights = access;
  80. this.identity = account;
  81. }
  82. public override bool Equals(object obj)
  83. {
  84. var compareObject = obj as SimpleFileSystemAccessRule;
  85. if (compareObject == null)
  86. {
  87. return false;
  88. }
  89. if (this.AccessRights == compareObject.AccessRights && this.Identity == compareObject.Identity && this.AccessControlType == compareObject.AccessControlType)
  90. {
  91. return true;
  92. }
  93. else
  94. {
  95. return false;
  96. }
  97. }
  98. public override int GetHashCode()
  99. {
  100. return this.Identity.GetHashCode() | this.AccessRights.GetHashCode() | this.AccessControlType.GetHashCode();
  101. }
  102. }
  103. }