Exemple #1
0
 public LdapBindRequest(int messageId, string dn, string password, LdapControl[] controls)
     : base(messageId, controls)
 {
     Version = 3;
     Name    = new LdapDistinguishedName(dn);
     Simple  = password.LdapString();
 }
 public LdapSearchRequest(int messageId, string baseDn, SearchScope scope, string filter, string[] attributes, bool attributesOnly, TimeSpan timeout, int sizeLimit, LdapControl[] controls)
     : base(messageId, controls)
 {
     if (timeout < TimeSpan.Zero)
     {
         throw new LdapProtocolException("invalid timeLimit");
     }
     if (sizeLimit < 0)
     {
         throw new LdapProtocolException("invalid sizeLimit");
     }
     BaseObject = new LdapDistinguishedName(baseDn);
     Scope      = scope;
     Filter     = LdapFilter.Parse(filter);
     if (attributes != null && attributes.Length > 0)
     {
         var ldapAttributes = new LdapAttributeSelection[attributes.Length];
         for (int i = 0; i < attributes.Length; i++)
         {
             ldapAttributes[i] = new LdapAttributeSelection(attributes[i]);
         }
         Attributes = ldapAttributes;
     }
     else
     {
         Attributes = Array.Empty <LdapAttributeSelection>();
     }
     TypesOnly = attributesOnly;
     TimeLimit = timeout;
     SizeLimit = sizeLimit;
 }
 internal LdapResponseMessage(Asn1LDAPResult result, Asn1LdapMessage message)
     : base(message)
 {
     ResultCode        = result.ResultCode;
     MatchedDN         = new LdapDistinguishedName(result.MatchedDN.Span);
     DiagnosticMessage = result.DiagnosticMessage.Span.LdapString();
     Referrals         = this.GetReferrals(result.Referral);
 }
 internal LdapBindResponse(int id, ResultCode resultCode, LdapDistinguishedName matchedDN, string message, string[] referrals)
     : base(id, Array.Empty <LdapControl>())
 {
     ResultCode        = resultCode;
     MatchedDN         = matchedDN;
     DiagnosticMessage = message;
     Referrals         = referrals;
 }
Exemple #5
0
        internal LdapCompareRequest(Asn1LdapMessage message)
            : base(message)
        {
            var compare = message.ProtocolOp.CompareRequest;

            Entry     = new LdapDistinguishedName(compare.Entry.Span);
            Assertion = new LdapAttributeAssertion(compare.Assertion);
        }
Exemple #6
0
 public LdapBindRequest(int messageId, string dn, string mechanism, ReadOnlyMemory <byte> credentials, LdapControl[] controls)
     : base(messageId, controls)
 {
     Version         = 3;
     Name            = new LdapDistinguishedName(dn);
     SaslMechanism   = mechanism;
     SaslCredentials = credentials;
 }
 internal LdapResponseMessage(int messageId, ResultCode resultCode, LdapDistinguishedName matchedDN,
                              string message, string[] referrals, LdapControl[] controls)
     : base(messageId, controls)
 {
     ResultCode        = resultCode;
     MatchedDN         = matchedDN;
     DiagnosticMessage = message;
     Referrals         = referrals;
 }
Exemple #8
0
        public LdapDistinguishedName(LdapRelativeDistinguishedName rdn, LdapDistinguishedName parent)
        {
            var rdns = new LdapRelativeDistinguishedName[parent.RDNs.Count + 1];

            rdns[0] = rdn;
            for (int i = 0; i < parent.RDNs.Count; i++)
            {
                rdns[i + 1] = parent.RDNs[i];
            }
            RDNs = rdns;
        }
        internal LdapBindResponse(Asn1LdapMessage message)
            : base(message)
        {
            var bindResponse = message.ProtocolOp.BindResponse;

            ResultCode        = bindResponse.ResultCode;
            MatchedDN         = new LdapDistinguishedName(bindResponse.MatchedDN.Span);
            DiagnosticMessage = bindResponse.DiagnosticMessage.Span.LdapString();
            Referrals         = this.GetReferrals(bindResponse.Referral);
            ServerSaslCreds   = bindResponse.ServerSaslCreds;
        }
Exemple #10
0
        internal LdapModifyDNRequest(Asn1LdapMessage message) : base(message)
        {
            var modify = message.ProtocolOp.ModifyDNRequest;

            Entry        = new LdapDistinguishedName(modify.Entry.Span);
            NewRDN       = new LdapRelativeDistinguishedName(modify.NewRDN.Span.LdapString());
            DeleteOldRDN = modify.DeleteOldRDN;
            if (modify.NewSuperior.HasValue)
            {
                NewSuperior = new LdapDistinguishedName(modify.NewSuperior.Value.Span);
            }
        }
Exemple #11
0
        internal LdapModifyRequest(Asn1LdapMessage message)
            : base(message)
        {
            var modify = message.ProtocolOp.ModifyRequest;

            ObjectDN = new LdapDistinguishedName(modify.Object.Span);
            var changes = new LdapChange[modify.Changes.Length];

            for (int i = 0; i < modify.Changes.Length; i++)
            {
                changes[i] = new LdapChange(modify.Changes[i]);
            }
            Changes = changes;
        }
