1998-08-09 08:43:13 +08:00
|
|
|
/* compare.c - ldbm backend compare routine */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-07 07:07:46 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
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(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
2001-12-27 03:05:26 +08:00
|
|
|
struct berval *dn,
|
|
|
|
struct berval *ndn,
|
2000-02-07 05:09:44 +08:00
|
|
|
AttributeAssertion *ava
|
1998-08-09 08:43:13 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
1999-07-16 10:45:46 +08:00
|
|
|
Entry *matched;
|
1998-08-09 08:43:13 +08:00
|
|
|
Entry *e;
|
|
|
|
Attribute *a;
|
1998-11-05 14:49:49 +08:00
|
|
|
int rc;
|
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 */
|
2002-01-01 21:31:20 +08:00
|
|
|
if ( (e = dn2entry_r( be, ndn, &matched )) == NULL ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
char *matched_dn = NULL;
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray refs = NULL;
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
matched_dn = ch_strdup( matched->e_dn );
|
|
|
|
refs = is_entry_referral( matched )
|
2001-12-27 04:59:24 +08:00
|
|
|
? get_entry_referrals( be, conn, op, matched )
|
1999-07-16 10:45:46 +08:00
|
|
|
: NULL;
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
|
|
|
} else {
|
2001-10-26 10:05:14 +08:00
|
|
|
refs = referral_rewrite( default_referral,
|
2001-12-27 04:59:24 +08:00
|
|
|
NULL, 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);
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
matched_dn, NULL, refs, NULL );
|
|
|
|
|
2002-01-14 09:43:17 +08:00
|
|
|
if ( refs ) ber_bvarray_free( refs );
|
2001-10-26 10:05:14 +08:00
|
|
|
free( matched_dn );
|
1998-11-24 04:08:25 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
if (!manageDSAit && is_entry_referral( e ) ) {
|
|
|
|
/* entry is a referral, don't allow add */
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray refs = get_entry_referrals( be,
|
2001-12-27 04:59:24 +08:00
|
|
|
conn, op, e );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( BACK_LDBM, INFO,
|
|
|
|
"ldbm_back_compare: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
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
|
|
|
#endif
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
e->e_dn, NULL, refs, NULL );
|
|
|
|
|
2002-01-14 09:43:17 +08:00
|
|
|
if (refs ) ber_bvarray_free( refs );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
|
|
|
rc = 1;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2000-02-07 05:09:44 +08:00
|
|
|
if ( ! access_allowed( be, conn, op, e,
|
2002-02-09 13:14:17 +08:00
|
|
|
ava->aa_desc, &ava->aa_value, ACL_COMPARE, NULL ) )
|
1999-01-19 13:10:50 +08:00
|
|
|
{
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
rc = 1;
|
|
|
|
goto return_results;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2000-02-29 05:16:05 +08:00
|
|
|
rc = LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
|
|
|
|
for(a = attrs_find( e->e_attrs, ava->aa_desc );
|
|
|
|
a != NULL;
|
2000-05-25 02:00:30 +08:00
|
|
|
a = attrs_find( a->a_next, ava->aa_desc ))
|
2000-02-07 05:09:44 +08:00
|
|
|
{
|
2000-02-29 05:16:05 +08:00
|
|
|
rc = LDAP_COMPARE_FALSE;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2003-03-16 09:39:39 +08:00
|
|
|
#ifdef SLAP_NVALUES
|
|
|
|
if ( value_find_ex( ava->aa_desc,
|
|
|
|
SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
|
|
|
|
SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
|
2003-03-24 09:56:56 +08:00
|
|
|
a->a_nvals, &ava->aa_value ) == 0 )
|
2003-03-16 09:39:39 +08:00
|
|
|
#else
|
|
|
|
if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 )
|
|
|
|
#endif
|
|
|
|
{
|
2000-02-29 05:16:05 +08:00
|
|
|
rc = LDAP_COMPARE_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send_ldap_result( conn, op, rc,
|
|
|
|
NULL, NULL, NULL, NULL );
|
|
|
|
|
|
|
|
if( rc != LDAP_NO_SUCH_ATTRIBUTE ) {
|
|
|
|
rc = 0;
|
|
|
|
}
|
1998-09-21 04:22:46 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
|
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);
|
1998-09-21 04:22:46 +08:00
|
|
|
return( rc );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|