From 9d42fa6c7191ca8133403245f76346607458f4e1 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 19 Apr 2019 09:53:44 +0200 Subject: [PATCH] Add possibility to specify the scope of an LDAP search --- LdapServer.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/LdapServer.py b/LdapServer.py index 169c817..b32b859 100644 --- a/LdapServer.py +++ b/LdapServer.py @@ -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: