mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* escape ldap search filter
* move escape to separate line
* add changelog fragment
* Update changelogs/fragments/5435-escape-ldap-param.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
* fix encoding
* fixup! fix encoding
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 1a97ca1a6f
)
Co-authored-by: Reto Kupferschmid <kupferschmid@puzzle.ch>
This commit is contained in:
parent
24a4d6e685
commit
b726110f1f
2 changed files with 6 additions and 2 deletions
2
changelogs/fragments/5435-escape-ldap-param.yml
Normal file
2
changelogs/fragments/5435-escape-ldap-param.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- ldap_attrs - fix bug which caused a ``Bad search filter`` error. The error was occuring when the ldap attribute value contained special characters such as ``(`` or ``*`` (https://github.com/ansible-collections/community.general/issues/5434, https://github.com/ansible-collections/community.general/pull/5435).
|
|
@ -168,7 +168,7 @@ modlist:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||||
from ansible.module_utils.common.text.converters import to_native, to_bytes
|
from ansible.module_utils.common.text.converters import to_native, to_bytes, to_text
|
||||||
from ansible_collections.community.general.plugins.module_utils.ldap import LdapGeneric, gen_specs
|
from ansible_collections.community.general.plugins.module_utils.ldap import LdapGeneric, gen_specs
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -176,6 +176,7 @@ import re
|
||||||
LDAP_IMP_ERR = None
|
LDAP_IMP_ERR = None
|
||||||
try:
|
try:
|
||||||
import ldap
|
import ldap
|
||||||
|
import ldap.filter
|
||||||
|
|
||||||
HAS_LDAP = True
|
HAS_LDAP = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -264,7 +265,8 @@ class LdapAttrs(LdapGeneric):
|
||||||
def _is_value_present(self, name, value):
|
def _is_value_present(self, name, value):
|
||||||
""" True if the target attribute has the given value. """
|
""" True if the target attribute has the given value. """
|
||||||
try:
|
try:
|
||||||
filterstr = "(%s=%s)" % (name, value.decode())
|
escaped_value = ldap.filter.escape_filter_chars(to_text(value))
|
||||||
|
filterstr = "(%s=%s)" % (name, escaped_value)
|
||||||
dns = self.connection.search_s(self.dn, ldap.SCOPE_BASE, filterstr)
|
dns = self.connection.search_s(self.dn, ldap.SCOPE_BASE, filterstr)
|
||||||
is_present = len(dns) == 1
|
is_present = len(dns) == 1
|
||||||
except ldap.NO_SUCH_OBJECT:
|
except ldap.NO_SUCH_OBJECT:
|
||||||
|
|
Loading…
Reference in a new issue