1998-08-08 20:43:13 -04:00
|
|
|
/* compare.c - ldbm backend compare routine */
|
1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-06 19:07:46 -04:00
|
|
|
/*
|
2003-01-03 15:20:47 -05:00
|
|
|
* Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-06 19:07:46 -04:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1998-10-24 21:41:42 -04:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <stdio.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include "slap.h"
|
|
|
|
|
#include "back-ldbm.h"
|
1998-09-20 16:22:46 -04:00
|
|
|
#include "proto-back-ldbm.h"
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ldbm_back_compare(
|
|
|
|
|
Backend *be,
|
|
|
|
|
Connection *conn,
|
|
|
|
|
Operation *op,
|
2001-12-26 14:05:26 -05:00
|
|
|
struct berval *dn,
|
|
|
|
|
struct berval *ndn,
|
2000-02-06 16:09:44 -05:00
|
|
|
AttributeAssertion *ava
|
1998-08-08 20:43:13 -04:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
1999-07-15 22:45:46 -04:00
|
|
|
Entry *matched;
|
1998-08-08 20:43:13 -04:00
|
|
|
Entry *e;
|
|
|
|
|
Attribute *a;
|
1998-11-05 01:49:49 -05:00
|
|
|
int rc;
|
1999-07-15 22:45:46 -04:00
|
|
|
int manageDSAit = get_manageDSAit( op );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-01-29 12:58:36 -05:00
|
|
|
/* grab giant lock for reading */
|
|
|
|
|
ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
|
|
|
|
|
|
1998-09-20 16:22:46 -04:00
|
|
|
/* get entry with reader lock */
|
2002-01-01 08:31:20 -05:00
|
|
|
if ( (e = dn2entry_r( be, ndn, &matched )) == NULL ) {
|
1999-07-15 22:45:46 -04:00
|
|
|
char *matched_dn = NULL;
|
2002-01-13 20:43:17 -05:00
|
|
|
BerVarray refs = NULL;
|
1999-07-15 22:45:46 -04:00
|
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
|
matched_dn = ch_strdup( matched->e_dn );
|
|
|
|
|
refs = is_entry_referral( matched )
|
2001-12-26 15:59:24 -05:00
|
|
|
? get_entry_referrals( be, conn, op, matched )
|
1999-07-15 22:45:46 -04:00
|
|
|
: NULL;
|
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
|
|
|
|
} else {
|
2001-10-25 22:05:14 -04:00
|
|
|
refs = referral_rewrite( default_referral,
|
2001-12-26 15:59:24 -05:00
|
|
|
NULL, dn, LDAP_SCOPE_DEFAULT );
|
1999-07-15 22:45:46 -04:00
|
|
|
}
|
|
|
|
|
|
2002-01-29 12:58:36 -05:00
|
|
|
ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
|
|
|
|
|
|
1999-07-15 22:45:46 -04:00
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
|
matched_dn, NULL, refs, NULL );
|
|
|
|
|
|
2002-01-13 20:43:17 -05:00
|
|
|
if ( refs ) ber_bvarray_free( refs );
|
2001-10-25 22:05:14 -04:00
|
|
|
free( matched_dn );
|
1998-11-23 15:08:25 -05:00
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
return( 1 );
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-15 22:45:46 -04:00
|
|
|
if (!manageDSAit && is_entry_referral( e ) ) {
|
|
|
|
|
/* entry is a referral, don't allow add */
|
2002-01-13 20:43:17 -05:00
|
|
|
BerVarray refs = get_entry_referrals( be,
|
2001-12-26 15:59:24 -05:00
|
|
|
conn, op, e );
|
1999-07-15 22:45:46 -04:00
|
|
|
|
2001-01-17 12:01:19 -05:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-11 16:33:24 -04:00
|
|
|
LDAP_LOG( BACK_LDBM, INFO,
|
|
|
|
|
"ldbm_back_compare: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
|
2001-01-17 12:01:19 -05:00
|
|
|
#else
|
1999-07-15 22:45:46 -04:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
|
|
|
|
0, 0 );
|
2001-01-17 12:01:19 -05:00
|
|
|
#endif
|
|
|
|
|
|
1999-07-15 22:45:46 -04:00
|
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
|
e->e_dn, NULL, refs, NULL );
|
|
|
|
|
|
2002-01-13 20:43:17 -05:00
|
|
|
if (refs ) ber_bvarray_free( refs );
|
1999-07-15 22:45:46 -04:00
|
|
|
|
|
|
|
|
rc = 1;
|
|
|
|
|
goto return_results;
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-06 16:09:44 -05:00
|
|
|
if ( ! access_allowed( be, conn, op, e,
|
2002-02-09 00:14:17 -05:00
|
|
|
ava->aa_desc, &ava->aa_value, ACL_COMPARE, NULL ) )
|
1999-01-19 00:10:50 -05:00
|
|
|
{
|
1999-07-15 22:45:46 -04:00
|
|
|
send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
|
NULL, NULL, NULL, NULL );
|
1998-09-20 16:22:46 -04:00
|
|
|
rc = 1;
|
|
|
|
|
goto return_results;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2000-02-28 16:16:05 -05:00
|
|
|
rc = LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
|
|
|
|
|
|
for(a = attrs_find( e->e_attrs, ava->aa_desc );
|
|
|
|
|
a != NULL;
|
2000-05-24 14:00:30 -04:00
|
|
|
a = attrs_find( a->a_next, ava->aa_desc ))
|
2000-02-06 16:09:44 -05:00
|
|
|
{
|
2000-02-28 16:16:05 -05:00
|
|
|
rc = LDAP_COMPARE_FALSE;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2001-12-29 10:01:10 -05:00
|
|
|
if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) {
|
2000-02-28 16:16:05 -05: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-20 16:22:46 -04:00
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1998-09-20 16:22:46 -04:00
|
|
|
return_results:;
|
|
|
|
|
cache_return_entry_r( &li->li_cache, e );
|
2002-01-29 12:58:36 -05:00
|
|
|
ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
|
1998-09-20 16:22:46 -04:00
|
|
|
return( rc );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|