Skip to content

Commit

Permalink
added example script which finds highest uidNumber/gidNumber values
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder committed Sep 26, 2016
1 parent eefffeb commit 79b9922
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Demo/pyasn1/sss_highest_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
"""
This sample script demonstrates the use of the server-side-sorting control
(see RFC 2891)
Requires module pyasn1 (see http://pyasn1.sourceforge.net/)
"""

import pprint,ldap

from ldap.controls.sss import SSSRequestControl

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

l = ldap.initialize(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'):
sss_control = SSSRequestControl(ordering_rules=['-%s' % (id_attr)])
ldap_result = l.search_ext_s(
'dc=demo1,dc=freeipa,dc=org',
ldap.SCOPE_SUBTREE,
'(%s=*)' % (id_attr),
attrlist=[id_attr],
serverctrls = [sss_control],
)
print 'Highest value of %s' % (id_attr)
if ldap_result:
dn,entry = ldap_result[0]
print '->',entry[id_attr]
else:
print 'not found'

0 comments on commit 79b9922

Please sign in to comment.