Exemple #12
0
        internal LdapExtendedResponse(Asn1LdapMessage message)
            : base(message)
        {
            var extended = message.ProtocolOp.ExtendedResponse;

            ResultCode        = extended.ResultCode;
            MatchedDN         = new LdapDistinguishedName(extended.MatchedDN.Span);
            DiagnosticMessage = extended.DiagnosticMessage.Span.LdapString();
            Referrals         = this.GetReferrals(extended.Referral);
            if (extended.Name.HasValue)
            {
                Name = extended.Name.Value.Span.NumericOid();
            }
            Value = extended.Value;
        }
Exemple #13
0
        internal LdapAddRequest(Asn1LdapMessage message)
            : base(message)
        {
            var add = message.ProtocolOp.AddRequest;

            Entry = new LdapDistinguishedName(add.Entry.Span);
            if (add.Attributes.Length == 0)
            {
                throw new ArgumentException("at least one attribute required");
            }
            var attributes = new LdapAttribute[add.Attributes.Length];

            for (int i = 0; i < add.Attributes.Length; i++)
            {
                attributes[i] = new LdapAttribute(add.Attributes[i]);
            }
            Attributes = attributes;
        }
        internal LdapSearchRequest(Asn1LdapMessage message)
            : base(message)
        {
            var search = message.ProtocolOp.SearchRequest;

            BaseObject   = new LdapDistinguishedName(search.BaseObject.Span);
            Scope        = search.Scope;
            DerefAliases = search.DerefAliases;
            if (DerefAliases < DerefAliases.NeverDerefAliases || DerefAliases > DerefAliases.DerefAlways)
            {
                throw new LdapProtocolException("invalid derefAliases");
            }
            SizeLimit = search.SizeLimit;
            if (SizeLimit == 0)
            {
                SizeLimit = Int32.MaxValue;
            }
            else if (SizeLimit < 0)
            {
                throw new LdapProtocolException("invalid sizeLimit");
            }
            TimeLimit = TimeSpan.FromSeconds(search.TimeLimit);
            if (TimeLimit < TimeSpan.Zero)
            {
                throw new LdapProtocolException("invalid timeLimit");
            }
            TypesOnly = search.TypesOnly;
            Filter    = LdapFilter.Create(search.Filter);
            if (search.Attributes.Length > 0)
            {
                var attributes = new LdapAttributeSelection[search.Attributes.Length];
                for (int i = 0; i < search.Attributes.Length; i++)
                {
                    attributes[i] = new LdapAttributeSelection(search.Attributes[i].Span);
                }
                Attributes = attributes;
            }
            else
            {
                Attributes = Array.Empty <LdapAttributeSelection>();
            }
        }
        internal LdapSearchResultEntry(Asn1LdapMessage message)
            : base(message)
        {
            var search = message.ProtocolOp.SearchResEntry;

            ObjectName = new LdapDistinguishedName(search.ObjectName.Span);
            if (search.Attributes.Length > 0)
            {
                var attributes = new LdapAttribute[search.Attributes.Length];
                for (int i = 0; i < search.Attributes.Length; i++)
                {
                    attributes[i] = new LdapAttribute(search.Attributes[i]);
                }
                Attributes = attributes;
            }
            else
            {
                Attributes = Array.Empty <LdapAttribute>();
            }
        }
Exemple #16
0
        internal LdapBindRequest(Asn1LdapMessage message)
            : base(message)
        {
            var bindRequest = message.ProtocolOp.BindRequest;

            Version = bindRequest.Version;
            if (Version < 1 || Version > 127)
            {
                throw new ArgumentException("invalid LDAP version");
            }
            Name = new LdapDistinguishedName(bindRequest.Name.Span);
            var auth = bindRequest.Authentication;

            if (auth.Simple != null)
            {
                Simple = auth.Simple.Value.ToArray();
            }
            else if (auth.Sasl != null)
            {
                var sasl = auth.Sasl;
                SaslMechanism   = sasl.Mechanism.Span.LdapString();
                SaslCredentials = sasl.Credentials;
            }
        }
 public LdapSearchResultEntry Result(LdapDistinguishedName objectName, LdapAttribute[] attributes, LdapControl[] controls)
 {
     return(new LdapSearchResultEntry(Id, objectName, attributes, controls));
 }
Exemple #18
0
 protected virtual Task <ResultCode> OnSaslBindAsync(LdapDistinguishedName bindDN, string username, ReadOnlyMemory <byte> password, LdapClientConnection connection)
 {
     return(Task.FromResult(ResultCode.Other));
 }
 internal LdapSearchResultEntry(int messageId, LdapDistinguishedName objectName, LdapAttribute[] attributes, LdapControl[] controls)
     : base(messageId, controls)
 {
     ObjectName = objectName;
     Attributes = attributes;
 }
Exemple #20
0
 internal LdapSearchResultDone(int id, ResultCode resultCode, LdapDistinguishedName matchedDN, string message,
                               string[] referrals, LdapControl[] controls)
     : base(id, resultCode, matchedDN, message, referrals, controls)
 {
 }
Exemple #21
0
 internal LdapCompareRequest(int messageId, string dn, LdapAttributeAssertion assertion, LdapControl[] controls)
     : base(messageId, controls)
 {
     Entry     = new LdapDistinguishedName(dn);
     Assertion = assertion;
 }
Exemple #22
0
 public LdapDistinguishedName(string type, string value, LdapDistinguishedName parent)
     : this(new LdapRelativeDistinguishedName(new LdapAttributeTypeAndValue(type, value, false)), parent)
 {
 }
 internal LdapDeleteRequest(Asn1LdapMessage message)
     : base(message)
 {
     DN = new LdapDistinguishedName(message.ProtocolOp.DelRequest.Value.Span);
 }