]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/search.c
Cleanup db_lock/unlock parameters
[openldap] / servers / slapd / search.c
index b83b2d165dade425af7cb65f62282d45732081b1..b6eb2832f4c952b9401a359d40a242cc609656d1 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -92,9 +92,7 @@ do_search(
        case LDAP_SCOPE_BASE:
        case LDAP_SCOPE_ONELEVEL:
        case LDAP_SCOPE_SUBTREE:
-#ifdef LDAP_SCOPE_SUBORDINATE
        case LDAP_SCOPE_SUBORDINATE:
-#endif
                break;
        default:
                send_ldap_error( op, rs, LDAP_PROTOCOL_ERROR, "invalid scope" );
@@ -155,8 +153,13 @@ do_search(
                op->ors_attrs[i].an_desc = NULL;
                op->ors_attrs[i].an_oc = NULL;
                op->ors_attrs[i].an_oc_exclude = 0;
-               slap_bv2ad(&op->ors_attrs[i].an_name,
-                       &op->ors_attrs[i].an_desc, &dummy);
+               if ( slap_bv2ad( &op->ors_attrs[i].an_name,
+                       &op->ors_attrs[i].an_desc, &dummy ) != LDAP_SUCCESS )
+               {
+                       slap_bv2undef_ad( &op->ors_attrs[i].an_name,
+                               &op->ors_attrs[i].an_desc, &dummy,
+                               SLAP_AD_PROXIED|SLAP_AD_NOINSERT );
+               };
        }
 
        if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
@@ -238,6 +241,7 @@ fe_op_search( Operation *op, SlapReply *rs )
 {
        int                     manageDSAit;
        int                     be_manageDSAit;
+       BackendDB               *bd = op->o_bd;
 
        manageDSAit = get_manageDSAit( op );
 
@@ -278,9 +282,17 @@ fe_op_search( Operation *op, SlapReply *rs )
                        rs->sr_err = test_filter( op, entry, op->ors_filter );
 
                        if( rs->sr_err == LDAP_COMPARE_TRUE ) {
+                               /* note: we set no limits because either
+                                * no limit is specified, or at least 1
+                                * is specified, and we're going to return
+                                * at most one entry */                 
+                               op->ors_slimit = SLAP_NO_LIMIT;
+                               op->ors_tlimit = SLAP_NO_LIMIT;
+
                                rs->sr_entry = entry;
                                rs->sr_attrs = op->ors_attrs;
                                rs->sr_operational_attrs = NULL;
+                               rs->sr_flags = 0;
                                send_search_entry( op, rs );
                                rs->sr_entry = NULL;
                                rs->sr_operational_attrs = NULL;
@@ -317,9 +329,8 @@ fe_op_search( Operation *op, SlapReply *rs )
 
                if (!rs->sr_ref) rs->sr_ref = default_referral;
                rs->sr_err = LDAP_REFERRAL;
-               op->o_bd = frontendDB;
+               op->o_bd = bd;
                send_ldap_result( op, rs );
-               op->o_bd = NULL;
 
                if (rs->sr_ref != default_referral)
                ber_bvarray_free( rs->sr_ref );
@@ -338,9 +349,28 @@ fe_op_search( Operation *op, SlapReply *rs )
                goto return_results;
        }
 
-       /* actually do the search and send the result(s) */
-       if ( op->o_bd->be_search ) {
+       if ( SLAP_SHADOW(op->o_bd) && get_dontUseCopy(op) ) {
+               /* don't use shadow copy */
+               BerVarray defref = op->o_bd->be_update_refs
+                       ? op->o_bd->be_update_refs : default_referral;
+
+               if( defref != NULL ) {
+                       rs->sr_ref = referral_rewrite( defref,
+                               NULL, &op->o_req_dn, op->ors_scope );
+                       if( !rs->sr_ref) rs->sr_ref = defref;
+                       rs->sr_err = LDAP_REFERRAL;
+                       send_ldap_result( op, rs );
+
+                       if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
+
+               } else {
+                       send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
+                               "copy not used; no referral information available" );
+               }
+
+       } else if ( op->o_bd->be_search ) {
                if ( limits_check( op, rs ) == 0 ) {
+                       /* actually do the search and send the result(s) */
                        (op->o_bd->be_search)( op, rs );
                }
                /* else limits_check() sends error */
@@ -351,6 +381,7 @@ fe_op_search( Operation *op, SlapReply *rs )
        }
 
 return_results:;
+       op->o_bd = bd;
        return rs->sr_err;
 }