]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/compare.c
278a806d6fdd7ed034c7d30e554fffe0a102c001
[openldap] / servers / slapd / back-ldbm / compare.c
1 /* compare.c - ldbm backend compare routine */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/socket.h>
12 #include <ac/string.h>
13
14 #include "slap.h"
15 #include "back-ldbm.h"
16 #include "proto-back-ldbm.h"
17
18 int
19 ldbm_back_compare(
20     Backend     *be,
21     Connection  *conn,
22     Operation   *op,
23     char        *dn,
24     Ava         *ava
25 )
26 {
27         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
28         Entry           *matched;
29         Entry           *e;
30         Attribute       *a;
31         int             rc;
32         int             manageDSAit = get_manageDSAit( op );
33
34         /* get entry with reader lock */
35         if ( (e = dn2entry_r( be, dn, &matched )) == NULL ) {
36                 char *matched_dn = NULL;
37                 struct berval **refs = NULL;
38
39                 if ( matched != NULL ) {
40                         matched_dn = ch_strdup( matched->e_dn );
41                         refs = is_entry_referral( matched )
42                                 ? get_entry_referrals( be, conn, op, matched )
43                                 : NULL;
44                         cache_return_entry_r( &li->li_cache, matched );
45                 } else {
46                         refs = default_referral;
47                 }
48
49                 send_ldap_result( conn, op, LDAP_REFERRAL,
50                         matched_dn, NULL, refs, NULL );
51
52                 if( matched != NULL ) {
53                         ber_bvecfree( refs );
54                         free( matched_dn );
55                 }
56
57                 return( 1 );
58         }
59
60         if (!manageDSAit && is_entry_referral( e ) ) {
61                 /* entry is a referral, don't allow add */
62                 struct berval **refs = get_entry_referrals( be,
63                         conn, op, e );
64
65                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
66                     0, 0 );
67
68                 send_ldap_result( conn, op, LDAP_REFERRAL,
69                     e->e_dn, NULL, refs, NULL );
70
71                 ber_bvecfree( refs );
72
73                 rc = 1;
74                 goto return_results;
75         }
76
77         if ( ! access_allowed( be, conn, op, e,
78                 ava->ava_type, &ava->ava_value, ACL_COMPARE ) )
79         {
80                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
81                         NULL, NULL, NULL, NULL );
82                 rc = 1;
83                 goto return_results;
84         }
85
86         if ( (a = attr_find( e->e_attrs, ava->ava_type )) == NULL ) {
87                 send_ldap_result( conn, op, LDAP_NO_SUCH_ATTRIBUTE,
88                         NULL, NULL, NULL, NULL );
89                 rc = 1;
90                 goto return_results;
91         }
92
93         if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 ) 
94                 send_ldap_result( conn, op, LDAP_COMPARE_TRUE,
95                         NULL, NULL, NULL, NULL );
96         else
97                 send_ldap_result( conn, op, LDAP_COMPARE_FALSE,
98                         NULL, NULL, NULL, NULL );
99
100         rc = 0;
101
102 return_results:;
103         cache_return_entry_r( &li->li_cache, e );
104         return( rc );
105 }