From: Frank Brehm Date: Mon, 20 Mar 2017 09:15:11 +0000 (+0100) Subject: Adding etc/mk-home.ini.default and defining some better behaviour on a failing bind... X-Git-Tag: 0.1.2~250 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=bfa10b023d85af52eba5a7bc08373e2d720d22f8;p=pixelpark%2Fadmin-tools.git Adding etc/mk-home.ini.default and defining some better behaviour on a failing bind password. --- diff --git a/etc/ldap.ini.default b/etc/ldap.ini.default index 00708c9..510748b 100644 --- a/etc/ldap.ini.default +++ b/etc/ldap.ini.default @@ -1,9 +1,19 @@ +# Template for ldap.ini +# +# Please copy it to /etc/pixelpark/ldap.ini, /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 index 0000000..214abeb --- /dev/null +++ b/etc/mk-home.ini.default @@ -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, /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 = + +# vim: filetype=dosini diff --git a/pp_lib/ldap_app.py b/pp_lib/ldap_app.py index e840fb7..e14aac1 100644 --- a/pp_lib/ldap_app.py +++ b/pp_lib/ldap_app.py @@ -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