forked from richm/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgtest.py
58 lines (52 loc) · 1.39 KB
/
pgtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
url = "ldap://localhost:1130/"
base = "dc=example,dc=com"
search_flt = r'(objectClass=*)'
page_size = 100
import ldap,pprint
from ldap.controls import SimplePagedResultsControl
searchreq_attrlist=['cn','mail','objectClass']
#ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
ldap.set_option(ldap.OPT_REFERRALS, 0)
l = ldap.initialize(url,trace_level=1)
l.protocol_version = 3
l.simple_bind_s("cn=directory manager", "password")
lc = SimplePagedResultsControl(
ldap.LDAP_CONTROL_PAGE_OID,True,(page_size,'')
)
# Send search request
msgid = l.search_ext(
base,
ldap.SCOPE_SUBTREE,
search_flt,
attrlist=searchreq_attrlist,
serverctrls=[lc]
)
pages = 0
while True:
pages += 1
print "Getting page %d" % (pages,)
rtype, rdata, rmsgid, serverctrls = l.result3(msgid)
print '%d results' % len(rdata)
pprint.pprint(rdata)
pctrls = [
c
for c in serverctrls
if c.controlType == ldap.LDAP_CONTROL_PAGE_OID
]
if pctrls:
pprint.pprint(pctrls)
est, cookie = pctrls[0].controlValue
if cookie:
lc.controlValue = (page_size, cookie)
msgid = l.search_ext(
base,
ldap.SCOPE_SUBTREE,
search_flt,
attrlist=searchreq_attrlist,
serverctrls=[lc]
)
else:
break
else:
print "Warning: Server ignores RFC 2696 control."
break