mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ldap_attrs: search_s based _is_value_present (#5385)
* search_s based _is_value_present * Fix formatted string and ldap import * Add changelog fragment * Remove superfluous import ldap * Improve fragment * Code format {x} prefix * Lower-case fixes * Fix suggestions to changelog * Break with the past and let bools be bools * Let ldap_attrs break on invalid DN's
This commit is contained in:
parent
c88f0f4ca0
commit
091bdc77c3
2 changed files with 7 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- ldap_attrs - fix ordering issue by ignoring the ``{x}`` prefix on attribute values (https://github.com/ansible-collections/community.general/issues/977, https://github.com/ansible-collections/community.general/pull/5385).
|
|
@ -170,6 +170,7 @@ 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
|
||||||
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
|
||||||
|
|
||||||
LDAP_IMP_ERR = None
|
LDAP_IMP_ERR = None
|
||||||
|
@ -263,9 +264,10 @@ 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:
|
||||||
is_present = bool(
|
filterstr = "(%s=%s)" % (name, value.decode())
|
||||||
self.connection.compare_s(self.dn, name, value))
|
dns = self.connection.search_s(self.dn, ldap.SCOPE_BASE, filterstr)
|
||||||
except ldap.NO_SUCH_ATTRIBUTE:
|
is_present = len(dns) == 1
|
||||||
|
except ldap.NO_SUCH_OBJECT:
|
||||||
is_present = False
|
is_present = False
|
||||||
|
|
||||||
return is_present
|
return is_present
|
||||||
|
|
Loading…
Reference in a new issue