dsbenghe / Novell.Directory.Ldap.NETStandard

.NET LDAP client library for .NET Standard >= 2.0, .NET Core >=1.0, NET5/NET6/NET7/NET8 - works with any LDAP protocol compatible directory server (including Microsoft Active Directory).
MIT License
555 stars 151 forks source link

Referral filter is not decoded. Space character (%20) breaks the following LDAP search (3.6.0) #240

Open msstep opened 9 months ago

msstep commented 9 months ago

Hello, I use ReferralFollowing settings for a cross domain LDAP search. If there is a space character in the filter, it does not work.

It looks like this:

Response with referral exception:

image

response content:

image

the following query returns "noSuchObject":

image

You may have forgotten to use the static "Decode" method

image

For example, here

image

Is there a workaround?

My code:

      var ldapConnection = new LdapConnection { SecureSocketLayer = false };

      // connect to domain A
      ldapConnection.Connect("domenA.rt.test", 389);

      // use referral settings
      Novell.Directory.Ldap.LdapSearchConstraints cons = ldapConnection.SearchConstraints;
      cons.ReferralFollowing = true;
      cons.setReferralHandler(new MyReferralHandler("user1-from-A", "123456"));
      ldapConnection.Constraints = cons;

      // bind to A
      ldapConnection.Bind(3, "user1-from-A", "123456");
      string[] attr = { "objectClass", "member", "distinguishedName", "userPrincipalName", "sAMAccountName", "mail", "objectGUID" };

      // use search filter with domain B ("users B" with space symbol between)

      var searchResults =
          ldapConnection.Search(
              "CN=user1-from-B,OU=users B,DC=domenB,DC=rt,DC=test",
              2,
              "(|(objectCategory=group)(objectClass=group)(&(objectCategory=person)(objectClass=user)))",
              attr,
              false,
              (LdapSearchConstraints)null
          );