1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import ldap
from ldap.controls import SimplePagedResultsControl
PAGE_SIZE = 500
l = ldap.initialize('ldap://my-server:3268')
l.bind_s("user@domain.com","password")
pg_ctrl = SimplePagedResultsControl(None, False, (PAGE_SIZE, ""))
while True:
msgid = l.search_ext('dc=domain,dc=com',ldap.SCOPE_SUBTREE,'(&(objectClass=User)(objectCategory=Person))',['sAMAccountName', 'mail'], serverctrls=[pg_ctrl])
_, res_data, _, srv_ctrls = l.result3(msgid)
for dn, attrs in res_data:
if 'mail' in attrs:
mail = attrs['mail'][0]
else:
mail = 'NO MAIL'
print '%s (%s)' % (attrs['sAMAccountName'],mail)
cookie = srv_ctrls[0].controlValue[1]
if cookie:
pg_ctrl.controlValue = (PAGE_SIZE, cookie)
else:
break |
Partager