+#ifdef LDAP_CLIENT_UPDATE
+ if ( !( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) )
+#endif /* LDAP_CLIENT_UPDATE */
+ {
+ if( pbase.bv_val != NULL) free( pbase.bv_val );
+ if( nbase.bv_val != NULL) free( nbase.bv_val );
+
+ if( fstr.bv_val != NULL) free( fstr.bv_val );
+ if( filter != NULL) filter_free( filter );
+ if( an != NULL ) free( an );
+#ifdef LDAP_SLAPI
+ if( attrs != NULL) ch_free( attrs );
+#endif /* LDAP_SLAPI */
+ }
+
+ return rc;
+}
+
+#ifdef LDAP_SLAPI
+
+static char **anlist2charray( AttributeName *an )
+{
+ char **attrs;
+ int i;
+
+ if ( an != NULL ) {
+ for ( i = 0; an[i].an_name.bv_val != NULL; i++ )
+ ;
+ attrs = (char **)ch_malloc( (i + 1) * sizeof(char *) );
+ for ( i = 0; an[i].an_name.bv_val != NULL; i++ ) {
+ attrs[i] = an[i].an_name.bv_val;
+ }
+ attrs[i] = NULL;
+ } else {
+ attrs = NULL;
+ }
+
+ return attrs;
+}
+
+static Slapi_PBlock *initSearchPlugin( Backend *be, Connection *conn, Operation *op,
+ struct berval *base, int scope, int deref, int sizelimit,
+ int timelimit, Filter *filter, struct berval *fstr,
+ char **attrs, int attrsonly, int managedsait )
+{
+ Slapi_PBlock *pb;
+
+ pb = op->o_pb;
+
+ 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_ATTRS, (void *)attrs );
+ slapi_pblock_set( pb, SLAPI_SEARCH_ATTRSONLY, (void *)attrsonly );
+ slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)managedsait );
+
+ return pb;
+}
+
+static int doPreSearchPluginFNs( Backend *be, Slapi_PBlock *pb )
+{
+ int rc;
+
+ rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_SEARCH_FN, pb );
+ if ( rc != 0 ) {
+ /*
+ * A preoperation plugin failure will abort the
+ * entire operation.
+ */
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, INFO, "doPreSearchPluginFNs: search preoperation plugin "
+ "returned %d\n", rc, 0, 0 );
+#else
+ Debug(LDAP_DEBUG_TRACE, "doPreSearchPluginFNs: search preoperation plugin "
+ "returned %d.\n", rc, 0, 0);
+#endif
+ if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rc ) != 0)
+ rc = LDAP_OTHER;
+ } else {
+ rc = LDAP_SUCCESS;