mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-06 10:46:21 +08:00
major namespace cleanup & minor fixes
This commit is contained in:
parent
4d8267595f
commit
5422345e55
@ -65,7 +65,7 @@ meta_back_add( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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";
|
||||
@ -76,19 +76,19 @@ meta_back_add( Operation *op, SlapReply *rs )
|
||||
}
|
||||
|
||||
/* 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;
|
||||
@ -121,15 +121,18 @@ meta_back_add( Operation *op, SlapReply *rs )
|
||||
}
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ meta_back_attribute(
|
||||
} /* else */
|
||||
|
||||
candidate = meta_back_select_unique_candidate( li, ndn );
|
||||
if ( candidate == -1 ) {
|
||||
if ( candidate == META_TARGET_NONE ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -151,54 +151,48 @@ extern int ldap_dnattr_result_rewrite( dncookie *dc, BerVarray a_vals );
|
||||
/* (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;
|
||||
char *mt_uri;
|
||||
struct berval mt_psuffix; /* pretty suffix */
|
||||
struct berval mt_nsuffix; /* normalized suffix */
|
||||
struct berval mt_binddn;
|
||||
struct berval mt_bindpw;
|
||||
|
||||
struct berval pseudorootdn;
|
||||
struct berval pseudorootpw;
|
||||
struct berval mt_pseudorootdn;
|
||||
struct berval mt_pseudorootpw;
|
||||
|
||||
#if 0
|
||||
struct rewrite_info *rwinfo;
|
||||
|
||||
struct ldapmap oc_map;
|
||||
struct ldapmap at_map;
|
||||
#endif
|
||||
struct ldaprwmap rwmap;
|
||||
struct ldaprwmap mt_rwmap;
|
||||
};
|
||||
|
||||
struct metadncache {
|
||||
@ -333,6 +327,7 @@ meta_dncache_dup(
|
||||
void *c2
|
||||
);
|
||||
|
||||
#define META_TARGET_NONE (-1)
|
||||
extern int
|
||||
meta_dncache_get_target(
|
||||
struct metadncache *cache,
|
||||
|
@ -57,9 +57,9 @@ meta_back_bind( Operation *op, SlapReply *rs )
|
||||
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,
|
||||
@ -76,20 +76,20 @@ meta_back_bind( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -107,29 +107,29 @@ meta_back_bind( Operation *op, SlapReply *rs )
|
||||
"", "", "" );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -172,17 +172,16 @@ meta_back_do_single_bind(
|
||||
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";
|
||||
@ -193,7 +192,7 @@ meta_back_do_single_bind(
|
||||
}
|
||||
|
||||
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 );
|
||||
@ -204,31 +203,60 @@ meta_back_do_single_bind(
|
||||
/* 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
|
||||
@ -252,24 +280,25 @@ return_results:;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -277,7 +306,7 @@ meta_back_dobind( struct metaconn *lc, Operation *op )
|
||||
* 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;
|
||||
@ -287,7 +316,7 @@ meta_back_dobind( struct metaconn *lc, Operation *op )
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@ -297,24 +326,54 @@ meta_back_dobind( struct metaconn *lc, Operation *op )
|
||||
* (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"
|
||||
@ -332,7 +391,7 @@ meta_back_dobind( struct metaconn *lc, Operation *op )
|
||||
continue;
|
||||
} /* else */
|
||||
|
||||
lsc->bound = META_ANONYMOUS;
|
||||
lsc->msc_bound = META_ANONYMOUS;
|
||||
++bound;
|
||||
}
|
||||
|
||||
@ -354,11 +413,11 @@ meta_back_is_valid( struct metaconn *lc, int candidate )
|
||||
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;
|
||||
@ -374,10 +433,11 @@ static int
|
||||
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 );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -386,19 +446,21 @@ meta_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
|
||||
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;
|
||||
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;
|
||||
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
|
||||
@ -406,9 +468,9 @@ meta_back_op_result( struct metaconn *lc, Operation *op, SlapReply *rs )
|
||||
* 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 );
|
||||
|
||||
|
@ -95,7 +95,8 @@ meta_back_count_candidates(
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -131,7 +132,7 @@ meta_back_select_unique_candidate(
|
||||
struct berval *ndn
|
||||
)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
switch ( meta_back_count_candidates( li, ndn ) ) {
|
||||
case 1:
|
||||
@ -139,16 +140,17 @@ meta_back_select_unique_candidate(
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -170,7 +172,7 @@ meta_clear_unused_candidates(
|
||||
if ( i == candidate ) {
|
||||
continue;
|
||||
}
|
||||
meta_clear_one_candidate( &lc->conns[ i ], reallyclean );
|
||||
meta_clear_one_candidate( &lc->mc_conns[ i ], reallyclean );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -187,27 +189,25 @@ meta_clear_one_candidate(
|
||||
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;
|
||||
|
@ -34,15 +34,21 @@
|
||||
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 );
|
||||
@ -69,12 +75,12 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
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;
|
||||
}
|
||||
@ -82,7 +88,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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:
|
||||
@ -96,9 +102,9 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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' ) {
|
||||
@ -108,18 +114,18 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
* 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;
|
||||
@ -136,23 +142,27 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -167,7 +177,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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;
|
||||
|
||||
@ -175,7 +185,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
continue;
|
||||
}
|
||||
|
||||
lrc = ldap_result( lsc->ld, msgid[ i ],
|
||||
lrc = ldap_result( lsc->msc_ld, msgid[ i ],
|
||||
0, NULL, &res );
|
||||
|
||||
if ( lrc == 0 ) {
|
||||
@ -193,8 +203,16 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
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:
|
||||
@ -217,13 +235,13 @@ meta_back_compare( Operation *op, SlapReply *rs )
|
||||
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;
|
||||
|
@ -45,8 +45,8 @@ new_target( void )
|
||||
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;
|
||||
}
|
||||
@ -62,17 +62,17 @@ new_target( void )
|
||||
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;
|
||||
}
|
||||
@ -161,8 +161,8 @@ meta_back_db_config(
|
||||
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",
|
||||
@ -183,9 +183,9 @@ meta_back_db_config(
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
@ -206,7 +206,7 @@ meta_back_db_config(
|
||||
/*
|
||||
* 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",
|
||||
@ -322,7 +322,7 @@ meta_back_db_config(
|
||||
|
||||
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: "
|
||||
@ -348,7 +348,7 @@ meta_back_db_config(
|
||||
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 ) {
|
||||
@ -382,7 +382,7 @@ meta_back_db_config(
|
||||
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",
|
||||
@ -407,7 +407,7 @@ meta_back_db_config(
|
||||
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 ) {
|
||||
@ -492,7 +492,7 @@ meta_back_db_config(
|
||||
* 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 ... */
|
||||
@ -503,12 +503,12 @@ meta_back_db_config(
|
||||
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 ) {
|
||||
@ -521,8 +521,8 @@ meta_back_db_config(
|
||||
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 {
|
||||
|
@ -53,7 +53,7 @@ meta_back_conn_cmp(
|
||||
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 );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -71,7 +71,7 @@ meta_back_conn_dup(
|
||||
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 );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -87,15 +87,15 @@ ravl_print( Avlnode *root, int depth )
|
||||
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
|
||||
@ -136,23 +136,21 @@ metaconn_alloc( int ntargets )
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@ -171,8 +169,8 @@ metaconn_free(
|
||||
return;
|
||||
}
|
||||
|
||||
if ( lc->conns ) {
|
||||
ch_free( lc->conns );
|
||||
if ( lc->mc_conns ) {
|
||||
ch_free( lc->mc_conns );
|
||||
}
|
||||
|
||||
free( lc );
|
||||
@ -198,14 +196,14 @@ init_one_conn(
|
||||
/*
|
||||
* 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 );
|
||||
}
|
||||
@ -215,32 +213,33 @@ init_one_conn(
|
||||
* 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";
|
||||
@ -249,28 +248,29 @@ init_one_conn(
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -295,12 +295,14 @@ meta_back_getconn(
|
||||
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 );
|
||||
@ -309,10 +311,37 @@ meta_back_getconn(
|
||||
/* 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
|
||||
*/
|
||||
@ -326,14 +355,14 @@ meta_back_getconn(
|
||||
* 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 );
|
||||
}
|
||||
@ -343,8 +372,8 @@ meta_back_getconn(
|
||||
}
|
||||
|
||||
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
|
||||
@ -357,7 +386,7 @@ meta_back_getconn(
|
||||
* sends the appropriate result.
|
||||
*/
|
||||
err = init_one_conn( op, rs, li->targets[ i ],
|
||||
&lc->conns[ i ] );
|
||||
&lc->mc_conns[ i ] );
|
||||
if ( err != LDAP_SUCCESS ) {
|
||||
|
||||
/*
|
||||
@ -365,7 +394,7 @@ meta_back_getconn(
|
||||
* 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 );
|
||||
}
|
||||
@ -376,38 +405,14 @@ meta_back_getconn(
|
||||
*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
|
||||
@ -415,7 +420,7 @@ meta_back_getconn(
|
||||
*/
|
||||
int lerr = init_one_conn( op, rs,
|
||||
li->targets[ i ],
|
||||
&lc->conns[ i ] );
|
||||
&lc->mc_conns[ i ] );
|
||||
if ( lerr != LDAP_SUCCESS ) {
|
||||
|
||||
/*
|
||||
@ -423,7 +428,7 @@ meta_back_getconn(
|
||||
* 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;
|
||||
}
|
||||
@ -431,6 +436,7 @@ meta_back_getconn(
|
||||
}
|
||||
}
|
||||
|
||||
done:;
|
||||
/* clear out init_one_conn non-fatal errors */
|
||||
rs->sr_err = LDAP_SUCCESS;
|
||||
rs->sr_text = NULL;
|
||||
@ -451,8 +457,8 @@ meta_back_getconn(
|
||||
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
|
||||
@ -463,10 +469,11 @@ meta_back_getconn(
|
||||
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;
|
||||
|
@ -57,7 +57,7 @@ meta_back_delete( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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";
|
||||
@ -67,10 +67,12 @@ meta_back_delete( Operation *op, SlapReply *rs )
|
||||
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 );
|
||||
|
@ -96,7 +96,7 @@ meta_dncache_get_target(
|
||||
{
|
||||
struct metadncacheentry tmp_entry, *entry;
|
||||
time_t curr_time;
|
||||
int target = -1;
|
||||
int target = META_TARGET_NONE;
|
||||
|
||||
assert( cache );
|
||||
assert( ndn );
|
||||
@ -115,6 +115,7 @@ meta_dncache_get_target(
|
||||
*/
|
||||
if ( cache->ttl < 0 ) {
|
||||
target = entry->target;
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
|
@ -112,7 +112,7 @@ meta_back_group(
|
||||
} /* else: do the search */
|
||||
|
||||
candidate = meta_back_select_unique_candidate( li, gr_ndn );
|
||||
if ( candidate == -1 ) {
|
||||
if ( candidate == META_TARGET_NONE ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -110,22 +110,23 @@ conn_free(
|
||||
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 );
|
||||
}
|
||||
|
||||
@ -143,34 +144,34 @@ target_free(
|
||||
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
|
||||
|
@ -53,7 +53,8 @@ meta_back_modify( Operation *op, SlapReply *rs )
|
||||
}
|
||||
|
||||
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;
|
||||
@ -62,7 +63,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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";
|
||||
@ -72,7 +73,7 @@ meta_back_modify( Operation *op, SlapReply *rs )
|
||||
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 );
|
||||
@ -89,17 +90,17 @@ meta_back_modify( Operation *op, SlapReply *rs )
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -113,16 +114,20 @@ meta_back_modify( Operation *op, SlapReply *rs )
|
||||
* 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 {
|
||||
@ -133,14 +138,16 @@ meta_back_modify( Operation *op, SlapReply *rs )
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,11 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
|
||||
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;
|
||||
@ -59,11 +62,11 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
|
||||
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 ) {
|
||||
/*
|
||||
@ -79,19 +82,20 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
|
||||
* 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;
|
||||
}
|
||||
@ -100,26 +104,30 @@ meta_back_modrdn( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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 ) {
|
||||
@ -128,7 +136,7 @@ cleanup:;
|
||||
} /* else */
|
||||
|
||||
send_ldap_result( op, rs );
|
||||
return rc;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ meta_back_search( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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;
|
||||
@ -107,31 +107,31 @@ meta_back_search( Operation *op, SlapReply *rs )
|
||||
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:
|
||||
@ -141,9 +141,9 @@ meta_back_search( Operation *op, SlapReply *rs )
|
||||
* 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 {
|
||||
@ -157,17 +157,17 @@ meta_back_search( Operation *op, SlapReply *rs )
|
||||
|
||||
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;
|
||||
@ -242,7 +242,7 @@ meta_back_search( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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 ) {
|
||||
@ -256,26 +256,28 @@ meta_back_search( Operation *op, SlapReply *rs )
|
||||
/*
|
||||
* 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:;
|
||||
@ -301,13 +303,13 @@ 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;
|
||||
}
|
||||
@ -327,7 +329,7 @@ new_candidate:;
|
||||
* 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 ) {
|
||||
@ -339,6 +341,7 @@ new_candidate:;
|
||||
continue;
|
||||
|
||||
} else if ( rc == -1 ) {
|
||||
really_bad:;
|
||||
/* something REALLY bad happened! */
|
||||
( void )meta_clear_unused_candidates( li,
|
||||
lc, -1, 0 );
|
||||
@ -354,7 +357,7 @@ new_candidate:;
|
||||
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 );
|
||||
@ -380,7 +383,7 @@ new_candidate:;
|
||||
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;
|
||||
|
||||
@ -429,20 +432,25 @@ new_candidate:;
|
||||
}
|
||||
|
||||
} 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,
|
||||
@ -468,8 +476,9 @@ new_candidate:;
|
||||
|
||||
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;
|
||||
@ -492,7 +501,7 @@ new_candidate:;
|
||||
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;
|
||||
@ -565,7 +574,7 @@ meta_send_entry(
|
||||
/*
|
||||
* 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";
|
||||
@ -602,7 +611,7 @@ meta_send_entry(
|
||||
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;
|
||||
@ -644,7 +653,7 @@ meta_send_entry(
|
||||
|
||||
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 ) {
|
||||
@ -652,7 +661,7 @@ meta_send_entry(
|
||||
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 );
|
||||
|
@ -38,13 +38,14 @@ meta_back_conn_destroy(
|
||||
)
|
||||
{
|
||||
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,
|
||||
@ -55,22 +56,22 @@ meta_back_conn_destroy(
|
||||
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 );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user