Exemple #1
0
        private async Task <LdapBindResponse> OnBindAsync(LdapBindRequest request, LdapClientConnection connection)
        {
            ResultCode result = ResultCode.AuthMethodNotSupported;

            if (request.Simple != null)
            {
                result = await OnBindAsync(request.Name, request.Simple.Value, connection).ConfigureAwait(false);
            }
            else if (request.SaslMechanism == SupportedSASLMechanismsAttribute.Anonymous)
            {
                var credentials = request.SaslCredentials.GetValueOrDefault(ReadOnlyMemory <byte> .Empty);
                result = await OnSaslBindAsync(request.Name, String.Empty, credentials, connection).ConfigureAwait(false);
            }
            else if (request.SaslMechanism == SupportedSASLMechanismsAttribute.Plain)
            {
                if (request.SaslCredentials == null)
                {
                    result = ResultCode.InappropriateAuthentication;
                }
                else
                {
                    var credentials = request.SaslCredentials.Value;
                    var first       = credentials.Span.IndexOf((byte)0);
                    var last        = credentials.Span.LastIndexOf((byte)0);
                    if (first == last)
                    {
                        result = ResultCode.InappropriateAuthentication;
                    }
                    else
                    {
                        first++;
                        var user     = Encoding.UTF8.GetString(credentials.Slice(first, last - first).Span);
                        var password = credentials.Slice(last + 1);
                        result = await OnSaslBindAsync(request.Name, user, password, connection).ConfigureAwait(false);
                    }
                }
            }
            switch (result)
            {
            case ResultCode.Other:
                return(request.Response(result, "Not implemented"));

            case ResultCode.Success:
                return(request.Response());

            default:
                return(request.Response(result, String.Empty));
            }
        }
Exemple #2
0
 private Task <LdapBindResponse> BindRequestAsync(LdapBindRequest request, LdapClientConnection connection)
 {
     if (request.Version != 3)
     {
         return(Task.FromResult(request.Response(ResultCode.ProtocolError, "only version 3 is supported")));
     }
     if (!CriticalControlsSupported(request.Controls))
     {
         return(Task.FromResult(request.Response(ResultCode.UnavailableCriticalExtension, String.Empty)));
     }
     if (request.Simple.HasValue && request.Simple.Value.Length == 0 && request.Name.RDNs.Count > 0)
     {
         //https://tools.ietf.org/html/rfc4513#section-5.1.2
         return(Task.FromResult(request.Response(ResultCode.UnwillingToPerform, "Unauthenticated Bind")));
     }
     if (request.SaslMechanism != null && request.SaslMechanism.Length == 0)
     {
         return(Task.FromResult(request.Response(ResultCode.AuthMethodNotSupported, "SASL aborted")));
     }
     return(OnBindAsync(request, connection));
 }