diff options
-rw-r--r-- | linaro_ldap.py | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/linaro_ldap.py b/linaro_ldap.py index e51f329..4a5be6e 100644 --- a/linaro_ldap.py +++ b/linaro_ldap.py @@ -3,10 +3,13 @@ import os import subprocess import tempfile import ldap -import ConfigParser -SSSD_CONF = "/etc/sssd/sssd.conf" -SSSD_SECTION = "domain/LDAP" + +# To provide alternative ldap bind credentials, override the LDAP_CONF +# environment variable when calling your script that makes use of the this +# library +LDAP_CONF = os.environ.get('LDAP_CONF', '/etc/ldap.conf') + @contextlib.contextmanager def ldap_client(config): @@ -21,12 +24,20 @@ def ldap_client(config): def build_config(): config = {} - cp = ConfigParser.RawConfigParser(allow_no_value=True) - cp.read(SSSD_CONF) - config["binddn"] = cp.get(SSSD_SECTION, "ldap_default_bind_dn") - config["bindpw"] = cp.get(SSSD_SECTION, "ldap_default_authtok") - config["basedn"] = cp.get(SSSD_SECTION, "ldap_user_search_base") - config["uri"] = cp.get(SSSD_SECTION, "ldap_uri") + with open(LDAP_CONF) as f: + for line in f: + if line.startswith('binddn'): + if "binddn" not in config: + config["binddn"] = line.split(' ', 1)[1].strip() + elif line.startswith('bindpw'): + if "bindpw" not in config: + config["bindpw"] = line.split(' ', 1)[1].strip() + elif line.startswith('base'): + if "basedn" not in config: + config["basedn"] = line.split(' ', 1)[1].strip() + elif line.startswith('uri'): + if "uri" not in config: + config["uri"] = line.split(' ', 1)[1].strip() return config |