- /* deref the base if needed */
- suffix_alias( be, &nbase );
-
-#if defined( LDAP_SLAPI )
- slapi_x_backend_set_pb( pb, be );
- slapi_x_connection_set_pb( pb, conn );
- slapi_x_operation_set_pb( pb, op );
- slapi_pblock_set( pb, SLAPI_SEARCH_TARGET, (void *)base.bv_val );
- slapi_pblock_set( pb, SLAPI_SEARCH_SCOPE, (void *)scope );
- slapi_pblock_set( pb, SLAPI_SEARCH_DEREF, (void *)deref );
- slapi_pblock_set( pb, SLAPI_SEARCH_SIZELIMIT, (void *)sizelimit );
- slapi_pblock_set( pb, SLAPI_SEARCH_TIMELIMIT, (void *)timelimit );
- slapi_pblock_set( pb, SLAPI_SEARCH_FILTER, (void *)filter );
- slapi_pblock_set( pb, SLAPI_SEARCH_STRFILTER, (void *)fstr.bv_val );
- slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly );
- slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) );
-
- rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_SEARCH_FN, pb );
- if ( rc != 0 ) {
+#ifdef LDAP_SLAPI
+ if ( op->o_pb ) {
+ attrs = anlist2charray_x( op->ors_attrs, 0, op->o_tmpmemctx );
+ init_search_pblock( op, attrs, manageDSAit );
+ rs->sr_err = call_search_preop_plugins( op );
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ goto return_results;
+ }
+
+ call_search_rewrite_plugins( op );
+ }
+#endif /* LDAP_SLAPI */
+
+ /* actually do the search and send the result(s) */
+ if ( op->o_bd->be_search ) {
+ if ( limits_check( op, rs ) == 0 ) {
+ (op->o_bd->be_search)( op, rs );
+ }
+ /* else limits_check() sends error */
+
+ } else {
+ send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
+ "operation not supported within namingContext" );
+ }
+
+#ifdef LDAP_SLAPI
+ if ( op->o_pb ) call_search_postop_plugins( op );
+#endif /* LDAP_SLAPI */
+
+#ifdef LDAP_SLAPI
+ if( attrs != NULL) op->o_tmpfree( attrs, op->o_tmpmemctx );
+#endif /* LDAP_SLAPI */
+
+return_results:;
+ return rs->sr_err;
+}
+
+#ifdef LDAP_SLAPI
+
+static void init_search_pblock( Operation *op,
+ char **attrs, int managedsait )
+{
+ slapi_int_pblock_set_operation( op->o_pb, op );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_TARGET, (void *)op->o_req_dn.bv_val );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_SCOPE, (void *)op->ors_scope );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_DEREF, (void *)op->ors_deref );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_SIZELIMIT, (void *)op->ors_slimit );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_TIMELIMIT, (void *)op->ors_tlimit );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_FILTER, (void *)op->ors_filter );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_STRFILTER, (void *)op->ors_filterstr.bv_val );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_ATTRS, (void *)attrs );
+ slapi_pblock_set( op->o_pb, SLAPI_SEARCH_ATTRSONLY, (void *)op->ors_attrsonly );
+ slapi_pblock_set( op->o_pb, SLAPI_MANAGEDSAIT, (void *)managedsait );
+}
+
+static int call_search_preop_plugins( Operation *op )
+{
+ int rc;
+
+ rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_SEARCH_FN, op->o_pb );
+ if ( rc < 0 ) {