]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/compare.c
More changes to let BDB build without LDBM.
[openldap] / servers / slapd / back-bdb / compare.c
1 /* compare.c - bdb 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 #include <ac/string.h>
12
13 #include "back-bdb.h"
14 #include "external.h"
15
16 int
17 bdb_compare(
18         BackendDB       *be,
19         Connection      *conn,
20         Operation       *op,
21         const char      *dn,
22         const char      *ndn,
23         AttributeAssertion *ava
24 )
25 {
26         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
27         Entry           *matched;
28         Entry           *e;
29         Attribute       *a;
30         int                     rc; 
31         const char      *text = NULL;
32         int             manageDSAit = get_manageDSAit( op );
33
34         /* get entry */
35         rc = bdb_dn2entry( be, NULL, ndn, &e, &matched, 0 );
36
37         switch( rc ) {
38         case DB_NOTFOUND:
39                 break;
40         default:
41                 rc = LDAP_OTHER;
42                 text = "internal error";
43                 goto return_results;
44         }
45
46         if ( e == NULL ) {
47                 char *matched_dn = NULL;
48                 struct berval **refs = NULL;
49
50                 if ( matched != NULL ) {
51                         matched_dn = ch_strdup( matched->e_dn );
52                         refs = is_entry_referral( matched )
53                                 ? get_entry_referrals( be, conn, op, matched )
54                                 : NULL;
55                         bdb_entry_return( be, matched );
56                         matched = NULL;
57
58                 } else {
59                         refs = default_referral;
60                 }
61
62                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
63                         matched_dn, NULL, refs, NULL );
64
65                 if( matched != NULL ) {
66                         ber_bvecfree( refs );
67                         free( matched_dn );
68                 }
69
70                 goto done;
71         }
72
73         if (!manageDSAit && is_entry_referral( e ) ) {
74                 /* entry is a referral, don't allow add */
75                 struct berval **refs = get_entry_referrals( be,
76                         conn, op, e );
77
78                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
79                         0, 0 );
80
81                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
82                         e->e_dn, NULL, refs, NULL );
83
84                 ber_bvecfree( refs );
85                 goto done;
86         }
87
88         if ( ! access_allowed( be, conn, op, e,
89                 ava->aa_desc, ava->aa_value, ACL_COMPARE ) )
90         {
91                 rc = LDAP_INSUFFICIENT_ACCESS;
92                 goto return_results;
93         }
94
95         rc = LDAP_NO_SUCH_ATTRIBUTE;
96
97         for(a = attrs_find( e->e_attrs, ava->aa_desc );
98                 a != NULL;
99                 a = attrs_find( a->a_next, ava->aa_desc ))
100         {
101                 rc = LDAP_COMPARE_FALSE;
102
103                 if ( value_find( ava->aa_desc, a->a_vals, ava->aa_value ) == 0 )
104                 {
105                         rc = LDAP_COMPARE_TRUE;
106                         break;
107                 }
108
109         }
110
111         if( rc != LDAP_NO_SUCH_ATTRIBUTE ) {
112                 rc = LDAP_SUCCESS;
113         }
114
115
116 return_results:
117         send_ldap_result( conn, op, LDAP_SUCCESS,
118                 NULL, text, NULL, NULL );
119
120 done:
121         /* free entry */
122         if( e != NULL ) {
123                 bdb_entry_return( be, e );
124         }
125
126         return rc;
127 }