+#ifdef LDAP_SLAPI
+ attrs = anlist2charray( an );
+ pb = initSearchPlugin( be, conn, op, &pbase,
+ scope, deref, sizelimit,
+ timelimit, filter, &fstr, attrs, attrsonly,
+ manageDSAit );
+ rc = doPreSearchPluginFNs( be, pb );
+ if ( rc != LDAP_SUCCESS ) {
+ goto return_results;
+ }
+
+ doSearchRewriteFNs( be, pb, &filter, &fstr );
+#endif /* LDAP_SLAPI */
+
+ /* actually do the search and send the result(s) */
+ if ( be->be_search ) {
+ (*be->be_search)( be, conn, op, &pbase, &nbase,
+ scope, deref, sizelimit,
+ timelimit, filter, &fstr, an, attrsonly );
+ } else {
+ send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
+ NULL, "operation not supported within namingContext",
+ NULL, NULL );
+ }
+
+#ifdef LDAP_SLAPI
+ doPostSearchPluginFNs( be, pb );
+#endif /* LDAP_SLAPI */
+
+return_results:;
+#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;
+