|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /usr/share/doc/python-ldap-2.2.0/Demo/Lib/ldapurl/ |
Upload File : |
"""
Do a search with the LDAP URL specified at command-line.
No output of LDAP data is produced except trace output.
"""
import sys,getpass,ldap,ldapurl
try:
ldapUrl = ldapurl.LDAPUrl(ldapUrl=sys.argv[1])
except IndexError:
print 'Usage: %s [LDAP URL]' % (sys.argv[0])
sys.exit(1)
for a in [
'urlscheme','hostport','dn','attrs','scope',
'filterstr','extensions','who','cred'
]:
print a,repr(getattr(ldapUrl,a))
l = ldap.initialize(ldapUrl.initializeUrl(),trace_level=1)
if ldapUrl.who!=None:
if ldapUrl.cred!=None:
cred=ldapUrl.cred
else:
print 'Enter password for simple bind with',repr(ldapUrl.who)
cred=getpass.getpass()
l.simple_bind_s(ldapUrl.who,cred)
res = l.search_s(ldapUrl.dn,ldapUrl.scope,ldapUrl.filterstr,ldapUrl.attrs)
print len(res),'search results'