]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/compare.c
Happy new year! (belated)
[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-2008 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         int             rc;
36
37         /* get entry with reader lock */
38         monitor_cache_dn2entry( op, rs, &op->o_req_ndn, &e, &matched );
39         if ( e == NULL ) {
40                 rs->sr_err = LDAP_NO_SUCH_OBJECT;
41                 if ( matched ) {
42 #ifdef SLAP_ACL_HONOR_DISCLOSE
43                         if ( !access_allowed_mask( op, matched,
44                                         slap_schema.si_ad_entry,
45                                         NULL, ACL_DISCLOSE, NULL, NULL ) )
46                         {
47                                 /* do nothing */ ;
48                         } else 
49 #endif /* SLAP_ACL_HONOR_DISCLOSE */
50                         {
51                                 rs->sr_matched = matched->e_dn;
52                         }
53                 }
54                 send_ldap_result( op, rs );
55                 if ( matched ) {
56                         monitor_cache_release( mi, matched );
57                         rs->sr_matched = NULL;
58                 }
59
60                 return rs->sr_err;
61         }
62
63         rs->sr_err = access_allowed( op, e, op->oq_compare.rs_ava->aa_desc,
64                         &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL );
65         if ( !rs->sr_err ) {
66                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
67                 goto return_results;
68         }
69
70         rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
71
72         for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
73                         a != NULL;
74                         a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc )) {
75                 rs->sr_err = LDAP_COMPARE_FALSE;
76
77                 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
78                         SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
79                                 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
80                         a->a_nvals, &op->oq_compare.rs_ava->aa_value,
81                         op->o_tmpmemctx ) == 0 )
82                 {
83                         rs->sr_err = LDAP_COMPARE_TRUE;
84                         break;
85                 }
86         }
87
88 return_results:;
89         rc = rs->sr_err;
90         switch ( rc ) {
91         case LDAP_COMPARE_FALSE:
92         case LDAP_COMPARE_TRUE:
93                 rc = LDAP_SUCCESS;
94                 break;
95
96         case LDAP_NO_SUCH_ATTRIBUTE:
97                 break;
98
99         default:
100 #ifdef SLAP_ACL_HONOR_DISCLOSE
101                 if ( !access_allowed_mask( op, e, slap_schema.si_ad_entry,
102                                 NULL, ACL_DISCLOSE, NULL, NULL ) )
103                 {
104                         rs->sr_err = LDAP_NO_SUCH_OBJECT;
105                 }
106 #endif /* SLAP_ACL_HONOR_DISCLOSE */
107                 break;
108         }
109                 
110         send_ldap_result( op, rs );
111         rs->sr_err = rc;
112
113         monitor_cache_release( mi, e );
114
115         return rs->sr_err;
116 }
117