The following example logs the DN of the client that requests the search. Refer to install-path/examples/testbind.c for complete example code.
Before using the plug-in function as shown in this section, set up the example suffix and register the plug-in. See Extending the Bind Operation and “To register the Plug-in”, as described previously. The plug-in, Test Bind, also includes the pre-search function.
The test_search() function logs the request, as shown in the following example.
#include "slapi-plugin.h" int test_search(Slapi_PBlock * pb) { char * requestor_dn; /* DN of client searching */ int is_repl; /* Is this replication? */ int is_intl; /* Is this an internal op? */ int connId, opId, rc = 0; long msgId; rc |=slapi_pblock_get(pb, SLAPI_OPERATION_MSGID, &msgId); rc |=slapi_pblock_get(pb, SLAPI_CONN_ID, &connId); rc |=slapi_pblock_get(pb, SLAPI_OPERATION_ID, &opId); rc |=slapi_pblock_get(pb, SLAPI_REQUESTOR_DN, &requestor_dn); rc |=slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_repl); rc |=slapi_pblock_get(pb, SLAPI_IS_INTERNAL_OPERATION, &is_intl); if (rc != 0) return (rc); /* Do not interfere with replication and internal operations. */ if (is_repl || is_intl) return 0; if (requestor_dn != NULL && *requestor_dn != '\0') { slapi_log_info_ex( SLAPI_LOG_INFO_AREA_PLUGIN, SLAPI_LOG_INFO_LEVEL_DEFAULT, msgId, connId, opId, "test_search in test-bind plug-in", "Search requested by %s\n", requestor_dn ); } else { slapi_log_info_ex( SLAPI_LOG_INFO_AREA_PLUGIN, SLAPI_LOG_INFO_LEVEL_DEFAULT, msgId, connId, opId, "test_search in test-bind plug-in", "Search requested by anonymous client.\n" ); } return (rc); }
After activating the plug-in in the server, perform a search.
$ ldapsearch -D uid=kvaughan,ou=people,dc=example,dc=com -w bribery \ -h localhost -p 1389 -b dc=example,dc=com uid=bjensen |
Search instance-path/logs/errors for the resulting message. The last field of the log entry shows the following:
With the plug-in activated in Directory Server, perform a search as Kirsten Vaughan:
Authenticated: uid=kvaughan,ou=people,dc=example,dc=com