HP-UX Directory Server 8.1 plug-in reference

Table Of Contents
4 An example plug-in
This chapter provides an example of a preoperation HP-UX Directory Server plug-in that you
can compile and run. It provides both the source code and a Makefile that you can use to build
the plug-in.
Even though you may not understand all the functionality contained in the example, all the
necessary concepts are explained in detail in the chapters that follow.
The example shows how to create a preoperation plug-in for the LDAP search operation. That
is, the Directory Server will process the registered plug-in functions before it processes each
LDAP search operation. The example contains two primary functions:
The test_preop_search() function logs information about the search, including the
base DN of the search, the search scope, and the type of filter used.
The test_preop_init() function is the initialization function that registers
test_preop_search() as a SLAPI_PLUGIN_PRE_SEARCH_FN preoperation plug-in
function for LDAP search operations.
These functions illustrate the data in the parameter block that is available to your function. You
can get and manipulate the parameter block data by calling various front end API functions.
4.1 Writing the plug-in example
The following example code includes the sample preoperation search function and the sample
initialization function.
Sample Preoperation search and initialization functions
#include <stdio.h>
#include <string.h>
#include "slapi-plugin.h"/* function prototypes */
int test_preop_init( Slapi_PBlock *pb );
int test_preop_search( Slapi_PBlock *pb );
/* Description of the plug-in */
Slapi_PluginDesc srchpdesc = { "test-search", "example.com",
"0.5","sample preoperation search plugin" };
/* Initialization function
* This function registers your plug-in function as a
* preoperation search function in the Directory Server.
* You need to specify this initialization function in the
* server configuration file so that the server calls
* this initialization function on startup. */
#ifdef _WIN32
__declspec(dllexport)
#endif
int test_preop_init( Slapi_PBlock *pb )
{
/* Specify the version of the plug-in ( "01" in this release ) */
if (slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01
) != 0 ||
/* Specify the description of the plug-in */
slapi_pblock_set( pb,SLAPI_PLUGIN_DESCRIPTION, (void *)&srchpdesc ) !=
0 ||
4.1 Writing the plug-in example 43