|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System.Security.AccessControl;
-
- namespace Security2
- {
- public class SimpleFileSystemAccessRule
- {
- private string fullName;
- private IdentityReference2 identity;
- private FileSystemRights2 accessRights;
- private AccessControlType type;
-
- public AccessControlType AccessControlType
- {
- get { return type; }
- set { type = value; }
- }
-
- public string FullName
- {
- get { return fullName; }
- }
-
- public string Name
- {
- get
- {
- return System.IO.Path.GetFileName(fullName);
- }
- }
-
- public IdentityReference2 Identity
- {
- get { return identity; }
- }
-
- public SimpleFileSystemAccessRights AccessRights
- {
- get
- {
- SimpleFileSystemAccessRights result = SimpleFileSystemAccessRights.None;
-
- if ((accessRights & FileSystemRights2.Read) == FileSystemRights2.Read)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.CreateFiles) == FileSystemRights2.CreateFiles)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.AppendData) == FileSystemRights2.AppendData)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.ReadExtendedAttributes) == FileSystemRights2.ReadExtendedAttributes)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.WriteExtendedAttributes) == FileSystemRights2.WriteExtendedAttributes)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.ExecuteFile) == FileSystemRights2.ExecuteFile)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.DeleteSubdirectoriesAndFiles) == FileSystemRights2.DeleteSubdirectoriesAndFiles)
- { result |= SimpleFileSystemAccessRights.Delete; }
-
- if ((accessRights & FileSystemRights2.ReadAttributes) == FileSystemRights2.ReadAttributes)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.WriteAttributes) == FileSystemRights2.WriteAttributes)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.Delete) == FileSystemRights2.Delete)
- { result |= SimpleFileSystemAccessRights.Delete; }
-
- if ((accessRights & FileSystemRights2.ReadPermissions) == FileSystemRights2.ReadPermissions)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.ChangePermissions) == FileSystemRights2.ChangePermissions)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.TakeOwnership) == FileSystemRights2.TakeOwnership)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.Synchronize) == FileSystemRights2.Synchronize)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.FullControl) == FileSystemRights2.FullControl)
- { result = (SimpleFileSystemAccessRights.Write | SimpleFileSystemAccessRights.Read | SimpleFileSystemAccessRights.Delete); }
-
- if ((accessRights & FileSystemRights2.GenericRead) == FileSystemRights2.GenericRead)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.GenericWrite) == FileSystemRights2.GenericWrite)
- { result |= SimpleFileSystemAccessRights.Write; }
-
- if ((accessRights & FileSystemRights2.GenericExecute) == FileSystemRights2.GenericExecute)
- { result |= SimpleFileSystemAccessRights.Read; }
-
- if ((accessRights & FileSystemRights2.GenericAll) == FileSystemRights2.GenericAll)
- { result = (SimpleFileSystemAccessRights.Write | SimpleFileSystemAccessRights.Read | SimpleFileSystemAccessRights.Delete); }
-
- return result;
- }
- }
-
- public SimpleFileSystemAccessRule(string Path, IdentityReference2 account, FileSystemRights2 access)
- {
- this.fullName = Path;
- this.accessRights = access;
- this.identity = account;
- }
-
- public override bool Equals(object obj)
- {
- var compareObject = obj as SimpleFileSystemAccessRule;
-
- if (compareObject == null)
- {
- return false;
- }
-
- if (this.AccessRights == compareObject.AccessRights && this.Identity == compareObject.Identity && this.AccessControlType == compareObject.AccessControlType)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- public override int GetHashCode()
- {
- return this.Identity.GetHashCode() | this.AccessRights.GetHashCode() | this.AccessControlType.GetHashCode();
- }
- }
- }
|