From: Luca Falavigna Date: Mon, 12 Aug 2013 12:00:06 +0000 (+0000) Subject: Implement get_users_from_ldap function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e93767672db4a47c1b4c876f1172a1a05c587709;p=dak Implement get_users_from_ldap function Signed-off-by: Luca Falavigna --- diff --git a/daklib/utils.py b/daklib/utils.py index 899c16f4..bc524aa9 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -1424,6 +1424,30 @@ def get_logins_from_ldap(fingerprint='*'): ################################################################################ +def get_users_from_ldap(): + """retrieve login and user names from LDAP""" + + LDAPDn = Cnf['Import-LDAP-Fingerprints::LDAPDn'] + LDAPServer = Cnf['Import-LDAP-Fingerprints::LDAPServer'] + l = ldap.open(LDAPServer) + l.simple_bind_s('','') + Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL, + '(uid=*)', ['uid', 'cn', 'mn', 'sn']) + users = {} + for elem in Attrs: + elem = elem[1] + name = [] + for k in ('cn', 'mn', 'sn'): + try: + if elem[k][0] != '-': + name.append(elem[k][0]) + except KeyError: + pass + users[' '.join(name)] = elem['uid'][0] + return users + +################################################################################ + def clean_symlink (src, dest, root): """ Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'.