From aa529ac88c01f265379a4ed08bad9582bea134c7 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 21 Aug 2023 14:43:35 +0200 Subject: [PATCH] Enabling overriding configures Base DN in lib/pp_admintools/app/ldap.py --- lib/pp_admintools/app/ldap.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 41e3e02..3779180 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -46,7 +46,7 @@ from ..config.ldap import DEFAULT_TIMEOUT from ..config.ldap import LdapConfiguration, LdapConnectionInfo from ..xlate import XLATOR, format_list -__version__ = '0.11.9' +__version__ = '0.12.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -435,6 +435,15 @@ class BaseLdapApplication(BaseDPXApplication): ldap_group.add_argument('-I', '--instance', **arg_params) + if not self.use_multiple_ldap_connections: + + 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.') + ) + if self.show_cmdline_ldap_timeout: ldap_group.add_argument( '-T', '--timeout', metavar=_('SECONDS'), dest='ldap_timeout', @@ -589,6 +598,9 @@ class BaseLdapApplication(BaseDPXApplication): self._validate_given_instances(filtered_instances) + if not self.use_multiple_ldap_connections: + self._apply_target_cmdline_params(filtered_instances) + if self.verbose > 1: LOG.debug(_('LDAP instances to use:') + ' ' + pp(self.ldap_instances)) @@ -614,6 +626,15 @@ class BaseLdapApplication(BaseDPXApplication): if not all_ok: self.exit(1) + # ------------------------------------------------------------------------- + def _apply_target_cmdline_params(self, filtered_instances): + + for inst in filtered_instances: + + v = getattr(self.args, 'ldap_base_dn', None) + if v: + self.cfg.ldap_connection[inst].base_dn = v + # ------------------------------------------------------------------------- def _init_default_connection(self): -- 2.39.5