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

ldap_attrs: search_s based _is_value_present #5385

Merged
merged 10 commits into from
Oct 25, 2022
10 changes: 6 additions & 4 deletions plugins/modules/net_tools/ldap/ldap_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
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 ldap, LdapGeneric, gen_specs

import re

LDAP_IMP_ERR = None
Expand Down Expand Up @@ -263,9 +264,10 @@ def exact(self):
def _is_value_present(self, name, value):
""" True if the target attribute has the given value. """
try:
is_present = bool(
self.connection.compare_s(self.dn, name, value))
except ldap.NO_SUCH_ATTRIBUTE:
filterstr = "(%s=%s)" % (name, value.decode())
dns = self.connection.search_s(self.dn, ldap.SCOPE_BASE, filterstr)
is_present = bool(len(dns) == 1)
mrvanes marked this conversation as resolved.
Show resolved Hide resolved
except (ldap.INVALID_DN_SYNTAX, ldap.NO_SUCH_OBJECT):
is_present = False

return is_present
Expand Down