From: Pierangelo Masarati Date: Sun, 28 Jan 2007 00:53:11 +0000 (+0000) Subject: cleanup back-meta according to back-ldap X-Git-Tag: OPENLDAP_REL_ENG_2_4_4ALPHA~8^2~112 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ff9b674899ae213b69a1e6f02e205e84fa77676c;p=openldap cleanup back-meta according to back-ldap --- diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index da0db48616..04d7ba885c 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -298,7 +298,6 @@ typedef struct metatarget_t { sig_atomic_t mt_isquarantined; slap_retry_info_t mt_quarantine; ldap_pvt_thread_mutex_t mt_quarantine_mutex; -#define META_BACK_TGT_QUARANTINE(mt) ( (mt)->mt_quarantine.ri_num != NULL ) unsigned mt_flags; #define META_BACK_TGT_ISSET(mt,f) ( ( (mt)->mt_flags & (f) ) == (f) ) @@ -311,6 +310,7 @@ typedef struct metatarget_t { #define META_BACK_TGT_IGNORE(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_IGNORE ) #define META_BACK_TGT_CANCEL(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK, LDAP_BACK_F_CANCEL_EXOP ) #define META_BACK_TGT_CANCEL_DISCOVER(mt) META_BACK_TGT_ISMASK( (mt), LDAP_BACK_F_CANCEL_MASK2, LDAP_BACK_F_CANCEL_EXOP_DISCOVER ) +#define META_BACK_TGT_QUARANTINE(mt) META_BACK_TGT_ISSET( (mt), LDAP_BACK_F_QUARANTINE ) int mt_version; time_t mt_network_timeout; @@ -363,8 +363,6 @@ typedef struct metainfo_t { /* NOTE: quarantine uses the connection mutex */ slap_retry_info_t mi_quarantine; - -#define META_BACK_QUARANTINE(mi) ( (mi)->mi_quarantine.ri_num != NULL ) meta_back_quarantine_f mi_quarantine_f; void *mi_quarantine_p; @@ -388,6 +386,8 @@ typedef struct metainfo_t { #define META_BACK_PROXYAUTHZ_ANON(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_PROXYAUTHZ_ANON ) #define META_BACK_PROXYAUTHZ_NOANON(mi) LDAP_BACK_ISSET( (mi), META_BACK_F_PROXYAUTHZ_NOANON ) +#define META_BACK_QUARANTINE(mi) LDAP_BACK_ISSET( (mi), LDAP_BACK_F_QUARANTINE ) + int mi_version; time_t mi_network_timeout; time_t mi_conn_ttl; diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index f458047cc3..f0297d4a1b 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -1290,15 +1290,14 @@ meta_back_proxy_authz_cred( send_ldap_result( op, rs ); } LDAP_BACK_CONN_ISBOUND_CLEAR( msc ); + goto done; - } else { - rs->sr_err = LDAP_SUCCESS; - *binddn = slap_empty_bv; - *bindcred = slap_empty_bv; - break; } - goto done; + rs->sr_err = LDAP_SUCCESS; + *binddn = slap_empty_bv; + *bindcred = slap_empty_bv; + break; } else if ( mt->mt_idassert_authz && !be_isroot( op ) ) { struct berval authcDN; @@ -1317,15 +1316,13 @@ meta_back_proxy_authz_cred( send_ldap_result( op, rs ); } LDAP_BACK_CONN_ISBOUND_CLEAR( msc ); - - } else { - rs->sr_err = LDAP_SUCCESS; - *binddn = slap_empty_bv; - *bindcred = slap_empty_bv; - break; + goto done; } - goto done; + rs->sr_err = LDAP_SUCCESS; + *binddn = slap_empty_bv; + *bindcred = slap_empty_bv; + break; } } diff --git a/servers/slapd/back-meta/config.c b/servers/slapd/back-meta/config.c index bb60979931..d90e40ec25 100644 --- a/servers/slapd/back-meta/config.c +++ b/servers/slapd/back-meta/config.c @@ -1228,6 +1228,13 @@ idassert-authzFrom "dn:" fname, lineno, buf ); return 1; } + + if ( mi->mi_ntargets ) { + mi->mi_flags |= LDAP_BACK_F_QUARANTINE; + + } else { + mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags |= LDAP_BACK_F_QUARANTINE; + } /* dn massaging */ } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) { diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 49d94faccb..e5d84842f8 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -279,28 +279,33 @@ meta_back_init_one_conn( slap_retry_info_t *ri = &mt->mt_quarantine; int dont_retry = 1; - if ( mt->mt_isquarantined == LDAP_BACK_FQ_YES ) { - dont_retry = ( ri->ri_num[ ri->ri_idx ] == SLAP_RETRYNUM_TAIL - || slap_get_time() < ri->ri_last + ri->ri_interval[ ri->ri_idx ] ); - if ( !dont_retry ) { - if ( LogTest( LDAP_DEBUG_ANY ) ) { - char buf[ SLAP_TEXT_BUFLEN ]; - - snprintf( buf, sizeof( buf ), - "meta_back_init_one_conn[%d]: quarantine " - "retry block #%d try #%d", - candidate, ri->ri_idx, ri->ri_count ); - Debug( LDAP_DEBUG_ANY, "%s %s.\n", - op->o_log_prefix, buf, 0 ); + if ( mt->mt_quarantine.ri_interval ) { + ldap_pvt_thread_mutex_lock( &mt->mt_quarantine_mutex ); + if ( mt->mt_isquarantined == LDAP_BACK_FQ_YES ) { + dont_retry = ( ri->ri_num[ ri->ri_idx ] == SLAP_RETRYNUM_TAIL + || slap_get_time() < ri->ri_last + ri->ri_interval[ ri->ri_idx ] ); + if ( !dont_retry ) { + if ( LogTest( LDAP_DEBUG_ANY ) ) { + char buf[ SLAP_TEXT_BUFLEN ]; + + snprintf( buf, sizeof( buf ), + "meta_back_init_one_conn[%d]: quarantine " + "retry block #%d try #%d", + candidate, ri->ri_idx, ri->ri_count ); + Debug( LDAP_DEBUG_ANY, "%s %s.\n", + op->o_log_prefix, buf, 0 ); + } } mt->mt_isquarantined = LDAP_BACK_FQ_RETRYING; } + ldap_pvt_thread_mutex_unlock( &mt->mt_quarantine_mutex ); } if ( dont_retry ) { rs->sr_err = LDAP_UNAVAILABLE; if ( op->o_conn && ( sendok & LDAP_BACK_SENDERR ) ) { + rs->sr_text = "Target is quarantined"; send_ldap_result( op, rs ); } return rs->sr_err; @@ -336,6 +341,7 @@ retry_lock:; /* sounds more appropriate */ rs->sr_err = LDAP_BUSY; + rs->sr_text = "No connections to target are available"; do_return = 1; } else if ( META_BACK_CONN_INITED( msc ) ) { @@ -355,7 +361,10 @@ retry_lock:; } if ( do_return ) { - if ( rs->sr_err != LDAP_SUCCESS && op->o_conn && ( sendok & LDAP_BACK_SENDERR ) ) { + if ( rs->sr_err != LDAP_SUCCESS + && op->o_conn + && ( sendok & LDAP_BACK_SENDERR ) ) + { send_ldap_result( op, rs ); } @@ -399,8 +408,10 @@ retry_lock:; #ifdef HAVE_TLS /* start TLS ("tls [try-]{start|propagate}" statement) */ - if ( ( LDAP_BACK_USE_TLS( mi ) || ( op->o_conn->c_is_tls && LDAP_BACK_PROPAGATE_TLS( mi ) ) ) - && !is_ldaps ) + if ( ( LDAP_BACK_USE_TLS( mi ) + || ( op->o_conn->c_is_tls + && LDAP_BACK_PROPAGATE_TLS( mi ) ) ) + && !is_ldaps ) { #ifdef SLAP_STARTTLS_ASYNCHRONOUS /* @@ -447,14 +458,14 @@ retry:; struct berval *data = NULL; /* NOTE: right now, data is unused, so don't get it */ - rs->sr_err = ldap_parse_extended_result( msc->msc_ld, res, - NULL, NULL /* &data */ , 0 ); + rs->sr_err = ldap_parse_extended_result( msc->msc_ld, + res, NULL, NULL /* &data */ , 0 ); if ( rs->sr_err == LDAP_SUCCESS ) { int err; /* FIXME: matched? referrals? response controls? */ - rs->sr_err = ldap_parse_result( msc->msc_ld, res, - &err, NULL, NULL, NULL, NULL, 1 ); + rs->sr_err = ldap_parse_result( msc->msc_ld, + res, &err, NULL, NULL, NULL, NULL, 1 ); res = NULL; if ( rs->sr_err == LDAP_SUCCESS ) { @@ -471,14 +482,12 @@ retry:; } else if ( rs->sr_err == LDAP_REFERRAL ) { /* FIXME: LDAP_OPERATIONS_ERROR? */ rs->sr_err = LDAP_OTHER; - rs->sr_text = "unwilling to chase referral returned by Start TLS exop"; + rs->sr_text = "Unwilling to chase referral " + "returned by Start TLS exop"; } if ( data ) { - if ( data->bv_val ) { - ber_memfree( data->bv_val ); - } - ber_memfree( data ); + ber_bvfree( data ); } } @@ -502,12 +511,16 @@ retry:; * of misconfiguration, but also when used in the chain * overlay, where the "uri" can be parsed out of a referral */ if ( rs->sr_err == LDAP_SERVER_DOWN - || ( rs->sr_err != LDAP_SUCCESS && LDAP_BACK_TLS_CRITICAL( mi ) ) ) + || ( rs->sr_err != LDAP_SUCCESS + && LDAP_BACK_TLS_CRITICAL( mi ) ) ) { #ifdef DEBUG_205 - Debug( LDAP_DEBUG_ANY, "### %s meta_back_init_one_conn(TLS) ldap_unbind_ext[%d] ld=%p\n", - op->o_log_prefix, candidate, (void *)msc->msc_ld ); + Debug( LDAP_DEBUG_ANY, + "### %s meta_back_init_one_conn(TLS) " + "ldap_unbind_ext[%d] ld=%p\n", + op->o_log_prefix, candidate, + (void *)msc->msc_ld ); #endif /* DEBUG_205 */ /* need to trash a failed Start TLS */ @@ -576,8 +589,11 @@ retry:; { #ifdef DEBUG_205 - Debug( LDAP_DEBUG_ANY, "### %s meta_back_init_one_conn(rewrite) ldap_unbind_ext[%d] ld=%p\n", - op->o_log_prefix, candidate, (void *)msc->msc_ld ); + Debug( LDAP_DEBUG_ANY, + "### %s meta_back_init_one_conn(rewrite) " + "ldap_unbind_ext[%d] ld=%p\n", + op->o_log_prefix, candidate, + (void *)msc->msc_ld ); #endif /* DEBUG_205 */ /* need to trash a connection not fully established */ @@ -619,7 +635,6 @@ error_return:; rs->sr_err = slap_map_api2result( rs ); if ( sendok & LDAP_BACK_SENDERR ) { send_ldap_result( op, rs ); - rs->sr_text = NULL; } } @@ -772,7 +787,7 @@ meta_back_retry( if ( sendok & LDAP_BACK_SENDERR ) { rs->sr_err = rc; - rs->sr_text = NULL; + rs->sr_text = "Unable to retry"; send_ldap_result( op, rs ); } } @@ -831,7 +846,7 @@ meta_back_get_candidate( */ if ( candidate == META_TARGET_NONE ) { rs->sr_err = LDAP_NO_SUCH_OBJECT; - rs->sr_text = "no suitable candidate target found"; + rs->sr_text = "No suitable candidate target found"; } else if ( candidate == META_TARGET_MULTIPLE ) { Filter f = { 0 }; @@ -884,7 +899,7 @@ meta_back_get_candidate( } else { rs->sr_err = LDAP_UNWILLING_TO_PERFORM; - rs->sr_text = "cannot select unique candidate target"; + rs->sr_text = "Unable to select unique candidate target"; } break; } @@ -1260,7 +1275,6 @@ retry_lock:; rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val; } send_ldap_result( op, rs ); - rs->sr_text = NULL; rs->sr_matched = NULL; } @@ -1308,7 +1322,6 @@ retry_lock:; rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val; } send_ldap_result( op, rs ); - rs->sr_text = NULL; rs->sr_matched = NULL; } @@ -1323,10 +1336,9 @@ retry_lock:; } rs->sr_err = LDAP_UNWILLING_TO_PERFORM; - rs->sr_text = "cross-target rename not supported"; + rs->sr_text = "Cross-target rename not supported"; if ( sendok & LDAP_BACK_SENDERR ) { send_ldap_result( op, rs ); - rs->sr_text = NULL; } return NULL; @@ -1504,7 +1516,6 @@ retry_lock2:; if ( META_BACK_ONERR_STOP( mi ) ) { if ( sendok & LDAP_BACK_SENDERR ) { send_ldap_result( op, rs ); - rs->sr_text = NULL; } if ( new_conn ) { mc->mc_refcnt = 0; @@ -1517,7 +1528,6 @@ retry_lock2:; return NULL; } - rs->sr_text = NULL; continue; } @@ -1547,7 +1557,6 @@ retry_lock2:; rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val; } send_ldap_result( op, rs ); - rs->sr_text = NULL; rs->sr_matched = NULL; } @@ -1633,10 +1642,9 @@ done:; meta_back_conn_free( mc ); rs->sr_err = LDAP_OTHER; - rs->sr_text = "proxy bind collision"; + rs->sr_text = "Proxy bind collision"; if ( sendok & LDAP_BACK_SENDERR ) { send_ldap_result( op, rs ); - rs->sr_text = NULL; } return NULL; } @@ -1699,6 +1707,7 @@ meta_back_release_conn_lock( tmpmc = avl_delete( &mi->mi_conninfo.lai_tree, ( caddr_t )mc, meta_back_conndnmc_cmp ); + /* Overparanoid, but useful... */ assert( tmpmc == NULL || tmpmc == mc ); }