Skip to content

Commit

Permalink
fix: set collected correctly for domains
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jan 18, 2024
1 parent 17f6f6d commit cf35034
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/BaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -64,6 +65,8 @@ public void UpdateLoopTime()
CurrentLoopTime = $"{DateTime.Now:yyyyMMddHHmmss}";
}

public HashSet<string> CollectedDomainSids { get; } = new();

public async Task DoDelay()
{
if (Throttle == 0)
Expand Down
1 change: 1 addition & 0 deletions src/Client/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ public interface IContext
string ResolveFileName(string filename, string extension, bool addTimestamp);
EnumerationDomain[] Domains { get; set; }
void UpdateLoopTime();
public HashSet<string> CollectedDomainSids { get; }
}
}
11 changes: 2 additions & 9 deletions src/Producers/LdapProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override async Task Produce()

foreach (var domain in Context.Domains)
{
Context.Logger.LogInformation("Beginning LDAP search for {Domain}", domain);
Context.Logger.LogInformation("Beginning LDAP search for {Domain}", domain.Name);
//Do a basic LDAP search and grab results
var successfulConnect = false;
try
Expand All @@ -64,14 +64,7 @@ public override async Task Produce()
continue;
}

await OutputChannel.Writer.WriteAsync(new Domain
{
ObjectIdentifier = domain.DomainSid,
Properties = new Dictionary<string, object>
{
{ "collected", true },
}
});
Context.CollectedDomainSids.Add(domain.DomainSid);

foreach (var searchResult in Context.LDAPUtils.QueryLDAP(ldapData.Filter.GetFilter(), SearchScope.Subtree,
ldapData.Props.Distinct().ToArray(), cancellationToken, domain.Name,
Expand Down
5 changes: 5 additions & 0 deletions src/Runtime/LDAPConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ internal static async Task ConsumeSearchResults(Channel<ISearchResultEntry> inpu
watch.Elapsed.TotalMilliseconds, res.DisplayName);
if (processed == null)
continue;

if (processed is Domain d && context.CollectedDomainSids.Contains(d.ObjectIdentifier))
{
d.Properties.Add("collected", true);
}
await outputChannel.Writer.WriteAsync(processed);
}
catch (Exception e)
Expand Down

0 comments on commit cf35034

Please sign in to comment.