コード例 #1
0
 internal void RemovePending(LdapRequestMessage message)
 {
     if (_pending.TryRemove(message.Id, out var request))
     {
         request.Dispose();
     }
 }
コード例 #2
0
ファイル: LdapServer.cs プロジェクト: zivillian/ldap.net
        private async Task OnRequestAsync(LdapRequestMessage message, LdapClientConnection connection)
        {
            if (!await connection.TryAddPendingAsync(message).ConfigureAwait(false))
            {
                return;
            }
            try
            {
                if (message is LdapAbandonRequest abandon)
                {
                    connection.ContinueRead();
                    if (CriticalControlsSupported(abandon.Controls))
                    {
                        connection.AbandonRequest(abandon.MessageId);
                    }
                }
                else if (message is LdapBindRequest bind)
                {
                    connection.ContinueRead();
                    try
                    {
                        await connection.BeginBindAsync().ConfigureAwait(false);

                        var response = await BindRequestAsync(bind, connection).ConfigureAwait(false);
                        await WriteAsync(response, connection).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        await WriteAsync(bind.Response(ResultCode.Other, ex.Message), connection).ConfigureAwait(false);
                    }
                    finally
                    {
                        connection.FinishBind();
                    }
                }
                else if (message is LdapUnbindRequest)
                {
                    connection.ContinueRead();
                    UnbindRequest(connection);
                }
                else if (message is LdapSearchRequest search)
                {
                    connection.ContinueRead();
                    await SearchRequestAsync(search, connection).ConfigureAwait(false);
                }
                else if (message is LdapExtendedRequest extended)
                {
                    await ExtendedRequestAsync(extended, connection).ConfigureAwait(false);
                }
                else
                {
                    connection.ContinueRead();
                    throw new NotImplementedException();
                }
            }
            finally
            {
                connection.RemovePending(message);
            }
        }
コード例 #3
0
        private static async Task WriteLdapMessage(Socket socket, LdapRequestMessage ldap, CancellationToken cancellationToken)
        {
            var asn = ldap.GetAsn();

            using (var asnwriter = new AsnWriter(AsnEncodingRules.BER))
            {
                asn.Encode(asnwriter);
                var bytes = asnwriter.Encode();
                await socket.SendAsync(bytes, SocketFlags.None, cancellationToken);
            }
        }
コード例 #4
0
        internal async Task <bool> TryAddPendingAsync(LdapRequestMessage message)
        {
            await _bindLock.WaitAsync(CancellationToken).ConfigureAwait(false);

            try
            {
                return(_pending.TryAdd(message.Id, new LdapRequest(message, CancellationToken)));
            }
            finally
            {
                _bindLock.Release();
            }
        }
コード例 #5
0
 internal bool Add(LdapRequestMessage message)
 {
     if (message is LdapSearchResultEntry entry)
     {
         _entries.Add(entry);
         return(true);
     }
     else if (message is LdapSearchResultReference reference)
     {
         _references.Add(reference);
         return(true);
     }
     else if (message is LdapSearchResultDone)
     {
         return(false);
     }
     else
     {
         throw new LdapProtocolException($"unexpected response type '{message.GetType().FullName}'");
     }
 }
コード例 #6
0
 protected virtual LdapRequestMessage OnSendToClient(Guid clientId, LdapRequestMessage message)
 {
     return(message);
 }
コード例 #7
0
        private static LdapRequestMessage ReadLdapMessage(ReadOnlyMemory <byte> buffer)
        {
            var message = Asn1Serializer.Deserialize(buffer);

            return(LdapRequestMessage.Create(message));
        }
コード例 #8
0
ファイル: LdapReader.cs プロジェクト: zivillian/ldap.net
        public static LdapRequestMessage ReadMessage(ReadOnlyMemory <byte> source)
        {
            var message = Asn1Serializer.Deserialize(source);

            return(LdapRequestMessage.Create(message));
        }
コード例 #9
0
ファイル: LdapReader.cs プロジェクト: zivillian/ldap.net
 public static byte[] WriteMessage(LdapRequestMessage message)
 {
     return(Asn1Serializer.Serialize(message.GetAsn()));
 }
コード例 #10
0
 public LdapRequest(LdapRequestMessage request, CancellationToken cancellationToken)
 {
     Request = request;
     _cts    = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
 }