From: Frank Brehm Date: Tue, 6 Sep 2022 16:15:58 +0000 (+0200) Subject: Defining regex for a LDAP DN X-Git-Tag: 0.5.0^2~2^2~14 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=861fcd87171ceada85b3d61df05d1643dedf570e;p=pixelpark%2Fpp-admin-tools.git Defining regex for a LDAP DN --- 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