On 08/03/2014, at 18:15, Howard Chu hyc@symas.com wrote:
Werner - Google wrote:
Hi,
I've the sample code bellow, and when i intentionally put the wrong credentials, i get from "ldap_err2string( rc ) the error message: "Invalid credentials".
Read the ldap_get_option(3), ldap_bind(3), and ldap_result(3) manages.
Thx for the quick reply.
I've read them many times, but I'm still unable to understand/find a way to use the ldap_result with "synchronous" function of bind/search.
If i understood the man pages correctly ldap_result is a companion to ldap_simple_bind/ldap_search_ext (asynchronous) . Is there a way of using it with the ldap_simple_bind_s()/ ldap_search_ext_s() functions? Or should/must i take the time and rewrite my entire code and find a way of doing things using the asynchronous functions?
i noted that i've not provided the library versions: I'm on ubuntu, with :
$ slapd -V @(#) $OpenLDAP: slapd (Ubuntu) (Oct 8 2013 20:51:43) $ buildd@akateko:/build/buildd/openldap-2.4.31/debian/build/servers/slapd
$ ldapsearch -VV ldapsearch: @(#) $OpenLDAP: ldapsearch (Ubuntu) (Oct 8 2013 20:50:56) $ buildd@akateko:/build/buildd/openldap-2.4.31/debian/build/clients/tools (LDAP library: OpenLDAP 20431)
sample code:
if ( (ld = (LDAP *)ldap_init( pHostName, iPortNum )) == NULL ) { perror( "ldap_init failed. Reason?:" ); exit ( 1 ); }
if ( (rc=ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version)) != LDAP_SUCCESS ){ fprintf( stderr, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION): %s\n", ldap_err2string( rc ) ); exit( 1 ); }
if ( (rc=ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF)) != LDAP_SUCCESS){ fprintf( stderr, "ldap_set_option(LDAP_OPT_REFERRALS): %s\n", ldap_err2string( rc )); exit( 1 ); }
rc = ldap_simple_bind_s( ld, "auth_dn", "auth_pw" );
if ( rc != LDAP_SUCCESS ) { fprintf( stderr, "ldap_simple_bind_s() Failed: %s [%d]\n", ldap_err2string(rc), rc); ldap_unbind_s(ld); /* try unbind the failed connection anyway */ exit ( 1 ); }
-- -- Howard Chu CTO, Symas Corp. http://www.symas.com Director, Highland Sun http://highlandsun.com/hyc/ Chief Architect, OpenLDAP http://www.openldap.org/project/