TestimoX

API Reference

Class

LdapEngine

Namespace ADPlayground.LdapEngine
Assembly ADPlayground
Implements
Modifiers sealed

Lightweight LDAP access layer with DC health tracking, quick probes, and sane defaults for timeouts/referrals/paging. Prefer this over ad-hoc DirectoryEntry/DirectorySearcher usage.

Inheritance

  • Object
  • LdapEngine

Constructors

public LdapEngine(AdxLdapOptions options) #

Creates a new instance of LdapEngine.

Parameters

options ADPlayground.LdapEngine.AdxLdapOptions requiredposition: 0
Engine options.

Methods

public Void BanDc(String dc, TimeSpan ttl) #
Returns: Void

Temporarily bans a domain controller from selection (e.g., after a timeout) for the specified TTL.

Parameters

dc System.String requiredposition: 0
Domain controller host name.
ttl System.TimeSpan requiredposition: 1
Ban duration.
public virtual DirectoryEntry CreateEntry(String domainName, String distinguishedName) #
Returns: DirectoryEntry

Creates a DirectoryEntry bound to a preferred DC, falling back to a serverless LDAP path when none is available.

Parameters

domainName System.String requiredposition: 0
DNS domain name used to pick a DC.
distinguishedName System.String requiredposition: 1
DN to bind.

Returns

Configured DirectoryEntry.

public IEnumerable<String> GetPreferredDcs(String domain) #
Returns: IEnumerable<String>

Returns domain controllers ordered by recent health observations and host policy.

Parameters

domain System.String requiredposition: 0
DNS domain name; when null or empty, returns an empty sequence.

Returns

Preferred DC names.

public Boolean IsDcBanned(String dc) #
Returns: Boolean

Returns true when a DC is currently banned by the engine.

Parameters

dc System.String requiredposition: 0
public Boolean QuickRootDsePing(String dc, Int32 timeoutMs = 1000, Boolean banOnFailure = true) #
Returns: Boolean

Quick RootDSE availability check against a specific DC with tight timeouts. Bans the DC on failure when banOnFailure is true.

Parameters

dc System.String requiredposition: 0
Domain controller host name.
timeoutMs System.Int32 = 1000 optionalposition: 1
Overall timeout budget in milliseconds.
banOnFailure System.Boolean = true optionalposition: 2
When true, bans the DC for a short period on failure.

Returns

True when the DC responds to a rootDSE query or quick ping.

public IEnumerable<SearchResult> SearchAnyDc(String domain, String baseDn, String filter, String[] propertiesToLoad, SearchScope scope = Subtree, Int32 pageSize = 1000, Int32 attemptTimeoutMs = 0, Nullable<Int32> maxBatch = null, Boolean suppressNotFound = false, Int32 sizeLimit = 0, SecurityMasks securityMasks = None) #
Returns: IEnumerable<SearchResult>

Searches across preferred DCs and returns the first successful result set. Uses pre-probes and small concurrent batches to avoid hammering unhealthy DCs.

Parameters

domain System.String requiredposition: 0
DNS domain name.
baseDn System.String requiredposition: 1
Base distinguished name.
filter System.String requiredposition: 2
RFC 2254 LDAP filter.
propertiesToLoad System.String[] requiredposition: 3
Attributes to request.
scope System.DirectoryServices.SearchScope = Subtree optionalposition: 4
Search scope (default Subtree).
pageSize System.Int32 = 1000 optionalposition: 5
Page size (default 1000).
attemptTimeoutMs System.Int32 = 0 optionalposition: 6
Per‑attempt timeout used for probes and search (ms). Default derives from host policy.
maxBatch System.Nullable{System.Int32} = null optionalposition: 7
Max concurrent DCs per batch.
suppressNotFound System.Boolean = false optionalposition: 8
When true, suppresses LDAP_NO_SUCH_OBJECT warnings for missing bases and returns an empty set.
sizeLimit System.Int32 = 0 optionalposition: 9
Optional server-side size limit (0 = no limit).
securityMasks System.DirectoryServices.SecurityMasks = None optionalposition: 10
Security masks to request (e.g., Owner).

Returns

First successful set of results (may be empty).

public virtual IEnumerable<SearchResult> SearchDomain(String domainName, String baseDn, String filter, String[] propertiesToLoad, SearchScope scope = Subtree, Int32 pageSize = 1000, CancellationToken cancellationToken = null, Int32 sizeLimit = 0, SecurityMasks securityMasks = None) #
Returns: IEnumerable<SearchResult>

Searches a domain by racing a small batch of DCs, then falling back to guarded sequential attempts.

Parameters

