]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/compare.c
Do include of sys/time.h to define struct timeval used in back-bdb2/add.c
[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         struct timeval  time1;
77         int             ret;
78
79         bdb2i_start_timing( be->bd_info, &time1 );
80
81         if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
82
83                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
84                 return( 1 );
85
86         }
87
88         ret = bdb2i_back_compare_internal( be, conn, op, dn, ava );
89         (void) bdb2i_leave_backend_r( lock );
90         bdb2i_stop_timing( be->bd_info, time1, "CMP", conn, op );
91
92         return( ret );
93 }
94
95