From 861fcd87171ceada85b3d61df05d1643dedf570e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 6 Sep 2022 18:15:58 +0200 Subject: [PATCH] Defining regex for a LDAP DN --- lib/pp_admintools/app/ldap.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 615032c..16ddd32 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -11,6 +11,7 @@ from __future__ import absolute_import import logging import os import argparse +import re try: from pathlib import Path @@ -44,7 +45,7 @@ from ..config.ldap import LdapConnectionInfo, LdapConfiguration # rom ..config.ldap import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from ..config.ldap import DEFAULT_TIMEOUT, MAX_TIMEOUT -__version__ = '0.3.1' +__version__ = '0.3.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -157,6 +158,16 @@ class BaseLdapApplication(FbConfigApplication): use_multiple_ldap_connections = False show_cmdline_ldap_timeout = True + # pattern_re_ldap_dn = ( + # '^([a-z][a-z0-9-]*)=(?![ #])(((?![\\="+,;<>]).)|(\\[ \\#="+,;<>])|(\\[a-f0-9][a-f0-9]))*' + # '(,([a-z][a-z0-9-]*)=(?![ #])(((?![\\="+,;<>]).)|(\\[ \\#="+,;<>])|(\\[a-f0-9][a-f0-9]))*)*$' + # ) + + an = r'[a-z][a-z0-9-]' + token_ldap_dn = r'(?:{an}*)=(?![ #])(((?![\="+,;<>]).)|(\[ \#="+,;<>])|(\{an}))*'.format(an=an) + pattern_re_ldap_dn = r'^{pat}(,{pat})*$'.format(pat=token_ldap_dn) + re_ldap_dn = re.compile(pattern_re_ldap_dn, re.IGNORECASE) + # ------------------------------------------------------------------------- def __init__( self, appname=None, verbose=0, version=GLOBAL_VERSION, base_dir=None, @@ -229,6 +240,7 @@ class BaseLdapApplication(FbConfigApplication): res = super(BaseLdapApplication, self).as_dict(short=short) + res['pattern_re_ldap_dn'] = self.pattern_re_ldap_dn res['password_file'] = self.password_file res['show_cmdline_ldap_timeout'] = self.show_cmdline_ldap_timeout res['use_default_ldap_connection'] = self.use_default_ldap_connection -- 2.39.5