#include <ldap.h>
int ldap_simple_bind(LDAP *ld, const char *who,
const char *passwd);
ld |
Connection handle, which is a pointer to an |
who | |
passwd |
ldap_simple_bind() operation. To check the result of this operation, call ldap_result() and ldap_result2error().
ldap_simple_bind() function authenticates to the LDAP server. The function verifies that the password supplied for authentication matches the userPassword attribute of the given entry.
ldap_simple_bind() is an asynchronous function; it does not directly return results. If you want the results to be returned directly by the function, call the synchronous function ldap_simple_bind_s() instead. (For more information on asynchronous and synchronous functions, see "Calling Synchronous and Asynchronous Functions" on page 80.)
Note that if you specify a DN but no password, your client will bind to the server anonymously. If you want a NULL password to be rejected as an incorrect password, you need to write code to perform the check before you call the ldap_simple_bind() function.
For additional information on authenticating to the LDAP server, see "Binding and Authenticating to an LDAP Server" on page 56.
ldap_simple_bind() to authenticate the user "Barbara Jensen" to the directory.
#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
char *host = "ldap.netscape.com";
char *dn = "uid=bjensen, ou=People, o=Airius.com";
char *pw = "hifalutin";
struct timeval zerotime;
zerotime.tv_sec = zerotime.tv_usec = 0L;
...
/* Initialize a session with the LDAP server ldap.netscape.com:389 */
if ( ( ld = ldap_init( host, LDAP_PORT ) ) == NULL ) { perror( "ldap_init" );
return( 1 );
}
/* Attempt to bind with the LDAP server */
msgid = ldap_simple_bind( ld, dn, pw );
/* Initialize the value returned by ldap_result() */
rc = 0;
/* While the operation is still running, do this: */
while ( rc == 0 ) {... /* do other work while waiting */...
/* Check the status of the LDAP operation */
rc = ldap_result( ld, msgid, NULL, &zerotime, &result );
switch( rc ) {/* If -1 was returned, an error occurred */
case -1:
ldap_perror( ld, "Error in results: " );
return( 1 );
/* If 0 was returned, the operation is still in progress */
case 0:
continue;
/* If any other value is returned, assume we are done */
default:
/* Check if the "bind" operation was successful */
if ( ldap_result2error( result ) != LDAP_SUCCESS ) {ldap_perror( ld, "Error binding to server: " );
return( 1 );
}
}
}
...
ldap_simple_bind_s().
Last Updated: 10/01/98 17:06:23