diff --git a/src/CommonLib/LdapUtils.cs b/src/CommonLib/LdapUtils.cs index 17293d3b..5eabc54e 100644 --- a/src/CommonLib/LdapUtils.cs +++ b/src/CommonLib/LdapUtils.cs @@ -168,8 +168,9 @@ public IAsyncEnumerable> PagedQuery(LdapQueryParame //pass } - using (var ctx = new PrincipalContext(ContextType.Domain)) { - try { + + try { + using (var ctx = new PrincipalContext(ContextType.Domain)) { var principal = Principal.FindByIdentity(ctx, IdentityType.Sid, sid); if (principal != null) { var entry = ((DirectoryEntry)principal.GetUnderlyingObject()).ToDirectoryObject(); @@ -178,11 +179,12 @@ public IAsyncEnumerable> PagedQuery(LdapQueryParame return (true, type); } } - } catch { - //pass } + } catch { + //pass } + return (false, Label.Base); } @@ -212,8 +214,9 @@ public IAsyncEnumerable> PagedQuery(LdapQueryParame //pass } - using (var ctx = new PrincipalContext(ContextType.Domain)) { - try { + + try { + using (var ctx = new PrincipalContext(ContextType.Domain)) { var principal = Principal.FindByIdentity(ctx, IdentityType.Guid, guid); if (principal != null) { var entry = ((DirectoryEntry)principal.GetUnderlyingObject()).ToDirectoryObject(); @@ -222,9 +225,9 @@ public IAsyncEnumerable> PagedQuery(LdapQueryParame return (true, type); } } - } catch { - //pass } + } catch { + //pass } return (false, Label.Base); @@ -345,8 +348,9 @@ public IAsyncEnumerable> PagedQuery(LdapQueryParame return (true, domainName); } - using (var ctx = new PrincipalContext(ContextType.Domain)) { - try { + + try { + using (var ctx = new PrincipalContext(ContextType.Domain)) { var principal = Principal.FindByIdentity(ctx, IdentityType.Sid, sid); if (principal != null) { var dn = principal.DistinguishedName; @@ -355,9 +359,9 @@ public IAsyncEnumerable> PagedQuery(LdapQueryParame return (true, Helpers.DistinguishedNameToDomain(dn)); } } - } catch { - //pass } + } catch { + //pass } return (false, string.Empty); @@ -877,8 +881,9 @@ public async Task IsDomainController(string computerObjectId, string domai return (true, principal); } - using (var ctx = new PrincipalContext(ContextType.Domain)) { - try { + + try { + using (var ctx = new PrincipalContext(ContextType.Domain)) { var lookupPrincipal = Principal.FindByIdentity(ctx, IdentityType.DistinguishedName, distinguishedName); if (lookupPrincipal != null) { @@ -895,11 +900,11 @@ public async Task IsDomainController(string computerObjectId, string domai } } - return (false, default); - } catch { - _unresolvablePrincipals.Add(distinguishedName); return (false, default); } + } catch { + _unresolvablePrincipals.Add(distinguishedName); + return (false, default); } }