2000-09-24 14:04:58 +08:00
|
|
|
/* compare.c - bdb backend compare routine */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
2000-09-24 14:04:58 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
2000-09-25 06:48:13 +08:00
|
|
|
#include "external.h"
|
2000-09-24 14:04:58 +08:00
|
|
|
|
|
|
|
int
|
2003-03-30 17:03:54 +08:00
|
|
|
bdb_compare( Operation *op, SlapReply *rs )
|
2000-09-24 14:04:58 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2003-05-02 21:24:44 +08:00
|
|
|
Entry *e = NULL;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei;
|
2000-09-24 14:04:58 +08:00
|
|
|
Attribute *a;
|
|
|
|
int manageDSAit = get_manageDSAit( op );
|
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
u_int32_t locker;
|
|
|
|
DB_LOCK lock;
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
|
|
|
|
switch(rs->sr_err) {
|
2002-08-20 11:10:08 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
|
|
|
|
return rs->sr_err;
|
2002-08-20 11:10:08 +08:00
|
|
|
}
|
2002-06-01 04:49:19 +08:00
|
|
|
|
|
|
|
dn2entry_retry:
|
2000-09-24 14:04:58 +08:00
|
|
|
/* get entry */
|
2003-04-17 00:23:36 +08:00
|
|
|
rs->sr_err = bdb_dn2entry( op->o_bd, NULL, &op->o_req_ndn, &ei, 1, locker, &lock, op->o_tmpmemctx );
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-24 14:04:58 +08:00
|
|
|
case DB_NOTFOUND:
|
2001-11-13 04:28:23 +08:00
|
|
|
case 0:
|
2000-09-24 14:04:58 +08:00
|
|
|
break;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "ldap server busy";
|
2002-04-20 05:41:32 +08:00
|
|
|
goto return_results;
|
2002-06-01 04:49:19 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto dn2entry_retry;
|
2000-09-24 14:04:58 +08:00
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2000-09-24 14:04:58 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
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 )
|
2000-09-24 14:04:58 +08:00
|
|
|
: NULL;
|
2003-04-17 00:23:36 +08:00
|
|
|
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
|
|
|
|
e = NULL;
|
2000-09-28 10:27:49 +08:00
|
|
|
|
2000-09-24 14:04:58 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral,
|
|
|
|
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
2000-09-24 14:04:58 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
free( (char *)rs->sr_matched );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-24 14:04:58 +08:00
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!manageDSAit && is_entry_referral( e ) ) {
|
|
|
|
/* entry is a referral, don't allow add */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = get_entry_referrals( op, e );
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2002-03-27 01:47:52 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, DETAIL1,
|
|
|
|
"bdb_compare: entry is referral\n", 0, 0, 0 );
|
2002-03-27 01:47:52 +08:00
|
|
|
#else
|
2000-09-24 14:04:58 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
2000-09-28 06:28:59 +08:00
|
|
|
0, 0 );
|
2002-03-27 01:47:52 +08:00
|
|
|
#endif
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
rs->sr_matched = e->e_name.bv_val;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-24 14:04:58 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
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;
|
2000-09-24 14:04:58 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
|
2000-09-24 14:04:58 +08:00
|
|
|
a != NULL;
|
2003-03-30 17:03:54 +08:00
|
|
|
a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
|
2000-09-24 14:04:58 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_COMPARE_FALSE;
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
|
2003-03-16 06:47:17 +08:00
|
|
|
SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
|
|
|
|
SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
|
2003-04-11 09:29:28 +08:00
|
|
|
a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 )
|
2003-02-27 09:54:43 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_COMPARE_TRUE;
|
2000-09-24 14:04:58 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return_results:
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) {
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2002-01-26 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2000-09-24 14:04:58 +08:00
|
|
|
done:
|
|
|
|
/* free entry */
|
2000-09-28 10:27:49 +08:00
|
|
|
if( e != NULL ) {
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
|
2000-09-28 10:27:49 +08:00
|
|
|
}
|
2000-09-24 14:04:58 +08:00
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
return rs->sr_err;
|
2001-10-23 17:48:18 +08:00
|
|
|
}
|