Skip to content

Instantly share code, notes, and snippets.

@ssbarnea
Created July 6, 2014 17:06
Show Gist options
  • Save ssbarnea/876fd9e8ea7acc3697bb to your computer and use it in GitHub Desktop.
Save ssbarnea/876fd9e8ea7acc3697bb to your computer and use it in GitHub Desktop.
u = urlparse(url)
if u.scheme == 'ldaps':
use_ssl = True
else:
use_ssl = False
if ":" in u.hostname:
u.hostname = u.hostname.split(":")[0]
if dn is None:
import netrc
netrc_config = netrc.netrc()
for h in netrc_config.hosts:
if h == u.hostname:
dn, account, secret = netrc_config.authenticators(h)
break
self.server = ldap3.Server(host=u.hostname, port=u.port, use_ssl=use_ssl)
self.conn = ldap3.Connection(self.server,
auto_bind = True,
client_strategy = ldap3.STRATEGY_SYNC,
user=dn,
password=secret,
authentication=ldap3.AUTH_SIMPLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment