]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/compare.c
27a555182d4c8464717935acd035180fbd20f95b
[openldap] / servers / slapd / back-bdb2 / compare.c
1 /* compare.c - bdb2 backend compare routine */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
13
14 static int
15 bdb2i_back_compare_internal(
16     BackendDB   *be,
17     Connection  *conn,
18     Operation   *op,
19     char        *dn,
20     Ava         *ava
21 )
22 {
23         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
24         char            *matched;
25         Entry           *e;
26         Attribute       *a;
27         int             rc;
28
29         /* get entry with reader lock */
30         if ( (e = bdb2i_dn2entry_r( be, dn, &matched )) == NULL ) {
31                 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
32
33                 if(matched == NULL) free(matched);
34                 return( 1 );
35         }
36
37         /* check for deleted */
38         if ( ! access_allowed( be, conn, op, e,
39                 ava->ava_type, &ava->ava_value, ACL_COMPARE ) )
40         {
41                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
42                 rc = 1;
43                 goto return_results;
44         }
45
46         if ( (a = attr_find( e->e_attrs, ava->ava_type )) == NULL ) {
47                 send_ldap_result( conn, op, LDAP_NO_SUCH_ATTRIBUTE, "", "" );
48                 rc = 1;
49                 goto return_results;
50         }
51
52         if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 ) 
53                 send_ldap_result( conn, op, LDAP_COMPARE_TRUE, "", "" );
54         else
55                 send_ldap_result( conn, op, LDAP_COMPARE_FALSE, "", "" );
56
57         rc = 0;
58
59 return_results:;
60         bdb2i_cache_return_entry_r( &li->li_cache, e );
61         return( rc );
62 }
63
64
65 int
66 bdb2_back_compare(
67     BackendDB   *be,
68     Connection  *conn,
69     Operation   *op,
70     char        *dn,
71     Ava         *ava
72 )
73 {
74         DB_LOCK  lock;
75         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
76
77         struct timeval  time1, time2;
78         char   *elapsed_time;
79         int    ret;
80
81         gettimeofday( &time1, NULL );
82
83         if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
84
85                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
86                 return( 1 );
87
88         }
89
90         ret = bdb2i_back_compare_internal( be, conn, op, dn, ava );
91
92         (void) bdb2i_leave_backend( get_dbenv( be ), lock );
93
94         if ( bdb2i_do_timing ) {
95
96                 gettimeofday( &time2, NULL);
97                 elapsed_time = bdb2i_elapsed( time1, time2 );
98                 Debug( LDAP_DEBUG_ANY, "conn=%d op=%d CMP elapsed=%s\n",
99                                 conn->c_connid, op->o_opid, elapsed_time );
100                 free( elapsed_time );
101
102         }
103
104         return( ret );
105 }
106
107