* get the current connection
*/
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
- &op->o_req_ndn, &candidate );
- if ( !lc ) {
- send_ldap_result( op, rs );
+ &op->o_req_ndn, &candidate, LDAP_BACK_SENDERR );
+ if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
return rs->sr_err;
}
- if ( !meta_back_dobind( lc, op )
- || !meta_back_is_valid( lc, candidate ) ) {
+ if ( !meta_back_is_valid( lc, candidate ) ) {
rs->sr_err = LDAP_UNAVAILABLE;
send_ldap_result( op, rs );
return rs->sr_err;
SlapReply *rs,
int op_type,
struct berval *dn,
- int *candidate
+ int *candidate,
+ ldap_back_send_t sendok
);
extern int
meta_back_dobind(
struct metaconn *lc,
- Operation *op
+ Operation *op,
+ ldap_back_send_t sendok
);
extern int
op_type = META_OP_REQUIRE_ALL;
}
lc = meta_back_getconn( op, rs, op_type,
- &op->o_req_ndn, NULL );
+ &op->o_req_ndn, NULL, LDAP_BACK_SENDERR );
if ( !lc ) {
Debug( LDAP_DEBUG_ANY,
"meta_back_bind: no target for dn %s.\n%s%s",
lsc->msc_bound = META_BOUND;
lc->mc_bound_target = candidate;
- if ( li->flags & LDAP_BACK_F_SAVECRED ) {
+ if ( LDAP_BACK_SAVECRED( li ) ) {
if ( !BER_BVISNULL( &lsc->msc_cred ) ) {
/* destroy sensitive data */
memset( lsc->msc_cred.bv_val, 0, lsc->msc_cred.bv_len );
* meta_back_dobind
*/
int
-meta_back_dobind( struct metaconn *lc, Operation *op )
+meta_back_dobind( struct metaconn *lc, Operation *op, ldap_back_send_t sendok )
{
struct metasingleconn *lsc;
int bound = 0, i;
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_ALLOW_MULTIPLE,
- &op->o_req_ndn, NULL );
- if ( !lc ) {
- send_ldap_result( op, rs );
- return -1;
+ &op->o_req_ndn, NULL, LDAP_BACK_SENDERR );
+ if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+ return rs->sr_err;
}
- if ( !meta_back_dobind( lc, op ) ) {
- rs->sr_err = LDAP_UNAVAILABLE;
- send_ldap_result( op, rs );
- return -1;
- }
-
msgid = ch_calloc( sizeof( int ), li->ntargets );
if ( msgid == NULL ) {
return -1;
li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
+ } else if ( strncasecmp( argv[0], "tls-", STRLENOF( "tls-" ) ) == 0 ) {
+
+ /* start tls */
+ if ( strcasecmp( argv[0], "tls-start" ) == 0 ) {
+ if ( argc != 1 ) {
+ fprintf( stderr,
+ "%s: line %d: tls-start takes no arguments\n",
+ fname, lineno );
+ return( 1 );
+ }
+ li->flags |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
+
+ /* try start tls */
+ } else if ( strcasecmp( argv[0], "tls-try-start" ) == 0 ) {
+ if ( argc != 1 ) {
+ fprintf( stderr,
+ "%s: line %d: tls-try-start takes no arguments\n",
+ fname, lineno );
+ return( 1 );
+ }
+ li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
+ li->flags |= LDAP_BACK_F_USE_TLS;
+
+ /* propagate start tls */
+ } else if ( strcasecmp( argv[0], "tls-propagate" ) == 0 ) {
+ if ( argc != 1 ) {
+ fprintf( stderr,
+ "%s: line %d: tls-propagate takes no arguments\n",
+ fname, lineno );
+ return( 1 );
+ }
+ li->flags |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
+
+ /* try start tls */
+ } else if ( strcasecmp( argv[0], "tls-try-propagate" ) == 0 ) {
+ if ( argc != 1 ) {
+ fprintf( stderr,
+ "%s: line %d: tls-try-propagate takes no arguments\n",
+ fname, lineno );
+ return( 1 );
+ }
+ li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
+ li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
+ }
+
/* name to use as pseudo-root dn */
} else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
int i = li->ntargets-1;
Operation *op,
SlapReply *rs,
struct metatarget *lt,
- struct metasingleconn *lsc
- )
+ struct metasingleconn *lsc,
+ ldap_back_send_t sendok )
{
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
int vers;
*/
rs->sr_err = ldap_initialize( &lsc->msc_ld, lt->mt_uri );
if ( rs->sr_err != LDAP_SUCCESS ) {
- return slap_map_api2result( rs );
+ goto error_return;
}
/*
ldap_set_option( lsc->msc_ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
/* automatically chase referrals ("chase-referrals"/"dont-chase-referrals" statement) */
- if ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) {
+ if ( LDAP_BACK_CHASE_REFERRALS( li ) ) {
ldap_set_option( lsc->msc_ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
}
+ /* start TLS ("start-tls"/"try-start-tls" statements) */
+ if ( ( LDAP_BACK_USE_TLS( li ) || ( op->o_conn->c_is_tls && LDAP_BACK_PROPAGATE_TLS( li ) ) )
+ && !ldap_is_ldaps_url( lt->mt_uri ) )
+ {
+ int rc, msgid;
+ LDAPMessage *res;
+ int retries = 1;
+
+retry:;
+ rc = ldap_start_tls( lsc->msc_ld, NULL, NULL, &msgid );
+ if ( rc == LDAP_SUCCESS ) {
+ struct timeval tv = { 0, 0 };
+
+ rc = ldap_result( lsc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res );
+ if ( rc < 0 ) {
+ rs->sr_err = LDAP_OTHER;
+
+ } else if ( rc == 0 ) {
+ if ( retries ) {
+ retries--;
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000;
+ goto retry;
+ }
+ rs->sr_err = LDAP_OTHER;
+
+ } else {
+ if ( rc == LDAP_RES_EXTENDED ) {
+ rc = ldap_parse_result( lsc->msc_ld, res,
+ &rs->sr_err, NULL, NULL, NULL, NULL, 1 );
+ if ( rc != LDAP_SUCCESS ) {
+ rs->sr_err = rc;
+
+ /* FIXME: in case a referral
+ * is returned, should we try
+ * using it instead of the
+ * configured URI? */
+ } else if ( rs->sr_err == LDAP_REFERRAL ) {
+ rs->sr_err = LDAP_OTHER;
+ rs->sr_text = "unwilling to chase referral returned by Start TLS exop";
+ }
+
+ } else {
+ ldap_msgfree( res );
+ rs->sr_err = LDAP_OTHER;
+ }
+ }
+ }
+
+ /* if StartTLS is requested, only attempt it if the URL
+ * is not "ldaps://"; this may occur not only in case
+ * 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( li ) ) )
+ {
+ ldap_unbind_ext_s( lsc->msc_ld, NULL, NULL );
+ goto error_return;
+ }
+ }
+
/*
* Set the network timeout if set
*/
/*
* If the connection DN is not null, an attempt to rewrite it is made
*/
- if ( op->o_conn->c_dn.bv_len != 0 ) {
+ if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
dc.rwmap = <->mt_rwmap;
dc.conn = op->o_conn;
dc.rs = rs;
if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn,
&lsc->msc_bound_ndn ) )
{
- send_ldap_result( op, rs );
- return rs->sr_err;
+ goto error_return;
}
/* copy the DN idf needed */
ber_dupbv( &lsc->msc_bound_ndn, &op->o_conn->c_dn );
}
- assert( lsc->msc_bound_ndn.bv_val );
+ assert( !BER_BVISNULL( &lsc->msc_bound_ndn ) );
} else {
ber_str2bv( "", 0, 1, &lsc->msc_bound_ndn );
lsc->msc_bound = META_UNBOUND;
- /*
- * The candidate is activated
- */
- lsc->msc_candidate = META_CANDIDATE;
- return LDAP_SUCCESS;
+error_return:;
+ if ( rs->sr_err != LDAP_SUCCESS ) {
+ rs->sr_err = slap_map_api2result( rs );
+ if ( sendok & LDAP_BACK_SENDERR ) {
+ send_ldap_result( op, rs );
+ rs->sr_text = NULL;
+ }
+
+ } else {
+
+ /*
+ * The candidate is activated
+ */
+ lsc->msc_candidate = META_CANDIDATE;
+ }
+
+ return rs->sr_err;
}
/*
*/
struct metaconn *
meta_back_getconn(
- Operation *op,
- SlapReply *rs,
- int op_type,
- struct berval *ndn,
- int *candidate )
+ Operation *op,
+ SlapReply *rs,
+ int op_type,
+ struct berval *ndn,
+ int *candidate,
+ ldap_back_send_t sendok )
{
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
struct metaconn *lc, lc_curr;
* also init'd
*/
int lerr = init_one_conn( op, rs, li->targets[ i ],
- &lc->mc_conns[ i ] );
+ &lc->mc_conns[ i ], sendok );
if ( lerr != LDAP_SUCCESS ) {
/*
* sends the appropriate result.
*/
err = init_one_conn( op, rs, li->targets[ i ],
- &lc->mc_conns[ i ] );
+ &lc->mc_conns[ i ], sendok );
if ( err != LDAP_SUCCESS ) {
/*
*/
int lerr = init_one_conn( op, rs,
li->targets[ i ],
- &lc->mc_conns[ i ] );
+ &lc->mc_conns[ i ], sendok );
if ( lerr != LDAP_SUCCESS ) {
/*
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
- &op->o_req_ndn, &candidate );
- if ( !lc ) {
- send_ldap_result( op, rs );
- return -1;
+ &op->o_req_ndn, &candidate, LDAP_BACK_SENDERR );
+ if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+ return rs->sr_err;
}
-
- if ( !meta_back_dobind( lc, op ) ) {
- rs->sr_err = LDAP_UNAVAILABLE;
- } else if ( !meta_back_is_valid( lc, candidate ) ) {
+ if ( !meta_back_is_valid( lc, candidate ) ) {
rs->sr_err = LDAP_OTHER;
- }
-
- if ( rs->sr_err != LDAP_SUCCESS ) {
send_ldap_result( op, rs );
- return -1;
+ return rs->sr_err;
}
/*
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
- &op->o_req_ndn, &candidate );
- if ( !lc ) {
- rc = -1;
- goto cleanup;
+ &op->o_req_ndn, &candidate, LDAP_BACK_SENDERR );
+ if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+ return rs->sr_err;
}
- if ( !meta_back_dobind( lc, op ) ) {
- rs->sr_err = LDAP_UNAVAILABLE;
-
- } else if ( !meta_back_is_valid( lc, candidate ) ) {
+ if ( !meta_back_is_valid( lc, candidate ) ) {
rs->sr_err = LDAP_OTHER;
- }
-
- if ( rs->sr_err != LDAP_SUCCESS ) {
- rc = -1;
- goto cleanup;
+ send_ldap_result( op, rs );
+ return rs->sr_err;
}
/*
dncookie dc;
lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
- &op->o_req_ndn, &candidate );
+ &op->o_req_ndn, &candidate, LDAP_BACK_SENDERR );
if ( !lc ) {
- rc = -1;
- goto cleanup;
+ return rs->sr_err;
}
assert( candidate != META_TARGET_NONE );
- if ( !meta_back_dobind( lc, op ) ) {
- rs->sr_err = LDAP_UNAVAILABLE;
-
- } else if ( !meta_back_is_valid( lc, candidate ) ) {
- rs->sr_err = LDAP_OTHER;
+ if ( !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+ return rs->sr_err;
}
-
- if ( rs->sr_err != LDAP_SUCCESS ) {
- rc = -1;
- goto cleanup;
+
+ if ( !meta_back_is_valid( lc, candidate ) ) {
+ rs->sr_err = LDAP_OTHER;
+ send_ldap_result( op, rs );
+ return rs->sr_err;
}
dc.conn = op->o_conn;
* to map attrs and maybe rewrite value
*/
lc = meta_back_getconn( op, rs, META_OP_ALLOW_MULTIPLE,
- &op->o_req_ndn, NULL );
- if ( !lc ) {
- send_ldap_result( op, rs );
- return -1;
- }
-
- if ( !meta_back_dobind( lc, op ) ) {
- rs->sr_err = LDAP_UNAVAILABLE;
- send_ldap_result( op, rs );
- return -1;
+ &op->o_req_ndn, NULL, LDAP_BACK_SENDERR );
+ if ( !lc || !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
+ return rs->sr_err;
}
/*