Index: trunk/extensions/OpenStackManager/scripts/ldapsupportlib.py |
— | — | @@ -2,10 +2,10 @@ |
3 | 3 | import os, traceback, getpass, sys |
4 | 4 | |
5 | 5 | try: |
6 | | - import ldap |
| 6 | + import ldap |
7 | 7 | except ImportError: |
8 | | - sys.stderr.write("Unable to import LDAP library.\n") |
9 | | - sys.exit(1) |
| 8 | + sys.stderr.write("Unable to import LDAP library.\n") |
| 9 | + sys.exit(1) |
10 | 10 | |
11 | 11 | class LDAPSupportLib: |
12 | 12 | |
— | — | @@ -15,8 +15,6 @@ |
16 | 16 | self.sslType = self.getLdapInfo("ssl") |
17 | 17 | self.binddn = self.getLdapInfo("binddn") |
18 | 18 | self.bindpw = self.getLdapInfo("bindpw") |
19 | | - # TODO: add a config file to set this |
20 | | - self.bindfile = "/etc/ldap/changeme" |
21 | 19 | self.defaults = {} |
22 | 20 | |
23 | 21 | def addParserOptions(self, parser, default="proxy"): |
— | — | @@ -67,8 +65,8 @@ |
68 | 66 | self.binddn = "uid=" + options.bindas + ",ou=people," + self.base |
69 | 67 | self.bindpw = getpass.getpass() |
70 | 68 | elif options.scriptuser: |
71 | | - self.binddn = self.getLdapInfo('USER', self.bindfile) |
72 | | - self.bindpw = self.getLdapInfo('PASS', self.bindfile) |
| 69 | + self.binddn = self.getLdapInfo('USER', '/etc/ldap/.ldapscriptrc') |
| 70 | + self.bindpw = self.getLdapInfo('PASS', '/etc/ldap/.ldapscriptrc') |
73 | 71 | |
74 | 72 | def setBindDN(self, binddn): |
75 | 73 | self.binddn = binddn |
— | — | @@ -83,12 +81,18 @@ |
84 | 82 | return self.ldapHost |
85 | 83 | |
86 | 84 | def getLdapInfo(self, attr, conffile="/etc/ldap.conf"): |
87 | | - f = open(conffile) |
| 85 | + try: |
| 86 | + f = open(conffile) |
| 87 | + except IOError: |
| 88 | + if conffile == "/etc/ldap.conf": |
| 89 | + # fallback to /etc/ldap/ldap.conf, which will likely |
| 90 | + # have less information |
| 91 | + f = open("/etc/ldap/ldap.conf") |
88 | 92 | for line in f: |
89 | 93 | if line.strip() == "": |
90 | 94 | continue |
91 | | - if line.split()[0] == attr: |
92 | | - return line.split()[1] |
| 95 | + if line.split()[0].lower() == attr.lower(): |
| 96 | + return line.split(None, 1)[1].strip() |
93 | 97 | break |
94 | 98 | |
95 | 99 | def connect(self): |