1 /* compare.cpp - ndb backend compare routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * This work was initially developed by Howard Chu for inclusion
18 * in OpenLDAP Software. This work was sponsored by MySQL.
24 #include <ac/string.h>
29 ndb_back_compare( Operation *op, SlapReply *rs )
31 struct ndb_info *ni = (struct ndb_info *) op->o_bd->be_private;
34 int manageDSAit = get_manageDSAit( op );
38 struct berval matched;
40 /* Get our NDB handle */
41 rs->sr_err = ndb_thread_handle( op, &NA.ndb );
45 e.e_name = op->o_req_dn;
46 e.e_nname = op->o_req_ndn;
49 NA.txn = NA.ndb->startTransaction();
52 Debug( LDAP_DEBUG_TRACE,
53 LDAP_XSTRING(ndb_compare) ": startTransaction failed: %s (%d)\n",
54 NA.ndb->getNdbError().message, NA.ndb->getNdbError().code, 0 );
55 rs->sr_err = LDAP_OTHER;
56 rs->sr_text = "internal error";
62 rs->sr_err = ndb_entry_get_info( op->o_bd, &NA, 0, &matched );
63 switch( rs->sr_err ) {
66 case LDAP_NO_SUCH_OBJECT:
67 rs->sr_matched = matched.bv_val;
70 rs->sr_text = "ldap server busy";
73 case DB_LOCK_DEADLOCK:
74 case DB_LOCK_NOTGRANTED:
78 rs->sr_err = LDAP_OTHER;
79 rs->sr_text = "internal error";
83 rs->sr_err = ndb_entry_get_data( op->o_bd, &NA, 0 );
84 ber_bvarray_free( NA.ocs );
85 if (!manageDSAit && is_entry_referral( &e ) ) {
86 /* return referral only if "disclose" is granted on the object */
87 if ( !access_allowed( op, &e, slap_schema.si_ad_entry,
88 NULL, ACL_DISCLOSE, NULL ) )
90 rs->sr_err = LDAP_NO_SUCH_OBJECT;
92 /* entry is a referral, don't allow compare */
93 rs->sr_ref = get_entry_referrals( op, &e );
94 rs->sr_err = LDAP_REFERRAL;
95 rs->sr_matched = e.e_name.bv_val;
98 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0, 0, 0 );
102 if ( get_assert( op ) &&
103 ( test_filter( op, &e, (Filter *)get_assertion( op )) != LDAP_COMPARE_TRUE ))
105 if ( !access_allowed( op, &e, slap_schema.si_ad_entry,
106 NULL, ACL_DISCLOSE, NULL ) )
108 rs->sr_err = LDAP_NO_SUCH_OBJECT;
110 rs->sr_err = LDAP_ASSERTION_FAILED;
115 if ( !access_allowed( op, &e, op->oq_compare.rs_ava->aa_desc,
116 &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ) )
118 /* return error only if "disclose"
119 * is granted on the object */
120 if ( !access_allowed( op, &e, slap_schema.si_ad_entry,
121 NULL, ACL_DISCLOSE, NULL ) )
123 rs->sr_err = LDAP_NO_SUCH_OBJECT;
125 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
130 rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
132 for ( a = attrs_find( e.e_attrs, op->oq_compare.rs_ava->aa_desc );
134 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) )
136 rs->sr_err = LDAP_COMPARE_FALSE;
138 if ( attr_valfind( a,
139 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
140 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
141 &op->oq_compare.rs_ava->aa_value, NULL,
142 op->o_tmpmemctx ) == 0 )
144 rs->sr_err = LDAP_COMPARE_TRUE;
152 attrs_free( e.e_attrs );
155 send_ldap_result( op, rs );
157 ber_bvarray_free( rs->sr_ref );
160 switch ( rs->sr_err ) {
161 case LDAP_COMPARE_FALSE:
162 case LDAP_COMPARE_TRUE:
163 rs->sr_err = LDAP_SUCCESS;