Red Hat DIRECTORY SERVER 7.1 - PLUG-IN PROGRAMMERS Manual page 118

Table of Contents

Advertisement

Using SASL with an LDAP Client
The following example is an LDAP client that authenticates using the SASL
method named
Code Example 8-3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ldap.h>
int
main( int argc, char **argv )
{
LDAP
LDAPMod
LDAPMod
LDAPMod
char
char
time_t
char
struct berval cred;
struct berval *servcred;
int version;
/* get a handle to an LDAP connection */
if ( (ld = ldap_init( "localhost", 389 )) == NULL ) {
perror( "ldap_init" );
return( 1 );
}
/* Set the LDAP protocol version supported by the client
to 3. (By default, this is set to 2. Extended operations
are part of version 3 of the LDAP protocol.) */
version = LDAP_VERSION3;
ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
/* authenticate */
cred.bv_val = "magic";
cred.bv_len = sizeof( "magic" ) - 1;
if ( ldap_sasl_bind_s( ld, "uid=bjensen,ou=people,l=US,
dc=example,dc=com", "babsmechanism", &cred, NULL, NULL, &servcred
) != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_sasl_bind_s" );
return( 1 );
}
/* get and print the credentials returned by the server */
printf( "Server credentials: %s\n", servcred->bv_val );
/* construct the list of modifications to make */
mod0.mod_op = LDAP_MOD_REPLACE;
mod0.mod_type = "mail";
vals0[0] = "babs@example.com";
vals0[1] = NULL;
mod0.mod_values = vals0;
mod1.mod_op = LDAP_MOD_ADD;
mod1.mod_type = "description";
time( &now );
116
Red Hat Directory Server Plug-in Programmer's Guide • May 2005
babsmechanism
LDAP Client Authenticating Using SASL Method
*ld;
mod0;
mod1;
*mods[ 3 ];
*vals0[ 2 ];
*vals1[ 2 ];
now;
buf[ 128 ];
.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Directory server 7.1

Table of Contents