rich.py 文件源码

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

项目:kerberom 作者: Synacktiv 项目源码 文件源码
def ConnectToLDAP(pConnectionInformation):

    dwRes = ULONG(LDAP_SUCCESS)
    version = ULONG(LDAP_VERSION3)
    size = ULONG(LDAP_NO_LIMIT)
    time = ULONG(LDAP_NO_LIMIT)

    hLDAPConnection = ldap_init(pConnectionInformation, LDAP_PORT)

    if hLDAPConnection == 0:
        print "Impossible to connect to LDAP\n"
        return 0

    dwRes = ldap_set_option(hLDAPConnection, LDAP_OPT_PROTOCOL_VERSION, byref(version))

    if dwRes != LDAP_SUCCESS:
        print "Unable to set LDAP protocol option (ErrorCode: %d).\r\n" % dwRes
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_set_option(hLDAPConnection, LDAP_OPT_SIZELIMIT, byref(size))

    if dwRes != LDAP_SUCCESS:
        print "Unable to set LDAP size limit option (ErrorCode: %d).\r\n" % dwRes
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_set_option(hLDAPConnection, LDAP_OPT_TIMELIMIT, byref(time))

    if dwRes != LDAP_SUCCESS:
        print "Unable to set LDAP time limit option (ErrorCode: %d).\r\n" % dwRes
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_connect(hLDAPConnection, 0);

    if dwRes != LDAP_SUCCESS:
        print "Unable to connect to LDAP server\n"
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    dwRes = ldap_bind_s(hLDAPConnection, 0, 0, LDAP_AUTH_NEGOTIATE);

    if dwRes != LDAP_SUCCESS:
        print "Unable to bind to LDAP server\n"
        if hLDAPConnection != 0:
            ldap_unbind(hLDAPConnection)
            return 0

    return cast(hLDAPConnection, PLDAP)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号