]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/compare.c
refuse illegal values for "threads" (ITS#4433)
[openldap] / servers / slapd / back-ldbm / compare.c
1 /* compare.c - ldbm backend compare routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2006 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/socket.h>
22 #include <ac/string.h>
23
24 #include "slap.h"
25 #include "back-ldbm.h"
26 #include "proto-back-ldbm.h"
27
28 int
29 ldbm_back_compare(
30         Operation       *op,
31         SlapReply       *rs )
32 {
33         struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
34         Entry           *matched;
35         Entry           *e;
36         Attribute       *a;
37         int             manageDSAit = get_manageDSAit( op );
38
39         rs->sr_matched = NULL;
40         rs->sr_ref = NULL;
41
42         /* grab giant lock for reading */
43         ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
44
45         /* get entry with reader lock */
46         e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched );
47         if ( e == NULL ) {
48                 if ( matched != NULL ) {
49                         rs->sr_matched = ch_strdup( matched->e_dn );
50                         rs->sr_ref = is_entry_referral( matched )
51                                 ? get_entry_referrals( op, matched )
52                                 : NULL;
53                         cache_return_entry_r( &li->li_cache, matched );
54                 } else {
55                         rs->sr_ref = referral_rewrite( default_referral,
56                                 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
57                 }
58
59                 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
60
61                 rs->sr_err = LDAP_REFERRAL;
62                 goto return_results;
63         }
64
65         if ( !manageDSAit && is_entry_referral( e ) ) {
66                 struct berval   bv;
67
68                 /* entry is a referral, don't allow add */
69                 rs->sr_ref = get_entry_referrals( op, e );
70
71                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
72                     0, 0 );
73
74
75                 rs->sr_err = LDAP_REFERRAL;
76                 ber_dupbv_x( &bv, &e->e_name, op->o_tmpmemctx );
77                 rs->sr_matched = bv.bv_val;
78
79                 goto return_results;
80         }
81
82         if ( ! access_allowed( op, e,
83                 op->oq_compare.rs_ava->aa_desc, &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ) )
84         {
85                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
86                         NULL );
87                 goto return_results;
88         }
89
90         rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
91
92         for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
93                 a != NULL;
94                 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
95         {
96                 rs->sr_err = LDAP_COMPARE_FALSE;
97
98                 if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
99                         SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
100                                 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
101                         a->a_nvals, &op->oq_compare.rs_ava->aa_value,
102                         op->o_tmpmemctx ) == 0 )
103                 {
104                         rs->sr_err = LDAP_COMPARE_TRUE;
105                         break;
106                 }
107         }
108
109 return_results:;
110         cache_return_entry_r( &li->li_cache, e );
111         ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
112
113         send_ldap_result( op, rs );
114
115         switch ( rs->sr_err ) {
116         case LDAP_COMPARE_FALSE:
117         case LDAP_COMPARE_TRUE:
118                 rs->sr_err = LDAP_SUCCESS;
119                 break;
120         }
121
122         if ( rs->sr_ref != NULL ) {
123                 ber_bvarray_free( rs->sr_ref );
124                 rs->sr_ref = NULL;
125         }
126
127         if ( rs->sr_matched != NULL ) {
128                 op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
129                 rs->sr_matched = NULL;
130         }
131
132         return rs->sr_err;
133 }