-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
stroeder
committed
Apr 24, 2008
1 parent
8cf374c
commit ea882a0
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# How to bind to MS AD with python-ldap and various methods | ||
|
||
import ldap,ldap.sasl | ||
|
||
ldap_uri = "ldap://dc1.example.com" | ||
dn = "CN=Anna Blume,CN=Users,DC=addomain,DC=example,DC=com" | ||
sAMAccountName = "ABlume" | ||
userPrincipalName = "ablume@addomain.example.com" | ||
password = 'testsecret' | ||
|
||
trace_level = 2 | ||
|
||
l = ldap.initialize(ldap_uri,trace_level=trace_level) | ||
|
||
# Normal LDAPv3 compliant simple bind | ||
l.simple_bind_s(dn,password) | ||
|
||
# This is AD-specific and not LDAPv3 compliant | ||
l.simple_bind_s(userPrincipalName,password) | ||
|
||
# This is AD-specific and not LDAPv3 compliant | ||
l.simple_bind_s(userPrincipalName,password) | ||
|
||
# SASL bind with mech DIGEST-MD5 with sAMAccountName as SASL user name | ||
sasl_auth = ldap.sasl.sasl( | ||
{ | ||
ldap.sasl.CB_AUTHNAME:sAMAccountName, | ||
ldap.sasl.CB_PASS :password, | ||
}, | ||
'DIGEST-MD5' | ||
) | ||
l.sasl_interactive_bind_s("", sasl_auth) | ||
|
||
# SASL bind with mech GSSAPI | ||
# with the help of Kerberos V TGT obtained before with command | ||
# kinit ablume@ADDOMAIN.EXAMPLE.COM | ||
sasl_auth = ldap.sasl.sasl({},'GSSAPI') | ||
l.sasl_interactive_bind_s("", sasl_auth) |