-
Notifications
You must be signed in to change notification settings - Fork 135
Add ldap.filter.is_filter() which checks filter syntax #272
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
base: main
Are you sure you want to change the base?
Conversation
3f0a7e6 to
084b622
Compare
Codecov Report
@@ Coverage Diff @@
## master #272 +/- ##
==========================================
+ Coverage 71.30% 71.72% +0.41%
==========================================
Files 50 49 -1
Lines 4796 5033 +237
Branches 802 894 +92
==========================================
+ Hits 3420 3610 +190
- Misses 1045 1067 +22
- Partials 331 356 +25
Continue to review full report at Codecov.
|
tiran
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 on this approach.
It seems rather wasteful and slow to create a LDAP connection object to verify that a string is a valid filter. The call will also connect to the default ldap server from /etc/openldap/ldap.conf on success. This will spam the error log of the default LDAP server.
ldap_pvt_put_filter might work, but the function is not exposed in ldap.h.
|
@tiran Would it create a ldap connection if I had a |
|
If there is no connection involved, why catch |
|
If the ldap object is uninitialized and unconnected it raises ldap.SERVER_DOWN without any connection attempt. What I can see is that it reads my "/etc/ldap/ldap.conf" and tries to read ~/.ldaprc. |
|
The main problem is that, however you connect, on |
Suggested in python-ldap#272
|
I don't want to merge code that can silently hide a failure, so I'll reject this approach. It might be suitable for a library that builds on top of python-ldap, rather than for python-ldap itself. |
|
There is no REOPEN button. |
|
If you set LDAPNOINIT the client libraries will bypass reading ldap.conf/.ldaprc. This is what the OpenLDAP test suite does to ensure that local client configurations don't interfere. |
|
In my opinion the patch is not a clean solution but a hack. I don't like to add such hacks to python-ldap. You can easily ship the short function in your application. I wouldn't mind to add this feature iff OpenLDAP adds a public API to perform the check. |
Apologies, I had wrong assumptions of the GitHub UI. My main objection is that |
Yes, that would be the best. You already mentioned the not exposed function
The ldap connection there is not connected and will never be. At least I could not get any connection attempt with that code. If that code really does a connection, how would I set this up to reproduce this? We are using the above code since years and it works. We have a |
|
I took the name |
|
I see. I misunderstood the code. Still, this does rely on undocumented behavior, so
IOW, if this is the easiest way to check filter validity using OpenLDAP, it's an issue in OpenLDAP. |
|
Did you raise the issue with OpenLDAP upstream to request a filter validation function? I'm hesitant to use an internal, private function |
084b622 to
42b87b0
Compare
|
Sorry, I did not see your latest answer. I created a feature request at openldap: https://bugs.openldap.org/show_bug.cgi?id=9393 I also updated the pull request, made it more clear that |
|
They aren't replying at all. |
What you filed is a feature request. The earliest it would be done is OpenLDAP 2.7. |
|
Meanwhile openldap exposed Target Milestone of the bug says OpenLDAP 2.7, it's not released yet (no git tag, just in branch master). But I wrote my own Filter parsing library which should be identical to the OpenLDAP one. I have over 500 test cases and hope to have catched all possible combinations. OpenLDAP isn't strictly following the RFC, especially regarding whitespace. https://docs.freeiam.org/en/latest/examples/ldap_filter.html |
Yes, I guess we could do what we used to do with
I really like the interface in this! What exactly are the differences between libldap's parsing and the RFC? I think I knew it was slightly more lenient on extra whitespace in a position or two, anything else? Was there a python parsing library that could work at build-time? I think there were people who wanted to keep the dependencies of python-ldap to a minimum. Only gripe is that |
I don't remember exactly every case anymore but:
I don't understand the question?
You mean In theory a presence filter has no attribute
Thanks, I fixed it, will be released soon. I stored it wrong in my brain, not the first time for this word.
You mean |
Sorry for nerd sniping both of us I guess. I wrapped
That's consistent with the above, maybe not great for a
As expected this is equal to
They actually behave exactly according to the RFC (as substring filters)?
Yes, again for good reason (noone would use the command line tools otherwise) but not ideal for
That one encodes correctly (preserving everything), what you're probably seeing is matching rule processing on the server (e.g.
True, the project never had a way to test these library level things. There is a start on a Python test suite which would be able to now, but also a limit on people's attention so writing a test suite for something that is probably working fine is not high on people's list... It's a shame when someone wants to write a parallel implementation, sure.
I thought you were suggesting we adopt something similar here.
No, what I mean is that if you set
Which is why I'm saying that using something like
Exactly
Yeah, it was bikeshedding and I apologise. |
I only need to validate whether the filter will be accepted by OpenLDAP - so the function should also just accept it and shouldn't be stricter than what is actually possible.
Okay, nice that the matching rule is responsible for it. I didn't had a look yet, whether those spaces were transmitted along with on protocol level.
Well no, as I wrote it for myself I have something - purely python.
Ah, now I understand :-) |
In here then, you could do what I suggested, use
Do they provide command-line tools (that don't use libldap) or other interfaces that process string representations? Because over the wire, the filter structure is completely unambiguous and value-agnostic.
I checked the output of
Given I'm planning on providing much more pythonic APIs, a filter abstraction (creation only, so an algebraic structure) has always been on the list that would be useful and I think you hit the nail on the head in terms of a desirable shape for one. Sure, that means we probably don't need to parse string representations. And that would be definitely be a whole new PR, targeting 4.0+.
Saw those updates, nice. Just a note, very few attributes allow an empty value, so that's probably why you wrote what you wrote originally, but they exist. |
869809d to
cdedcf0
Compare
done. |
|
btw does |
→ the two spaces are transmitted correctly: → and then the filter is normalized inside of slapd. |
Yes, it was originally a private API, normally private APIs are only available to other code in the project, but the project decided to expose it as is. |
cdedcf0 to
97b7e31
Compare
6633668 to
2a823e8
Compare
|
I'm ok with this. @tiran you put this on hold, what do you think of this version? |
Add a utility functions
ldap.filter.is_filterwhich can be used to check if the ldap filter has valid syntax.This uses an unbound ldap connection, so the values are ensured to be correct via the C library.
I added test cases for the function.