コード例 #1
0
        private void RecurseDirectories(string path)
        {
            try
            {
                List <string> directories = Directory.GetDirectories(path).ToList();

                foreach (string directory in directories)
                {
                    _folders.Insert(0, directory);
                    UpdateFoldersIdentifiedCount();
                    UpdateFolersLeftToProcessCount();

                    RecurseDirectories(directory);
                }
            }
            catch (UnauthorizedAccessException exc)
            {
                if (_getFileDetails)
                {
                    FileDetails details = new FileDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path  = path;
                    SaveFileDetailsToFile(details);
                }
                else if (_getFolderSecurityDetails)
                {
                    FolderSecurityDetails details = new FolderSecurityDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path  = path;
                    SaveFolderSecurityDetailsToFile(details);
                }
            }
        }
コード例 #2
0
 private void SaveFolderSecurityDetailsToFile(FolderSecurityDetails details)
 {
     using (StreamWriter writer = File.AppendText(_outputFileName))
     {
         writer.WriteLine(details.ToCsvFormattedString());
     }
 }
コード例 #3
0
        private void GetFolderSecurityDetails(string path)
        {
            DirectorySecurity dirSec = null;

            try
            {
                dirSec = Directory.GetAccessControl(path);
            }
            catch (UnauthorizedAccessException exc)
            {
                FolderSecurityDetails details = new FolderSecurityDetails()
                {
                    Path  = path,
                    Error = "Unauthroized Access Exception"
                };

                SaveFolderSecurityDetailsToFile(details);
                return;
            }

            AuthorizationRuleCollection authColl = dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

            foreach (AuthorizationRule authRule in authColl)
            {
                AccessRule accessRule = authRule as AccessRule;

                FolderSecurityDetails details = new FolderSecurityDetails()
                {
                    Path = path,
                    IdentityReference = accessRule.IdentityReference.Value,
                    InheritanceFlags  = accessRule.InheritanceFlags.ToString(),
                    IsInherited       = accessRule.IsInherited,
                    PropagationFlags  = accessRule.PropagationFlags.ToString(),
                    AccessControlType = accessRule.AccessControlType.ToString()
                };

                SaveFolderSecurityDetailsToFile(details);
            }
        }
コード例 #4
0
        private void RecurseDirectories(string path)
        {
            try
            {

                List<string> directories = Directory.GetDirectories(path).ToList();

                foreach (string directory in directories)
                {
                    _folders.Insert(0, directory);
                    UpdateFoldersIdentifiedCount();
                    UpdateFolersLeftToProcessCount();
                    
                    RecurseDirectories(directory);
                }
            }
            catch (UnauthorizedAccessException exc)
            {
                if (_getFileDetails)
                {
                    FileDetails details = new FileDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path = path;
                    SaveFileDetailsToFile(details);
                }
                else if (_getFolderSecurityDetails)
                {
                    FolderSecurityDetails details = new FolderSecurityDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path = path;
                    SaveFolderSecurityDetailsToFile(details);
                }
            }
        }
コード例 #5
0
 private void SaveFolderSecurityDetailsToFile(FolderSecurityDetails details)
 {
     using (StreamWriter writer = File.AppendText(_outputFileName))
     {
         writer.WriteLine(details.ToCsvFormattedString());
     }
 }
コード例 #6
0
        private void GetFolderSecurityDetails(string path)
        {
            DirectorySecurity dirSec = null;

            try
            {
                dirSec = Directory.GetAccessControl(path);
            }
            catch (UnauthorizedAccessException exc)
            {
                FolderSecurityDetails details = new FolderSecurityDetails()
                {
                    Path = path,
                    Error = "Unauthroized Access Exception"
                };

                SaveFolderSecurityDetailsToFile(details);
                return;
            }

            AuthorizationRuleCollection authColl = dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

            foreach (AuthorizationRule authRule in authColl)
            {
                AccessRule accessRule = authRule as AccessRule;

                FolderSecurityDetails details = new FolderSecurityDetails()
                {
                    Path = path,
                    IdentityReference = accessRule.IdentityReference.Value,
                    InheritanceFlags = accessRule.InheritanceFlags.ToString(),
                    IsInherited = accessRule.IsInherited,
                    PropagationFlags = accessRule.PropagationFlags.ToString(),
                    AccessControlType = accessRule.AccessControlType.ToString()
                };

                SaveFolderSecurityDetailsToFile(details);
            }
        }