From 130478a7532a8d3dfb0c8e3fbeac494908b8ec55 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 18 Nov 2018 10:05:11 -0800 Subject: [PATCH] config.parse_config: fix parsing of non-word characters If there were significant non-word characters at the end of a config value, such as in a LDAP filter, the config parser silently dropped them, because it used \b, which is defined as the boundary between \w and \W. This lead to ldap.FILTER_ERROR (Bad search filter) otherwise. Instead of using \b, just capture everything up to the comment marker, and strip the whitespace afterwards. Input: pam_filter (&(|(c1=v1)(c1=v2))(c2=active)) Before: {'pam_filter': '(&(|(c1=v1)(c1=v2))(c2=active' } Fixed: {'pam_filter': '(&(|(c1=v1)(c1=v2))(c2=active))' } Signed-off-by: Robin H. Johnson --- ssh_ldap_pubkey/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ssh_ldap_pubkey/config.py b/ssh_ldap_pubkey/config.py index 99eb77c..7b2b0f3 100644 --- a/ssh_ldap_pubkey/config.py +++ b/ssh_ldap_pubkey/config.py @@ -28,9 +28,9 @@ def parse_config(content): dict: Parsed options. """ return { - match.group(1).lower(): match.group(2) + match.group(1).lower(): match.group(2).strip() for match in ( - re.match(r'^(\w+)\s+([^#]+\b)', line) + re.match(r'^(\w+)\s+([^#]+)', line) for line in content.splitlines() ) if match }