openldap/servers/slapd/back-bdb/compare.c

150 lines
3.4 KiB
C
Raw Normal View History

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
bdb_compare( Operation *op, SlapReply *rs )
2000-09-24 14:04:58 +08:00
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
2000-09-24 14:04:58 +08:00
Entry *matched;
Entry *e;
Attribute *a;
int manageDSAit = get_manageDSAit( op );
u_int32_t locker;
DB_LOCK lock;
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:
2000-09-24 14:04:58 +08:00
/* get entry */
rs->sr_err = bdb_dn2entry_r( op->o_bd, NULL, &op->o_req_ndn, &e, &matched, 0, locker, &lock );
2000-09-24 14:04:58 +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:
rs->sr_text = "ldap server busy";
2002-04-20 05:41:32 +08:00
goto return_results;
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
goto dn2entry_retry;
2000-09-24 14:04:58 +08:00
default:
rs->sr_err = LDAP_OTHER;
rs->sr_text = "internal error";
2000-09-24 14:04:58 +08:00
goto return_results;
}
if ( e == NULL ) {
if ( matched != NULL ) {
rs->sr_matched = ch_strdup( matched->e_dn );
rs->sr_ref = is_entry_referral( matched )
? get_entry_referrals( op, matched )
2000-09-24 14:04:58 +08:00
: NULL;
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, matched, &lock );
2000-09-28 10:27:49 +08:00
matched = NULL;
2000-09-24 14:04:58 +08:00
} else {
rs->sr_ref = referral_rewrite( default_referral,
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
2000-09-24 14:04:58 +08:00
}
rs->sr_err = LDAP_REFERRAL;
send_ldap_result( op, rs );
2000-09-24 14:04:58 +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 */
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
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,
0, 0 );
2002-03-27 01:47:52 +08:00
#endif
2000-09-24 14:04:58 +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
ber_bvarray_free( rs->sr_ref );
rs->sr_ref = NULL;
rs->sr_matched = NULL;
2000-09-24 14:04:58 +08:00
goto done;
}
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;
}
rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
2000-09-24 14:04:58 +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;
a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
2000-09-24 14:04:58 +08:00
{
rs->sr_err = LDAP_COMPARE_FALSE;
2000-09-24 14:04:58 +08:00
#ifdef SLAP_NVALUES
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 ) == 0 )
#else
if ( value_find( op->oq_compare.rs_ava->aa_desc, a->a_vals, &op->oq_compare.rs_ava->aa_value ) == 0 )
#endif
{
rs->sr_err = LDAP_COMPARE_TRUE;
2000-09-24 14:04:58 +08:00
break;
}
}
return_results:
send_ldap_result( op, rs );
2000-09-24 14:04:58 +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 ) {
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
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
return rs->sr_err;
}