]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/compare.c
Use #ifdef, not #if
[openldap] / servers / slapd / back-bdb2 / compare.c
1 /* compare.c - bdb2 backend compare routine */
2 /* $OpenLDAP$ */
3
4 #include "portable.h"
5
6 #include <stdio.h>
7
8 #include <ac/socket.h>
9 #include <ac/string.h>
10
11 #include "slap.h"
12 #include "back-bdb2.h"
13 #include "proto-back-bdb2.h"
14
15 static int
16 bdb2i_back_compare_internal(
17     BackendDB   *be,
18     Connection  *conn,
19     Operation   *op,
20     char        *dn,
21     Ava         *ava
22 )
23 {
24         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
25         Entry           *matched;
26         Entry           *e;
27         Attribute       *a;
28         int             rc;
29         int             manageDSAit = get_manageDSAit( op );
30
31         /* get entry with reader lock */
32         if ( (e = bdb2i_dn2entry_r( be, dn, &matched )) == NULL ) {
33                 char *matched_dn = NULL;
34                 struct berval **refs = NULL;
35
36                 if ( matched != NULL ) {
37                         matched_dn = ch_strdup( matched->e_dn );
38                         refs = is_entry_referral( matched )
39                                 ? get_entry_referrals( be, conn, op, matched )
40                                 : NULL;
41                         bdb2i_cache_return_entry_r( &li->li_cache, matched );
42                 } else {
43                         refs = default_referral;
44                 }
45
46                 send_ldap_result( conn, op, LDAP_REFERRAL,
47                         matched_dn, NULL, refs, NULL );
48
49                 if( matched != NULL ) {
50                         ber_bvecfree( refs );
51                         free( matched_dn );
52                 }
53
54                 return( 1 );
55         }
56
57         if (!manageDSAit && is_entry_referral( e ) ) {
58                 /* entry is a referral, don't allow add */
59                 struct berval **refs = get_entry_referrals( be,
60                         conn, op, e );
61
62                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
63                         0, 0 );
64
65                 send_ldap_result( conn, op, LDAP_REFERRAL,
66                         e->e_dn, NULL, refs, NULL );
67
68                 ber_bvecfree( refs );
69
70                 rc = 1;
71                 goto return_results;
72         }
73
74         if ( ! access_allowed( be, conn, op, e,
75                 ava->ava_type, &ava->ava_value, ACL_COMPARE ) )
76         {
77                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
78                         NULL, NULL, NULL, NULL );
79                 rc = 1;
80                 goto return_results;
81         }
82
83         if ( (a = attr_find( e->e_attrs, ava->ava_type )) == NULL ) {
84                 send_ldap_result( conn, op, LDAP_NO_SUCH_ATTRIBUTE,
85                         NULL, NULL, NULL, NULL );
86                 rc = 1;
87                 goto return_results;
88         }
89
90         if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 ) 
91                 send_ldap_result( conn, op, LDAP_COMPARE_TRUE,
92                         NULL, NULL, NULL, NULL );
93         else
94                 send_ldap_result( conn, op, LDAP_COMPARE_FALSE,
95                         NULL, NULL, NULL, NULL );
96
97         rc = 0;
98
99 return_results:;
100         bdb2i_cache_return_entry_r( &li->li_cache, e );
101         return( rc );
102 }
103
104
105 int
106 bdb2_back_compare(
107     BackendDB   *be,
108     Connection  *conn,
109     Operation   *op,
110     char        *dn,
111     char        *ndn,
112     Ava         *ava
113 )
114 {
115         DB_LOCK         lock;
116         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
117         struct timeval  time1;
118         int             ret;
119
120         bdb2i_start_timing( be->bd_info, &time1 );
121
122         if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
123
124                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
125                         NULL, NULL, NULL, NULL );
126                 return( 1 );
127
128         }
129
130         ret = bdb2i_back_compare_internal( be, conn, op, ndn, ava );
131         (void) bdb2i_leave_backend_r( lock );
132         bdb2i_stop_timing( be->bd_info, time1, "CMP", conn, op );
133
134         return( ret );
135 }
136
137