]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/compare.c
Added bdb_attribute and bdb_group ACL support routines
[openldap] / servers / slapd / back-ldbm / compare.c
1 /* compare.c - ldbm backend compare routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 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     const char  *dn,
25     const char  *ndn,
26         AttributeAssertion *ava
27 )
28 {
29         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
30         Entry           *matched;
31         Entry           *e;
32         Attribute       *a;
33         int             rc;
34         int             manageDSAit = get_manageDSAit( op );
35
36         /* get entry with reader lock */
37         if ( (e = dn2entry_r( be, ndn, &matched )) == NULL ) {
38                 char *matched_dn = NULL;
39                 struct berval **refs = NULL;
40
41                 if ( matched != NULL ) {
42                         matched_dn = ch_strdup( matched->e_dn );
43                         refs = is_entry_referral( matched )
44                                 ? get_entry_referrals( be, conn, op, matched,
45                                         dn, LDAP_SCOPE_DEFAULT )
46                                 : NULL;
47                         cache_return_entry_r( &li->li_cache, matched );
48                 } else {
49                         refs = referral_rewrite( default_referral,
50                                 NULL, dn, LDAP_SCOPE_DEFAULT );
51                 }
52
53                 send_ldap_result( conn, op, LDAP_REFERRAL,
54                         matched_dn, NULL, refs, NULL );
55
56                 ber_bvecfree( refs );
57                 free( matched_dn );
58
59                 return( 1 );
60         }
61
62         if (!manageDSAit && is_entry_referral( e ) ) {
63                 /* entry is a referral, don't allow add */
64                 struct berval **refs = get_entry_referrals( be,
65                         conn, op, e, dn, LDAP_SCOPE_DEFAULT );
66
67 #ifdef NEW_LOGGING
68                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
69                            "ldbm_back_compare: entry (%s) is a referral.\n", e->e_dn ));
70 #else
71                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
72                     0, 0 );
73 #endif
74
75
76                 send_ldap_result( conn, op, LDAP_REFERRAL,
77                     e->e_dn, NULL, refs, NULL );
78
79                 ber_bvecfree( refs );
80
81                 rc = 1;
82                 goto return_results;
83         }
84
85         if ( ! access_allowed( be, conn, op, e,
86                 ava->aa_desc, ava->aa_value, ACL_COMPARE ) )
87         {
88                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
89                         NULL, NULL, NULL, NULL );
90                 rc = 1;
91                 goto return_results;
92         }
93
94         rc = LDAP_NO_SUCH_ATTRIBUTE;
95
96         for(a = attrs_find( e->e_attrs, ava->aa_desc );
97                 a != NULL;
98                 a = attrs_find( a->a_next, ava->aa_desc ))
99         {
100                 rc = LDAP_COMPARE_FALSE;
101
102                 if ( value_find_ex( ava->aa_desc,
103                                     SLAP_MR_VALUE_IS_IN_MR_SYNTAX,
104                                     a->a_vals, ava->aa_value ) == 0 )
105                 {
106                         rc = LDAP_COMPARE_TRUE;
107                         break;
108                 }
109
110         }
111
112         send_ldap_result( conn, op, rc,
113                 NULL, NULL, NULL, NULL );
114
115         if( rc != LDAP_NO_SUCH_ATTRIBUTE ) {
116                 rc = 0;
117         }
118
119
120 return_results:;
121         cache_return_entry_r( &li->li_cache, e );
122         return( rc );
123 }