def getusercredbyuid(self, username):
baseDN = "ou=People,"+self.dc
searchScope = ldap.SCOPE_SUBTREE
searchFilter = "uid="+username
searchAttrList = ["givenName","sn"]
try:
# Result is a list of touple (one for each match) of dn and attrs.
# Attrs is a dict, each value is a list of string.
result = self.conn.search_s(baseDN, searchScope, searchFilter, searchAttrList)
if ( result==[] ):
print("User %s does not exist!", username)
return
result = [value[0] for value in result[0][1].values()]
# Returns 2-element list, name and surname
return result
except ldap.LDAPError as e:
print(e)
return
评论列表
文章目录