HP-UX Directory Server 8.1 plug-in reference

Table Of Contents
/* Set the DN and the authentication method for the connection. */
if ( slapi_pblock_set( pb, SLAPI_CONN_DN, slapi_ch_strdup( dn ) ) != 0 ||
slapi_pblock_set( pb, SLAPI_CONN_AUTHTYPE, SLAPD_AUTH_SIMPLE ) != 0 ) {
slapi_log_error( SLAPI_LOG_PLUGIN, "testbind_init" ,
"Failed to set DN and auth method for connection\n" );
rc = LDAP_OPERATIONS_ERROR;
break;
}
/* Send a "success" result code back to the client. */
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,
"Authenticated: %s\n" , dn );
rc = LDAP_SUCCESS;
break;
/* If NONE is specified, the client is requesting to bind
* anonymously.
* Normally, this case should be handled by the server's front end
* before it calls this plug-in function. Just in case this does
* get through to the plug-in function, you can handle this by
* sending a successful result code back to the client and
* returning 1.
*/
case LDAP_AUTH_NONE:
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,
"Authenticating" anonymously\n" );
rc = LDAP_SUCCESS;
break;
/* This plug-in does not support any other method of
* authentication */
case LDAP_AUTH_SASL:
default:
slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind" ,
"Unsupported authentication method requested: %d\n" , method );
rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
break;
}
if ( searchpb ) {
slapi_free_search_results_internal( searchpb );
slapi_ch_free( ( void ** )&searchpb );
} slapi_send_ldap_result( pb, rc, NULL, NULL, 0, NULL );
return( 1 );
}
8.5.3.2 Example of an initialization function
To initialize your plug-in, write an initialization function to:
Call “slapi_pblock_set()” to set the SLAPI_PLUGIN_PRE_BIND_FN parameter to the name
of your preoperation bind function. (For details, see “Registering your plug-in functions”.)
If you are using SASL as the authentication method, call the Chapter 22 “Functions for syntax
plug-ins” function to register your SASL mechanism with the Directory Server.
The following is an example of an initialization function that registers the preoperation bind
function.
#include <stdio.h>
#include <string.h>
#include "slapi-plugin.h"
Slapi_PluginDesc bindpdesc = { "test-bind" ,
"HP" , "0.5" ,"sample bind preoperation plugin" };
/* Initialization function */
#ifdef _WIN32
__declspec(dllexport)
#endif
int testbind_init( Slapi_PBlock *pb )
{
/* Register the preoperation bind function and specify
the server plug-in version. */
if
( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,SLAPI_PLUGIN_VERSION_01 ) != 0 ||
8.5 Writing a preoperation bind plug-in 77