aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdano Arendartchuk <bogdano@mandriva.org>2007-05-03 20:48:49 +0000
committerBogdano Arendartchuk <bogdano@mandriva.org>2007-05-03 20:48:49 +0000
commit0833f46a1926dfe84abf75ad21e8fdf2e1d0736f (patch)
treea73355d80e707678e57f16b3248c45eab67168ec
parent566f7d59b539ae76271486c5deb2fab738e67bba (diff)
downloadmgarepo-0833f46a1926dfe84abf75ad21e8fdf2e1d0736f.tar
mgarepo-0833f46a1926dfe84abf75ad21e8fdf2e1d0736f.tar.gz
mgarepo-0833f46a1926dfe84abf75ad21e8fdf2e1d0736f.tar.bz2
mgarepo-0833f46a1926dfe84abf75ad21e8fdf2e1d0736f.tar.xz
mgarepo-0833f46a1926dfe84abf75ad21e8fdf2e1d0736f.zip
Changed the interpolation method. Now variable are defined with $name. not
%(name)s. Things may break.
-rw-r--r--RepSys/plugins/ldapusers.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/RepSys/plugins/ldapusers.py b/RepSys/plugins/ldapusers.py
index 34551ea..e3f696c 100644
--- a/RepSys/plugins/ldapusers.py
+++ b/RepSys/plugins/ldapusers.py
@@ -15,28 +15,29 @@ options in the [global] section of repsys.conf:
ldap-bindpw [optional] [default: empty]
the password used to bind
ldap-filterformat [optional]
- [default: (&(objectClass=inetOrgPerson)(uid=%s))]
+ [default: (&(objectClass=inetOrgPerson)(uid=$username))]
RFC-2254 filter string used in the search of the user entry.
- Note that this is a python format string and will have the user
- name as parameter. For example:
+ Note that this is a python template string and will have the
+ user name as parameter. For example:
- ldap-filterformat = (&(objectClass=inetOrgPerson)(uid=%s))
+ ldap-filterformat = (&(objectClass=inetOrgPerson)(uid=$username))
Will result in the search filter:
(&(objectClass=inetOrgPerson)(uid=john))
- ldap-format [optional] [default: %(cn)s <%(mail)s>]
- This is a python format string. This string will be
+ ldap-format [optional] [default: $cn <$mail>]
+ This is a python template string. This string will be
formatted using one dict object containing the fields
returned in the LDAP search, for example:
- >>> format = "%(cn)s <%(mail)s>"
+ >>> format = Template("$cn <$mail>")
>>> d = search(basedn, filter)
- >>> d = {"cn": "John Doe", "mail": "john@mandriva.org",
- "uidNumber": "1290", "loginShell": "/bin/bash",
- ... many other attributes ... }
- >>> value = format % d
+ >>> d
+ {"cn": "John Doe", "mail": "john@mandriva.org",
+ "uidNumber": "1290", "loginShell": "/bin/bash",
+ ... many other attributes ... }
+ >>> value = format.substitute(d)
>>> print value
John Doe <john@mandriva.org>
@@ -53,6 +54,8 @@ For more information, look http://qa.mandriva.com/show_bug.cgi?id=30549
"""
from RepSys import Error, config
+import string
+
users_cache = {}
class LDAPError(Error):
@@ -69,8 +72,9 @@ def strip_entry(entry):
return new
def interpolate(optname, format, data):
+ tmpl = string.Template(format)
try:
- return format % data
+ return tmpl.substitute(data)
except KeyError, e:
raise Error, "the key %s was not found in LDAP search, " \
"check your %s configuration" % (e, optname)
@@ -85,8 +89,8 @@ def make_handler():
binddn = config.get("global", "ldap-binddn")
bindpw = config.get("global", "ldap-bindpw", "")
filterformat = config.get("global", "ldap-filterformat",
- "(&(objectClass=inetOrgPerson)(uid=%s))", raw=1)
- format = config.get("global", "ldap-format", "%(cn)s <%(mail)s>", raw=1)
+ "(&(objectClass=inetOrgPerson)(uid=$username))", raw=1)
+ format = config.get("global", "ldap-format", "$cn <$mail>", raw=1)
if server is None:
def dummy_wrapper(section, option=None, default=None, walk=False):
@@ -117,7 +121,8 @@ def make_handler():
except ldap.LDAPError, e:
raise LDAPError(e)
- filter = interpolate("ldap-filterformat", filterformat, option)
+ data = {"username": option}
+ filter = interpolate("ldap-filterformat", filterformat, data)
try:
found = l.search_s(basedn, ldap.SCOPE_SUBTREE, filter)
except ldap.LDAPError, e: