Add possibility to specify the scope of an LDAP search

This commit is contained in:
Benjamin Renard 2019-04-19 09:53:44 +02:00 committed by root
parent 15cb807c2f
commit 9d42fa6c71

View file

@ -50,8 +50,17 @@ class LdapServer(object):
return False
return True
def search(self,basedn,filter,attrs,sizelimit=0):
res_id = self.con.search(basedn,ldap.SCOPE_SUBTREE,filter,attrs)
def get_scope(self, scope):
if scope == 'base':
return ldap.SCOPE_BASE
elif scope == 'one':
return ldap.SCOPE_ONELEVEL
elif scope == 'sub':
return ldap.SCOPE_SUBTREE
raise Exception("Unknown LDAP scope '%s'" % scope)
def search(self, basedn, filterstr, attrs, sizelimit=0, scope='sub'):
res_id = self.con.search(basedn, self.get_scope(scope), filterstr, attrs)
ret = {}
c=0
while 1: