From 8cedde3bd292ce1e0aba8c8c9834d1c502c94ef8 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 18 May 2022 16:18:30 +0200 Subject: [PATCH] Fixing modules pp_admintools.ldap_app and pp_admintools.ldap_config --- lib/pp_admintools/ldap_app.py | 4 ++-- lib/pp_admintools/ldap_config.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/pp_admintools/ldap_app.py b/lib/pp_admintools/ldap_app.py index 8674d26..d699fb2 100644 --- a/lib/pp_admintools/ldap_app.py +++ b/lib/pp_admintools/ldap_app.py @@ -35,7 +35,7 @@ from .ldap_config import LdapConnectionInfo, LdapConfiguration # rom .ldap_config import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from .ldap_config import DEFAULT_TIMEOUT -__version__ = '0.2.0' +__version__ = '0.2.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -144,7 +144,7 @@ class BaseLdapApplication(FbConfigApplication): ldap_bind_dn = LdapConfiguration.default_bind_dn ldap_group.add_argument( - '-h', '--ldap-host', metavar=_("HOST"), dest="ldap_host", + '-H', '--ldap-host', metavar=_("HOST"), dest="ldap_host", help=_( "Hostname or address of the LDAP server to use. Default: {!r}").format( ldap_host), diff --git a/lib/pp_admintools/ldap_config.py b/lib/pp_admintools/ldap_config.py index 810fb08..d3e8adc 100644 --- a/lib/pp_admintools/ldap_config.py +++ b/lib/pp_admintools/ldap_config.py @@ -30,7 +30,7 @@ from . import MAX_PORT_NUMBER, DEFAULT_CONFIG_DIR from .xlate import XLATOR -__version__ = '0.2.3' +__version__ = '0.2.4' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -156,8 +156,11 @@ class LdapConnectionInfo(FbBaseObject): @base_dn.setter def base_dn(self, value): if value is None or str(value).strip() == '': - msg = _("An empty Base DN for LDAP searches is not allowed.") - raise LdapConfigError(msg) + if self.verbose > 5: + msg = _("An empty Base DN for LDAP searches is not allowed.") + LOG.debug(msg) + self._base_dn = None + return self._base_dn = str(value).strip() # ----------------------------------------------------------- @@ -296,7 +299,7 @@ class LdapConfiguration(BaseMultiConfig): re_ldap_port_key = re.compile(r'^\s*port\s*$', re.IGNORECASE) re_ldap_base_dn_key = re.compile(r'^\s*base[_-]*dn\s*$', re.IGNORECASE) re_ldap_bind_dn_key = re.compile(r'^\s*bind[_-]*dn\s*$', re.IGNORECASE) - re_ldap_bind_pw_key = re.compile(r'^\s*bind[_-]*pw\s*$', re.IGNORECASE) + re_ldap_bind_pw_key = re.compile(r'^\s*bind[_-]*(?:pw|password)\s*$', re.IGNORECASE) # ------------------------------------------------------------------------- def __init__( @@ -347,7 +350,7 @@ class LdapConfiguration(BaseMultiConfig): if sn == 'ldap': for key in section.keys(): sub = section[key] - if key.lower.strip() == 'timeout': + if key.lower().strip() == 'timeout': self._eval_ldap_timeout(sub) continue self._eval_ldap_connection(key, sub) @@ -431,7 +434,7 @@ class LdapConfiguration(BaseMultiConfig): connection.bind_dn = value continue - if self.re_ldap_bind_pw.match(key): + if self.re_ldap_bind_pw_key.match(key): connection.bind_pw = value continue @@ -439,6 +442,11 @@ class LdapConfiguration(BaseMultiConfig): key=key, sec=section_name) LOG.error(msg) + if not connection.base_dn: + msg = _("An empty Base DN for LDAP searches in section {!r} is not allowed.").format( + section_name) + raise LdapConfigError(msg) + self.ldap_connection[connection_name] = connection -- 2.39.5