1998-08-09 08:43:13 +08:00
|
|
|
/* compare.c - ldbm backend compare routine */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2006-01-04 07:11:52 +08:00
|
|
|
* Copyright 1998-2006 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>.
|
1999-08-07 07:07:46 +08:00
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
1998-09-21 04:22:46 +08:00
|
|
|
#include "proto-back-ldbm.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_back_compare(
|
2003-03-30 17:03:54 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
|
1999-07-16 10:45:46 +08:00
|
|
|
Entry *matched;
|
1998-08-09 08:43:13 +08:00
|
|
|
Entry *e;
|
|
|
|
Attribute *a;
|
1999-07-16 10:45:46 +08:00
|
|
|
int manageDSAit = get_manageDSAit( op );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2002-01-30 01:58:36 +08:00
|
|
|
/* grab giant lock for reading */
|
|
|
|
ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* get entry with reader lock */
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( (e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched )) == NULL ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
if ( matched != NULL ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = ch_strdup( matched->e_dn );
|
|
|
|
rs->sr_ref = is_entry_referral( matched )
|
|
|
|
? get_entry_referrals( op, matched )
|
1999-07-16 10:45:46 +08:00
|
|
|
: NULL;
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
|
|
|
} else {
|
2004-10-06 13:51:38 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral,
|
2003-03-30 17:03:54 +08:00
|
|
|
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
1999-07-16 10:45:46 +08:00
|
|
|
}
|
|
|
|
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
|
|
|
|
free( (char *)rs->sr_matched );
|
2003-09-27 15:36:20 +08:00
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2006-01-07 19:39:18 +08:00
|
|
|
return rs->sr_err;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
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 );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
|
|
|
0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
1999-07-16 10:45:46 +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 );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
|
2003-09-27 15:36:20 +08:00
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
1999-07-16 10:45:46 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ! access_allowed( op, e,
|
|
|
|
op->oq_compare.rs_ava->aa_desc, &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ) )
|
1999-01-19 13:10:50 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
goto return_results;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
|
2000-02-29 05:16:05 +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-02-29 05:16:05 +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-02-07 05:09:44 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_COMPARE_FALSE;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
|
2003-03-16 09:39:39 +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-03-16 09:39:39 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_COMPARE_TRUE;
|
2000-02-29 05:16:05 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
return_results:;
|
|
|
|
cache_return_entry_r( &li->li_cache, e );
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
|
2006-01-07 19:39:18 +08:00
|
|
|
|
|
|
|
switch ( rs->sr_err ) {
|
|
|
|
case LDAP_NO_SUCH_ATTRIBUTE:
|
|
|
|
case LDAP_COMPARE_FALSE:
|
|
|
|
case LDAP_COMPARE_TRUE:
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
if ( rs->sr_err != LDAP_NO_SUCH_ATTRIBUTE ) {
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rs->sr_err;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|