Skip to content

Commit

Permalink
chore: add disposable to ldap utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 2, 2024
1 parent ddeb003 commit 2bf6ee4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
12 changes: 0 additions & 12 deletions src/CommonLib/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ internal static bool GetMachineSid(string key, out string value)
return false;
}

internal static void AddConvertedValue(string key, string value)
{
CacheInstance?.ValueToIdCache.TryAdd(key, value);
}

internal static void AddPrefixedValue(string key, string domain, string value)
{
CacheInstance?.ValueToIdCache.TryAdd(GetPrefixKey(key, domain), value);
Expand All @@ -112,13 +107,6 @@ internal static bool GetGCCache(string key, out string[] value)
return false;
}

internal static bool GetConvertedValue(string key, out string value)
{
if (CacheInstance != null) return CacheInstance.ValueToIdCache.TryGetValue(key, out value);
value = null;
return false;
}

internal static bool GetPrefixedValue(string key, string domain, out string value)
{
if (CacheInstance != null)
Expand Down
3 changes: 2 additions & 1 deletion src/CommonLib/ILdapUtils.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using SharpHoundCommonLib.OutputTypes;

namespace SharpHoundCommonLib {
public interface ILdapUtils {
public interface ILdapUtils : IDisposable {
IAsyncEnumerable<LdapResult<ISearchResultEntry>> Query(LdapQueryParameters queryParameters,
CancellationToken cancellationToken = new());

Expand Down
5 changes: 5 additions & 0 deletions src/CommonLib/LdapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ public bool GetDomain(out Domain domain) {
}
}

Cache.AddGCCache(name, sids.ToArray());
return (true, sids.ToArray());
}

Expand Down Expand Up @@ -1442,5 +1443,9 @@ public void SetLdapConfig(LDAPConfig config) {
public Task<(bool Success, string Message)> TestLdapConnection(string domain) {
return _connectionPool.TestDomainConnection(domain, false);
}

public void Dispose() {
_connectionPool?.Dispose();
}
}
}

0 comments on commit 2bf6ee4

Please sign in to comment.