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
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* 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,
|
|
|
|
char *dn,
|
1999-09-19 07:40:03 +08:00
|
|
|
char *ndn,
|
2000-02-07 05:09:44 +08:00
|
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT
|
|
|
|
AttributeAssertion *ava
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Ava *ava
|
2000-02-07 05:09:44 +08:00
|
|
|
#endif
|
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
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* get entry with reader lock */
|
1999-09-19 07:40:03 +08:00
|
|
|
if ( (e = dn2entry_r( be, ndn, &matched )) == NULL ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
char *matched_dn = NULL;
|
|
|
|
struct berval **refs = NULL;
|
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
matched_dn = ch_strdup( matched->e_dn );
|
|
|
|
refs = is_entry_referral( matched )
|
|
|
|
? get_entry_referrals( be, conn, op, matched )
|
|
|
|
: NULL;
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
|
|
|
} else {
|
|
|
|
refs = default_referral;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
matched_dn, NULL, refs, NULL );
|
|
|
|
|
|
|
|
if( matched != NULL ) {
|
|
|
|
ber_bvecfree( refs );
|
|
|
|
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 */
|
|
|
|
struct berval **refs = get_entry_referrals( be,
|
|
|
|
conn, op, e );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
|
|
|
|
0, 0 );
|
|
|
|
|
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL,
|
|
|
|
e->e_dn, NULL, refs, NULL );
|
|
|
|
|
|
|
|
ber_bvecfree( refs );
|
|
|
|
|
|
|
|
rc = 1;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2000-02-07 05:09:44 +08:00
|
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT
|
|
|
|
if ( ! access_allowed( be, conn, op, e,
|
|
|
|
ava->aa_desc->ad_type->sat_cname, ava->aa_value, ACL_COMPARE ) )
|
|
|
|
#else
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( ! access_allowed( be, conn, op, e,
|
|
|
|
ava->ava_type, &ava->ava_value, ACL_COMPARE ) )
|
2000-02-07 05:09:44 +08:00
|
|
|
#endif
|
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-07 05:09:44 +08:00
|
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT
|
|
|
|
if ( (a = attr_find( e->e_attrs, ava->aa_desc->ad_cname->bv_val )) == NULL )
|
|
|
|
#else
|
|
|
|
if ( (a = attr_find( e->e_attrs, ava->ava_type )) == NULL )
|
|
|
|
#endif
|
|
|
|
{
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_NO_SUCH_ATTRIBUTE,
|
|
|
|
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-01 06:14:16 +08:00
|
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT
|
|
|
|
/* not yet implemented */
|
|
|
|
#else
|
1998-09-21 04:22:46 +08:00
|
|
|
if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 )
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_COMPARE_TRUE,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
else
|
2000-01-28 09:17:58 +08:00
|
|
|
#endif
|
1999-07-16 10:45:46 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_COMPARE_FALSE,
|
|
|
|
NULL, NULL, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
|
|
|
|
rc = 0;
|
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 );
|
|
|
|
return( rc );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|