public SimpleFileSystemAccessRule(string path, IdentityReference2 account, FileSystemRights2 access, AccessControlType accessControlType)
 {
     fullName     = path;
     accessRights = access;
     identity     = account;
     type         = accessControlType;
 }
        public static IEnumerable <FileSystemAuditRule2> RemoveFileSystemAuditRule(FileSystemSecurity2 sd, List <IdentityReference2> accounts, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removeSpecific = false)
        {
            var aces = new List <FileSystemAuditRule2>();

            foreach (var account in accounts)
            {
                aces.Add(RemoveFileSystemAuditRule(sd, account, rights, type, inheritanceFlags, propagationFlags));
            }

            return(aces);
        }
        public static FileSystemAuditRule2 AddFileSystemAuditRule(FileSystemSecurity2 sd, IdentityReference2 account, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            FileSystemAuditRule2 ace = null;

            if (sd.IsFile)
            {
                ace = (FileSystemAuditRule)sd.SecurityDescriptor.AuditRuleFactory(account, (int)rights, false, InheritanceFlags.None, PropagationFlags.None, type);
                ((FileSecurity)sd.SecurityDescriptor).AddAuditRule(ace);
            }
            else
            {
                ace = (FileSystemAuditRule)sd.SecurityDescriptor.AuditRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);
                ((DirectorySecurity)sd.SecurityDescriptor).AddAuditRule(ace);
            }

            return(ace);
        }
 public static IEnumerable <FileSystemAuditRule2> AddFileSystemAuditRule(string path, List <IdentityReference2> accounts, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
 {
     if (File.Exists(path))
     {
         var item = new FileInfo(path);
         foreach (var account in accounts)
         {
             yield return(AddFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags));
         }
     }
     else
     {
         var item = new DirectoryInfo(path);
         foreach (var account in accounts)
         {
             yield return(AddFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags));
         }
     }
 }
        public static IEnumerable <FileSystemAuditRule2> AddFileSystemAuditRule(FileSystemInfo item, List <IdentityReference2> accounts, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            var aces = new List <FileSystemAuditRule2>();

            foreach (var account in accounts)
            {
                aces.Add(AddFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags));
            }

            return(aces);
        }
        public static FileSystemAuditRule2 AddFileSystemAuditRule(string path, IdentityReference2 account, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            FileSystemAuditRule ace = null;

            if (File.Exists(path))
            {
                var item = new FileInfo(path);
                ace = AddFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags);
            }
            else
            {
                var item = new DirectoryInfo(path);
                ace = AddFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags);
            }

            return(ace);
        }
示例#7
0
        public static IEnumerable <FileSystemAccessRule2> AddFileSystemAccessRule(FileSystemSecurity2 sd, List <IdentityReference2> accounts, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            var aces = new List <FileSystemAccessRule2>();

            foreach (var account in accounts)
            {
                aces.Add(AddFileSystemAccessRule(sd, account, rights, type, inheritanceFlags, propagationFlags));
            }

            return(aces);
        }
        public static void RemoveFileSystemAuditRule(FileSystemInfo item, IdentityReference2 account, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            FileSystemAuditRule ace = null;

            if (item is FileInfo)
            {
                var file = (FileInfo)item;
                var sd   = file.GetAccessControl(AccessControlSections.Audit);

                ace = (FileSystemAuditRule)sd.AuditRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);

                sd.RemoveAuditRule(ace);

                file.SetAccessControl(sd);
            }
            else
            {
                DirectoryInfo directory = (DirectoryInfo)item;

                var sd = directory.GetAccessControl(AccessControlSections.Audit);

                ace = (FileSystemAuditRule)sd.AuditRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);
                sd.RemoveAuditRule(ace);

                directory.SetAccessControl(sd);
            }
        }
示例#9
0
 public static void RemoveFileSystemAccessRule(string path, List <IdentityReference2> account, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removeSpecific = false)
 {
     if (File.Exists(path))
     {
         var item = new FileInfo(path);
         RemoveFileSystemAccessRule(item, account, rights, type, inheritanceFlags, propagationFlags, removeSpecific);
     }
     else
     {
         var item = new DirectoryInfo(path);
         RemoveFileSystemAccessRule(item, account, rights, type, inheritanceFlags, propagationFlags, removeSpecific);
     }
 }
示例#10
0
        public static FileSystemAccessRule2 RemoveFileSystemAccessRule(FileSystemSecurity2 sd, IdentityReference2 account, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removeSpecific = false)
        {
            if (type == AccessControlType.Allow)
            {
                rights = rights | FileSystemRights2.Synchronize;
            }

            var ace = (FileSystemAccessRule)sd.SecurityDescriptor.AccessRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);

            if (sd.IsFile)
            {
                if (removeSpecific)
                {
                    ((FileSecurity)sd.SecurityDescriptor).RemoveAccessRuleSpecific(ace);
                }
                else
                {
                    ((FileSecurity)sd.SecurityDescriptor).RemoveAccessRule(ace);
                }
            }
            else
            {
                if (removeSpecific)
                {
                    ((DirectorySecurity)sd.SecurityDescriptor).RemoveAccessRuleSpecific(ace);
                }
                else
                {
                    ((DirectorySecurity)sd.SecurityDescriptor).RemoveAccessRule(ace);
                }
            }

            return(ace);
        }
示例#11
0
 public SimpleFileSystemAccessRule(string Path, IdentityReference2 account, FileSystemRights2 access)
 {
     this.fullName     = Path;
     this.accessRights = access;
     this.identity     = account;
 }
