ldap.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:ldap2pg 作者: dalibo 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号