-
Notifications
You must be signed in to change notification settings - Fork 126
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.
|
The tests fail only due to an upstream error in spinx when building the documentation:
|
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. |
Add a utility functions
ldap.filter.is_filter
which 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.