Beispiel #1
0
        public void SetGroupSelected()
        {
            if (_inAction)
            {
                return;
            }

            _inAction = true;

            UserInfos.Clear();

            foreach (var item in GroupInfos)
            {
                if (item.IsSelected)
                {
                    AddGroupUsers(item);
                }
            }

            _inAction = false;
        }
Beispiel #2
0
        public void SetPathSelected(FileSystemInfo info)
        {
            if (_inAction)
            {
                return;
            }

            _inAction = true;

            RuleInfos.Clear();
            UserInfos.Clear();
            GroupInfos.Clear();

            SelectedFileSystemInfo = info;

            try
            {
                AuthorizationRuleCollection rules;
                bool container = info is DirectoryInfo;

                if (container)
                {
                    DirectorySecurity security = Directory.GetAccessControl(info.FullName);
                    rules = security.GetAccessRules(true, true, typeof(NTAccount));
                }
                else
                {
                    FileSecurity security = File.GetAccessControl(info.FullName);
                    rules = security.GetAccessRules(true, true, typeof(NTAccount));
                }

                foreach (FileSystemAccessRule rule in rules)
                {
                    var  identityValue = rule.IdentityReference.Value;
                    var  principal     = Helpers.FindByIdentity(identityValue);
                    bool isGroup       = principal is GroupPrincipal; // principal.IsSecurityGroup?

                    if (principal == null)                            // user "NT AUTHORITY\"
                    {
                        continue;
                    }

                    string name = isGroup ? principal.Name : principal.SamAccountName;

                    if (Helpers.IsSystemName(isGroup, name))
                    {
                        continue;
                    }

                    bool deny    = rule.AccessControlType.HasFlag(AccessControlType.Deny);
                    bool danger  = false;
                    bool transit = false;
                    var  flags   = new StringBuilder();

                    if (deny)
                    {
                        _ = flags.Append(_rightDeny);

                        if (rule.FileSystemRights.HasFlag(FileSystemRights.Write) ||
                            rule.FileSystemRights.HasFlag(FileSystemRights.Delete) ||
                            rule.FileSystemRights.HasFlag(FileSystemRights.DeleteSubdirectoriesAndFiles))
                        {
                            _ = flags.Append(_rightWrite);
                        }
                    }
                    else
                    {
                        if (rule.FileSystemRights.HasFlag(FileSystemRights.FullControl))
                        {
                            danger = true;
                            _      = flags.Append(_rightFull);
                        }

                        if (rule.FileSystemRights.HasFlag(FileSystemRights.ReadAndExecute))
                        {
                            if (container && rule.InheritanceFlags.Equals(InheritanceFlags.None))
                            {
                                transit = true;
                                _       = flags.Append(_rightTransit);
                            }
                            else
                            {
                                _ = flags.Append(_rightRead);
                            }
                        }

                        if (rule.FileSystemRights.HasFlag(FileSystemRights.Modify) ||
                            rule.FileSystemRights.HasFlag(FileSystemRights.Delete))
                        {
                            danger = true;
                            _      = flags.Append(_rightWrite);
                        }
                    }

                    string domain = Environment.UserDomainName;

                    var ruleInfo = new RuleInfo
                    {
                        Comment       = Helpers.GetRightsEnum(rule),
                        Deny          = deny,
                        Domain        = identityValue.StartsWith(domain),
                        Flags         = flags.ToString(),
                        IsDanger      = danger,
                        IsGroup       = isGroup,
                        IsInherited   = rule.IsInherited,
                        IsSelected    = false,
                        IsTransit     = transit,
                        Principal     = principal,
                        PrincipalName = name,
                        Rule          = rule
                    };

                    RuleInfos.Add(ruleInfo);

                    //if (principal != null) // continue above
                    //{
                    AddRuleUsers(ruleInfo);
                    //}

                    if (isGroup)
                    {
                        AddNestedGroups(ruleInfo);
                    }
                }
            }
            catch { }

            _inAction = false;
        }