/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2003-2010 The OpenLDAP Foundation.
+ * Copyright 2003-2012 The OpenLDAP Foundation.
* Portions Copyright 2003 Pierangelo Masarati.
* All rights reserved.
*
}
static rwm_op_cb *
-rwm_callback_get( Operation *op, SlapReply *rs )
+rwm_callback_get( Operation *op )
{
- rwm_op_cb *roc = NULL;
+ rwm_op_cb *roc;
roc = op->o_tmpalloc( sizeof( struct rwm_op_cb ), op->o_tmpmemctx );
roc->cb.sc_cleanup = rwm_op_cleanup;
roc->ros.r_tag = op->o_tag;
roc->ros.ro_dn = op->o_req_dn;
roc->ros.ro_ndn = op->o_req_ndn;
- roc->ros.o_request = op->o_request;
BER_BVZERO( &roc->ros.r_dn );
BER_BVZERO( &roc->ros.r_ndn );
+ BER_BVZERO( &roc->ros.rx_dn );
+ BER_BVZERO( &roc->ros.rx_ndn );
+ roc->ros.mapped_attrs = NULL;
+ roc->ros.o_request = op->o_request;
return roc;
}
char *olddn = op->o_req_dn.bv_val;
int isupdate;
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "addDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
int rc;
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "bindDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
int rc;
struct berval mapped_vals[2] = { BER_BVNULL, BER_BVNULL };
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "compareDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
int rc;
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "deleteDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
Modifications **mlp;
int rc;
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "modifyDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
&mapping, RWM_MAP );
if ( drop_missing || ( mapping != NULL && BER_BVISNULL( &mapping->m_dst ) ) )
{
- goto cleanup_mod;
+ goto skip_mod;
}
}
mlp = &ml->sml_next;
continue;
+skip_mod:;
+ *mlp = (*mlp)->sml_next;
+ continue;
+
cleanup_mod:;
ml = *mlp;
*mlp = (*mlp)->sml_next;
int rc;
dncookie dc;
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
if ( op->orr_newSup ) {
struct berval nnewSup = BER_BVNULL;
ObjectClass *oc, AttributeDescription *at, int rw, Entry **ep )
{
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
- struct ldaprwmap *rwmap =
- (struct ldaprwmap *)on->on_bi.bi_private;
-
int rc;
- dncookie dc;
-
BackendDB db;
Operation op2;
SlapReply rs = { REP_SEARCH };
/* duplicate & release */
op2.o_bd->bd_info = (BackendInfo *)on;
rc = rwm_send_entry( &op2, &rs );
+ RS_ASSERT( rs.sr_flags & REP_ENTRY_MUSTFLUSH );
if ( rc == SLAP_CB_CONTINUE ) {
*ep = rs.sr_entry;
rc = LDAP_SUCCESS;
+ } else {
+ assert( rc != LDAP_SUCCESS && rs.sr_entry == *ep );
+ *ep = NULL;
+ op2.o_bd->bd_info = (BackendInfo *)on->on_info;
+ be_entry_release_r( &op2, rs.sr_entry );
+ op2.o_bd->bd_info = (BackendInfo *)on;
}
}
char *text = NULL;
- rwm_op_cb *roc = rwm_callback_get( op, rs );
+ rwm_op_cb *roc = rwm_callback_get( op );
rc = rewrite_session_var_set( rwmap->rwm_rw, op->o_conn,
"searchFilter", op->ors_filterstr.bv_val );
ber_dupbv_x( &op->o_req_ndn, &op->o_ndn, op->o_tmpmemctx );
}
- roc = rwm_callback_get( op, rs );
+ roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
}
}
- roc = rwm_callback_get( op, rs );
+ roc = rwm_callback_get( op );
rc = rwm_op_dn_massage( op, rs, "extendedDN", &roc->ros );
if ( rc != LDAP_SUCCESS ) {
return SLAP_CB_CONTINUE;
}
-static int
+static void
rwm_matched( Operation *op, SlapReply *rs )
{
slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
int rc;
if ( rs->sr_matched == NULL ) {
- return SLAP_CB_CONTINUE;
+ return;
}
dc.rwmap = rwmap;
if ( rc != LDAP_SUCCESS ) {
rs->sr_err = rc;
rs->sr_text = "Rewrite error";
- return 1;
- }
- if ( mdn.bv_val != dn.bv_val ) {
+ } else if ( mdn.bv_val != dn.bv_val ) {
if ( rs->sr_flags & REP_MATCHED_MUSTBEFREED ) {
ch_free( (void *)rs->sr_matched );
}
rs->sr_matched = mdn.bv_val;
}
-
- return SLAP_CB_CONTINUE;
}
static int
NULL );
if ( rc != LDAP_SUCCESS ) {
- BER_BVZERO( &(*ap)->a_nvals[i] );
+ /* FIXME: this is wrong, putting a non-normalized value
+ * into nvals. But when a proxy sends us bogus data,
+ * we still need to give it to the client, even if it
+ * violates the syntax. I.e., we don't want to silently
+ * drop things and trigger an apparent data loss.
+ */
+ ber_dupbv( &(*ap)->a_nvals[i], &(*ap)->a_vals[i] );
}
}
BER_BVZERO( &(*ap)->a_nvals[i] );
return 0;
}
+/* Should return SLAP_CB_CONTINUE or failure, never LDAP_SUCCESS. */
static int
rwm_send_entry( Operation *op, SlapReply *rs )
{
(struct ldaprwmap *)on->on_bi.bi_private;
Entry *e = NULL;
- slap_mask_t flags;
struct berval dn = BER_BVNULL,
ndn = BER_BVNULL;
dncookie dc;
dc.ctx = "searchEntryDN";
e = rs->sr_entry;
- flags = rs->sr_flags;
if ( !( rs->sr_flags & REP_ENTRY_MODIFIABLE ) ) {
/* FIXME: all we need to duplicate are:
* - dn
* - attributes that are requested
* - no values if attrsonly is set
*/
-
e = entry_dup( e );
if ( e == NULL ) {
rc = LDAP_NO_MEMORY;
goto fail;
}
-
- flags &= ~REP_ENTRY_MUSTRELEASE;
- flags |= ( REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED );
+ } else if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
+ /* ITS#6423: REP_ENTRY_MUSTRELEASE incompatible
+ * with REP_ENTRY_MODIFIABLE */
+ RS_ASSERT( 0 );
+ rc = 1;
+ goto fail;
}
/*
* to return, and remap them accordingly */
(void)rwm_attrs( op, rs, &e->e_attrs, 1 );
- if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
- /* ITS#6423: REP_ENTRY_MUSTRELEASE incompatible
- * with REP_ENTRY_MODIFIABLE */
- if ( rs->sr_entry == e ) {
- rc = 1;
- goto fail;
+ if ( e != rs->sr_entry ) {
+ /* Reimplementing rs_replace_entry(), I suppose to
+ * bypass our own dubious rwm_entry_release_rw() */
+ if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
+ rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
+ op->o_bd->bd_info = (BackendInfo *)on->on_info;
+ be_entry_release_r( op, rs->sr_entry );
+ op->o_bd->bd_info = (BackendInfo *)on;
+ } else if ( rs->sr_flags & REP_ENTRY_MUSTBEFREED ) {
+ entry_free( rs->sr_entry );
}
-
- op->o_bd->bd_info = (BackendInfo *)on->on_info;
- be_entry_release_r( op, rs->sr_entry );
- op->o_bd->bd_info = (BackendInfo *)on;
+ rs->sr_entry = e;
+ rs->sr_flags |= REP_ENTRY_MODIFIABLE | REP_ENTRY_MUSTBEFREED;
}
- rs->sr_entry = e;
- rs->sr_flags = flags;
-
return SLAP_CB_CONTINUE;
fail:;
dc.rs = NULL;
dc.ctx = "referralDN";
rc = rwm_referral_result_rewrite( &dc, rs->sr_ref );
+ /* FIXME: impossible, so far */
if ( rc != LDAP_SUCCESS ) {
- rc = 1;
+ rs->sr_err = rc;
break;
}
}
- rc = rwm_matched( op, rs );
- break;
- default:
- rc = SLAP_CB_CONTINUE;
+ rwm_matched( op, rs );
break;
}
- return rc;
+ return SLAP_CB_CONTINUE;
}
static int
return rwm_bva_add( &rwmap->rwm_bva_rewrite, idx, argv );
}
+#ifdef unused
static int
rwm_bva_map_add(
struct ldaprwmap *rwmap,
{
return rwm_bva_add( &rwmap->rwm_bva_map, idx, argv );
}
+#endif /* unused */
static int
rwm_info_init( struct rewrite_info ** rwm_rw )