]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Defining regex for a LDAP DN
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Sep 2022 16:15:58 +0000 (18:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Sep 2022 16:15:58 +0000 (18:15 +0200)
lib/pp_admintools/app/ldap.py

index 615032c42cb158f1bc42d7642d174929fcedcbe3..16ddd32dafc9e9205af06b09cb9d1c4b9a9f683b 100644 (file)
@@ -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