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

144 lines
3.2 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/>.
*
2012-01-01 23:07:45 +08:00
* Copyright 2000-2012 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
int manageDSAit = get_manageDSAit( op );
DB_TXN *rtxn;
DB_LOCK lock;
rs->sr_err = bdb_reader_get(op, bdb->bi_dbenv, &rtxn);
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, rtxn, &op->o_req_ndn, &ei, 1,
&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;
}
2010-12-24 05:45:36 +08:00
rs->sr_err = slap_compare_entry( op, e, op->orc_ava );
2000-09-24 14:04:58 +08:00
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
return rs->sr_err;
}