]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/search.c
re-fix previus commit the other way 'round (rids are < 1000)
[openldap] / servers / slapd / back-sql / search.c
index ba54bef33bd02628346ea6a177b7b38786e606b7..b9d9365034b735526651ffff4ebd15cb70c633e1 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2007 The OpenLDAP Foundation.
  * Portions Copyright 1999 Dmitry Kovalev.
  * Portions Copyright 2002 Pierangelo Masarati.
  * Portions Copyright 2004 Mark Adamson.
@@ -314,9 +314,7 @@ backsql_init_search(
                                }
 
                        } else {
-                               rs->sr_ref = referral_rewrite( default_referral,
-                                               NULL, &op->o_req_dn, scope );
-                               rc = rs->sr_err = LDAP_REFERRAL;
+                               rs->sr_err = rc;
                        }
                }
        }
@@ -654,9 +652,35 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f )
 
        Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter()\n", 0, 0, 0 );
        if ( f->f_choice == SLAPD_FILTER_COMPUTED ) {
+               struct berval   flt;
+               char            *msg = NULL;
+
+               switch ( f->f_result ) {
+               case LDAP_COMPARE_TRUE:
+                       BER_BVSTR( &flt, "10=10" );
+                       msg = "TRUE";
+                       break;
+
+               case LDAP_COMPARE_FALSE:
+                       BER_BVSTR( &flt, "11=0" );
+                       msg = "FALSE";
+                       break;
+
+               case SLAPD_COMPARE_UNDEFINED:
+                       BER_BVSTR( &flt, "12=0" );
+                       msg = "UNDEFINED";
+                       break;
+
+               default:
+                       rc = -1;
+                       goto done;
+               }
+
                Debug( LDAP_DEBUG_TRACE, "backsql_process_filter(): "
-                       "invalid filter\n", 0, 0, 0 );
-               rc = -1;
+                       "filter computed (%s)\n", msg, 0, 0 );
+               backsql_strfcat_x( &bsi->bsi_flt_where,
+                               bsi->bsi_op->o_tmpmemctx, "b", &flt );
+               rc = 1;
                goto done;
        }
 
@@ -1517,16 +1541,16 @@ backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
                BER_BVZERO( query );
        }
  
-       free( bsi->bsi_sel.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_sel.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_sel.bb_val );
        bsi->bsi_sel.bb_len = 0;
-       free( bsi->bsi_from.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_from.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_from.bb_val );
        bsi->bsi_from.bb_len = 0;
-       free( bsi->bsi_join_where.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_join_where.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_join_where.bb_val );
        bsi->bsi_join_where.bb_len = 0;
-       free( bsi->bsi_flt_where.bb_val.bv_val );
+       bsi->bsi_op->o_tmpfree( bsi->bsi_flt_where.bb_val.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &bsi->bsi_flt_where.bb_val );
        bsi->bsi_flt_where.bb_len = 0;
        
@@ -1620,7 +1644,7 @@ backsql_oc_get_candidates( void *v_oc, void *v_bsi )
                        query.bv_val, 0, 0 );
 
        rc = backsql_Prepare( bsi->bsi_dbh, &sth, query.bv_val, 0 );
-       free( query.bv_val );
+       bsi->bsi_op->o_tmpfree( query.bv_val, bsi->bsi_op->o_tmpmemctx );
        BER_BVZERO( &query );
        if ( rc != SQL_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
@@ -1968,9 +1992,8 @@ backsql_search( Operation *op, SlapReply *rs )
                /* fall thru */
 
        default:
-#ifdef SLAP_ACL_HONOR_DISCLOSE
                if ( !BER_BVISNULL( &base_entry.e_nname )
-                               && ! access_allowed( op, &base_entry,
+                               && !access_allowed( op, &base_entry,
                                        slap_schema.si_ad_entry, NULL,
                                        ACL_DISCLOSE, NULL ) )
                {
@@ -1982,7 +2005,6 @@ backsql_search( Operation *op, SlapReply *rs )
                        rs->sr_matched = NULL;
                        rs->sr_text = NULL;
                }
-#endif /* SLAP_ACL_HONOR_DISCLOSE */
 
                send_ldap_result( op, rs );
 
@@ -1991,9 +2013,12 @@ backsql_search( Operation *op, SlapReply *rs )
                        rs->sr_ref = NULL;
                }
 
+               if ( !BER_BVISNULL( &base_entry.e_nname ) ) {
+                       entry_clean( &base_entry );
+               }
+
                goto done;
        }
-#ifdef SLAP_ACL_HONOR_DISCLOSE
        /* NOTE: __NEW__ "search" access is required
         * on searchBase object */
        {
@@ -2024,7 +2049,6 @@ backsql_search( Operation *op, SlapReply *rs )
                        goto done;
                }
        }
-#endif /* SLAP_ACL_HONOR_DISCLOSE */
 
        bsi.bsi_e = NULL;
 
@@ -2374,20 +2398,23 @@ send_results:;
        if ( op->o_sync ) {
                Operation       op2 = *op;
                SlapReply       rs2 = { 0 };
-               Entry           e = { 0 };
+               Entry           *e = entry_alloc();
                slap_callback   cb = { 0 };
 
                op2.o_tag = LDAP_REQ_ADD;
                op2.o_bd = select_backend( &op->o_bd->be_nsuffix[0], 0, 0 );
-               op2.ora_e = &e;
+               op2.ora_e = e;
                op2.o_callback = &cb;
 
-               e.e_name = op->o_bd->be_suffix[0];
-               e.e_nname = op->o_bd->be_nsuffix[0];
+               ber_dupbv( &e->e_name, op->o_bd->be_suffix );
+               ber_dupbv( &e->e_nname, op->o_bd->be_nsuffix );
 
                cb.sc_response = slap_null_cb;
 
                op2.o_bd->be_add( &op2, &rs2 );
+
+               if ( op2.ora_e == e )
+                       entry_free( e );
        }
 #endif /* BACKSQL_SYNCPROV */
 
@@ -2445,7 +2472,7 @@ backsql_entry_get(
                BER_BVZERO( &anlist[ 1 ].an_name );
        }
 
-       bsi.bsi_e = ch_malloc( sizeof( Entry ) );
+       bsi.bsi_e = entry_alloc();
        rc = backsql_init_search( &bsi,
                        ndn,
                        LDAP_SCOPE_BASE,