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

157 lines
3.6 KiB
C
Raw Normal View History

2000-09-24 14:04:58 +08:00
/* compare.c - bdb backend compare routine */
/* $OpenLDAP$ */
2003-11-29 05:08:20 +08:00
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
2004-01-02 03:15:16 +08:00
* Copyright 2000-2004 The OpenLDAP Foundation.
2003-11-29 05:08:20 +08:00
* 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
* <http://www.OpenLDAP.org/license.html>.
2000-09-24 14:04:58 +08:00
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include "back-bdb.h"
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;
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 );
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( op, NULL, &op->o_req_ndn, &ei, 1, 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;
}
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 {
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
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
0, 0 );
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;
}
if ( get_assert( op ) &&
( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
{
rs->sr_err = LDAP_ASSERTION_FAILED;
goto return_results;
}
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
if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
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 )
{
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;
}