From 2f04bd32d044c5a73a5eb93fb127fead27d55b37 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 19:30:04 +0100 Subject: [PATCH] [PR #7697/a5cd4ebe backport][stable-7] Simplify regex for identifying order number in DN (#7646) (#7913) Simplify regex for identifying order number in DN (#7646) (#7697) Assume that if a string of digits occurs between curly braces anywhere in the first component of the DN, that this is an order number. The sequence does not necessarily have to occur after an equals sign. (cherry picked from commit a5cd4ebea2dad7ea32d2d766ddd54711d3aac29f) Co-authored-by: Aaron Sowry --- .../fragments/7646-fix-order-number-detection-in-dn.yml | 2 ++ plugins/module_utils/ldap.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/7646-fix-order-number-detection-in-dn.yml diff --git a/changelogs/fragments/7646-fix-order-number-detection-in-dn.yml b/changelogs/fragments/7646-fix-order-number-detection-in-dn.yml new file mode 100644 index 0000000000..f2d2379872 --- /dev/null +++ b/changelogs/fragments/7646-fix-order-number-detection-in-dn.yml @@ -0,0 +1,2 @@ +bugfixes: + - ldap - previously the order number (if present) was expected to follow an equals sign in the DN. This makes it so the order number string is identified correctly anywhere within the DN (https://github.com/ansible-collections/community.general/issues/7646). diff --git a/plugins/module_utils/ldap.py b/plugins/module_utils/ldap.py index ef444e9778..fccf073047 100644 --- a/plugins/module_utils/ldap.py +++ b/plugins/module_utils/ldap.py @@ -139,5 +139,7 @@ class LdapGeneric(object): def _xorder_dn(self): # match X_ORDERed DNs - regex = r"\w+=\{\d+\}.+" - return re.match(regex, self.module.params['dn']) is not None + regex = r".+\{\d+\}.+" + explode_dn = ldap.dn.explode_dn(self.module.params['dn']) + + return re.match(regex, explode_dn[0]) is not None