aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Hart <matthew.hart@linaro.org>2015-09-15 18:07:59 +0100
committerMatt Hart <matthew.hart@linaro.org>2015-09-15 18:07:59 +0100
commitdd3162c0ddb011417726ab6822a678bb5a628f82 (patch)
treecd98b2a257b1f56fff8860a66888a156989aa2ab
parentf4785bc01a82d28bf072174800b5e463fea55327 (diff)
downloadlinaro-git-tools-dd3162c0ddb011417726ab6822a678bb5a628f82.tar.gz
Revert "use sssd.conf for linaro_ldap library"
This reverts commit f4785bc01a82d28bf072174800b5e463fea55327.
-rw-r--r--linaro_ldap.py29
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