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