private async Task SearchRequestAsync(LdapSearchRequest request, LdapClientConnection connection, CancellationToken cancellationToken) { try { if (request.BaseObject.RDNs.Count == 0 && request.Scope == SearchScope.BaseObject && request.Filter is LdapPresentFilter filter && (filter.Attribute.Oid.Equals("objectClass", StringComparison.OrdinalIgnoreCase) || filter.Attribute.Oid == "2.5.4.0")) { ICollection <LdapAttribute> attributes = _rootDse.GetAttributes(request.Attributes, request.TypesOnly).ToList(); if (_sslOptions != null && request.Attributes.Where(x => x.Selector != null).Any(x => x.Selector.Oid == SupportedExtensionAttribute.OidValue || x.Selector.Oid == SupportedExtensionAttribute.ShortName)) { var attribute = attributes.OfType <SupportedExtensionAttribute>().FirstOrDefault(); if (attribute == null) { attribute = new SupportedExtensionAttribute { Entries = { LdapExtendedRequest.StartTLS } }; attributes.Add(attribute); } else { attribute.Entries.Add(LdapExtendedRequest.StartTLS); } } attributes = await OnGetRootDSEAsync(attributes, connection, cancellationToken).ConfigureAwait(false); var entry = request.Result(LdapDistinguishedName.Empty, attributes.ToArray(), Array.Empty <LdapControl>()); await WriteAsync(entry, connection).ConfigureAwait(false); await WriteAsync(request.Done(), connection).ConfigureAwait(false); } else { var results = await OnSearchAsync(request, connection, cancellationToken).ConfigureAwait(false); bool done = false; foreach (var response in results) { await WriteAsync(response, connection).ConfigureAwait(false); if (response is LdapSearchResultDone) { done = true; break; } } if (!done) { await WriteAsync(request.Done(), connection).ConfigureAwait(false); } } }
private async Task SearchRequestAsync(LdapSearchRequest request, LdapClientConnection connection) { if (request.TimeLimit != TimeSpan.Zero) { using (var cts = new CancellationTokenSource(request.TimeLimit)) using (var combined = CancellationTokenSource.CreateLinkedTokenSource(connection.CancellationToken, cts.Token)) { await SearchRequestAsync(request, connection, combined.Token).ConfigureAwait(false); } } else { await SearchRequestAsync(request, connection, connection.CancellationToken).ConfigureAwait(false); } }
protected virtual Task <IEnumerable <LdapRequestMessage> > OnSearchAsync(LdapSearchRequest request, LdapClientConnection connection, CancellationToken cancellationToken) { return(Task.FromResult(Enumerable.Empty <LdapRequestMessage>())); }