< Summary

Class:SharpHoundRPC.Wrappers.SAMDomain
Assembly:SharpHoundRPC
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\SharpHoundRPC\Wrappers\SAMDomain.cs
Covered lines:0
Uncovered lines:32
Coverable lines:32
Total lines:63
Line coverage:0% (0 of 32)
Covered branches:0
Total branches:12
Branch coverage:0% (0 of 12)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%100%
LookupPrincipalByRid(...)0%200%
GetAliases()0%200%
OpenAlias(...)0%200%
OpenAlias(...)0%600%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\SharpHoundRPC\Wrappers\SAMDomain.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using SharpHoundRPC.Handles;
 5using SharpHoundRPC.SAMRPCNative;
 6using SharpHoundRPC.Shared;
 7
 8namespace SharpHoundRPC.Wrappers
 9{
 10    public class SAMDomain : SAMBase, ISAMDomain
 11    {
 012        public SAMDomain(SAMHandle handle) : base(handle)
 013        {
 014        }
 15
 16        public Result<(string Name, SharedEnums.SidNameUse Type)> LookupPrincipalByRid(int rid)
 017        {
 018            var (status, namePointer, usePointer) = SAMMethods.SamLookupIdsInDomain(Handle, rid);
 19
 020            if (status.IsError()) return status;
 21
 022            return (namePointer.GetData<SharedStructs.UnicodeString>().ToString(),
 023                (SharedEnums.SidNameUse) usePointer.GetData<int>());
 024        }
 25
 26        public Result<IEnumerable<(string Name, int Rid)>> GetAliases()
 027        {
 028            var (status, ridPointer, count) = SAMMethods.SamEnumerateAliasesInDomain(Handle);
 29
 030            if (status.IsError())
 031            {
 032                return status;
 33            }
 34
 035            var ret = Result<IEnumerable<(string Name, int Rid)>>.Ok(ridPointer
 036                .GetEnumerable<SAMStructs.SamRidEnumeration>(count)
 037                .Select(x => (x.Name.ToString(), x.Rid)));
 38
 039            return ret;
 040        }
 41
 42        public Result<ISAMAlias> OpenAlias(int rid,
 43            SAMEnums.AliasOpenFlags desiredAccess = SAMEnums.AliasOpenFlags.ListMembers)
 044        {
 045            var (status, aliasHandle) = SAMMethods.SamOpenAlias(Handle, desiredAccess, rid);
 046            if (status.IsError()) return status;
 47
 048            return new SAMAlias(aliasHandle);
 049        }
 50
 51        public Result<ISAMAlias> OpenAlias(string name)
 052        {
 053            var getAliasesResult = GetAliases();
 054            if (getAliasesResult.IsFailed) return getAliasesResult.Status;
 55
 056            foreach (var alias in getAliasesResult.Value)
 057                if (alias.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
 058                    return OpenAlias(alias.Rid);
 59
 060            return $"Alias {name} was not found";
 061        }
 62    }
 63}