@@ -177,20 +177,33 @@ public static Dictionary<string, object> ReadOUProperties(IDirectoryObject entry
177177 var props = GetCommonProps ( entry ) ;
178178 return props ;
179179 }
180+
181+ public Task < GroupProperties > ReadGroupPropertiesAsync ( IDirectoryObject entry ,
182+ ResolvedSearchResult searchResult ) {
183+ return ReadGroupPropertiesAsync ( entry , searchResult . Domain ) ;
184+ }
180185
181186 /// <summary>
182187 /// Reads specific LDAP properties related to Groups
183188 /// </summary>
184189 /// <param name="entry"></param>
190+ /// <param name="domain"></param>
185191 /// <returns></returns>
186- public static Dictionary < string , object > ReadGroupProperties ( IDirectoryObject entry ) {
192+ public async Task < GroupProperties > ReadGroupPropertiesAsync ( IDirectoryObject entry , string domain )
193+ {
194+ var groupProperties = new GroupProperties ( ) ;
187195 var props = GetCommonProps ( entry ) ;
188196 entry . TryGetLongProperty ( LDAPProperties . AdminCount , out var ac ) ;
189197 props . Add ( "admincount" , ac != 0 ) ;
190198 entry . TryGetLongProperty ( LDAPProperties . GroupType , out var groupType ) ;
191199 props . Add ( "groupscope" , GetGroupScope ( groupType ) ) ;
200+ entry . TryGetByteArrayProperty ( LDAPProperties . SIDHistory , out var sh ) ;
201+ var ( sidHistoryStrings , sidHistoryPrincipals ) = await ProcessSidHistory ( sh , domain ) ;
202+ groupProperties . SidHistory = sidHistoryPrincipals ;
203+ props . Add ( "sidhistory" , sidHistoryStrings ) ;
204+ groupProperties . Props = props ;
192205
193- return props ;
206+ return groupProperties ;
194207 }
195208
196209 /// <summary>
@@ -307,25 +320,9 @@ await SendComputerStatus(new CSVComputerStatus {
307320 props . Add ( "supportedencryptiontypes" , encryptionTypes ) ;
308321
309322 entry . TryGetByteArrayProperty ( LDAPProperties . SIDHistory , out var sh ) ;
310- var sidHistoryList = new List < string > ( ) ;
311- var sidHistoryPrincipals = new List < TypedPrincipal > ( ) ;
312- foreach ( var sid in sh ) {
313- string sSid ;
314- try {
315- sSid = new SecurityIdentifier ( sid , 0 ) . Value ;
316- } catch {
317- continue ;
318- }
319-
320- sidHistoryList . Add ( sSid ) ;
321-
322- if ( await _utils . ResolveIDAndType ( sSid , domain ) is ( true , var res ) )
323- sidHistoryPrincipals . Add ( res ) ;
324- }
325-
326- userProps . SidHistory = sidHistoryPrincipals . Distinct ( ) . ToArray ( ) ;
327-
328- props . Add ( "sidhistory" , sidHistoryList . ToArray ( ) ) ;
323+ var ( sidHistoryStrings , sidHistoryPrincipals ) = await ProcessSidHistory ( sh , domain ) ;
324+ userProps . SidHistory = sidHistoryPrincipals ;
325+ props . Add ( "sidhistory" , sidHistoryStrings ) ;
329326
330327 userProps . Props = props ;
331328
@@ -424,25 +421,9 @@ await SendComputerStatus(new CSVComputerStatus {
424421 props . Add ( "operatingsystem" , os ) ;
425422
426423 entry . TryGetByteArrayProperty ( LDAPProperties . SIDHistory , out var sh ) ;
427- var sidHistoryList = new List < string > ( ) ;
428- var sidHistoryPrincipals = new List < TypedPrincipal > ( ) ;
429- foreach ( var sid in sh ) {
430- string sSid ;
431- try {
432- sSid = new SecurityIdentifier ( sid , 0 ) . Value ;
433- } catch {
434- continue ;
435- }
436-
437- sidHistoryList . Add ( sSid ) ;
438-
439- if ( await _utils . ResolveIDAndType ( sSid , domain ) is ( true , var res ) )
440- sidHistoryPrincipals . Add ( res ) ;
441- }
442-
443- compProps . SidHistory = sidHistoryPrincipals . ToArray ( ) ;
444-
445- props . Add ( "sidhistory" , sidHistoryList . ToArray ( ) ) ;
424+ var ( sidHistoryStrings , sidHistoryPrincipals ) = await ProcessSidHistory ( sh , domain ) ;
425+ compProps . SidHistory = sidHistoryPrincipals ;
426+ props . Add ( "sidhistory" , sidHistoryStrings ) ;
446427
447428 var smsaPrincipals = new List < TypedPrincipal > ( ) ;
448429 if ( entry . TryGetArrayProperty ( LDAPProperties . HostServiceAccount , out var hsa ) ) {
@@ -789,6 +770,30 @@ private static List<string> ConvertEncryptionTypes(string encryptionTypes) {
789770
790771 return supportedEncryptionTypes ;
791772 }
773+
774+ private async Task < ( string [ ] sidHistoryStrings , TypedPrincipal [ ] sidHistoryPrincipals ) >
775+ ProcessSidHistory ( byte [ ] [ ] sidHistory , string domain ) {
776+ var sidHistoryList = new List < string > ( ) ;
777+ var sidHistoryPrincipals = new List < TypedPrincipal > ( ) ;
778+
779+ if ( sidHistory == null ) return ( [ ] , [ ] ) ;
780+
781+ foreach ( var sid in sidHistory ) {
782+ string sSid ;
783+ try {
784+ sSid = new SecurityIdentifier ( sid , 0 ) . Value ;
785+ } catch {
786+ continue ;
787+ }
788+
789+ sidHistoryList . Add ( sSid ) ;
790+
791+ if ( await _utils . ResolveIDAndType ( sSid , domain ) is ( true , var res ) )
792+ sidHistoryPrincipals . Add ( res ) ;
793+ }
794+
795+ return ( sidHistoryList . ToArray ( ) , sidHistoryPrincipals . Distinct ( ) . ToArray ( ) ) ;
796+ }
792797
793798 private static string ConvertNanoDuration ( long duration ) {
794799 // In case duration is long.MinValue, Math.Abs will overflow. Value represents Forever or Never
@@ -984,6 +989,12 @@ public ParsedCertificate(byte[] rawCertificate) {
984989 }
985990 }
986991
992+ public class GroupProperties
993+ {
994+ public Dictionary < string , object > Props { get ; set ; } = new ( ) ;
995+ public TypedPrincipal [ ] SidHistory { get ; set ; } = Array . Empty < TypedPrincipal > ( ) ;
996+ }
997+
987998 public class UserProperties {
988999 public Dictionary < string , object > Props { get ; set ; } = new ( ) ;
9891000 public TypedPrincipal [ ] AllowedToDelegate { get ; set ; } = Array . Empty < TypedPrincipal > ( ) ;
0 commit comments