def connect(**kw):
# Sources order, see ldap.conf(3)
# variable $LDAPNOINIT, and if that is not set:
# system file /etc/ldap/ldap.conf,
# user files $HOME/ldaprc, $HOME/.ldaprc, ./ldaprc,
# system file $LDAPCONF,
# user files $HOME/$LDAPRC, $HOME/.$LDAPRC, ./$LDAPRC,
# user files <ldap2pg.yml>...
# variables $LDAP<uppercase option name>.
#
# Extra variable LDAPPASSWORD is supported.
options = gather_options(**kw)
logger.debug("Connecting to LDAP server %s.", options['URI'])
l = ldap.initialize(options['URI'])
if PY2: # pragma: nocover_py3
l = UnicodeModeLDAPObject(l)
l = LDAPLogger(l)
if options.get('USER'):
logger.debug("Trying SASL DIGEST-MD5 auth.")
auth = sasl.sasl({
sasl.CB_AUTHNAME: options['USER'],
sasl.CB_PASS: options['PASSWORD'],
}, 'DIGEST-MD5')
l.sasl_interactive_bind_s("", auth)
else:
logger.debug("Trying simple bind.")
l.simple_bind_s(options['BINDDN'], options['PASSWORD'])
return l
评论列表
文章目录