domainName System.String requiredposition: 0
DNS domain name.
baseDn System.String requiredposition: 1
Base distinguished name.
filter System.String requiredposition: 2
RFC 2254 LDAP filter.
propertiesToLoad System.String[] requiredposition: 3
Attributes to request.
scope System.DirectoryServices.SearchScope = Subtree optionalposition: 4
Search scope (default Subtree).
pageSize System.Int32 = 1000 optionalposition: 5
Page size (default 1000).
cancellationToken System.Threading.CancellationToken = null optionalposition: 6
Cancellation token.
sizeLimit System.Int32 = 0 optionalposition: 7
Optional server-side size limit (0 = no limit).
securityMasks System.DirectoryServices.SecurityMasks = None optionalposition: 8
Security masks to request (e.g., Owner).

Returns

Results from the first healthy DC, or empty when none succeed within budget.

public virtual Task<IEnumerable<SearchResult>> SearchDomainAsync(String domainName, String baseDn, String filter, String[] propertiesToLoad, SearchScope scope = Subtree, Int32 pageSize = 1000, CancellationToken cancellationToken = null, Int32 sizeLimit = 0, SecurityMasks securityMasks = None) #
Returns: Task<IEnumerable<SearchResult>>

Asynchronously searches a domain by racing a small batch of DCs, then falling back to guarded sequential attempts.

Parameters

domainName System.String requiredposition: 0
DNS domain name.
baseDn System.String requiredposition: 1
Base distinguished name.
filter System.String requiredposition: 2
RFC 2254 LDAP filter.
propertiesToLoad System.String[] requiredposition: 3
Attributes to request.
scope System.DirectoryServices.SearchScope = Subtree optionalposition: 4
Search scope (default Subtree).
pageSize System.Int32 = 1000 optionalposition: 5
Page size (default 1000).
cancellationToken System.Threading.CancellationToken = null optionalposition: 6
Cancellation token.
sizeLimit System.Int32 = 0 optionalposition: 7
Optional server-side size limit (0 = no limit).
securityMasks System.DirectoryServices.SecurityMasks = None optionalposition: 8
Security masks to request (e.g., Owner).

Returns

Results from the first healthy DC, or empty when none succeed within budget.

public virtual IEnumerable<SearchResult> SearchOnDc(String dc, String baseDn, String filter, String[] propertiesToLoad, SearchScope scope = Subtree, Int32 pageSize = 1000, CancellationToken cancellationToken = null, Boolean suppressNotFound = false, Int32 sizeLimit = 0, SecurityMasks securityMasks = None) #
Returns: IEnumerable<SearchResult>

Executes a search against a specific DC with paging and configured timeouts.

Parameters

dc System.String requiredposition: 0
Domain controller host name.
baseDn System.String requiredposition: 1
Base distinguished name for the search.
filter System.String requiredposition: 2
RFC 2254 LDAP filter.
propertiesToLoad System.String[] requiredposition: 3
Attributes to request.
scope System.DirectoryServices.SearchScope = Subtree optionalposition: 4
Search scope (default Subtree).
pageSize System.Int32 = 1000 optionalposition: 5
Page size (default 1000).
cancellationToken System.Threading.CancellationToken = null optionalposition: 6
Cancellation token.
suppressNotFound System.Boolean = false optionalposition: 7
When true, suppresses LDAP_NO_SUCH_OBJECT warnings for missing bases and returns an empty set.
sizeLimit System.Int32 = 0 optionalposition: 8
Optional server-side size limit (0 = no limit).
securityMasks System.DirectoryServices.SecurityMasks = None optionalposition: 9
Security masks to request (e.g., Owner).

Returns

Streamed SearchResult records.

Properties

public static LdapEngine Current { get; } #

Singleton instance configured with Default.

public virtual AdxLdapOptions Options { get; } #

Engine options controlling paging, timeouts, and referral behavior.

Extension Methods

public static DirectorySearcher CreateRootSearcher(LdapEngine engine, String domainName, String filter, Int32 pageSize = 1000) #
Returns: DirectorySearcher

Creates a DirectorySearcher at the domain root with engine defaults.

Parameters

engine ADPlayground.LdapEngine.LdapEngine requiredposition: 0
LDAP engine.
domainName System.String requiredposition: 1
DNS domain name.
filter System.String requiredposition: 2
RFC 2254 LDAP filter.
pageSize System.Int32 = 1000 optionalposition: 3
Page size (default 1000).

Returns

Configured DirectorySearcher.

public static DirectorySearcher CreateSearcher(LdapEngine engine, String domainName, String distinguishedName, String filter, SearchScope scope = Subtree, Int32 pageSize = 1000) #
Returns: DirectorySearcher

Creates a DirectorySearcher rooted at the specified DN on a preferred DC with engine timeouts/referrals/page size.

Parameters

engine ADPlayground.LdapEngine.LdapEngine requiredposition: 0
LDAP engine.
domainName System.String requiredposition: 1
DNS domain name (chooses DC).
distinguishedName System.String requiredposition: 2
Base DN for the search.
filter System.String requiredposition: 3
RFC 2254 LDAP filter.
scope System.DirectoryServices.SearchScope = Subtree optionalposition: 4
Search scope (default Subtree).
pageSize System.Int32 = 1000 optionalposition: 5
Page size (default 1000).

Returns

Configured DirectorySearcher.