compare.c 2.44 KB
Newer Older
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1
/* compare.c - ldbm backend compare routine */
2
/* $OpenLDAP$ */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
3
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
4
 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
Kurt Zeilenga's avatar
Kurt Zeilenga committed
5
6
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
7

Kurt Zeilenga's avatar
Kurt Zeilenga committed
8
9
#include "portable.h"

Kurt Zeilenga's avatar
Kurt Zeilenga committed
10
#include <stdio.h>
Kurt Zeilenga's avatar
Kurt Zeilenga committed
11
12
13
14

#include <ac/socket.h>
#include <ac/string.h>

Kurt Zeilenga's avatar
Kurt Zeilenga committed
15
16
#include "slap.h"
#include "back-ldbm.h"
17
#include "proto-back-ldbm.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
18
19
20
21
22
23

int
ldbm_back_compare(
    Backend	*be,
    Connection	*conn,
    Operation	*op,
24
25
    struct berval	*dn,
    struct berval	*ndn,
26
	AttributeAssertion *ava
Kurt Zeilenga's avatar
Kurt Zeilenga committed
27
28
29
)
{
	struct ldbminfo	*li = (struct ldbminfo *) be->be_private;
30
	Entry		*matched;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
31
32
	Entry		*e;
	Attribute	*a;
Hallvard Furuseth's avatar
Hallvard Furuseth committed
33
	int		rc;
34
	int		manageDSAit = get_manageDSAit( op );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
35

36
	/* get entry with reader lock */
37
	if ( (e = dn2entry_r( be, ndn->bv_val, &matched )) == NULL ) {
38
39
40
41
42
43
		char *matched_dn = NULL;
		struct berval **refs = NULL;

		if ( matched != NULL ) {
			matched_dn = ch_strdup( matched->e_dn );
			refs = is_entry_referral( matched )
44
				? get_entry_referrals( be, conn, op, matched )
45
46
47
				: NULL;
			cache_return_entry_r( &li->li_cache, matched );
		} else {
48
			refs = referral_rewrite( default_referral,
49
				NULL, dn, LDAP_SCOPE_DEFAULT );
50
51
52
53
54
		}

		send_ldap_result( conn, op, LDAP_REFERRAL,
			matched_dn, NULL, refs, NULL );

55
56
		ber_bvecfree( refs );
		free( matched_dn );
57

Kurt Zeilenga's avatar
Kurt Zeilenga committed
58
59
60
		return( 1 );
	}

61
62
63
	if (!manageDSAit && is_entry_referral( e ) ) {
		/* entry is a referral, don't allow add */
		struct berval **refs = get_entry_referrals( be,
64
			conn, op, e );
65

Gary Williams's avatar
Gary Williams committed
66
67
#ifdef NEW_LOGGING
		LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
68
			"ldbm_back_compare: entry (%s) is a referral.\n", e->e_dn ));
Gary Williams's avatar
Gary Williams committed
69
#else
70
71
		Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
		    0, 0 );
Gary Williams's avatar
Gary Williams committed
72
73
#endif

74
75
76
77
78
79
80
81
82
83

		send_ldap_result( conn, op, LDAP_REFERRAL,
		    e->e_dn, NULL, refs, NULL );

		ber_bvecfree( refs );

		rc = 1;
		goto return_results;
	}

84
	if ( ! access_allowed( be, conn, op, e,
85
		ava->aa_desc, &ava->aa_value, ACL_COMPARE ) )
86
	{
87
88
		send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
			NULL, NULL, NULL, NULL );
89
90
		rc = 1;
		goto return_results;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
91
92
	}

93
94
95
96
	rc = LDAP_NO_SUCH_ATTRIBUTE;

	for(a = attrs_find( e->e_attrs, ava->aa_desc );
		a != NULL;
97
		a = attrs_find( a->a_next, ava->aa_desc ))
98
	{
99
		rc = LDAP_COMPARE_FALSE;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
100

101
		if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) {
102
103
104
105
106
107
108
109
110
111
112
113
			rc = LDAP_COMPARE_TRUE;
			break;
		}

	}

	send_ldap_result( conn, op, rc,
		NULL, NULL, NULL, NULL );

	if( rc != LDAP_NO_SUCH_ATTRIBUTE ) {
		rc = 0;
	}
114

Kurt Zeilenga's avatar
Kurt Zeilenga committed
115

116
117
118
return_results:;
	cache_return_entry_r( &li->li_cache, e );
	return( rc );
Kurt Zeilenga's avatar
Kurt Zeilenga committed
119
}