]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Handling of unsuccessfu connection.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 Feb 2021 16:39:58 +0000 (17:39 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 Feb 2021 16:39:58 +0000 (17:39 +0100)
lib/ldap_migration/__init__.py

index 3d2f7a1dd24805e40783dddecd3de3c80fb42806..3b66dcc9a63ecf3f9087833be41a4bd2b0d729e3 100644 (file)
@@ -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(