Skip to content

Commit

Permalink
Simple search util also as a demo for using LDAP URLs with custom ext…
Browse files Browse the repository at this point in the history
…ension
  • Loading branch information
stroeder committed Mar 27, 2008
1 parent 12881e8 commit 305ec15
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tests/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys,pprint,ldap

from ldap.ldapobject import LDAPObject
from ldapurl import LDAPUrl

class MyLDAPUrl(LDAPUrl):
attr2extype = {
'who':'bindname',
'cred':'X-BINDPW',
'start_tls':'startTLS',
'trace_level':'trace',
}


ldap_url = MyLDAPUrl(sys.argv[1])
trace_level = int(ldap_url.trace_level or '0')

print '***trace_level',trace_level

ldap.trace_level = trace_level

l = LDAPObject(
ldap_url.initializeUrl(),
trace_level=trace_level,
)

l.protocol_version = 3
l.set_option(ldap.OPT_REFERRALS,0)
l.simple_bind_s((ldap_url.who or ''),(ldap_url.cred or ''))

result = l.search_s(
ldap_url.dn,
ldap_url.scope or ldap.SCOPE_SUBTREE,
ldap_url.filterstr or '(objectClass=*)',
ldap_url.attrs or ['*']
)

pprint.pprint(result)

print '***DIAGNOSTIC_MESSAGE',repr(l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE))

l.unbind_s()

0 comments on commit 305ec15

Please sign in to comment.