]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding etc/mk-home.ini.default and defining some better behaviour on a failing bind...
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Mar 2017 09:15:11 +0000 (10:15 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Mar 2017 09:15:11 +0000 (10:15 +0100)
etc/ldap.ini.default
etc/mk-home.ini.default [new file with mode: 0644]
pp_lib/ldap_app.py

index 00708c926573d7b9f7a02ae91bead5ebfb000654..510748b36ebe9eb6086e83a4b83444aa8a23bbf8 100644 (file)
@@ -1,9 +1,19 @@
+# Template for ldap.ini
+#
+# Please copy it to /etc/pixelpark/ldap.ini, <WORKDIR>/etc/ldap.ini
+# or $HOME/.config/pixelpark/ldap.ini to define LDAP-specific configuration values
+# for all LDAP based scripts in this working directory.
+#
+# Please note, that all of these values in the ldap.ini.default file are
+# the default values of the scripts, except bind_pw, which HAS to be configured.
+
 [LDAP]
 
 host = ldap.pixelpark.com
 port = 389
 base_dn = o=isp
 bind_dn = uid=Solaris_NSS,ou=Unix NSS,ou=Applications,o=pixelpark,o=isp
-bind_pw = .nss.pro
+#bind_pw = .nss.pro
 timeout = 5
 
+# vim: filetype=dosini
diff --git a/etc/mk-home.ini.default b/etc/mk-home.ini.default
new file mode 100644 (file)
index 0000000..214abeb
--- /dev/null
@@ -0,0 +1,12 @@
+# Template for mk-home.ini
+# Please set the correct Admin password in [LDAP]/bind_pw
+# and copy it to /etc/pixelpark/mk-home.ini, <WORKDIR>/etc/mk-home.ini
+# or $HOME/.config/pixelpark/mk-home.ini to set the correct
+# LDAP credentials for mk-home
+
+[LDAP]
+
+bind_dn = cn=admin
+#bind_pw = <LDAP admin password>
+
+# vim: filetype=dosini
index e840fb7edf27dfa1029349ef6385e0165d751dad..e14aac1316cccce8290a1d04213aaa3fe6dd16df 100644 (file)
@@ -23,6 +23,8 @@ import six
 
 import ldap3
 
+from ldap3.core.exceptions import LDAPPasswordIsMandatoryError
+
 # Own modules
 from .global_version import __version__ as __global_version__
 
@@ -34,7 +36,7 @@ from .merge import merge_structure
 
 from .cfg_app import PpCfgAppError, PpConfigApplication
 
-__version__ = '0.3.1'
+__version__ = '0.3.2'
 LOG = logging.getLogger(__name__)
 
 
@@ -219,7 +221,12 @@ class PpLdapApplication(PpConfigApplication):
             LOG.debug("executing pre_run() ...")
 
         LOG.debug("Binding to the LDAP servers ...")
-        self.ldap_connection.bind()
+        try:
+            self.ldap_connection.bind()
+        except LDAPPasswordIsMandatoryError as e:
+            msg = "Please configure [LDAP]/bind_pw in configuration - " + str(e)
+            self.handle_error(msg, e.__class__.__name__)
+            self.exit(1)
 
     # -------------------------------------------------------------------------
     def _run(self):
@@ -262,8 +269,13 @@ class PpLdapApplication(PpConfigApplication):
         if dn is None:
             dn = self.ldap_base_dn
 
-        self.ldap_connection.search(
-            dn, query_filter, search_scope=scope, attributes=attributes)
+        try:
+            self.ldap_connection.search(
+                dn, query_filter, search_scope=scope, attributes=attributes)
+        except LDAPPasswordIsMandatoryError as e:
+            msg = "Please configure [LDAP]/bind_pw in configuration - " + str(e)
+            LOG.error(msg)
+            return []
         entries = self.ldap_connection.entries
         return entries