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

191 lines
4.4 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/>.
*
2007-01-03 04:00:42 +08:00
* Copyright 2000-2007 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 );
2007-08-18 04:33:46 +08:00
BDB_LOCKER 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 */
2005-03-20 12:29:35 +08:00
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 ) {
2005-03-20 12:29:35 +08:00
/* return referral only if "disclose" is granted on the object */
if ( ! access_allowed( op, e, slap_schema.si_ad_entry,
2005-03-20 12:29:35 +08:00
NULL, ACL_DISCLOSE, NULL ) )
{
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} else {
rs->sr_matched = ch_strdup( e->e_dn );
rs->sr_ref = is_entry_referral( e )
? get_entry_referrals( op, e )
: NULL;
rs->sr_err = LDAP_REFERRAL;
}
2007-01-01 07:37:06 +08:00
bdb_cache_return_entry_r( bdb, e, &lock );
2003-04-17 00:23:36 +08:00
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 );
rs->sr_err = rs->sr_ref ? LDAP_REFERRAL : LDAP_NO_SUCH_OBJECT;
2000-09-24 14:04:58 +08:00
}
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 ) ) {
2005-03-20 12:29:35 +08:00
/* return referral only if "disclose" is granted on the object */
if ( !access_allowed( op, e, slap_schema.si_ad_entry,
2005-03-20 12:29:35 +08:00
NULL, ACL_DISCLOSE, NULL ) )
{
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} else {
/* entry is a referral, don't allow compare */
rs->sr_ref = get_entry_referrals( op, e );
rs->sr_err = LDAP_REFERRAL;
rs->sr_matched = e->e_name.bv_val;
}
2000-09-24 14:04:58 +08:00
2005-03-20 12:29:35 +08:00
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0, 0, 0 );
2000-09-24 14:04:58 +08:00
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 ))
{
2005-03-20 12:29:35 +08:00
if ( !access_allowed( op, e, slap_schema.si_ad_entry,
NULL, ACL_DISCLOSE, NULL ) )
{
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} else {
2005-03-20 12:29:35 +08:00
rs->sr_err = LDAP_ASSERTION_FAILED;
}
goto return_results;
}
if ( !access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
&op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ) )
{
/* return error only if "disclose"
* is granted on the object */
if ( !access_allowed( op, e, slap_schema.si_ad_entry,
NULL, ACL_DISCLOSE, NULL ) )
{
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} else {
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,
2005-03-20 12:29:35 +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
switch ( rs->sr_err ) {
case LDAP_COMPARE_FALSE:
case LDAP_COMPARE_TRUE:
rs->sr_err = LDAP_SUCCESS;
break;
2002-01-26 23:06:53 +08:00
}
2000-09-24 14:04:58 +08:00
done:
/* free entry */
if ( e != NULL ) {
2007-01-01 07:37:06 +08:00
bdb_cache_return_entry_r( bdb, 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;
}