/*
* Rewrite the add dn, if needed
*/
- dc.rwmap = &li->targets[ candidate ]->rwmap;
+ dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "addDN";
}
/* Count number of attributes in entry */
- for ( i = 1, a = op->oq_add.rs_e->e_attrs; a; i++, a = a->a_next );
+ for ( i = 1, a = op->ora_e->e_attrs; a; i++, a = a->a_next );
/* Create array of LDAPMods for ldap_add() */
attrs = ch_malloc( sizeof( LDAPMod * )*i );
- for ( i = 0, a = op->oq_add.rs_e->e_attrs; a; a = a->a_next ) {
+ for ( i = 0, a = op->ora_e->e_attrs; a; a = a->a_next ) {
int j;
if ( a->a_desc->ad_type->sat_no_user_mod ) {
continue;
}
- ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
+ ldap_back_map( &li->targets[ candidate ]->mt_rwmap.rwm_at,
&a->a_desc->ad_cname, &mapped, BACKLDAP_MAP );
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
continue;
}
attrs[ i ] = NULL;
- ldap_add_s( lc->conns[ candidate ].ld, mdn.bv_val, attrs );
+ (void)ldap_add_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
+ attrs, NULL, NULL );
for ( --i; i >= 0; --i ) {
free( attrs[ i ]->mod_vals.modv_bvals );
free( attrs[ i ] );
}
free( attrs );
- if ( mdn.bv_val != op->oq_add.rs_e->e_dn ) {
+ if ( mdn.bv_val != op->ora_e->e_dn ) {
free( mdn.bv_val );
+ BER_BVZERO( &mdn );
}
+
return meta_back_op_result( lc, op, rs );
}
} /* else */
candidate = meta_back_select_unique_candidate( li, ndn );
- if ( candidate == -1 ) {
+ if ( candidate == META_TARGET_NONE ) {
return 1;
}
/* (end of) from back-ldap.h before rwm removal */
struct metasingleconn {
- int candidate;
+ int msc_candidate;
#define META_NOT_CANDIDATE 0
#define META_CANDIDATE 1
#define META_LAST_CONN -1
- LDAP *ld;
- struct berval bound_dn;
- struct berval cred;
- int bound;
+ LDAP *msc_ld;
+ struct berval msc_bound_ndn;
+ struct berval msc_cred;
+ int msc_bound;
#define META_UNBOUND 0
#define META_BOUND 1
#define META_ANONYMOUS 2
};
-#define META_LAST(lsc) ((lsc)->candidate == META_LAST_CONN)
+#define META_LAST(lsc) ((lsc)->msc_candidate == META_LAST_CONN)
struct metaconn {
- struct slap_conn *conn;
- struct rewrite_info *rwinfo;
+ struct slap_conn *mc_conn;
+ struct rewrite_info *mc_rwinfo;
/*
* means that the connection is bound;
* of course only one target actually is ...
*/
- int bound_target;
+ int mc_bound_target;
#define META_BOUND_NONE -1
#define META_BOUND_ALL -2
/* supersedes the connection stuff */
- struct metasingleconn *conns;
+ struct metasingleconn *mc_conns;
};
struct metatarget {
- char *uri;
- struct berval psuffix; /* pretty suffix */
- struct berval suffix; /* normalized suffix */
- struct berval binddn;
- struct berval bindpw;
-
- struct berval pseudorootdn;
- struct berval pseudorootpw;
+ char *mt_uri;
+ struct berval mt_psuffix; /* pretty suffix */
+ struct berval mt_nsuffix; /* normalized suffix */
+ struct berval mt_binddn;
+ struct berval mt_bindpw;
-#if 0
- struct rewrite_info *rwinfo;
+ struct berval mt_pseudorootdn;
+ struct berval mt_pseudorootpw;
- struct ldapmap oc_map;
- struct ldapmap at_map;
-#endif
- struct ldaprwmap rwmap;
+ struct ldaprwmap mt_rwmap;
};
struct metadncache {
void *c2
);
+#define META_TARGET_NONE (-1)
extern int
meta_dncache_get_target(
struct metadncache *cache,
Debug( LDAP_DEBUG_ARGS, "meta_back_bind: dn: %s.\n%s%s",
op->o_req_dn.bv_val, "", "" );
- if ( op->oq_bind.rb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
+ if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
isroot = 1;
- ber_dupbv( &op->oq_bind.rb_edn, be_root_dn( op->o_bd ) );
+ ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ) );
op_type = META_OP_REQUIRE_ALL;
}
lc = meta_back_getconn( op, rs, op_type,
/*
* Each target is scanned ...
*/
- lc->bound_target = META_BOUND_NONE;
+ lc->mc_bound_target = META_BOUND_NONE;
ndnlen = op->o_req_ndn.bv_len;
for ( i = 0; i < li->ntargets; i++ ) {
int lerr;
struct berval orig_dn = op->o_req_dn;
struct berval orig_ndn = op->o_req_ndn;
- struct berval orig_cred = op->oq_bind.rb_cred;
- int orig_method = op->oq_bind.rb_method;
+ struct berval orig_cred = op->orb_cred;
+ int orig_method = op->orb_method;
/*
* Skip non-candidates
*/
- if ( lc->conns[ i ].candidate != META_CANDIDATE ) {
+ if ( lc->mc_conns[ i ].msc_candidate != META_CANDIDATE ) {
continue;
}
"", "", "" );
}
- if ( isroot && li->targets[ i ]->pseudorootdn.bv_val != NULL ) {
- op->o_req_dn = li->targets[ i ]->pseudorootdn;
- op->o_req_ndn = li->targets[ i ]->pseudorootdn;
- op->oq_bind.rb_cred = li->targets[ i ]->pseudorootpw;
- op->oq_bind.rb_method = LDAP_AUTH_SIMPLE;
+ if ( isroot && li->targets[ i ]->mt_pseudorootdn.bv_val != NULL ) {
+ op->o_req_dn = li->targets[ i ]->mt_pseudorootdn;
+ op->o_req_ndn = li->targets[ i ]->mt_pseudorootdn;
+ op->orb_cred = li->targets[ i ]->mt_pseudorootpw;
+ op->orb_method = LDAP_AUTH_SIMPLE;
}
lerr = meta_back_do_single_bind( lc, op, rs, i );
if ( lerr != LDAP_SUCCESS ) {
rs->sr_err = lerr;
- ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->mc_conns[ i ], 1 );
} else {
rc = LDAP_SUCCESS;
}
op->o_req_dn = orig_dn;
op->o_req_ndn = orig_ndn;
- op->oq_bind.rb_cred = orig_cred;
- op->oq_bind.rb_method = orig_method;
+ op->orb_cred = orig_cred;
+ op->orb_method = orig_method;
}
if ( isroot ) {
- lc->bound_target = META_BOUND_ALL;
+ lc->mc_bound_target = META_BOUND_ALL;
}
/*
int candidate
)
{
- struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
- struct berval mdn = BER_BVNULL;
- ber_int_t msgid;
- dncookie dc;
- struct metasingleconn *lsc = &lc->conns[ candidate ];
- LDAPMessage *res;
+ struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
+ struct berval mdn = BER_BVNULL;
+ dncookie dc;
+ struct metasingleconn *lsc = &lc->mc_conns[ candidate ];
+ int msgid;
/*
* Rewrite the bind dn if needed
*/
- dc.rwmap = &li->targets[ candidate ]->rwmap;
+ dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDN";
}
if ( op->o_ctrls ) {
- rs->sr_err = ldap_set_option( lsc->ld,
+ rs->sr_err = ldap_set_option( lsc->msc_ld,
LDAP_OPT_SERVER_CONTROLS, op->o_ctrls );
if ( rs->sr_err != LDAP_SUCCESS ) {
rs->sr_err = slap_map_api2result( rs );
/* FIXME: this fixes the bind problem right now; we need
* to use the asynchronous version to get the "matched"
* and more in case of failure ... */
- rs->sr_err = ldap_sasl_bind_s(lsc->ld, mdn.bv_val,
- LDAP_SASL_SIMPLE, &op->oq_bind.rb_cred,
- op->o_ctrls, NULL, NULL);
+ rs->sr_err = ldap_sasl_bind( lsc->msc_ld, mdn.bv_val,
+ LDAP_SASL_SIMPLE, &op->orb_cred,
+ op->o_ctrls, NULL, &msgid );
+ if ( rs->sr_err == LDAP_SUCCESS ) {
+ LDAPMessage *res;
+ struct timeval tv = { 0, 0 };
+ int rc;
+
+ /*
+ * handle response!!!
+ */
+retry:;
+ switch ( ldap_result( lsc->msc_ld, msgid, 0, &tv, &res ) ) {
+ case 0:
+ ldap_pvt_thread_yield();
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000; /* 0.1 s */
+ goto retry;
+
+ case -1:
+ ldap_get_option( lsc->msc_ld, LDAP_OPT_ERROR_NUMBER,
+ &rs->sr_err );
+ break;
+
+ default:
+ rc = ldap_parse_result( lsc->msc_ld, res, &rs->sr_err,
+ NULL, NULL, NULL, NULL, 1 );
+ if ( rc != LDAP_SUCCESS ) {
+ rs->sr_err = rc;
+ }
+ break;
+ }
+ }
+
if ( rs->sr_err != LDAP_SUCCESS ) {
rs->sr_err = slap_map_api2result( rs );
goto return_results;
}
- /*
- * FIXME: handle response!!!
- */
- if ( lsc->bound_dn.bv_val != NULL ) {
- ber_memfree( lsc->bound_dn.bv_val );
+ if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
+ ber_memfree( lsc->msc_bound_ndn.bv_val );
}
- ber_dupbv( &lsc->bound_dn, &op->o_req_dn );
- lsc->bound = META_BOUND;
- lc->bound_target = candidate;
+ ber_dupbv( &lsc->msc_bound_ndn, &op->o_req_dn );
+ lsc->msc_bound = META_BOUND;
+ lc->mc_bound_target = candidate;
if ( li->savecred ) {
- if ( lsc->cred.bv_val ) {
- memset( lsc->cred.bv_val, 0, lsc->cred.bv_len );
- ber_memfree( lsc->cred.bv_val );
+ if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
+ /* destroy sensitive data */
+ memset( lsc->msc_cred.bv_val, 0, lsc->msc_cred.bv_len );
+ ber_memfree( lsc->msc_cred.bv_val );
}
- ber_dupbv( &lsc->cred, &op->oq_bind.rb_cred );
- ldap_set_rebind_proc( lsc->ld, meta_back_rebind, lsc );
+ ber_dupbv( &lsc->msc_cred, &op->orb_cred );
+ ldap_set_rebind_proc( lsc->msc_ld, meta_back_rebind, lsc );
}
if ( li->cache.ttl != META_DNCACHE_DISABLED
int
meta_back_dobind( struct metaconn *lc, Operation *op )
{
- struct metasingleconn *lsc;
- int bound = 0, i;
+ struct metasingleconn *lsc;
+ int bound = 0, i;
/*
* all the targets are bound as pseudoroot
*/
- if ( lc->bound_target == META_BOUND_ALL ) {
+ if ( lc->mc_bound_target == META_BOUND_ALL ) {
return 1;
}
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) {
int rc;
struct berval cred = BER_BVC("");
+ int msgid;
/*
* Not a candidate or something wrong with this target ...
*/
- if ( lsc->ld == NULL ) {
+ if ( lsc->msc_ld == NULL ) {
continue;
}
* If required, set controls
*/
if ( op->o_ctrls ) {
- if ( ldap_set_option( lsc->ld, LDAP_OPT_SERVER_CONTROLS,
+ if ( ldap_set_option( lsc->msc_ld, LDAP_OPT_SERVER_CONTROLS,
op->o_ctrls ) != LDAP_SUCCESS ) {
( void )meta_clear_one_candidate( lsc, 1 );
continue;
/*
* If the target is already bound it is skipped
*/
- if ( lsc->bound == META_BOUND && lc->bound_target == i ) {
+ if ( lsc->msc_bound == META_BOUND && lc->mc_bound_target == i ) {
++bound;
continue;
}
* (note: if the target was already bound, the anonymous
* bind clears the previous bind).
*/
- if ( lsc->bound_dn.bv_val ) {
- ber_memfree( lsc->bound_dn.bv_val );
- lsc->bound_dn.bv_val = NULL;
- lsc->bound_dn.bv_len = 0;
+ if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
+ ber_memfree( lsc->msc_bound_ndn.bv_val );
+ BER_BVZERO( &lsc->msc_bound_ndn );
}
if ( /* FIXME: need li ... li->savecred && */
- lsc->cred.bv_val ) {
- memset( lsc->cred.bv_val, 0, lsc->cred.bv_len );
- ber_memfree( lsc->cred.bv_val );
- lsc->cred.bv_val = NULL;
- lsc->cred.bv_len = 0;
+ !BER_BVISNULL( &lsc->msc_cred ) )
+ {
+ /* destroy sensitive data */
+ memset( lsc->msc_cred.bv_val, 0, lsc->msc_cred.bv_len );
+ ber_memfree( lsc->msc_cred.bv_val );
+ BER_BVZERO( &lsc->msc_cred );
+ }
+
+ rc = ldap_sasl_bind( lsc->msc_ld, "", LDAP_SASL_SIMPLE, &cred,
+ op->o_ctrls, NULL, &msgid );
+ if ( rc == LDAP_SUCCESS ) {
+ LDAPMessage *res;
+ struct timeval tv = { 0, 0 };
+ int err;
+
+ /*
+ * handle response!!!
+ */
+retry:;
+ switch ( ldap_result( lsc->msc_ld, msgid, 0, &tv, &res ) ) {
+ case 0:
+ ldap_pvt_thread_yield();
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000; /* 0.1 s */
+ goto retry;
+
+ case -1:
+ ldap_get_option( lsc->msc_ld, LDAP_OPT_ERROR_NUMBER,
+ &rc );
+ break;
+
+ default:
+ rc = ldap_parse_result( lsc->msc_ld, res, &err,
+ NULL, NULL, NULL, NULL, 1 );
+ if ( rc == LDAP_SUCCESS ) {
+ rc = err;
+ }
+ break;
+ }
}
- rc = ldap_sasl_bind_s(lsc->ld, "", LDAP_SASL_SIMPLE, &cred,
- op->o_ctrls, NULL, NULL);
if ( rc != LDAP_SUCCESS ) {
-
Debug( LDAP_DEBUG_ANY,
"==>meta_back_dobind: (anonymous)"
" bind failed"
continue;
} /* else */
- lsc->bound = META_ANONYMOUS;
+ lsc->msc_bound = META_ANONYMOUS;
++bound;
}
return 0;
}
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc) && i < candidate;
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ) && i < candidate;
++i, ++lsc );
- if ( !META_LAST(lsc) ) {
- return( lsc->ld != NULL );
+ if ( !META_LAST( lsc ) ) {
+ return ( lsc->msc_ld != NULL );
}
return 0;
meta_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
ber_int_t msgid, void *params )
{
- struct metasingleconn *lc = params;
+ struct metasingleconn *lsc = params;
- return ldap_bind_s( ld, lc->bound_dn.bv_val, lc->cred.bv_val,
- LDAP_AUTH_SIMPLE );
+ return ldap_sasl_bind_s( ld, lsc->msc_bound_ndn.bv_val,
+ LDAP_SASL_SIMPLE, &lsc->msc_cred,
+ NULL, NULL, NULL );
}
/*
int
meta_back_op_result( struct metaconn *lc, Operation *op, SlapReply *rs )
{
- int i, rerr = LDAP_SUCCESS;
- struct metasingleconn *lsc;
- char *rmsg = NULL;
- char *rmatch = NULL;
- int free_rmsg = 0, free_rmatch = 0;
-
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
- char *msg = NULL;
- char *match = NULL;
+ int i,
+ rerr = LDAP_SUCCESS;
+ struct metasingleconn *lsc;
+ char *rmsg = NULL;
+ char *rmatch = NULL;
+ int free_rmsg = 0,
+ free_rmatch = 0;
+
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) {
+ char *msg = NULL;
+ char *match = NULL;
rs->sr_err = LDAP_SUCCESS;
- ldap_get_option( lsc->ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
+ ldap_get_option( lsc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
if ( rs->sr_err != LDAP_SUCCESS ) {
/*
* better check the type of error. In some cases
* success if at least one of the targets gave
* positive result ...
*/
- ldap_get_option( lsc->ld,
+ ldap_get_option( lsc->msc_ld,
LDAP_OPT_ERROR_STRING, &msg );
- ldap_get_option( lsc->ld,
+ ldap_get_option( lsc->msc_ld,
LDAP_OPT_MATCHED_DN, &match );
rs->sr_err = slap_map_api2result( rs );
assert( li->ntargets != 0 );
for ( i = 0; i < li->ntargets; ++i ) {
- if ( meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {
+ if ( meta_back_is_candidate( &li->targets[ i ]->mt_nsuffix, ndn ) )
+ {
++cnt;
}
}
struct berval *ndn
)
{
- int i;
+ int i;
switch ( meta_back_count_candidates( li, ndn ) ) {
case 1:
case 0:
default:
return ( li->defaulttarget == META_DEFAULT_TARGET_NONE
- ? -1 : li->defaulttarget );
+ ? META_TARGET_NONE : li->defaulttarget );
}
for ( i = 0; i < li->ntargets; ++i ) {
- if ( meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {
+ if ( meta_back_is_candidate( &li->targets[ i ]->mt_nsuffix, ndn ) )
+ {
return i;
}
}
- return -1;
+ return META_TARGET_NONE;
}
/*
if ( i == candidate ) {
continue;
}
- meta_clear_one_candidate( &lc->conns[ i ], reallyclean );
+ meta_clear_one_candidate( &lc->mc_conns[ i ], reallyclean );
}
return 0;
int reallyclean
)
{
- lsc->candidate = META_NOT_CANDIDATE;
+ lsc->msc_candidate = META_NOT_CANDIDATE;
if ( !reallyclean ) {
return 0;
}
- if ( lsc->ld ) {
- ldap_unbind( lsc->ld );
- lsc->ld = NULL;
+ if ( lsc->msc_ld ) {
+ ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL );
+ lsc->msc_ld = NULL;
}
- if ( lsc->bound_dn.bv_val != NULL ) {
- ber_memfree( lsc->bound_dn.bv_val );
- lsc->bound_dn.bv_val = NULL;
- lsc->bound_dn.bv_len = 0;
+ if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
+ ber_memfree( lsc->msc_bound_ndn.bv_val );
+ BER_BVZERO( &lsc->msc_bound_ndn );
}
- if ( lsc->cred.bv_val != NULL ) {
- ber_memfree( lsc->cred.bv_val );
- lsc->cred.bv_val = NULL;
- lsc->cred.bv_len = 0;
+ if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
+ ber_memfree( lsc->msc_cred.bv_val );
+ BER_BVZERO( &lsc->msc_cred );
}
return 0;
int
meta_back_compare( Operation *op, SlapReply *rs )
{
- struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
- struct metaconn *lc;
- struct metasingleconn *lsc;
- char *match = NULL, *err = NULL;
- struct berval mmatch = BER_BVNULL;
- int candidates = 0, last = 0, i, count = 0, rc;
- int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
- int *msgid;
- dncookie dc;
+ struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
+ struct metaconn *lc;
+ struct metasingleconn *lsc;
+ char *match = NULL,
+ *err = NULL;
+ struct berval mmatch = BER_BVNULL;
+ int candidates = 0,
+ last = 0,
+ i,
+ count = 0,
+ rc,
+ cres = LDAP_SUCCESS,
+ rres = LDAP_SUCCESS,
+ *msgid;
+ dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_ALLOW_MULTIPLE,
&op->o_req_ndn, NULL );
dc.rs = rs;
dc.ctx = "compareDN";
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) {
struct berval mdn = BER_BVNULL;
- struct berval mapped_attr = op->oq_compare.rs_ava->aa_desc->ad_cname;
- struct berval mapped_value = op->oq_compare.rs_ava->aa_value;
+ struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
+ struct berval mapped_value = op->orc_ava->aa_value;
- if ( lsc->candidate != META_CANDIDATE ) {
+ if ( lsc->msc_candidate != META_CANDIDATE ) {
msgid[ i ] = -1;
continue;
}
/*
* Rewrite the compare dn, if needed
*/
- dc.rwmap = &li->targets[ i ]->rwmap;
+ dc.rwmap = &li->targets[ i ]->mt_rwmap;
switch ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
case LDAP_UNWILLING_TO_PERFORM:
/*
* if attr is objectClass, try to remap the value
*/
- if ( op->oq_compare.rs_ava->aa_desc == slap_schema.si_ad_objectClass ) {
- ldap_back_map( &li->targets[ i ]->rwmap.rwm_oc,
- &op->oq_compare.rs_ava->aa_value,
+ if ( op->orc_ava->aa_desc == slap_schema.si_ad_objectClass ) {
+ ldap_back_map( &li->targets[ i ]->mt_rwmap.rwm_oc,
+ &op->orc_ava->aa_value,
&mapped_value, BACKLDAP_MAP );
if ( mapped_value.bv_val == NULL || mapped_value.bv_val[0] == '\0' ) {
* else try to remap the attribute
*/
} else {
- ldap_back_map( &li->targets[ i ]->rwmap.rwm_at,
- &op->oq_compare.rs_ava->aa_desc->ad_cname,
+ ldap_back_map( &li->targets[ i ]->mt_rwmap.rwm_at,
+ &op->orc_ava->aa_desc->ad_cname,
&mapped_attr, BACKLDAP_MAP );
if ( mapped_attr.bv_val == NULL || mapped_attr.bv_val[0] == '\0' ) {
continue;
}
- if ( op->oq_compare.rs_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
+ if ( op->orc_ava->aa_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
{
dc.ctx = "compareAttrDN";
- switch ( ldap_back_dn_massage( &dc, &op->oq_compare.rs_ava->aa_value, &mapped_value ) )
+ switch ( ldap_back_dn_massage( &dc, &op->orc_ava->aa_value, &mapped_value ) )
{
case LDAP_UNWILLING_TO_PERFORM:
rc = 1;
* that returns determines the result; a constraint on unicity
* of the result ought to be enforced
*/
- msgid[ i ] = ldap_compare( lc->conns[ i ].ld, mdn.bv_val,
- mapped_attr.bv_val, mapped_value.bv_val );
+ rc = ldap_compare_ext( lc->mc_conns[ i ].msc_ld, mdn.bv_val,
+ mapped_attr.bv_val, &mapped_value,
+ NULL, NULL, &msgid[ i ] );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
- mdn.bv_val = NULL;
+ BER_BVZERO( &mdn );
}
- if ( mapped_attr.bv_val != op->oq_compare.rs_ava->aa_desc->ad_cname.bv_val ) {
+ if ( mapped_attr.bv_val != op->orc_ava->aa_desc->ad_cname.bv_val ) {
free( mapped_attr.bv_val );
+ BER_BVZERO( &mapped_attr );
}
- if ( mapped_value.bv_val != op->oq_compare.rs_ava->aa_value.bv_val ) {
+ if ( mapped_value.bv_val != op->orc_ava->aa_value.bv_val ) {
free( mapped_value.bv_val );
+ BER_BVZERO( &mapped_value );
}
- if ( msgid[ i ] == -1 ) {
+ if ( rc != LDAP_SUCCESS ) {
+ /* FIXME: what should we do with the error? */
continue;
}
/*
* FIXME: should we check for abandon?
*/
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc); lsc++, i++ ) {
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); lsc++, i++ ) {
int lrc;
LDAPMessage *res = NULL;
continue;
}
- lrc = ldap_result( lsc->ld, msgid[ i ],
+ lrc = ldap_result( lsc->msc_ld, msgid[ i ],
0, NULL, &res );
if ( lrc == 0 ) {
rc = -1;
goto finish;
}
+
+ rc = ldap_parse_result( lsc->msc_ld, res,
+ &rs->sr_err,
+ NULL, NULL, NULL, NULL, 1 );
+ if ( rc != LDAP_SUCCESS ) {
+ rres = rc;
+ rc = -1;
+ goto finish;
+ }
- rs->sr_err = ldap_result2error( lsc->ld, res, 1 );
switch ( rs->sr_err ) {
case LDAP_COMPARE_TRUE:
case LDAP_COMPARE_FALSE:
if ( err != NULL ) {
free( err );
}
- ldap_get_option( lsc->ld,
+ ldap_get_option( lsc->msc_ld,
LDAP_OPT_ERROR_STRING, &err );
if ( match != NULL ) {
free( match );
}
- ldap_get_option( lsc->ld,
+ ldap_get_option( lsc->msc_ld,
LDAP_OPT_MATCHED_DN, &match );
last = i;
return NULL;
}
- lt->rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
- if ( lt->rwmap.rwm_rw == NULL ) {
+ lt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
+ if ( lt->mt_rwmap.rwm_rw == NULL ) {
free( lt );
return NULL;
}
rargv[ 0 ] = "rewriteContext";
rargv[ 1 ] = "searchFilter";
rargv[ 2 ] = NULL;
- rewrite_parse( lt->rwmap.rwm_rw, "<suffix massage>",
+ rewrite_parse( lt->mt_rwmap.rwm_rw, "<suffix massage>",
1, 2, rargv );
rargv[ 0 ] = "rewriteContext";
rargv[ 1 ] = "default";
rargv[ 2 ] = NULL;
- rewrite_parse( lt->rwmap.rwm_rw, "<suffix massage>",
+ rewrite_parse( lt->mt_rwmap.rwm_rw, "<suffix massage>",
1, 2, rargv );
}
- ldap_back_map_init( <->rwmap.rwm_at, &mapping );
+ ldap_back_map_init( <->mt_rwmap.rwm_at, &mapping );
return lt;
}
dn.bv_val = ludp->lud_dn;
dn.bv_len = strlen( ludp->lud_dn );
- rc = dnPrettyNormal( NULL, &dn, &li->targets[ i ]->psuffix,
- &li->targets[ i ]->suffix, NULL );
+ rc = dnPrettyNormal( NULL, &dn, &li->targets[ i ]->mt_psuffix,
+ &li->targets[ i ]->mt_nsuffix, NULL );
if( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: "
"target '%s' DN is invalid\n",
}
}
- li->targets[ i ]->uri = ldap_url_list2urls( ludp );
+ li->targets[ i ]->mt_uri = ldap_url_list2urls( ludp );
ldap_free_urllist( ludp );
- if ( li->targets[ i ]->uri == NULL) {
+ if ( li->targets[ i ]->mt_uri == NULL) {
fprintf( stderr, "%s: line %d: no memory?\n",
fname, lineno );
return( 1 );
/*
* uri MUST be a branch of a suffix!
*/
- if ( select_backend( &li->targets[ i ]->suffix, 0, 0 ) == NULL ) {
+ if ( select_backend( &li->targets[ i ]->mt_nsuffix, 0, 0 ) == NULL ) {
fprintf( stderr,
"%s: line %d: <naming context> of URI does not resolve to a backend"
" in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( argv[ 1 ] );
- if ( dnNormalize( 0, NULL, NULL, &dn, &li->targets[ i ]->binddn,
+ if ( dnNormalize( 0, NULL, NULL, &dn, &li->targets[ i ]->mt_binddn,
NULL ) != LDAP_SUCCESS )
{
fprintf( stderr, "%s: line %d: "
fname, lineno );
return 1;
}
- ber_str2bv( argv[ 1 ], 0L, 1, &li->targets[ i ]->bindpw );
+ ber_str2bv( argv[ 1 ], 0L, 1, &li->targets[ i ]->mt_bindpw );
/* save bind creds for referral rebinds? */
} else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
dn.bv_val = argv[ 1 ];
dn.bv_len = strlen( argv[ 1 ] );
if ( dnNormalize( 0, NULL, NULL, &dn,
- &li->targets[ i ]->pseudorootdn, NULL ) != LDAP_SUCCESS )
+ &li->targets[ i ]->mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
{
fprintf( stderr, "%s: line %d: "
"pseudoroot DN '%s' is invalid\n",
fname, lineno );
return 1;
}
- ber_str2bv( argv[ 1 ], 0L, 1, &li->targets[ i ]->pseudorootpw );
+ ber_str2bv( argv[ 1 ], 0L, 1, &li->targets[ i ]->mt_pseudorootpw );
/* dn massaging */
} else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
* FIXME: no extra rewrite capabilities should be added
* to the database
*/
- return suffix_massage_config( li->targets[ i ]->rwmap.rwm_rw,
+ return suffix_massage_config( li->targets[ i ]->mt_rwmap.rwm_rw,
&pvnc, &nvnc, &prnc, &nrnc );
/* rewrite stuff ... */
if ( strcasecmp( argv[0], "rewriteEngine" ) == 0 ) {
li->rwinfo = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
}
- return rewrite_parse(li->rwinfo, fname, lineno,
- argc, argv);
+ return rewrite_parse( li->rwinfo, fname, lineno,
+ argc, argv );
}
- return rewrite_parse( li->targets[ i ]->rwmap.rwm_rw, fname, lineno,
- argc, argv );
+ return rewrite_parse( li->targets[ i ]->mt_rwmap.rwm_rw,
+ fname, lineno, argc, argv );
/* objectclass/attribute mapping */
} else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
return 1;
}
- return ldap_back_map_config( &li->targets[ i ]->rwmap.rwm_oc,
- &li->targets[ i ]->rwmap.rwm_at,
+ return ldap_back_map_config( &li->targets[ i ]->mt_rwmap.rwm_oc,
+ &li->targets[ i ]->mt_rwmap.rwm_at,
fname, lineno, argc, argv );
/* anything else */
} else {
struct metaconn *lc1 = ( struct metaconn * )c1;
struct metaconn *lc2 = ( struct metaconn * )c2;
- return SLAP_PTRCMP( lc1->conn, lc2->conn );
+ return SLAP_PTRCMP( lc1->mc_conn, lc2->mc_conn );
}
/*
struct metaconn *lc1 = ( struct metaconn * )c1;
struct metaconn *lc2 = ( struct metaconn * )c2;
- return( ( lc1->conn == lc2->conn ) ? -1 : 0 );
+ return( ( lc1->mc_conn == lc2->mc_conn ) ? -1 : 0 );
}
/*
return;
}
- ravl_print( root->avl_right, depth+1 );
+ ravl_print( root->avl_right, depth + 1 );
for ( i = 0; i < depth; i++ ) {
printf( " " );
}
- printf( "c(%d) %d\n", ( ( struct metaconn * )root->avl_data )->conn->c_connid, root->avl_bf );
+ printf( "c(%d) %d\n", ( ( struct metaconn * )root->avl_data )->mc_conn->c_connid, root->avl_bf );
- ravl_print( root->avl_left, depth+1 );
+ ravl_print( root->avl_left, depth + 1 );
}
static void
/*
* make it a null-terminated array ...
*/
- lc->conns = ch_calloc( sizeof( struct metasingleconn ), ntargets+1 );
- if ( lc->conns == NULL ) {
+ lc->mc_conns = ch_calloc( sizeof( struct metasingleconn ), ntargets+1 );
+ if ( lc->mc_conns == NULL ) {
free( lc );
return NULL;
}
- lc->conns[ ntargets ].candidate = META_LAST_CONN;
+ lc->mc_conns[ ntargets ].msc_candidate = META_LAST_CONN;
for ( ; ntargets-- > 0; ) {
- lc->conns[ ntargets ].ld = NULL;
- lc->conns[ ntargets ].bound_dn.bv_val = NULL;
- lc->conns[ ntargets ].bound_dn.bv_len = 0;
- lc->conns[ ntargets ].cred.bv_val = NULL;
- lc->conns[ ntargets ].cred.bv_len = 0;
- lc->conns[ ntargets ].bound = META_UNBOUND;
+ lc->mc_conns[ ntargets ].msc_ld = NULL;
+ BER_BVZERO( &lc->mc_conns[ ntargets ].msc_bound_ndn );
+ BER_BVZERO( &lc->mc_conns[ ntargets ].msc_cred );
+ lc->mc_conns[ ntargets ].msc_bound = META_UNBOUND;
}
- lc->bound_target = META_BOUND_NONE;
+ lc->mc_bound_target = META_BOUND_NONE;
return lc;
}
return;
}
- if ( lc->conns ) {
- ch_free( lc->conns );
+ if ( lc->mc_conns ) {
+ ch_free( lc->mc_conns );
}
free( lc );
/*
* Already init'ed
*/
- if ( lsc->ld != NULL ) {
+ if ( lsc->msc_ld != NULL ) {
return LDAP_SUCCESS;
}
/*
* Attempts to initialize the connection to the target ds
*/
- rs->sr_err = ldap_initialize( &lsc->ld, lt->uri );
+ rs->sr_err = ldap_initialize( &lsc->msc_ld, lt->mt_uri );
if ( rs->sr_err != LDAP_SUCCESS ) {
return slap_map_api2result( rs );
}
* bound with a particular version, then so can we.
*/
vers = op->o_conn->c_protocol;
- ldap_set_option( lsc->ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
+ ldap_set_option( lsc->msc_ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
/* FIXME: configurable? */
- ldap_set_option(lsc->ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON);
+ ldap_set_option( lsc->msc_ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
/*
* Set the network timeout if set
*/
if (li->network_timeout != 0){
- struct timeval network_timeout;
+ struct timeval network_timeout;
network_timeout.tv_usec = 0;
network_timeout.tv_sec = li->network_timeout;
- ldap_set_option( lsc->ld, LDAP_OPT_NETWORK_TIMEOUT, (void *) &network_timeout);
+ ldap_set_option( lsc->msc_ld, LDAP_OPT_NETWORK_TIMEOUT,
+ (void *)&network_timeout );
}
/*
* Sets a cookie for the rewrite session
*/
- ( void )rewrite_session_init( lt->rwmap.rwm_rw, op->o_conn );
+ ( void )rewrite_session_init( lt->mt_rwmap.rwm_rw, op->o_conn );
/*
- * If the connection dn is not null, an attempt to rewrite it is made
+ * If the connection DN is not null, an attempt to rewrite it is made
*/
if ( op->o_conn->c_dn.bv_len != 0 ) {
- dc.rwmap = <->rwmap;
+ dc.rwmap = <->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "bindDN";
* Rewrite the bind dn if needed
*/
if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn,
- &lsc->bound_dn) ) {
+ &lsc->msc_bound_ndn ) )
+ {
send_ldap_result( op, rs );
return rs->sr_err;
}
/* copy the DN idf needed */
- if ( lsc->bound_dn.bv_val == op->o_conn->c_dn.bv_val ) {
- ber_dupbv( &lsc->bound_dn, &op->o_conn->c_dn );
+ if ( lsc->msc_bound_ndn.bv_val == op->o_conn->c_dn.bv_val ) {
+ ber_dupbv( &lsc->msc_bound_ndn, &op->o_conn->c_dn );
}
- assert( lsc->bound_dn.bv_val );
+ assert( lsc->msc_bound_ndn.bv_val );
} else {
- ber_str2bv( "", 0, 1, &lsc->bound_dn );
+ ber_str2bv( "", 0, 1, &lsc->msc_bound_ndn );
}
- lsc->bound = META_UNBOUND;
+ lsc->msc_bound = META_UNBOUND;
/*
* The candidate is activated
*/
- lsc->candidate = META_CANDIDATE;
+ lsc->msc_candidate = META_CANDIDATE;
return LDAP_SUCCESS;
}
int *candidate )
{
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
- struct metaconn *lc, lc_curr;
- int cached = -1, i = -1, err = LDAP_SUCCESS;
- int new_conn = 0;
+ struct metaconn *lc, lc_curr;
+ int cached = META_TARGET_NONE,
+ i = META_TARGET_NONE,
+ err = LDAP_SUCCESS,
+ new_conn = 0;
/* Searches for a metaconn in the avl tree */
- lc_curr.conn = op->o_conn;
+ lc_curr.mc_conn = op->o_conn;
ldap_pvt_thread_mutex_lock( &li->conn_mutex );
lc = (struct metaconn *)avl_find( li->conntree,
(caddr_t)&lc_curr, meta_back_conn_cmp );
/* Looks like we didn't get a bind. Open a new session... */
if ( !lc ) {
lc = metaconn_alloc( li->ntargets );
- lc->conn = op->o_conn;
+ lc->mc_conn = op->o_conn;
new_conn = 1;
}
+ /*
+ * require all connections ...
+ */
+ if ( op_type == META_OP_REQUIRE_ALL ) {
+ for ( i = 0; i < li->ntargets; i++ ) {
+
+ /*
+ * The target is activated; if needed, it is
+ * also init'd
+ */
+ int lerr = init_one_conn( op, rs, li->targets[ i ],
+ &lc->mc_conns[ i ] );
+ if ( lerr != LDAP_SUCCESS ) {
+
+ /*
+ * FIXME: in case one target cannot
+ * be init'd, should the other ones
+ * be tried?
+ */
+ ( void )meta_clear_one_candidate( &lc->mc_conns[ i ], 1 );
+ err = lerr;
+ continue;
+ }
+ }
+ goto done;
+ }
+
/*
* looks in cache, if any
*/
* tries to get a unique candidate
* (takes care of default target
*/
- if ( i < 0 ) {
+ if ( i == META_TARGET_NONE ) {
i = meta_back_select_unique_candidate( li, ndn );
}
/*
* if any is found, inits the connection
*/
- if ( i < 0 ) {
+ if ( i == META_TARGET_NONE ) {
if ( new_conn ) {
metaconn_free( lc );
}
}
Debug( LDAP_DEBUG_CACHE,
- "==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n%s",
- i, ndn->bv_val, "" );
+ "==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n",
+ i, ndn->bv_val, 0 );
/*
* Clear all other candidates
* sends the appropriate result.
*/
err = init_one_conn( op, rs, li->targets[ i ],
- &lc->conns[ i ] );
+ &lc->mc_conns[ i ] );
if ( err != LDAP_SUCCESS ) {
/*
* be init'd, should the other ones
* be tried?
*/
- ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->mc_conns[ i ], 1 );
if ( new_conn ) {
metaconn_free( lc );
}
*candidate = i;
}
- /*
- * require all connections ...
- */
- } else if (op_type == META_OP_REQUIRE_ALL) {
- for ( i = 0; i < li->ntargets; i++ ) {
-
- /*
- * The target is activated; if needed, it is
- * also init'd
- */
- int lerr = init_one_conn( op, rs, li->targets[ i ],
- &lc->conns[ i ] );
- if ( lerr != LDAP_SUCCESS ) {
-
- /*
- * FIXME: in case one target cannot
- * be init'd, should the other ones
- * be tried?
- */
- ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
- err = lerr;
- continue;
- }
- }
-
/*
* if no unique candidate ...
*/
} else {
for ( i = 0; i < li->ntargets; i++ ) {
if ( i == cached
- || meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {
+ || meta_back_is_candidate( &li->targets[ i ]->mt_nsuffix, ndn ) )
+ {
/*
* The target is activated; if needed, it is
*/
int lerr = init_one_conn( op, rs,
li->targets[ i ],
- &lc->conns[ i ] );
+ &lc->mc_conns[ i ] );
if ( lerr != LDAP_SUCCESS ) {
/*
* be init'd, should the other ones
* be tried?
*/
- ( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
+ ( void )meta_clear_one_candidate( &lc->mc_conns[ i ], 1 );
err = lerr;
continue;
}
}
}
+done:;
/* clear out init_one_conn non-fatal errors */
rs->sr_err = LDAP_SUCCESS;
rs->sr_text = NULL;
ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
Debug( LDAP_DEBUG_TRACE,
- "=>meta_back_getconn: conn %ld inserted\n%s%s",
- lc->conn->c_connid, "", "" );
+ "=>meta_back_getconn: conn %ld inserted\n",
+ lc->mc_conn->c_connid, 0, 0 );
/*
* Err could be -1 in case a duplicate metaconn is inserted
metaconn_free( lc );
return NULL;
}
+
} else {
Debug( LDAP_DEBUG_TRACE,
- "=>meta_back_getconn: conn %ld fetched\n%s%s",
- lc->conn->c_connid, "", "" );
+ "=>meta_back_getconn: conn %ld fetched\n",
+ lc->mc_conn->c_connid, 0, 0 );
}
return lc;
/*
* Rewrite the compare dn, if needed
*/
- dc.rwmap = &li->targets[ candidate ]->rwmap;
+ dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "deleteDN";
return -1;
}
- ldap_delete_s( lc->conns[ candidate ].ld, mdn.bv_val );
+ (void)ldap_delete_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
+ NULL, NULL );
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
+ BER_BVZERO( &mdn );
}
return meta_back_op_result( lc, op, rs );
{
struct metadncacheentry tmp_entry, *entry;
time_t curr_time;
- int target = -1;
+ int target = META_TARGET_NONE;
assert( cache );
assert( ndn );
*/
if ( cache->ttl < 0 ) {
target = entry->target;
+
} else {
/*
} /* else: do the search */
candidate = meta_back_select_unique_candidate( li, gr_ndn );
- if ( candidate == -1 ) {
+ if ( candidate == META_TARGET_NONE ) {
goto cleanup;
}
void *v_lc
)
{
- struct metaconn *lc = v_lc;
- struct metasingleconn *lsc;
+ struct metaconn *lc = v_lc;
+ struct metasingleconn *lsc;
- for ( lsc = lc->conns; !META_LAST(lsc); lsc++ ) {
- if ( lsc->ld != NULL ) {
- ldap_unbind( lsc->ld );
+ for ( lsc = lc->mc_conns; !META_LAST( lsc ); lsc++ ) {
+ if ( lsc->msc_ld != NULL ) {
+ ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL );
}
- if ( lsc->bound_dn.bv_val ) {
- ber_memfree( lsc->bound_dn.bv_val );
+ if ( !BER_BVISNULL( &lsc->msc_bound_ndn ) ) {
+ ber_memfree( lsc->msc_bound_ndn.bv_val );
}
- if ( lsc->cred.bv_val ) {
- memset( lsc->cred.bv_val, 0, lsc->cred.bv_len );
- ber_memfree( lsc->cred.bv_val );
+ if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
+ /* destroy sensitive data */
+ memset( lsc->msc_cred.bv_val, 0, lsc->msc_cred.bv_len );
+ ber_memfree( lsc->msc_cred.bv_val );
}
}
- free( lc->conns );
+ free( lc->mc_conns );
free( lc );
}
struct metatarget *lt
)
{
- if ( lt->uri ) {
- free( lt->uri );
+ if ( lt->mt_uri ) {
+ free( lt->mt_uri );
}
- if ( lt->psuffix.bv_val ) {
- free( lt->psuffix.bv_val );
+ if ( !BER_BVISNULL( <->mt_psuffix ) ) {
+ free( lt->mt_psuffix.bv_val );
}
- if ( lt->suffix.bv_val ) {
- free( lt->suffix.bv_val );
+ if ( !BER_BVISNULL( <->mt_nsuffix ) ) {
+ free( lt->mt_nsuffix.bv_val );
}
- if ( lt->binddn.bv_val ) {
- free( lt->binddn.bv_val );
+ if ( !BER_BVISNULL( <->mt_binddn ) ) {
+ free( lt->mt_binddn.bv_val );
}
- if ( lt->bindpw.bv_val ) {
- free( lt->bindpw.bv_val );
+ if ( !BER_BVISNULL( <->mt_bindpw ) ) {
+ free( lt->mt_bindpw.bv_val );
}
- if ( lt->pseudorootdn.bv_val ) {
- free( lt->pseudorootdn.bv_val );
+ if ( !BER_BVISNULL( <->mt_pseudorootdn ) ) {
+ free( lt->mt_pseudorootdn.bv_val );
}
- if ( lt->pseudorootpw.bv_val ) {
- free( lt->pseudorootpw.bv_val );
+ if ( !BER_BVISNULL( <->mt_pseudorootpw ) ) {
+ free( lt->mt_pseudorootpw.bv_val );
}
- if ( lt->rwmap.rwm_rw ) {
- rewrite_info_delete( <->rwmap.rwm_rw );
+ if ( lt->mt_rwmap.rwm_rw ) {
+ rewrite_info_delete( <->mt_rwmap.rwm_rw );
}
- avl_free( lt->rwmap.rwm_oc.remap, NULL );
- avl_free( lt->rwmap.rwm_oc.map, mapping_free );
- avl_free( lt->rwmap.rwm_at.remap, NULL );
- avl_free( lt->rwmap.rwm_at.map, mapping_free );
+ avl_free( lt->mt_rwmap.rwm_oc.remap, NULL );
+ avl_free( lt->mt_rwmap.rwm_oc.map, mapping_free );
+ avl_free( lt->mt_rwmap.rwm_at.remap, NULL );
+ avl_free( lt->mt_rwmap.rwm_at.map, mapping_free );
}
int
}
if ( !meta_back_dobind( lc, op )
- || !meta_back_is_valid( lc, candidate ) ) {
+ || !meta_back_is_valid( lc, candidate ) )
+ {
rs->sr_err = LDAP_OTHER;
rc = -1;
goto cleanup;
/*
* Rewrite the modify dn, if needed
*/
- dc.rwmap = &li->targets[ candidate ]->rwmap;
+ dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "modifyDN";
goto cleanup;
}
- for ( i = 0, ml = op->oq_modify.rs_modlist; ml; i++ ,ml = ml->sml_next )
+ for ( i = 0, ml = op->orm_modlist; ml; i++ ,ml = ml->sml_next )
;
mods = ch_malloc( sizeof( LDAPMod )*i );
}
dc.ctx = "modifyAttrDN";
- for ( i = 0, ml = op->oq_modify.rs_modlist; ml; ml = ml->sml_next ) {
+ for ( i = 0, ml = op->orm_modlist; ml; ml = ml->sml_next ) {
int j;
if ( ml->sml_desc->ad_type->sat_no_user_mod ) {
continue;
}
- ldap_back_map( &li->targets[ candidate ]->rwmap.rwm_at,
+ ldap_back_map( &li->targets[ candidate ]->mt_rwmap.rwm_at,
&ml->sml_desc->ad_cname, &mapped,
BACKLDAP_MAP );
- if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
+ if ( BER_BVISNULL( &mapped ) || mapped.bv_val[0] == '\0' ) {
continue;
}
* level.
*/
if ( strcmp( ml->sml_desc->ad_type->sat_syntax->ssyn_oid,
- SLAPD_DN_SYNTAX ) == 0 ) {
+ SLAPD_DN_SYNTAX ) == 0 )
+ {
( void )ldap_dnattr_rewrite( &dc, ml->sml_values );
}
- if ( ml->sml_values != NULL ){
- for (j = 0; ml->sml_values[ j ].bv_val; j++);
- mods[ i ].mod_bvalues = (struct berval **)ch_malloc((j+1) *
- sizeof(struct berval *));
- for (j = 0; ml->sml_values[ j ].bv_val; j++)
- mods[ i ].mod_bvalues[ j ] = &ml->sml_values[j];
+ if ( ml->sml_values != NULL ) {
+ for ( j = 0; ml->sml_values[ j ].bv_val; j++ )
+ ;
+ mods[ i ].mod_bvalues =
+ (struct berval **)ch_malloc( ( j + 1 ) *
+ sizeof(struct berval *) );
+ for ( j = 0; ml->sml_values[ j ].bv_val; j++ ) {
+ mods[ i ].mod_bvalues[ j ] = &ml->sml_values[ j ];
+ }
mods[ i ].mod_bvalues[ j ] = NULL;
} else {
}
modv[ i ] = 0;
- ldap_modify_s( lc->conns[ candidate ].ld, mdn.bv_val, modv );
+ rc = ldap_modify_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
+ modv, NULL, NULL ) != LDAP_SUCCESS;
cleanup:;
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
+ BER_BVZERO( &mdn );
}
if ( modv != NULL ) {
- for ( i = 0; modv[ i ]; i++) {
+ for ( i = 0; modv[ i ]; i++ ) {
free( modv[ i ]->mod_bvalues );
}
}
goto cleanup;
}
+ assert( candidate != META_TARGET_NONE );
+
if ( !meta_back_dobind( lc, op )
- || !meta_back_is_valid( lc, candidate ) ) {
+ || !meta_back_is_valid( lc, candidate ) )
+ {
rs->sr_err = LDAP_OTHER;
rc = -1;
goto cleanup;
dc.conn = op->o_conn;
dc.rs = rs;
- if ( op->oq_modrdn.rs_newSup ) {
+ if ( op->orr_newSup ) {
int nsCandidate, version = LDAP_VERSION3;
nsCandidate = meta_back_select_unique_candidate( li,
- op->oq_modrdn.rs_nnewSup );
+ op->orr_nnewSup );
if ( nsCandidate != candidate ) {
/*
* FIXME: is this the correct return code?
*/
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+ rs->sr_text = "cross-target rename not supported";
rc = -1;
goto cleanup;
}
- ldap_set_option( lc->conns[ nsCandidate ].ld,
+ ldap_set_option( lc->mc_conns[ nsCandidate ].msc_ld,
LDAP_OPT_PROTOCOL_VERSION, &version );
/*
* Rewrite the new superior, if defined and required
*/
- dc.rwmap = &li->targets[ nsCandidate ]->rwmap;
+ dc.rwmap = &li->targets[ nsCandidate ]->mt_rwmap;
dc.ctx = "newSuperiorDN";
- if ( ldap_back_dn_massage( &dc, op->oq_modrdn.rs_newSup, &mnewSuperior ) ) {
+ if ( ldap_back_dn_massage( &dc, op->orr_newSup, &mnewSuperior ) ) {
rc = -1;
goto cleanup;
}
/*
* Rewrite the modrdn dn, if required
*/
- dc.rwmap = &li->targets[ candidate ]->rwmap;
+ dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
dc.ctx = "modrDN";
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
rc = -1;
goto cleanup;
}
- ldap_rename2_s( lc->conns[ candidate ].ld, mdn.bv_val,
- op->oq_modrdn.rs_newrdn.bv_val,
+ rc = ldap_rename_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
+ op->orr_newrdn.bv_val,
mnewSuperior.bv_val,
- op->oq_modrdn.rs_deleteoldrdn );
+ op->orr_deleteoldrdn,
+ NULL, NULL ) != LDAP_SUCCESS;
cleanup:;
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
free( mdn.bv_val );
+ BER_BVZERO( &mdn );
}
- if ( mnewSuperior.bv_val != NULL
- && mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
+ if ( !BER_BVISNULL( &mnewSuperior )
+ && mnewSuperior.bv_val != op->orr_newSup->bv_val )
+ {
free( mnewSuperior.bv_val );
+ BER_BVZERO( &mnewSuperior );
}
if ( rc == 0 ) {
} /* else */
send_ldap_result( op, rs );
- return rc;
+ return rc;
}
/*
* Inits searches
*/
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc); ++i, ++lsc ) {
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); ++i, ++lsc ) {
struct berval realbase = op->o_req_dn;
int realscope = op->ors_scope;
ber_len_t suffixlen = 0;
struct berval mfilter = BER_BVNULL;
char **mapped_attrs = NULL;
- if ( lsc->candidate != META_CANDIDATE ) {
+ if ( lsc->msc_candidate != META_CANDIDATE ) {
msgid[ i ] = -1;
continue;
}
/* should we check return values? */
if ( op->ors_deref != -1 ) {
- ldap_set_option( lsc->ld, LDAP_OPT_DEREF,
+ ldap_set_option( lsc->msc_ld, LDAP_OPT_DEREF,
( void * )&op->ors_deref);
}
if ( op->ors_tlimit != SLAP_NO_LIMIT ) {
- ldap_set_option( lsc->ld, LDAP_OPT_TIMELIMIT,
+ ldap_set_option( lsc->msc_ld, LDAP_OPT_TIMELIMIT,
( void * )&op->ors_tlimit);
}
if ( op->ors_slimit != SLAP_NO_LIMIT ) {
- ldap_set_option( lsc->ld, LDAP_OPT_SIZELIMIT,
+ ldap_set_option( lsc->msc_ld, LDAP_OPT_SIZELIMIT,
( void * )&op->ors_slimit);
}
- dc.rwmap = &li->targets[ i ]->rwmap;
+ dc.rwmap = &li->targets[ i ]->mt_rwmap;
/*
* modifies the base according to the scope, if required
*/
- suffixlen = li->targets[ i ]->suffix.bv_len;
+ suffixlen = li->targets[ i ]->mt_nsuffix.bv_len;
if ( suffixlen > op->o_req_ndn.bv_len ) {
switch ( op->ors_scope ) {
case LDAP_SCOPE_SUBTREE:
* illegal bases may be turned into
* the suffix of the target.
*/
- if ( dnIsSuffix( &li->targets[ i ]->suffix,
+ if ( dnIsSuffix( &li->targets[ i ]->mt_nsuffix,
&op->o_req_ndn ) ) {
- realbase = li->targets[ i ]->suffix;
+ realbase = li->targets[ i ]->mt_nsuffix;
is_scope++;
} else {
case LDAP_SCOPE_ONELEVEL:
{
- struct berval rdn = li->targets[ i ]->suffix;
+ struct berval rdn = li->targets[ i ]->mt_nsuffix;
rdn.bv_len -= op->o_req_ndn.bv_len + STRLENOF( "," );
if ( dnIsOneLevelRDN( &rdn )
- && dnIsSuffix( &li->targets[ i ]->suffix, &op->o_req_ndn ) )
+ && dnIsSuffix( &li->targets[ i ]->mt_nsuffix, &op->o_req_ndn ) )
{
/*
* if there is exactly one level,
* make the target suffix the new
* base, and make scope "base"
*/
- realbase = li->targets[ i ]->suffix;
+ realbase = li->targets[ i ]->mt_nsuffix;
realscope = LDAP_SCOPE_BASE;
is_scope++;
break;
/*
* Maps required attributes
*/
- rc = ldap_back_map_attrs( &li->targets[ i ]->rwmap.rwm_at,
+ rc = ldap_back_map_attrs( &li->targets[ i ]->mt_rwmap.rwm_at,
op->ors_attrs, BACKLDAP_MAP,
&mapped_attrs );
if ( rc != LDAP_SUCCESS ) {
/*
* Starts the search
*/
- msgid[ i ] = ldap_search( lsc->ld, mbase.bv_val, realscope,
- mfilter.bv_val, mapped_attrs,
- op->ors_attrsonly );
+ rc = ldap_search_ext( lsc->msc_ld,
+ mbase.bv_val, realscope, mfilter.bv_val,
+ mapped_attrs, op->ors_attrsonly,
+ NULL, NULL,
+ NULL, op->ors_slimit, &msgid[ i ] );
if ( mapped_attrs ) {
free( mapped_attrs );
mapped_attrs = NULL;
}
if ( mfilter.bv_val != op->ors_filterstr.bv_val ) {
free( mfilter.bv_val );
- mfilter.bv_val = NULL;
+ BER_BVZERO( &mfilter );
}
if ( mbase.bv_val != realbase.bv_val ) {
free( mbase.bv_val );
- mbase.bv_val = NULL;
+ BER_BVZERO( &mbase );
}
- if ( msgid[ i ] == -1 ) {
+ if ( rc != LDAP_SUCCESS ) {
continue;
}
-
+
++candidates;
new_candidate:;
/* check for abandon */
ab = op->o_abandon;
- for ( i = 0, lsc = lc->conns; !META_LAST(lsc); lsc++, i++ ) {
+ for ( i = 0, lsc = lc->mc_conns; !META_LAST( lsc ); lsc++, i++ ) {
if ( msgid[ i ] == -1 ) {
continue;
}
if ( ab ) {
- ldap_abandon( lsc->ld, msgid[ i ] );
+ ldap_abandon_ext( lsc->msc_ld, msgid[ i ], NULL, NULL );
rc = 0;
break;
}
* get a LDAP_TIMELIMIT_EXCEEDED from
* one of them ...
*/
- rc = ldap_result( lsc->ld, msgid[ i ],
+ rc = ldap_result( lsc->msc_ld, msgid[ i ],
0, &tv, &res );
if ( rc == 0 ) {
continue;
} else if ( rc == -1 ) {
+really_bad:;
/* something REALLY bad happened! */
( void )meta_clear_unused_candidates( li,
lc, -1, 0 );
goto finish;
} else if ( rc == LDAP_RES_SEARCH_ENTRY ) {
- e = ldap_first_entry( lsc->ld, res );
+ e = ldap_first_entry( lsc->msc_ld, res );
meta_send_entry( op, rs, lc, i, e );
ldap_msgfree( res );
char **references = NULL;
int cnt;
- rc = ldap_parse_reference( lsc->ld, res,
+ rc = ldap_parse_reference( lsc->msc_ld, res,
&references, &rs->sr_ctrls, 1 );
res = NULL;
}
} else {
- rs->sr_err = ldap_result2error( lsc->ld,
- res, 1 );
+ if ( ldap_parse_result( lsc->msc_ld, res,
+ &rs->sr_err,
+ NULL, NULL, NULL, NULL, 1 ) )
+ {
+ res = NULL;
+ goto really_bad;
+ }
res = NULL;
sres = slap_map_api2result( rs );
if ( err != NULL ) {
free( err );
}
- ldap_get_option( lsc->ld,
+ ldap_get_option( lsc->msc_ld,
LDAP_OPT_ERROR_STRING, &err );
if ( match.bv_val != NULL ) {
free( match.bv_val );
}
- ldap_get_option( lsc->ld,
+ ldap_get_option( lsc->msc_ld,
LDAP_OPT_MATCHED_DN, &match.bv_val );
Debug( LDAP_DEBUG_ANY,
if ( gotit == 0 ) {
tv.tv_sec = 0;
- tv.tv_usec = 100000;
+ tv.tv_usec = 100000; /* 0.1 s */
ldap_pvt_thread_yield();
+
} else {
tv.tv_sec = 0;
tv.tv_usec = 0;
if ( candidate_match == initial_candidates
&& match.bv_val != NULL && *match.bv_val ) {
dc.ctx = "matchedDN";
- dc.rwmap = &li->targets[ last ]->rwmap;
+ dc.rwmap = &li->targets[ last ]->mt_rwmap;
if ( ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
mmatch.bv_val = NULL;
/*
* Rewrite the dn of the result, if needed
*/
- dc.rwmap = &li->targets[ target ]->rwmap;
+ dc.rwmap = &li->targets[ target ]->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
dc.ctx = "searchResult";
while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) {
int last = 0;
- ldap_back_map( &li->targets[ target ]->rwmap.rwm_at,
+ ldap_back_map( &li->targets[ target ]->mt_rwmap.rwm_at,
&a, &mapped, BACKLDAP_REMAP );
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0' ) {
continue;
if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR
|| attr->a_vals == NULL ) {
- attr->a_vals = &slap_dummy_bv;
+ attr->a_vals = (struct berval *)&slap_dummy_bv;
} else if ( attr->a_desc == slap_schema.si_ad_objectClass
|| attr->a_desc == slap_schema.si_ad_structuralObjectClass ) {
for ( last = 0; attr->a_vals[ last ].bv_val; ++last );
for ( bv = attr->a_vals; bv->bv_val; bv++ ) {
- ldap_back_map( &li->targets[ target ]->rwmap.rwm_oc,
+ ldap_back_map( &li->targets[ target ]->mt_rwmap.rwm_oc,
bv, &mapped, BACKLDAP_REMAP );
if ( mapped.bv_val == NULL || mapped.bv_val[0] == '\0') {
free( bv->bv_val );
)
{
struct metainfo *li = ( struct metainfo * )be->be_private;
- struct metaconn *lc, lc_curr;
+ struct metaconn *lc,
+ lc_curr = { 0 };
Debug( LDAP_DEBUG_TRACE,
- "=>meta_back_conn_destroy: fetching conn %ld\n%s%s",
- conn->c_connid, "", "" );
+ "=>meta_back_conn_destroy: fetching conn %ld\n",
+ conn->c_connid, 0, 0 );
- lc_curr.conn = conn;
+ lc_curr.mc_conn = conn;
ldap_pvt_thread_mutex_lock( &li->conn_mutex );
lc = avl_delete( &li->conntree, ( caddr_t )&lc_curr,
int i;
Debug( LDAP_DEBUG_TRACE,
- "=>meta_back_conn_destroy: destroying conn %ld\n%s%s",
- lc->conn->c_connid, "", "" );
+ "=>meta_back_conn_destroy: destroying conn %ld\n",
+ lc->mc_conn->c_connid, 0, 0 );
/*
* Cleanup rewrite session
*/
for ( i = 0; i < li->ntargets; ++i ) {
- if ( lc->conns[ i ].ld == NULL ) {
+ if ( lc->mc_conns[ i ].msc_ld == NULL ) {
continue;
}
- rewrite_session_delete( li->targets[ i ]->rwmap.rwm_rw, conn );
- meta_clear_one_candidate( &lc->conns[ i ], 1 );
+ rewrite_session_delete( li->targets[ i ]->mt_rwmap.rwm_rw, conn );
+ meta_clear_one_candidate( &lc->mc_conns[ i ], 1 );
}
- free( lc->conns );
+ free( lc->mc_conns );
free( lc );
}