示例#12
0
        public static IEnumerable <FileSystemAccessRule2> AddFileSystemAccessRule(string path, List <IdentityReference2> accounts, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            if (type == AccessControlType.Allow)
            {
                rights = rights | FileSystemRights2.Synchronize;
            }

            if (File.Exists(path))
            {
                var item = new FileInfo(path);
                foreach (var account in accounts)
                {
                    yield return(AddFileSystemAccessRule(item, account, rights, type, inheritanceFlags, propagationFlags));
                }
            }
            else
            {
                var item = new DirectoryInfo(path);
                foreach (var account in accounts)
                {
                    yield return(AddFileSystemAccessRule(item, account, rights, type, inheritanceFlags, propagationFlags));
                }
            }
        }
示例#13
0
        public static FileSystemAccessRule2 AddFileSystemAccessRule(FileSystemSecurity2 sd, IdentityReference2 account, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            if (type == AccessControlType.Allow)
            {
                rights = rights | FileSystemRights2.Synchronize;
            }

            FileSystemAccessRule ace = null;

            if (sd.IsFile)
            {
                ace = (FileSystemAccessRule)sd.SecurityDescriptor.AccessRuleFactory(account, (int)rights, false, InheritanceFlags.None, PropagationFlags.None, type);
                ((FileSecurity)sd.SecurityDescriptor).AddAccessRule(ace);
            }
            else
            {
                ace = (FileSystemAccessRule)sd.SecurityDescriptor.AccessRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);
                ((DirectorySecurity)sd.SecurityDescriptor).AddAccessRule(ace);
            }

            return(ace);
        }
示例#14
0
        public static FileSystemAccessRule2 AddFileSystemAccessRule(string path, IdentityReference2 account, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            if (type == AccessControlType.Allow)
            {
                rights = rights | FileSystemRights2.Synchronize;
            }

            FileSystemAccessRule ace = null;

            if (File.Exists(path))
            {
                var item = new FileInfo(path);
                ace = AddFileSystemAccessRule(item, account, rights, type, inheritanceFlags, propagationFlags);
            }
            else
            {
                var item = new DirectoryInfo(path);
                ace = AddFileSystemAccessRule(item, account, rights, type, inheritanceFlags, propagationFlags);
            }

            return(ace);
        }
 public static void RemoveFileSystemAuditRule(FileSystemInfo item, List <IdentityReference2> accounts, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removeSpecific = false)
 {
     foreach (var account in accounts)
     {
         RemoveFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags);
     }
 }
示例#16
0
        public static void RemoveFileSystemAccessRule(FileSystemInfo item, IdentityReference2 account, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removeSpecific = false)
        {
            if (type == AccessControlType.Allow)
            {
                rights = rights | FileSystemRights2.Synchronize;
            }

            FileSystemAccessRule ace = null;

            if (item as FileInfo != null)
            {
                var file = (FileInfo)item;
                var sd   = file.GetAccessControl(AccessControlSections.Access);

                ace = (FileSystemAccessRule)sd.AccessRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);
                if (removeSpecific)
                {
                    sd.RemoveAccessRuleSpecific(ace);
                }
                else
                {
                    sd.RemoveAccessRule(ace);
                }

                file.SetAccessControl(sd);
            }
            else
            {
                DirectoryInfo directory = (DirectoryInfo)item;

                var sd = directory.GetAccessControl(AccessControlSections.Access);

                ace = (FileSystemAccessRule)sd.AccessRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);
                if (removeSpecific)
                {
                    sd.RemoveAccessRuleSpecific(ace);
                }
                else
                {
                    sd.RemoveAccessRule(ace);
                }

                directory.SetAccessControl(sd);
            }
        }
 public static void RemoveFileSystemAuditRule(string path, IdentityReference2 account, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
 {
     if (File.Exists(path))
     {
         var item = new FileInfo(path);
         RemoveFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags);
     }
     else
     {
         var item = new DirectoryInfo(path);
         RemoveFileSystemAuditRule(item, account, rights, type, inheritanceFlags, propagationFlags);
     }
 }
        public static FileSystemAuditRule2 AddFileSystemAuditRule(FileSystemInfo item, IdentityReference2 account, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            var sd = new FileSystemSecurity2(item);

            var ace = AddFileSystemAuditRule(sd, account, rights, type, inheritanceFlags, propagationFlags);

            sd.Write();

            return(ace);
        }
        public static FileSystemAuditRule2 RemoveFileSystemAuditRule(FileSystemSecurity2 sd, IdentityReference2 account, FileSystemRights2 rights, AuditFlags type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, bool removeSpecific = false)
        {
            var ace = (FileSystemAuditRule)sd.SecurityDescriptor.AuditRuleFactory(account, (int)rights, false, inheritanceFlags, propagationFlags, type);

            if (sd.IsFile)
            {
                if (removeSpecific)
                {
                    ((FileSecurity)sd.SecurityDescriptor).RemoveAuditRuleSpecific(ace);
                }
                else
                {
                    ((FileSecurity)sd.SecurityDescriptor).RemoveAuditRule(ace);
                }
            }
            else
            {
                if (removeSpecific)
                {
                    ((DirectorySecurity)sd.SecurityDescriptor).RemoveAuditRuleSpecific(ace);
                }
                else
                {
                    ((DirectorySecurity)sd.SecurityDescriptor).RemoveAuditRule(ace);
                }
            }

            return(ace);
        }
示例#20
0
        public static FileSystemAccessRule2 AddFileSystemAccessRule(FileSystemInfo item, IdentityReference2 account, FileSystemRights2 rights, AccessControlType type, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags)
        {
            if (type == AccessControlType.Allow)
            {
                rights = rights | FileSystemRights2.Synchronize;
            }

            var sd = new FileSystemSecurity2(item);

            var ace = AddFileSystemAccessRule(sd, account, rights, type, inheritanceFlags, propagationFlags);

            sd.Write();

            return(ace);
        }