diff options
author | Matt Hart <matthew.hart@linaro.org> | 2015-09-09 14:34:38 +0100 |
---|---|---|
committer | Linaro Code Review <review@review.linaro.org> | 2015-09-15 15:37:59 +0000 |
commit | f4785bc01a82d28bf072174800b5e463fea55327 (patch) | |
tree | f71366148d569967c42d3ab7f6973193926f38b9 | |
parent | 9ddcbb308138a9d5fa0c5abb87272c2b3a2e32b7 (diff) |
use sssd.conf for linaro_ldap library
As Ben has started to use sssd, parse this config file for the
default ldap credentials.
Change-Id: Id0ba47ab49b8ea34be70f1e04d20736b5ee4933a
-rw-r--r-- | linaro_ldap.py | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/linaro_ldap.py b/linaro_ldap.py index 4a5be6e..e51f329 100644 --- a/linaro_ldap.py +++ b/linaro_ldap.py @@ -3,13 +3,10 @@ import os import subprocess import tempfile import ldap +import ConfigParser - -# 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') - +SSSD_CONF = "/etc/sssd/sssd.conf" +SSSD_SECTION = "domain/LDAP" @contextlib.contextmanager def ldap_client(config): @@ -24,20 +21,12 @@ def ldap_client(config): def build_config(): config = {} - 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() + 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") return config |