Skip to content

Instantly share code, notes, and snippets.

@arnobroekhof
Last active September 2, 2016 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnobroekhof/017692c3a03a69f522a00521710e0192 to your computer and use it in GitHub Desktop.
Save arnobroekhof/017692c3a03a69f522a00521710e0192 to your computer and use it in GitHub Desktop.
Python script for binding to ldap using kerbers and showing the authenticated users attributes
#!/usr/bin/env python
# Make sure the python-ldap module is installed
# pip install python-ldap
import ldap
import ldap.sasl
#Initialize your connection and force it to use TLS
con = ldap.initialize('ldap://ldap.example.com')
con.set_option(ldap.OPT_X_TLS_DEMAND, True)
con.start_tls_s()
#Configure auth to use GSSAPI
auth = ldap.sasl.gssapi("")
#Actually make the connection
con.sasl_interactive_bind_s("", auth)
result = con.search_s(con.whoami_s()[3:],ldap.SCOPE_SUBTREE)
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment