r89634 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89633‎ | r89634 | r89635 >
Date:08:44, 7 June 2011
Author:laner
Status:deferred
Tags:
Comment:
Bring into line with wmf version
Modified paths:
  • /trunk/extensions/OpenStackManager/scripts/ldapsupportlib.py (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/scripts/ldapsupportlib.py
@@ -2,10 +2,10 @@
33 import os, traceback, getpass, sys
44
55 try:
6 - import ldap
 6+ import ldap
77 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)
1010
1111 class LDAPSupportLib:
1212
@@ -15,8 +15,6 @@
1616 self.sslType = self.getLdapInfo("ssl")
1717 self.binddn = self.getLdapInfo("binddn")
1818 self.bindpw = self.getLdapInfo("bindpw")
19 - # TODO: add a config file to set this
20 - self.bindfile = "/etc/ldap/changeme"
2119 self.defaults = {}
2220
2321 def addParserOptions(self, parser, default="proxy"):
@@ -67,8 +65,8 @@
6866 self.binddn = "uid=" + options.bindas + ",ou=people," + self.base
6967 self.bindpw = getpass.getpass()
7068 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')
7371
7472 def setBindDN(self, binddn):
7573 self.binddn = binddn
@@ -83,12 +81,18 @@
8482 return self.ldapHost
8583
8684 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")
8892 for line in f:
8993 if line.strip() == "":
9094 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()
9397 break
9498
9599 def connect(self):

Status & tagging log