This simple function demonstrates how to do a simple connect and bind to an LDAP resource using Python and python-ldap. The parameters are: host - string representing the host (DNS name or IP address) binddn - string representing the user to bind as (i.e. "o=admin,ou=users") password - string representing the password port - port to connect on (defaults to 389)
import ldap
def connect( host, binddn, password, port=389):
handle = ldap.open( host, port )
if handle:
handle.simple_bind_s( binddn, password )
return handle
return False
© 2008 Novell, Inc. All Rights Reserved.