]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/compare.c
should we touch timestamps when internally updating?
[openldap] / servers / slapd / back-monitor / compare.c
1 /* compare.c - monitor backend compare routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2005 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25
26 #include <slap.h>
27 #include "back-monitor.h"
28
29 int
30 monitor_back_compare( struct slap_op *op, struct slap_rep *rs)
31 {
32         monitor_info_t  *mi = ( monitor_info_t * ) op->o_bd->be_private;
33         Entry           *e, *matched = NULL;
34         Attribute       *a;
35
36         /* get entry with reader lock */
37         monitor_cache_dn2entry( op, &op->o_req_ndn, &e, &matched );
38         if ( e == NULL ) {
39                 rs->sr_err = LDAP_NO_SUCH_OBJECT;
40                 if ( matched ) {
41                         rs->sr_matched = matched->e_dn;
42                 }
43                 send_ldap_result( op, rs );
44                 if ( matched ) {
45                         monitor_cache_release( mi, matched );
46                         rs->sr_matched = NULL;
47                 }
48
49                 return( 0 );
50         }
51
52         rs->sr_err = access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
53                         &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
54         if ( !rs->sr_err ) {
55                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
56                 goto return_results;
57         }
58
59         rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
60
61         for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
62                         a != NULL;
63                         a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc )) {
64                 rs->sr_err = LDAP_COMPARE_FALSE;
65
66                 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
67                         SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
68                                 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
69                         a->a_nvals, &op->oq_compare.rs_ava->aa_value,
70                         op->o_tmpmemctx ) == 0 )
71                 {
72                         rs->sr_err = LDAP_COMPARE_TRUE;
73                         break;
74                 }
75         }
76
77 return_results:;
78         send_ldap_result( op, rs );
79         if ( rs->sr_err == LDAP_COMPARE_FALSE
80                         || rs->sr_err == LDAP_COMPARE_TRUE ) {
81                 rs->sr_err = LDAP_SUCCESS;
82         }
83
84         monitor_cache_release( mi, e );
85
86         return( rs->sr_err );
87 }
88