< Summary

Class:SharpHoundCommonLib.ActiveDirectoryRuleDescriptor
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\SecurityDescriptor.cs
Covered lines:29
Uncovered lines:0
Coverable lines:29
Total lines:102
Line coverage:100% (29 of 29)
Covered branches:10
Total branches:10
Branch coverage:100% (10 of 10)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%10100%
AccessControlType()100%10100%
IdentityReference()100%10100%
IsInherited()100%10100%
IsAceInheritedFrom(...)100%100100%
ActiveDirectoryRights()100%10100%
ObjectType()100%10100%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\SecurityDescriptor.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.DirectoryServices;
 4using System.Security.AccessControl;
 5using SharpHoundCommonLib.Processors;
 6
 7namespace SharpHoundCommonLib
 8{
 9    public class ActiveDirectoryRuleDescriptor
 10    {
 11        private readonly ActiveDirectoryAccessRule _inner;
 12
 8713        public ActiveDirectoryRuleDescriptor(ActiveDirectoryAccessRule inner)
 8714        {
 8715            _inner = inner;
 8716        }
 17
 18        public virtual AccessControlType AccessControlType()
 3819        {
 3820            return _inner.AccessControlType;
 3821        }
 22
 23        public virtual string IdentityReference()
 3324        {
 3325            return _inner.IdentityReference.Value;
 3326        }
 27
 28        public virtual bool IsInherited()
 2529        {
 2530            return _inner.IsInherited;
 2531        }
 32
 33        public virtual bool IsAceInheritedFrom(string guid)
 3834        {
 35            //Check if the ace is inherited
 3836            var isInherited = _inner.IsInherited;
 37
 38            //The inheritedobjecttype needs to match the guid of the object type being enumerated or the guid for All
 3839            var inheritedType = _inner.InheritedObjectType.ToString();
 3840            isInherited = isInherited && (inheritedType == ACEGuids.AllGuid || inheritedType == guid);
 41
 42            //Special case for Exchange
 43            //If the ACE is not Inherited and is not an inherit-only ace, then it's set by exchange for reasons
 3844            if (!isInherited &&
 3845                (_inner.PropagationFlags & PropagationFlags.InheritOnly) != PropagationFlags.InheritOnly &&
 3846                !_inner.IsInherited)
 2647                isInherited = true;
 48
 3849            return isInherited;
 3850        }
 51
 52        public virtual ActiveDirectoryRights ActiveDirectoryRights()
 2553        {
 2554            return _inner.ActiveDirectoryRights;
 2555        }
 56
 57        public virtual Guid ObjectType()
 2558        {
 2559            return _inner.ObjectType;
 2560        }
 61    }
 62
 63    public class ActiveDirectorySecurityDescriptor
 64    {
 65        private readonly ActiveDirectorySecurity _sd;
 66
 67        public ActiveDirectorySecurityDescriptor(ActiveDirectorySecurity sd)
 68        {
 69            _sd = sd;
 70        }
 71
 72        public virtual bool AreAccessRulesProtected()
 73        {
 74            return _sd.AreAccessRulesProtected;
 75        }
 76
 77        public virtual List<ActiveDirectoryRuleDescriptor> GetAccessRules(bool includeExplicit, bool includeInherited,
 78            Type targetType)
 79        {
 80            var result = new List<ActiveDirectoryRuleDescriptor>();
 81            foreach (ActiveDirectoryAccessRule ace in _sd.GetAccessRules(includeExplicit, includeInherited, targetType))
 82                result.Add(new ActiveDirectoryRuleDescriptor(ace));
 83
 84            return result;
 85        }
 86
 87        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm)
 88        {
 89            _sd.SetSecurityDescriptorBinaryForm(binaryForm);
 90        }
 91
 92        public virtual void SetSecurityDescriptorBinaryForm(byte[] binaryForm, AccessControlSections type)
 93        {
 94            _sd.SetSecurityDescriptorBinaryForm(binaryForm, type);
 95        }
 96
 97        public virtual string GetOwner(Type targetType)
 98        {
 99            return _sd.GetOwner(targetType).Value;
 100        }
 101    }
 102}