|Plug-in Programmerís Guide
Red Hat Directory Server
A Quick Example
This chapter provides an example of a pre-operation Red Hat Directory Server (Directory Server) server plug-in that you can compile and run. Along with the source code to the example, the chapter provides a Solaris Makefile that you can use to build the plug-in.
You may not understand some of the functionality contained in the example program; however, all the concepts contained in the example code are explained in detail in chapters that follow.
An Example Pre-Operation Plug-in
The example shows how to create a pre-operation plug-in for the LDAP search operation. In other words, 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 pre-operation 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.
Writing the Plug-in Example
The following example code includes the sample pre-operation search function and the sample initialization function.
Compiling the Plug-in Example
On Solaris, you can use the following Makefile to compile the example. (This sample Makefile assumes that the source code is stored in srchxmpl.c and that you are compiling a plug-in named srchxmpl.so.)
$(LD) $(LDFLAGS) -o [email protected] $(OBJS)
Registering the Plug-in Example
To register this example plug-in, you should do the following:
- Create an LDIF configuration file in an ASCII text editor; see "Creating a Plug-in Configuration File," on page 47.
- Load the plug-in configuration file; see "Loading the Plug-in Configuration File," on page 52.
- Shut down the Directory Server.
- Restart the Directory Server.When you restart the Directory Server, it will read the entries in the dse.ldif file, which contain the entry for you new plug-in. If all is done correctly, your plug-in will now be loaded. (You may want to check the plug-ins list in the Directory Server Console.)
Running the Plug-in Example
After compiling the plug-in and registering it with the Directory Server, you're ready to make calls that are processed by the plug-in functions.
The first step is to restart the Directory Server and check the error log to see that the plug-in is properly registered. You should see the following line in the error log:Error log messsage here!
Verify that the Plugins log level is selected. (The sample source code logs messages to the error log with the Plugins severity level.)
If the plug-in is properly registered, you can then perform a few searches against the directory. The pre-operation search plug-in function should write data about each search to the error log.