Sample worker function
An code example helps you to understand the sample worker function.
/* Sample SASL Plug-in */
#include ldap.h
#include string.h
int ldap_plugin_sasl_bind_s_prepare ( LDAP_Pblock *pb )
{
LDAP *ld;
char *dn;
char *mechanism;
struct berval *cred;
LDAPControl **serverctrls;
LDAPControl **clientctrls;
struct berval *servercredp = NULL;
void * data;
int rc;
/**************************************************************************/
/* Query pblock to obtain ld, dn, mechanism, credentials, server controls */
/* and client controls, as supplied by application when it invoked the */
/* ldap_sasl_bind_s() API. */
/**************************************************************************/
if ( rc = ( ldap_plugin_pblock_get ( pb, LDAP_PLUGIN_LD, &data ))){
printf( "Could not get parameter for bind operation\n" );
return ( rc );
}
ld = ( LDAP * ) data;
if ( rc = ( ldap_plugin_pblock_get ( pb, LDAP_PLUGIN_SASL_DN,
&data )))
return ( rc );
dn = ( char * ) data;
if ( rc = ( ldap_plugin_pblock_get ( pb, LDAP_PLUGIN_SASL_BIND_MECHANISM,
&data )))
return ( rc );
mechanism = ( char * ) data;
if ( rc = ( ldap_plugin_pblock_get ( pb, LDAP_PLUGIN_SASL_BIND_CREDENTIALS,
&data )))
return ( rc );
cred = ( struct berval * ) data;
if ( rc = ( ldap_plugin_pblock_get ( pb, LDAP_PLUGIN_SASL_BIND_SERVERCTRLS,
&data )))
return ( rc );
serverctrls = ( LDAPControl ** ) data;
if ( rc = ( ldap_plugin_pblock_get ( pb, LDAP_PLUGIN_SASL_BIND_CLIENTCTRLS,
&data )))
return ( rc );
clientctrls = ( LDAPControl ** ) data;
/**************************************************************************/
/* Perform plug-in specific logic here to alter or obtain the user's */
/* distinguished name, credentials, etc. This could include obtaining */
/* additional data from the pblock, including: */
/* */
/* LDAP_PLUGIN_TYPE (e.g. "sasl") */
/* LDAP_PLUGIN_ARGV plug-in config variables */
/* LDAP_PLUGIN_ARGC plug-in config variable count */
/* */
/**************************************************************************/
if ( rc = ( ldap_plugin_sasl_bind_s (
ld,
dn,
mechanism,
cred,
serverctrls,
clientctrls,
&servercredp)))
return rc;
data = ( void * ) servercredp;
if ( rc = ( ldap_plugin_pblock_set ( pb, LDAP_PLUGIN_SASL_SERVER_CREDS,
&data )))
return rc;
return ( LDAP_SUCCESS );
}
ldap_plugin_init ( LDAP_Pblock *pb )
{
int argc;
char **argv;
if ( rc = (ldap_plugin_pblock_set ( pb, LDAP_PLUGIN_SASL_BIND_S_FN,
( void * )
ldap_plugin_sasl_bind_s_prepare )))
return ( rc );
return ( LDAP_SUCCESS );
}