【问题标题】:Binding to ldap server with "ldaps"使用“ldaps”绑定到 ldap 服务器
【发布时间】:2013-05-13 12:56:44
【问题描述】:

我正在编写一个程序,它将连接到端口 10389 上运行的 LDAP 服务器。我能够使用用户 dn 和密码成功地绑定到服务器。

这是我的示例程序:

#include "windows.h"
#include "winldap.h"
#include "stdio.h"

int main(int argc, char* argv[])
{
    LDAP* pLdapConnection = NULL;
    ULONG version = LDAP_VERSION3;
    ULONG connectSuccess = 0;
    INT returnCode = 0;

    pLdapConnection = ldap_init("localhost", 10389);

    if (pLdapConnection == NULL)
    {
        printf( "ldap_init failed");
        goto error_exit;
    }
    else
        printf("ldap_init succeeded \n");

    //  Set the version to 3.0 (default is 2.0).
    returnCode = ldap_set_option(pLdapConnection,
                                 LDAP_OPT_PROTOCOL_VERSION,
                                 (void*)&version);

    if(returnCode != LDAP_SUCCESS)
    {
        printf("SetOption Error:%0X\n", returnCode);
        goto error_exit;
    }

    // Connect to the server.
    connectSuccess = ldap_connect(pLdapConnection, NULL);

    if(connectSuccess == LDAP_SUCCESS)
        printf("ldap_connect succeeded \n");
    else
    {
        printf("ldap_connect failed with 0x%x.\n",connectSuccess);
        goto error_exit;
    }

    printf("Binding ...\n");

    returnCode = ldap_bind_s(pLdapConnection, "dc=mojo,dc=com", "mojo", LDAP_AUTH_SIMPLE);

    if (returnCode == LDAP_SUCCESS)
        printf("The bind was successful");
    else{
        printf("ldap_bind_s failed with 0x%x.\n",returnCode);
        goto error_exit;
    }

    //  Cleanup and exit.
    ldap_unbind(pLdapConnection);
    return 0;

    //  On error cleanup and exit.
    error_exit:
        ldap_unbind(pLdapConnection);
        return -1;
}

如何通过“ldaps://”进行连接? ldaps 服务器正在监听 10636 端口。

我的程序需要什么才能连接到端口 10636 上的“ldaps”?

【问题讨论】:

    标签: c++ c ldap


    【解决方案1】:

    LDAPS 是一种用于通过 SSL 隧道连接到 ldap 的协议。这意味着您必须启动 SSL 会话(或 TLS,具体取决于 ldap 版本),然后使用您的 ldap 协议连接到服务器。

    这里是 windows LDAPS 协议:http://support.microsoft.com/kb/938703

    【讨论】:

      猜你喜欢
      • 2013-06-02
      • 1970-01-01
      • 2023-03-26
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多