Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 18 Functions

ldap_simple_bind_s()

Synchronously authenticates your client to the LDAP server using a DN and a password.

Syntax

#include <ldap.h>
int ldap_simple_bind_s( LDAP *ld, const char *who,
   const char *passwd );

Parameters

This function has the following parameters:

ld

Connection handle, which is a pointer to an LDAP structure containing information about the connection to the LDAP server.

who

Distinguished name (DN) of the user who wants to authenticate. For anonymous authentication, set this or the passwd argument to NULL.

passwd

Password of the user who wants to authenticate. For anonymous authentication, set this or the who argument to NULL.

Returns

One of the following values:

The following result codes can be returned by the Netscape Directory Server when processing an LDAP search request. Other LDAP servers may send these result codes under different circumstances or may send different result codes back to your LDAP client.

Note that the Netscape Directory Server may send other result codes in addition to the codes described here (for example, the server may have loaded a custom plug-in that returns other result codes).

Description

The ldap_simple_bind_s() 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_s() is a synchronous function, which directly returns the results of the operation. If you want to perform other operations while waiting for the results of this operation, call the asynchronous function ldap_simple_bind() 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_s() function.

For additional information on authenticating to the LDAP server, see "Binding and Authenticating to an LDAP Server" on page 56.

Example

The following section of code uses the synchronous ldap_simple_bind_s() function to authenticate to the directory as the user "Barbara Jensen".

#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";
...
/* 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 */
if ( ldap_simple_bind_s( ld, dn, pw ) != LDAP_SUCCESS ) {
   ldap_perror( ld, "Authentication failed: " );
   return( 1 );
}
...

See Also

ldap_simple_bind().


Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:06:23