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

Fix Complex filters #33

Closed
wants to merge 4 commits into from
Closed

Fix Complex filters #33

wants to merge 4 commits into from

Conversation

robbat2
Copy link
Contributor

@robbat2 robbat2 commented Nov 18, 2018

Complex LDAP search filters used in pam_filter break both the config parser & the filter builder. This PR fixes them :-).

If there were significant non-word characters at the end of a config
value, such as in a LDAP filter, the config parser silently dropped
them, because it used \b, which is defined as the boundary between \w
and \W.

This lead to ldap.FILTER_ERROR (Bad search filter) otherwise.

Instead of using \b, just capture everything up to the comment marker,
and strip the whitespace afterwards.

Input:    pam_filter    (&(|(c1=v1)(c1=v2))(c2=active))
Before: {'pam_filter': '(&(|(c1=v1)(c1=v2))(c2=active' }
Fixed:  {'pam_filter': '(&(|(c1=v1)(c1=v2))(c2=active))' }

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
RFC4515 requires filters to be wrapped with parenthesis '(' and ')'.
Over-wrapped filters are invalid! e.g. '((uid=x))'

OpenLDAP permits simple filters to omit parenthesis entirely:
e.g. 'uid=x' is automatically treated as '(uid=x)'

The OpenLDAP behavior is taken as a given in many uses, which can
lead to bad assumptions merging filters, because over-wrapped filters
ARE still rejected.

To cope with these cases, only wrap the incoming filter in
parenthesis if it does NOT already have them.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
pyldap (now merged back into python-ldap-3), no longer supports
end-of-life versions, notably Python 3.3.

See: python-ldap/python-ldap@6e75fc4
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Tests for commit 130478a:
- Lines with trailing comments
- Lines ending in significant punctuation
- Lines with trailing whitespace

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
@jirutka
Copy link
Owner

jirutka commented Apr 27, 2019

I’ve merged it in 5b1772e, 0220dc7 and f4d1fa0. Thank you for your contribution!

@jirutka jirutka closed this Apr 27, 2019
@robbat2
Copy link
Contributor Author

robbat2 commented Apr 27, 2019

Can you merge in the testcases in 7de8b5c as well?

@jirutka
Copy link
Owner

jirutka commented Apr 27, 2019

It is merged, I just squashed it with the previous one.

@robbat2
Copy link
Contributor Author

robbat2 commented Apr 27, 2019

Thanks; i missed that in a quick check

@robbat2 robbat2 deleted the gentoo-fixes branch April 27, 2019 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants