From 8df4fef4bb3a8cb3648a2520797512f2ea371457 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 24 Feb 2021 17:39:58 +0100 Subject: [PATCH] Handling of unsuccessfu connection. --- lib/ldap_migration/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ldap_migration/__init__.py b/lib/ldap_migration/__init__.py index 3d2f7a1..3b66dcc 100644 --- a/lib/ldap_migration/__init__.py +++ b/lib/ldap_migration/__init__.py @@ -34,7 +34,7 @@ from ldap3 import BASE, LEVEL, SUBTREE, DEREF_NEVER, DEREF_SEARCH, DEREF_BASE, D from ldap3 import ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE from ldap3.core.exceptions import LDAPInvalidDnError, LDAPInvalidValueError -from ldap3.core.exceptions import LDAPException +from ldap3.core.exceptions import LDAPException, LDAPBindError # Own modules from fb_tools.colored import ColoredFormatter @@ -672,9 +672,14 @@ class LDAPMigrationApplication(BaseApplication): LOG.debug("Target server {s}: {re}".format( s=self.tgt_server, re=repr(self.tgt_server))) - self.target = Connection( - self.tgt_server, self.config.tgt_bind_dn, self.config.tgt_bind_pw, - client_strategy=SAFE_SYNC, auto_bind=True) + try: + self.target = Connection( + self.tgt_server, self.config.tgt_bind_dn, self.config.tgt_bind_pw, + client_strategy=SAFE_SYNC, auto_bind=True) + except LDAPBindError as e: + LOG.err("Could not connect to {t!r} as {u!r}: {e}".format( + t=self.config.tgt_server, u=self.config.tgt_bind_dn, e=e)) + self.exit(4) if self.verbose > 1: LOG.debug( -- 2.39.5