- char **attrs,
- int attrsonly )
-{
-#ifdef LDAP_SLAPI
- Connection *c;
- Operation *op = NULL;
- Slapi_PBlock *ptr = NULL;
- Slapi_PBlock *pSavePB = NULL;
- struct berval dn = BER_BVNULL;
- Filter *filter=NULL;
- struct berval fstr = BER_BVNULL;
- AttributeName *an = NULL;
- const char *text = NULL;
-
- int manageDsaIt = 0;
- int isCritical;
- int i;
-
- SlapReply rs = { REP_RESULT };
-
- c = slapi_int_init_connection( NULL, LDAP_REQ_SEARCH );
- if ( c == NULL ) {
- rs.sr_err = LDAP_NO_MEMORY;
- goto cleanup;
- }
-
- op = (Operation *)c->c_pending_ops.stqh_first;
- ptr = (Slapi_PBlock *)op->o_pb;
- op->o_ctrls = controls;
-
- if ( ldn != NULL ) {
- dn.bv_val = slapi_ch_strdup(ldn);
- dn.bv_len = strlen(ldn);
- }
-
- rs.sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, NULL );
- if ( rs.sr_err != LDAP_SUCCESS ) {
- goto cleanup;
- }
-
- if ( scope != LDAP_SCOPE_BASE &&
- scope != LDAP_SCOPE_ONELEVEL &&
- scope != LDAP_SCOPE_SUBTREE ) {
- rs.sr_err = LDAP_PROTOCOL_ERROR;
- goto cleanup;
- }
-
- filter = slapi_str2filter(filStr);
- if ( filter == NULL ) {
- rs.sr_err = LDAP_PROTOCOL_ERROR;
- goto cleanup;
- }
-
- filter2bv( filter, &fstr );
-
- for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
- ; /* count the number of attributes */
- }
-
- if (i > 0) {
- an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
- for (i = 0; attrs[i] != 0; i++) {
- an[i].an_desc = NULL;
- an[i].an_oc = NULL;
- an[i].an_oc_exclude = 0;
- an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
- an[i].an_name.bv_len = strlen(attrs[i]);
- slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
- }
- an[i].an_name.bv_val = NULL;
- }
-
- memset( &rs, 0, sizeof(rs) );
- rs.sr_type = REP_RESULT;
- rs.sr_err = LDAP_SUCCESS;
- rs.sr_entry = NULL; /* paranoia */
-
- if ( scope == LDAP_SCOPE_BASE ) {
- rs.sr_entry = NULL;
-
- if ( op->o_req_ndn.bv_len == 0 ) {
- rs.sr_err = root_dse_info( c, &rs.sr_entry, &rs.sr_text );
- }
-
- if( rs.sr_err != LDAP_SUCCESS ) {
- send_ldap_result( op, &rs );
- goto cleanup;
- } else if ( rs.sr_entry != NULL ) {
- rs.sr_err = test_filter( op, rs.sr_entry, filter );
-
- if ( rs.sr_err == LDAP_COMPARE_TRUE ) {
- rs.sr_type = REP_SEARCH;
- rs.sr_err = LDAP_SUCCESS;
- rs.sr_attrs = an;
- rs.sr_flags = REP_ENTRY_MODIFIABLE;
-
- send_search_entry( op, &rs );
- }
-
- entry_free( rs.sr_entry );
-
- rs.sr_type = REP_RESULT;
- rs.sr_err = LDAP_SUCCESS;
-
- send_ldap_result( op, &rs );
-
- goto cleanup;
- }
- }
-
- if ( !op->o_req_ndn.bv_len && default_search_nbase.bv_len ) {
- slapi_ch_free( (void **)&op->o_req_dn.bv_val );
- slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
-
- ber_dupbv( &op->o_req_dn, &default_search_base );
- ber_dupbv( &op->o_req_ndn, &default_search_nbase );
- }
-
- if ( slapi_control_present( controls,
- LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
- manageDsaIt = 1;
- }
-
- op->o_bd = select_backend( &op->o_req_ndn, manageDsaIt, 0 );
- if ( op->o_bd == NULL ) {
- if ( manageDsaIt == 1 ) {
- rs.sr_err = LDAP_NO_SUCH_OBJECT;
- } else {
- rs.sr_err = LDAP_PARTIAL_RESULTS;
- }
- goto cleanup;
- }
-
- op->o_dn = c->c_dn = op->o_bd->be_rootdn;
- op->o_ndn = c->c_ndn = op->o_bd->be_rootndn;
-
- op->oq_search.rs_scope = scope;
- op->oq_search.rs_deref = 0;
- op->oq_search.rs_slimit = LDAP_NO_LIMIT;
- op->oq_search.rs_tlimit = LDAP_NO_LIMIT;
- op->oq_search.rs_attrsonly = attrsonly;
- op->oq_search.rs_attrs = an;
- op->oq_search.rs_filter = filter;
- op->oq_search.rs_filterstr = fstr;
-
- if ( op->o_bd->be_search ) {
- if ( (*op->o_bd->be_search)( op, &rs ) != 0 ) {
- rs.sr_err = LDAP_OTHER;
- }
- } else {
- rs.sr_err = LDAP_UNWILLING_TO_PERFORM;
- }
-
-cleanup:
-
- if ( ptr != NULL )
- slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rs.sr_err );