Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.DirectoryServices.Protocols - Cannot use objectCategory filter on linux #43621

Open
null-d3v opened this issue Oct 19, 2020 · 7 comments
Labels
area-System.DirectoryServices os-linux Linux OS (any supported distro)
Milestone

Comments

@null-d3v
Copy link

Description

On linux, using a filter with objectCategory will result in the following:

System.DirectoryServices.Protocols.LdapException: The LDAP server returned an unknown error.
    at System.DirectoryServices.Protocols.LdapConnection.BeginSendRequest(DirectoryRequest request, TimeSpan requestTimeout, PartialResultProcessing partialMode, AsyncCallback callback, Object state)

Sample:

var searchRequest = new SearchRequest(
    "ou=Company,dc=company,dc=com",
    "(&(objectCategory=group)((|(objectGUID=\\D6\\F5\\F3\\0B\\04\\49\\D1\\4E\\B4\\9D\\C3\\D3\\87\\D9\\AD\\AC))))",
    SearchScope.Subtree,
    new[] { "cn", });
searchRequest.Controls.Add(
    new SearchOptionsControl(SearchOption.DomainScope));

var searchResults = (SearchResponse)await connection.SendRequestAsync(
    searchRequest, PartialResultProcessing.NoPartialResultSupport);

Configuration

  • .NET 5.0.0-rc.2.20475.5
  • aspnet:5.0-alpine docker image
  • x86_64
  • libldap 2.4
  • Windows Server 2019 DC
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.DirectoryServices untriaged New issue has not been triaged by the area owner labels Oct 19, 2020
@danmoseley
Copy link
Member

It might be good if ToString() on LdapException included ErrorCode. Is it possible to dump ErrorCode off this exception?

@null-d3v
Copy link
Author

Sure! In this case the error code I received was -7.

$"Exception: {ldapException.Message} | {ldapException.ErrorCode}"
Exception: The LDAP server returned an unknown error. | -7

@danmoseley
Copy link
Member

I don't know anything about libldap, but I downloaded the sources and ldap.h contains

#define LDAP_SERVER_DOWN				(-1)
#define LDAP_LOCAL_ERROR				(-2)
#define LDAP_ENCODING_ERROR				(-3)
#define LDAP_DECODING_ERROR				(-4)
#define LDAP_TIMEOUT					(-5)
#define LDAP_AUTH_UNKNOWN				(-6)
#define LDAP_FILTER_ERROR				(-7)
#define LDAP_USER_CANCELLED				(-8)
#define LDAP_PARAM_ERROR				(-9)
#define LDAP_NO_MEMORY					(-10)
#define LDAP_CONNECT_ERROR				(-11)
#define LDAP_NOT_SUPPORTED				(-12)
#define LDAP_CONTROL_NOT_FOUND			(-13)
#define LDAP_NO_RESULTS_RETURNED		(-14)
#define LDAP_MORE_RESULTS_TO_RETURN		(-15)	/* Obsolete */
#define LDAP_CLIENT_LOOP				(-16)
#define LDAP_REFERRAL_LIMIT_EXCEEDED	(-17)
#define	LDAP_X_CONNECTING			(-18)

It would be good for LdapException to translate each of these codes to nice messages, rather than defaulting to The LDAP server returned an unknown error. Perhaps that's a change someone could offer separately.

Someone knowledgeable like @joperezr may have an idea what your issue is though.

@danmoseley
Copy link
Member

Do you have the ability to try the same query on Windows, against the same server?

@joperezr
Copy link
Member

agreed that testing if the same code works in Windows would be valuable in case that is possible. Also, have you tried performing the search without the Search Control to see if that makes any difference?

It would be good for LdapException to translate each of these codes to nice messages, rather than defaulting to The LDAP server returned an unknown error. Perhaps that's a change someone could offer separately.

Completely agree here, it should be straight forward to do this but I'm fine with treating it separately.

@null-d3v
Copy link
Author

I can confirm that the query does return results on Windows. This is a conversion of a Windows service to docker/k8s.

Without the search control on linux, I am definitely able to get results. I can also do things like search with a distinguished name. Specifically though objectCategory searches will fail on linux but work on Windows.

Through working with changing the search request, I did find is another problem though that I will probably open another issue for. Response sizes above the maximum allowed size will always time out on linux, regardless of the time out setting on the connection. Additionally the maximum allowed size on linux is noticeably smaller than that on Windows.

@danmoseley
Copy link
Member

Created #46021 to fix the codes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.DirectoryServices os-linux Linux OS (any supported distro)
Projects
No open projects
Development

No branches or pull requests

4 participants