X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=servers%2Fslapd%2Fback-bdb%2Fcompare.c;h=6cc97f854647a729c797179590c913f92519d69d;hb=c59f0869ec670a8b2f58cb69a5c92202fd33f0c3;hp=25c8cf4f9554480bd81db6913ce5238dda08b2ba;hpb=6107ba67d2fd7eadb23ffdd1d284306011ef4013;p=openldap
diff --git a/servers/slapd/back-bdb/compare.c b/servers/slapd/back-bdb/compare.c
index 25c8cf4f95..6cc97f8546 100644
--- a/servers/slapd/back-bdb/compare.c
+++ b/servers/slapd/back-bdb/compare.c
@@ -1,8 +1,17 @@
/* compare.c - bdb backend compare routine */
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 2000-2004 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
*/
#include "portable.h"
@@ -14,78 +23,75 @@
#include "external.h"
int
-bdb_compare(
- BackendDB *be,
- Connection *conn,
- Operation *op,
- struct berval *dn,
- struct berval *ndn,
- AttributeAssertion *ava
-)
+bdb_compare( Operation *op, SlapReply *rs )
{
- struct bdb_info *bdb = (struct bdb_info *) be->be_private;
- Entry *matched;
- Entry *e;
+ struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
+ Entry *e = NULL;
+ EntryInfo *ei;
Attribute *a;
- int rc;
- const char *text = NULL;
int manageDSAit = get_manageDSAit( op );
u_int32_t locker;
DB_LOCK lock;
- LOCK_ID ( bdb->bi_dbenv, &locker );
+ rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
+ switch(rs->sr_err) {
+ case 0:
+ break;
+ default:
+ send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
+ return rs->sr_err;
+ }
dn2entry_retry:
/* get entry */
- rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0, locker, &lock );
+ rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1, locker, &lock );
- switch( rc ) {
+ switch( rs->sr_err ) {
case DB_NOTFOUND:
case 0:
break;
case LDAP_BUSY:
- text = "ldap server busy";
+ rs->sr_text = "ldap server busy";
goto return_results;
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
goto dn2entry_retry;
default:
- rc = LDAP_OTHER;
- text = "internal error";
+ rs->sr_err = LDAP_OTHER;
+ rs->sr_text = "internal error";
goto return_results;
}
- if ( e == NULL ) {
- char *matched_dn = NULL;
- BerVarray refs;
-
- if ( matched != NULL ) {
- matched_dn = ch_strdup( matched->e_dn );
- refs = is_entry_referral( matched )
- ? get_entry_referrals( be, conn, op, matched )
+ e = ei->bei_e;
+ if ( rs->sr_err == DB_NOTFOUND ) {
+ if ( e != NULL ) {
+ rs->sr_matched = ch_strdup( e->e_dn );
+ rs->sr_ref = is_entry_referral( e )
+ ? get_entry_referrals( op, e )
: NULL;
- bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, matched, &lock );
- matched = NULL;
+ bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
+ e = NULL;
} else {
- refs = referral_rewrite( default_referral,
- NULL, dn, LDAP_SCOPE_DEFAULT );
+ rs->sr_ref = referral_rewrite( default_referral,
+ NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
}
- send_ldap_result( conn, op, rc = LDAP_REFERRAL,
- matched_dn, NULL, refs, NULL );
+ rs->sr_err = LDAP_REFERRAL;
+ send_ldap_result( op, rs );
- ber_bvarray_free( refs );
- free( matched_dn );
+ ber_bvarray_free( rs->sr_ref );
+ free( (char *)rs->sr_matched );
+ rs->sr_ref = NULL;
+ rs->sr_matched = NULL;
goto done;
}
if (!manageDSAit && is_entry_referral( e ) ) {
/* entry is a referral, don't allow add */
- BerVarray refs = get_entry_referrals( be,
- conn, op, e );
+ rs->sr_ref = get_entry_referrals( op, e );
#ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, DETAIL1,
@@ -95,41 +101,53 @@ dn2entry_retry:
0, 0 );
#endif
- send_ldap_result( conn, op, rc = LDAP_REFERRAL,
- e->e_dn, NULL, refs, NULL );
+ rs->sr_err = LDAP_REFERRAL;
+ rs->sr_matched = e->e_name.bv_val;
+ send_ldap_result( op, rs );
- ber_bvarray_free( refs );
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
+ rs->sr_matched = NULL;
goto done;
}
- if ( ! access_allowed( be, conn, op, e,
- ava->aa_desc, &ava->aa_value, ACL_COMPARE, NULL ) )
+ if ( get_assert( op ) &&
+ ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
{
- rc = LDAP_INSUFFICIENT_ACCESS;
+ rs->sr_err = LDAP_ASSERTION_FAILED;
goto return_results;
}
- rc = LDAP_NO_SUCH_ATTRIBUTE;
+ rs->sr_err = access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
+ &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
+ if ( ! rs->sr_err ) {
+ rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
+ goto return_results;
+ }
+
+ rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
- for(a = attrs_find( e->e_attrs, ava->aa_desc );
+ for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
a != NULL;
- a = attrs_find( a->a_next, ava->aa_desc ))
+ a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
{
- rc = LDAP_COMPARE_FALSE;
-
- if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) {
- rc = LDAP_COMPARE_TRUE;
+ rs->sr_err = LDAP_COMPARE_FALSE;
+
+ if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
+ SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
+ SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
+ a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
+ {
+ rs->sr_err = LDAP_COMPARE_TRUE;
break;
}
-
}
return_results:
- send_ldap_result( conn, op, rc,
- NULL, text, NULL, NULL );
+ send_ldap_result( op, rs );
- if( rc == LDAP_COMPARE_FALSE || rc == LDAP_COMPARE_TRUE ) {
- rc = LDAP_SUCCESS;
+ if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
+ rs->sr_err = LDAP_SUCCESS;
}
done:
@@ -140,5 +158,5 @@ done:
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
- return rc;
+ return rs->sr_err;
}