Created
July 6, 2014 17:06
-
-
Save ssbarnea/876fd9e8ea7acc3697bb to your computer and use it in GitHub Desktop.
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
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