- char **attrs,
- int attrsonly )
-{
-#if defined(LDAP_SLAPI)
- Backend *be;
- Connection *c;
- Operation *op = NULL;
- Slapi_PBlock *ptr = NULL;
- Slapi_PBlock *pSavePB = NULL;
- struct berval dn = { 0, NULL };
- struct berval pdn = { 0, NULL };
- struct berval ndn = { 0, NULL };
- Filter *filter=NULL;
- struct berval fstr = { 0, NULL };
- AttributeName *an = NULL;
- const char *text = NULL;
-
- int deref=0;
- int sizelimit=-1, timelimit=-1;
-
- int manageDsaIt = 0;
- int isCritical;
-
- int i, rc = LDAP_SUCCESS;
-
- c = fakeConnection( NULL, LDAP_REQ_SEARCH );
- if (c == NULL) {
- rc = LDAP_NO_MEMORY;
- goto cleanup;
- }
-
- op = (Operation *)c->c_pending_ops.stqh_first;
- ptr = (Slapi_PBlock *)op->o_pb;
- op->o_ctrls = controls;
-
- dn.bv_val = slapi_ch_strdup(ldn);
- dn.bv_len = slapi_strlen(ldn);
-
- rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
- if (rc != LDAP_SUCCESS) goto cleanup;
-
- if ( scope != LDAP_SCOPE_BASE &&
- scope != LDAP_SCOPE_ONELEVEL &&
- scope != LDAP_SCOPE_SUBTREE ) {
- rc = LDAP_PROTOCOL_ERROR;
- goto cleanup;
- }
-
- filter = slapi_str2filter(filStr);
- if ( filter == NULL ) {
- rc = 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_name.bv_val = slapi_ch_strdup(attrs[i]);
- an[i].an_name.bv_len = slapi_strlen(attrs[i]);
- slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
- }
- an[i].an_name.bv_val = NULL;
- }
-
- if ( scope == LDAP_SCOPE_BASE ) {
- Entry *entry = NULL;
-
- if ( ndn.bv_len == 0 ) {
- rc = root_dse_info( c, &entry, &text );
- }
-
- if( rc != LDAP_SUCCESS ) {
- send_ldap_result( c, op, rc, NULL, text, NULL, NULL );
- goto cleanup;
- } else if ( entry != NULL ) {
- rc = test_filter( NULL, c, op, entry, filter );
-
- if( rc == LDAP_COMPARE_TRUE ) {
- send_search_entry( NULL, c, op, entry,
- an, attrsonly, NULL );
- }
-
- entry_free( entry );
-
- send_ldap_result( c, op, LDAP_SUCCESS,
- NULL, NULL, NULL, NULL );
-
- rc = LDAP_SUCCESS;
-
- goto cleanup;
- }
- }