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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ldap_attrs - Fixes issue 977 by ignoring the {x} prefix on attribute values (https://github.com/ansible-collections/community.general/pull/5385).
mrvanes marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 5 additions & 3 deletions plugins/modules/net_tools/ldap/ldap_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
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

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