/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2003-2009 The OpenLDAP Foundation.
+ * Copyright 2003-2012 The OpenLDAP Foundation.
* Portions Copyright 2003 Pierangelo Masarati.
* All rights reserved.
*
struct berval ro_ndn;
struct berval r_dn;
struct berval r_ndn;
+ struct berval rx_dn;
+ struct berval rx_ndn;
AttributeName *mapped_attrs;
OpRequest o_request;
} rwm_op_state;
static void
rwm_op_rollback( Operation *op, SlapReply *rs, rwm_op_state *ros )
{
- if ( !BER_BVISNULL( &ros->ro_dn ) ) {
- op->o_req_dn = ros->ro_dn;
- }
- if ( !BER_BVISNULL( &ros->ro_ndn ) ) {
- op->o_req_ndn = ros->ro_ndn;
- }
+ /* in case of successful extended operation cleanup
+ * gets called *after* (ITS#6632); this hack counts
+ * on others to cleanup our o_req_dn/o_req_ndn,
+ * while we cleanup theirs. */
+ if ( ros->r_tag == LDAP_REQ_EXTENDED && rs->sr_err == LDAP_SUCCESS ) {
+ if ( !BER_BVISNULL( &ros->rx_dn ) ) {
+ ch_free( ros->rx_dn.bv_val );
+ }
+ if ( !BER_BVISNULL( &ros->rx_ndn ) ) {
+ ch_free( ros->rx_ndn.bv_val );
+ }
- if ( !BER_BVISNULL( &ros->r_dn )
- && ros->r_dn.bv_val != ros->ro_dn.bv_val )
- {
- assert( ros->r_dn.bv_val != ros->r_ndn.bv_val );
- ch_free( ros->r_dn.bv_val );
- BER_BVZERO( &ros->r_dn );
- }
+ } else {
+ if ( !BER_BVISNULL( &ros->ro_dn ) ) {
+ op->o_req_dn = ros->ro_dn;
+ }
+ if ( !BER_BVISNULL( &ros->ro_ndn ) ) {
+ op->o_req_ndn = ros->ro_ndn;
+ }
- if ( !BER_BVISNULL( &ros->r_ndn )
- && ros->r_ndn.bv_val != ros->ro_ndn.bv_val )
- {
- ch_free( ros->r_ndn.bv_val );
- BER_BVZERO( &ros->r_ndn );
+ if ( !BER_BVISNULL( &ros->r_dn )
+ && ros->r_dn.bv_val != ros->ro_dn.bv_val )
+ {
+ assert( ros->r_dn.bv_val != ros->r_ndn.bv_val );
+ ch_free( ros->r_dn.bv_val );
+ }
+
+ if ( !BER_BVISNULL( &ros->r_ndn )
+ && ros->r_ndn.bv_val != ros->ro_ndn.bv_val )
+ {
+ ch_free( ros->r_ndn.bv_val );
+ }
}
+ BER_BVZERO( &ros->r_dn );
+ BER_BVZERO( &ros->r_ndn );
BER_BVZERO( &ros->ro_dn );
BER_BVZERO( &ros->ro_ndn );
+ BER_BVZERO( &ros->rx_dn );
+ BER_BVZERO( &ros->rx_ndn );
switch( ros->r_tag ) {
case LDAP_REQ_COMPARE:
}
break;
case LDAP_REQ_SEARCH:
- ch_free( ros->mapped_attrs );
+ op->o_tmpfree( ros->mapped_attrs, op->o_tmpmemctx );
filter_free_x( op, op->ors_filter, 1 );
- ch_free( op->ors_filterstr.bv_val );
+ op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
op->ors_attrs = ros->ors_attrs;
op->ors_filter = ros->ors_filter;
op->ors_filterstr = ros->ors_filterstr;
#if 0
ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
/* too late, c_mutex released */
- fprintf( stderr, "*** DN: \"%s\" => \"%s\"\n",
+ Debug( LDAP_DEBUG_ANY, "*** DN: \"%s\" => \"%s\"\n",
op->o_conn->c_ndn.bv_val,
op->o_req_ndn.bv_val );
ber_bvreplace( &op->o_conn->c_ndn,
}
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;
}
assert( BER_BVISNULL( &ros->r_ndn ) );
ros->r_ndn = ndn;
+ if ( ros->r_tag == LDAP_REQ_EXTENDED ) {
+ ros->rx_dn = ros->r_dn;
+ ros->rx_ndn = ros->r_ndn;
+ }
+
return LDAP_SUCCESS;
}
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 );
op->ors_filter = f;
op->ors_filterstr = fstr;
- rc = rwm_map_attrnames( &rwmap->rwm_at, &rwmap->rwm_oc,
+ rc = rwm_map_attrnames( op, &rwmap->rwm_at, &rwmap->rwm_oc,
op->ors_attrs, &an, RWM_MAP );
if ( rc != LDAP_SUCCESS ) {
text = "attribute list mapping error";
}
if ( !BER_BVISNULL( &fstr ) ) {
- ch_free( fstr.bv_val );
+ op->o_tmpfree( fstr.bv_val, op->o_tmpmemctx );
}
rwm_op_rollback( op, rs, &roc->ros );
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 );
}
-
- overlay_entry_release_ov( op, rs->sr_entry, 0, 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:;
*/
if ( argc == 2 ) {
if ( be->be_suffix == NULL ) {
- fprintf( stderr, "%s: line %d: "
+ Debug( LDAP_DEBUG_ANY, "%s: line %d: "
" \"suffixMassage [<suffix>]"
" <massaged suffix>\" without "
"<suffix> part requires database "
"suffix be defined first.\n",
- fname, lineno );
+ fname, lineno, 0 );
return 1;
}
bvnc = be->be_suffix[ 0 ];
massaged = 2;
} else {
- fprintf( stderr, "%s: line %d: syntax is"
+ Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is"
" \"suffixMassage [<suffix>]"
" <massaged suffix>\"\n",
- fname, lineno );
+ fname, lineno, 0 );
return 1;
}
if ( dnPrettyNormal( NULL, &bvnc, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
- fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
+ Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix DN %s is invalid\n",
fname, lineno, bvnc.bv_val );
return 1;
}
ber_str2bv( argv[ massaged ], 0, 0, &brnc );
if ( dnPrettyNormal( NULL, &brnc, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
- fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n",
+ Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix DN %s is invalid\n",
fname, lineno, brnc.bv_val );
free( nvnc.bv_val );
free( pvnc.bv_val );
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
} else if ( strcasecmp( argv[0], "t-f-support" ) == 0 ) {
if ( argc != 2 ) {
- fprintf( stderr,
+ Debug( LDAP_DEBUG_ANY,
"%s: line %d: \"t-f-support {no|yes|discover}\" needs 1 argument.\n",
- fname, lineno );
+ fname, lineno, 0 );
return( 1 );
}
/* TODO: not implemented yet */
} else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
- fprintf( stderr,
+ Debug( LDAP_DEBUG_ANY,
"%s: line %d: \"discover\" not supported yet "
"in \"t-f-support {no|yes|discover}\".\n",
- fname, lineno );
+ fname, lineno, 0 );
return( 1 );
#if 0
rwmap->rwm_flags |= RWM_F_SUPPORT_T_F_DISCOVER;
#endif
} else {
- fprintf( stderr,
+ Debug( LDAP_DEBUG_ANY,
"%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
fname, lineno, argv[ 1 ] );
return 1;
} else if ( strcasecmp( argv[0], "normalize-mapped-attrs" ) == 0 ) {
if ( argc !=2 ) {
- fprintf( stderr,
+ Debug( LDAP_DEBUG_ANY,
"%s: line %d: \"normalize-mapped-attrs {no|yes}\" needs 1 argument.\n",
- fname, lineno );
+ fname, lineno, 0 );
return( 1 );
}
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 )
switch ( c->type ) {
case RWM_CF_REWRITE:
if ( c->valx >= 0 ) {
- ConfigArgs ca = { 0 };
int i;
for ( i = 0; !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ i ] ); i++ )
for ( i = 0; !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ i ] ); i++ )
{
+ ConfigArgs ca = { 0 };
+
ca.line = rwmap->rwm_bva_rewrite[ i ].bv_val;
ca.argc = 0;
config_fp_parse_line( &ca );
case RWM_CF_REWRITE:
if ( c->valx >= 0 ) {
struct rewrite_info *rwm_rw = rwmap->rwm_rw;
- ConfigArgs ca = { 0 };
int i, last;
for ( last = 0; rwmap->rwm_bva_rewrite && !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ last ] ); last++ )
rc = rwm_info_init( &rwmap->rwm_rw );
for ( i = 0; i < c->valx; i++ ) {
+ ConfigArgs ca = { 0 };
+
ca.line = rwmap->rwm_bva_rewrite[ i ].bv_val;
ca.argc = 0;
config_fp_parse_line( &ca );
for ( i = c->valx; rwmap->rwm_bva_rewrite && !BER_BVISNULL( &rwmap->rwm_bva_rewrite[ i ] ); i++ )
{
+ ConfigArgs ca = { 0 };
+
ca.line = rwmap->rwm_bva_rewrite[ i ].bv_val;
ca.argc = 0;
config_fp_parse_line( &ca );