LdapServer: add get_object() method
This commit is contained in:
parent
d336ab3a8d
commit
1f72a85b71
1 changed files with 16 additions and 7 deletions
|
@ -64,20 +64,29 @@ class LdapServer(object):
|
|||
return ldap.SCOPE_SUBTREE
|
||||
raise Exception("Unknown LDAP scope '%s'" % scope)
|
||||
|
||||
def search(self, basedn, filterstr='(objectClass=*)', attrs=[], sizelimit=0, scope='sub'):
|
||||
res_id = self.con.search(basedn, self.get_scope(scope), filterstr, attrs)
|
||||
def search(self, basedn, filterstr=None, attrs=None, sizelimit=0, scope=None):
|
||||
res_id = self.con.search(
|
||||
basedn,
|
||||
self.get_scope(scope if scope else 'sub'),
|
||||
filterstr if filterstr else '(objectClass=*)',
|
||||
attrs if attrs else []
|
||||
)
|
||||
ret = {}
|
||||
c=0
|
||||
while 1:
|
||||
c = 0
|
||||
while True:
|
||||
res_type, res_data = self.con.result(res_id,0)
|
||||
if res_data == [] or sizelimit!=0 and c>sizelimit:
|
||||
if res_data == [] or (sizelimit and c > sizelimit):
|
||||
break
|
||||
else:
|
||||
if res_type == ldap.RES_SEARCH_ENTRY:
|
||||
ret[res_data[0][0]]=res_data[0][1]
|
||||
c=c+1
|
||||
ret[res_data[0][0]] = res_data[0][1]
|
||||
c += 1
|
||||
return ret
|
||||
|
||||
def get_object(self, dn, filterstr=None, attrs=None):
|
||||
result = self.search(dn, filterstr=filterstr, scope='base', attrs=attrs)
|
||||
return result[dn] if dn in result else None
|
||||
|
||||
def add_object(self,dn,attrs):
|
||||
ldif = modlist.addModlist(attrs)
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue