-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 - Linux -> search query with escape sequence character (\) #38609
Comments
Some more info. If that is the case I propose to add the escaping functionality to System.DirectoryServices.Protocols.LdapConnection, so both libraries act the same on the windows as well as on linux. As I said this is just a suspicion. I haven't been able to find a correct solution to ldap string escaping, to actually prove this theory. I will get to it again probably next week, but if anyone want's to try, or if anyone knows that this is a wrong theory, please let me know. |
@GrowSharp thanks for the investigation. Did you manage to get further -- did it work if you added escaping? That might help establish whether there is anything we can safely do for 5.0 here (which is almost done) |
Perhaps the same fix for #38611? |
@danmosemsft yes, I tried replacing special characters with their hexadecimal representation. Didn't worked for me tho. And yes, I agree that fixing this might also fix #38611. |
@GrowSharp can you share the filter you are using in the snippet above? Also is there a chance you can share the full CN you are trying to search here so that we can try reproing exactly the problem you are seeing? |
@joperezr sure. Filter with my custom escaping experiment that doesn't work: Without my escaping: |
I would just like to add for all these issues that the AD that I'm working with is a bloody mess. But it should still work tho, because on windows it does. |
I looked a little bit more on this, and it seems like this is a limitation on openldap. Seems like it encodes the distinguishedName property whenever it has special characters, which is why you probably can't find it when looking for an object via distinguishedName. In order to investigate this, I tried playing with
As you can see above, distinguishedName is correctly the full DN of the group, but when I try with a group that has special characters like yours, I get:
As you can see above, disntinguishedName property is encoded in this case which is likely why the search isn't really returning results. All of this points to a problem with the underneath library so far, but one thing apart from this is that we shouldn't be throwing an exception for filters like that, so I will do some more investigation on why are we throwing in this case. |
I see, well given you have a workaround for now and this is not blocking you I will push the fix/investigation for this to 6.0. Even if this is an underlying issue with the native library, I think we should either provide a workaround or do more research to see if there are other ways to add filters with special characters. |
I completely agree. |
I am having a similar issue with running on Linux. I can successfully search using
|
Another case with escaping is when filter argument (e.g. group CN) contains parentheses, e.g.
The correct representation, as per RFC, is:
What's interesting is that the first one works on Windows, but fails on Linux.
I think this might benefit from some general escape method which we can call manually when constructing filters, like:
Something along the lines of what I did here: dotnet/aspnetcore@7f72499 |
Thanks for the report @RoadTrain, and for the diagnosis of the right representation along with the examples.
I think this would be a great addition to System.DirectoryServices.Protocols. The search query language is part of the LDAP spec, so having an additional class which encodes the filter/query so that the query would be sent correctly would be very useful. That said, I would probably just focus on the encoding part of the equation, without necessarily validating that the query itself is valid as that would be a whole new can of worms, but at least ensuring the query is enconded correctly as per spec it would be great. Feel free to either use this issue or log a new one with the API proposal so that we can take a look at it. |
Description
When I try to search for a role by it's CN that contains the
\
character, I getThe LDAP server returned an unknown error. (ldap error code: -7)
Search request:
var searchRequest = new SearchRequest(LdapConstants.SETTING_GROUP_BASE_DIRECTORY, searchFilter, SearchScope.Subtree, LdapConstants.SettingGroupSearchAttributeFilter.ToArray());
Configuration
Domain joined CentOS 7.8.2003
also Ubuntu 20.04
.NET Core 3.1.301, commit: 7feb845744
.Protocols version 5.0.0-preview.5.20278.1
Regression?
On Windows it works correctly.
Other information
Only stack trace I got:
System.DirectoryServices.Protocols.LdapException: The LDAP server returned an unknown error. at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout) at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
The text was updated successfully, but these errors were encountered: