]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/compare.c
4757a29b9228684dbfb6e834b74ed8fa0c66e857
[openldap] / servers / slapd / back-ldbm / compare.c
1 /* compare.c - ldbm backend compare routine */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include "slap.h"
8 #include "back-ldbm.h"
9
10 extern Entry            *dn2entry();
11 extern Attribute        *attr_find();
12
13 int
14 ldbm_back_compare(
15     Backend     *be,
16     Connection  *conn,
17     Operation   *op,
18     char        *dn,
19     Ava         *ava
20 )
21 {
22         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
23         char            *matched;
24         Entry           *e;
25         Attribute       *a;
26         int             i;
27
28         if ( (e = dn2entry( be, dn, &matched )) == NULL ) {
29                 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
30                 return( 1 );
31         }
32
33         if ( ! access_allowed( be, conn, op, e, ava->ava_type, &ava->ava_value,
34             op->o_dn, ACL_COMPARE ) ) {
35                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
36                 cache_return_entry( &li->li_cache, e );
37                 return( 1 );
38         }
39
40         if ( (a = attr_find( e->e_attrs, ava->ava_type )) == NULL ) {
41                 send_ldap_result( conn, op, LDAP_NO_SUCH_ATTRIBUTE, "", "" );
42                 cache_return_entry( &li->li_cache, e );
43                 return( 1 );
44         }
45
46         if ( value_find( a->a_vals, &ava->ava_value, a->a_syntax, 1 ) == 0 ) {
47                 send_ldap_result( conn, op, LDAP_COMPARE_TRUE, "", "" );
48                 cache_return_entry( &li->li_cache, e );
49                 return( 0 );
50         }
51
52         send_ldap_result( conn, op, LDAP_COMPARE_FALSE, "", "" );
53         cache_return_entry( &li->li_cache, e );
54         return( 0 );
55 }