2

c プログラムを使用して openLDAP サーバーに接続しようとしています。openLDAP クライアント ライブラリが見つかり、次のプログラムを実装しました。このLDAP サーバーとローカルの LDAP サーバーに接続しようとします。このコマンドを使用して、エラーなしでプログラムをコンパイルします

gcc ldapClient.c -o ldapClient -lldap

このコマンドを使用してプログラムを実行しようとしました

./ldapClient euler password

それからそれは言います

ldap_simple_bind_s: プロトコル エラー

私はグーグルで検索して、このようないくつかの答えを見つけました。彼らは、このエラーにはプロトコルバージョンのミスマッチ ei: LDAPv2 and LDAPv3 が含まれていると言いますが、この問題を解決する方法をうまく見つけることができませんでした

  #include <stdio.h>
#include <ldap.h>
/* LDAP Server settings */
#define LDAP_SERVER "ldap://ldap.forumsys.com:389"
int
main( int argc, char **argv )
{
LDAP        *ld;
int        rc;
char        bind_dn[100];

/* Get username and password */
if( argc != 3 )
{
perror( "invalid args, required: username password" );
return( 1 );
}
sprintf( bind_dn, "cn=%s,ou=mathematicians,dc=example,dc=com", argv[1] );
printf( "Connecting as %s...\n", bind_dn );

/* Open LDAP Connection */
if( ldap_initialize( &ld, LDAP_SERVER ) )
{
perror( "ldap_initialize" );
return( 1 );
}

/* User authentication (bind) */
rc = ldap_simple_bind_s( ld, bind_dn, argv[2] );
if( rc != LDAP_SUCCESS )
{
fprintf(stderr, "ldap_simple_bind_s: %s\n", ldap_err2string(rc) );
return( 1 );
}
printf( "Successful authentication\n" );
ldap_unbind( ld );
return( 0 );
}
4

1 に答える 1