diff --git a/src/yunohost/utils/ldap.py b/src/yunohost/utils/ldap.py index 22e95ad07..b7111a6cd 100644 --- a/src/yunohost/utils/ldap.py +++ b/src/yunohost/utils/ldap.py @@ -19,8 +19,10 @@ """ +import os import atexit from moulinette.authenticators import ldap +from yunohost.utils.error import YunohostError # We use a global variable to do some caching # to avoid re-authenticating in case we call _get_ldap_authenticator multiple times @@ -32,6 +34,8 @@ def _get_ldap_interface(): if _ldap_interface is None: + assert_slapd_is_running() + conf = { "vendor": "ldap", "name": "as-root", "parameters": { 'uri': 'ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi', @@ -45,6 +49,13 @@ def _get_ldap_interface(): return _ldap_interface +def assert_slapd_is_running(): + + # Assert slapd is running... + if not os.system("pgrep slapd >dev/null") == 0: + raise YunohostError("Service slapd is not running but is required to perform this action ... You can try to investigate what's happening with 'systemctl status slapd'") + + # We regularly want to extract stuff like 'bar' in ldap path like # foo=bar,dn=users.example.org,ou=example.org,dc=org so this small helper allow # to do this without relying of dozens of mysterious string.split()[0]