[Patch] RFC 2696 and reception of server controls

Ames Andreas Andreas.Ames at comergo.com
Mon May 30 13:08:45 CEST 2005


Hi all,

the attached patch tries to implement what subject says.  It is barely
tested (only against Active Directory) and it is diffed against stock
2.0.7 release (because I need it this way and because I have no CVS
access by courtesy of a corp. firewall).  It is actually a small
add-on to Deepak Giridharagopal's control patch.

Here is a minimalistic usage example.  You might want to edit the four
constants at the very beginning of the sample code, to make it behave
meaningful in your environment:

------------ <demo> ----------------
url = "ldap://your.ldap.server/"
base = "ou=your,dc=base,dc=dn"
search_flt = r'(sn=a*)'
page_size = 100

import ldap
from ldap.controls import LDAPControl

ldap.set_option(ldap.OPT_REFERRALS, 0)
l = ldap.initialize(url)
l.bind_s(r"tnbk1\ts62fr", "webti", ldap.AUTH_SIMPLE)

pctrl_val = ldap.encode_page_control(page_size, '')
msgid = l.search_ext(base, ldap.SCOPE_SUBTREE, search_flt,
                     serverctrls=[LDAPControl(ldap.LDAP_CONTROL_PAGE_OID, True, pctrl_val)])

pages = 0
while True:
    pages += 1
    print "Getting page %d" % (pages,)
    rtype, rdata, rmsgid, serverctrls = l.result3(msgid)
    pctrls = [c for c in serverctrls if c[0] == ldap.LDAP_CONTROL_PAGE_OID]
    if pctrls:
        # l.result3 returns raw tuples, no LDAPControl instances
        # this is just a matter of taste and can be easily changed
        est, cookie = ldap.decode_page_control(pctrls[0][2])
        if cookie:
            pctrl_val = ldap.encode_page_control(page_size, cookie)
            msgid = l.search_ext(base, ldap.SCOPE_SUBTREE, search_flt,
                                 serverctrls=[LDAPControl(ldap.LDAP_CONTROL_PAGE_OID, True, pctrl_val)])
        else:
            break
    else:
        print "Warning:  Server ignores RFC 2696 control."
        break
------------ </demo> ----------------


HTH,

aa

-- 
Andreas Ames | Programmer | Comergo GmbH | 
Voice:  +49 69 7505 3213 | andreas . ames AT comergo . com


-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-ldap_page-control.patch
Type: text/x-patch
Size: 10014 bytes
Desc: enable rfc 2696 controls
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20050530/97f47f17/attachment.bin>


More information about the python-ldap mailing list