2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2013 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/string.h>
28 #include <ac/socket.h>
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
35 meta_back_compare( Operation *op, SlapReply *rs )
37 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
42 struct berval mdn = BER_BVNULL;
44 struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
45 struct berval mapped_value = op->orc_ava->aa_value;
47 ldap_back_send_t retrying = LDAP_BACK_RETRYING;
48 LDAPControl **ctrls = NULL;
50 mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
51 if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
55 assert( mc->mc_conns[ candidate ].msc_ld != NULL );
58 * Rewrite the modify dn, if needed
60 mt = mi->mi_targets[ candidate ];
66 switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
67 case LDAP_UNWILLING_TO_PERFORM:
76 * if attr is objectClass, try to remap the value
78 if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass ) {
79 ldap_back_map( &mt->mt_rwmap.rwm_oc,
80 &op->orc_ava->aa_value,
81 &mapped_value, BACKLDAP_MAP );
83 if ( BER_BVISNULL( &mapped_value ) || BER_BVISEMPTY( &mapped_value ) ) {
88 * else try to remap the attribute
91 ldap_back_map( &mt->mt_rwmap.rwm_at,
92 &op->orc_ava->aa_desc->ad_cname,
93 &mapped_attr, BACKLDAP_MAP );
94 if ( BER_BVISNULL( &mapped_attr ) || BER_BVISEMPTY( &mapped_attr ) ) {
98 if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
100 dc.ctx = "compareAttrDN";
102 switch ( ldap_back_dn_massage( &dc, &op->orc_ava->aa_value, &mapped_value ) )
104 case LDAP_UNWILLING_TO_PERFORM:
116 rc = meta_back_controls_add( op, rs, mc, candidate, &ctrls );
117 if ( rc != LDAP_SUCCESS ) {
118 send_ldap_result( op, rs );
122 rs->sr_err = ldap_compare_ext( mc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
123 mapped_attr.bv_val, &mapped_value,
124 ctrls, NULL, &msgid );
126 rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
127 mt->mt_timeout[ SLAP_OP_COMPARE ], ( LDAP_BACK_SENDRESULT | retrying ) );
128 if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
129 retrying &= ~LDAP_BACK_RETRYING;
130 if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR ) ) {
131 /* if the identity changed, there might be need to re-authz */
132 (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
138 (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
140 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
144 if ( op->orc_ava->aa_value.bv_val != mapped_value.bv_val ) {
145 free( mapped_value.bv_val );
149 meta_back_release_conn( mi, mc );