Skip to content

Commit

Permalink
async search to deal with ldap.SIZELIMIT_EXCEEDED, added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Sep 26, 2016
1 parent b5a5acf commit dbc6eec
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Demo/pyasn1/sss_highest_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@

import pprint,ldap

from ldap.ldapobject import LDAPObject
from ldap.controls.sss import SSSRequestControl
from ldap.resiter import ResultProcessor

class MyLDAPObject(LDAPObject,ResultProcessor):
pass

uri = "ldap://ipa.demo1.freeipa.org"

l = ldap.initialize(uri,trace_level=0)
l = MyLDAPObject(uri,trace_level=0)
l.simple_bind_s('uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org','Secret123')

for id_attr in ('uidNumber','gidNumber'):
# reverse sorting request control
sss_control = SSSRequestControl(ordering_rules=['-%s' % (id_attr)])
ldap_result = l.search_ext_s(
# send search request
msg_id = l.search_ext(
'dc=demo1,dc=freeipa,dc=org',
ldap.SCOPE_SUBTREE,
'(%s=*)' % (id_attr),
attrlist=[id_attr],
sizelimit=1,
serverctrls = [sss_control],
)
# collect result
ldap_result = []
try:
for res_type,res_data,res_msgid,res_controls in l.allresults(msg_id,add_ctrls=0):
ldap_result.extend(res_data)
except ldap.SIZELIMIT_EXCEEDED:
pass
# print result
print 'Highest value of %s' % (id_attr)
if ldap_result:
dn,entry = ldap_result[0]
Expand Down

0 comments on commit dbc6eec

Please sign in to comment.