From 326f518fd527ecbed088cdd19eef3b3a434730fa Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 13 Mar 2024 11:30:13 +0100 Subject: [PATCH] Fixing resolving the LDAP servername and the help text of the --base-dn cmdline option --- lib/pp_admintools/app/ldap.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 3e4471f..874e52b 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -64,7 +64,7 @@ from ..errors import DpxNoLdapServerAddressError from ..errors import DpxWriteLdapItemError from ..xlate import XLATOR, format_list -__version__ = '1.4.0' +__version__ = '1.4.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -107,9 +107,16 @@ class BaseLdapApplication(BaseDPXApplication): pattern_dntoken = r'^([^=\s]+)\s*=\s*(\S.*)\S*$' re_dntoken = re.compile(pattern_dntoken) + pattern_ldap_url_service = r'^ldap[si]?://' + re_ldap_url_service = re.compile(pattern_ldap_url_service, re.IGNORECASE) + person_object_classes = FrozenCIStringSet([ 'account', 'inetOrgPerson', 'inetUser', 'posixAccount', 'sambaSamAccount']) + helptext_ldap_base_dn = _( + 'Override the configured base DN of the instance used as the ' + 'root for the LDAP searches.') + # ------------------------------------------------------------------------- @classmethod def compare_ldap_dns(cls, x, y): @@ -445,9 +452,7 @@ class BaseLdapApplication(BaseDPXApplication): ldap_group.add_argument( '-b', '--base-dn', metavar='DN', dest='ldap_base_dn', - help=_( - 'Override the configured base DN of the instance used as the ' - 'root for the LDAP searches.') + help=self.helptext_ldap_base_dn, ) ldap_group.add_argument( @@ -796,15 +801,16 @@ class BaseLdapApplication(BaseDPXApplication): LOG.debug(_('Already resolved hostname {h!r} to {a!r}.').format( h=connect_info.host, a=str(server_ip))) else: - LOG.debug(_('Resolving hostname {!r} to an IP address ...').format(connect_info.host)) + hostname = self.re_ldap_url_service.sub('', connect_info.host) + LOG.debug(_('Resolving hostname {!r} to an IP address ...').format(hostname)) try: - addresses = self.get_address(connect_info.host) + addresses = self.get_address(hostname) except gaierror as e: - msg = _('Could not resolve hostname {!r}:').format(connect_info.host) + msg = _('Could not resolve hostname {!r}:').format(hostname) msg += ' ' + str(e) raise DpxNoLdapServerAddressError(msg) if not addresses: - msg = _('Could not resolve hostname {!r}.').format(connect_info.host) + msg = _('Could not resolve hostname {!r}.').format(hostname) raise DpxNoLdapServerAddressError(msg) server_ip = addresses[0] connect_info.ip = server_ip -- 2.39.5