2003-11-27 14:35:14 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 1999-2005 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
|
|
|
* Portions Copyright 1999-2003 Howard Chu.
|
2003-11-27 14:35:14 +08:00
|
|
|
* All rights reserved.
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
2003-11-27 14:35:14 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by the Howard Chu for inclusion
|
|
|
|
* in OpenLDAP Software and subsequently enhanced by Pierangelo
|
|
|
|
* Masarati.
|
|
|
|
*/
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define AVL_INTERNAL
|
|
|
|
#include "slap.h"
|
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-meta.h"
|
|
|
|
|
2003-02-06 06:04:20 +08:00
|
|
|
static LDAP_REBIND_PROC meta_back_rebind;
|
|
|
|
|
2002-08-29 22:39:31 +08:00
|
|
|
static int
|
2005-04-21 11:17:31 +08:00
|
|
|
meta_back_single_bind(
|
2002-08-29 22:39:31 +08:00
|
|
|
Operation *op,
|
2003-04-06 00:53:57 +08:00
|
|
|
SlapReply *rs,
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metaconn *mc,
|
|
|
|
int candidate );
|
2002-08-29 22:39:31 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
int
|
2003-04-04 05:35:54 +08:00
|
|
|
meta_back_bind( Operation *op, SlapReply *rs )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2003-04-04 05:35:54 +08:00
|
|
|
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metaconn *mc;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
int rc = LDAP_OTHER,
|
2005-04-21 11:17:31 +08:00
|
|
|
i, gotit = 0, isroot = 0;
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
char *candidates = meta_back_candidates_get( op );
|
2003-04-06 00:53:57 +08:00
|
|
|
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2001-05-20 01:02:39 +08:00
|
|
|
|
2003-04-04 05:35:54 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, "meta_back_bind: dn: %s.\n%s%s",
|
|
|
|
op->o_req_dn.bv_val, "", "" );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-01-08 17:20:54 +08:00
|
|
|
if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
|
2001-05-20 01:02:39 +08:00
|
|
|
isroot = 1;
|
2005-01-08 17:20:54 +08:00
|
|
|
ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ) );
|
2001-05-20 01:02:39 +08:00
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
/* we need meta_back_getconn() not send result even on error,
|
|
|
|
* because we want to intercept the error and make it
|
|
|
|
* invalidCredentials */
|
2005-04-21 11:17:31 +08:00
|
|
|
mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_DONTSEND );
|
|
|
|
if ( !mc ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2005-04-16 10:25:41 +08:00
|
|
|
"meta_back_bind: no target "
|
|
|
|
"for dn \"%s\" (%d: %s).\n",
|
|
|
|
op->o_req_dn.bv_val, rs->sr_err,
|
|
|
|
rs->sr_text ? rs->sr_text : "" );
|
|
|
|
/* FIXME: there might be cases where we don't want
|
|
|
|
* to map the error onto invalidCredentials */
|
|
|
|
switch ( rs->sr_err ) {
|
|
|
|
case LDAP_NO_SUCH_OBJECT:
|
|
|
|
case LDAP_UNWILLING_TO_PERFORM:
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2003-04-04 05:35:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2005-04-16 10:25:41 +08:00
|
|
|
return rs->sr_err;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each target is scanned ...
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
mc->mc_auth_target = META_BOUND_NONE;
|
2005-04-16 10:25:41 +08:00
|
|
|
for ( i = 0; i < li->mi_ntargets; i++ ) {
|
2003-04-04 08:43:40 +08:00
|
|
|
int lerr;
|
2005-04-21 11:17:31 +08:00
|
|
|
Operation op2 = *op;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip non-candidates
|
|
|
|
*/
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( candidates[ i ] != META_CANDIDATE ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( gotit == 0 ) {
|
|
|
|
gotit = 1;
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
} else if ( isroot == 0 ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* A bind operation is expected to have
|
|
|
|
* ONE CANDIDATE ONLY!
|
|
|
|
*/
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2001-05-14 07:44:22 +08:00
|
|
|
"==>meta_back_bind: more than one"
|
2005-04-16 10:25:41 +08:00
|
|
|
" candidate is trying to bind...\n",
|
|
|
|
0, 0, 0 );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( isroot && !BER_BVISNULL( &li->mi_targets[ i ]->mt_pseudorootdn ) )
|
|
|
|
{
|
2005-04-21 11:17:31 +08:00
|
|
|
op2.o_req_dn = li->mi_targets[ i ]->mt_pseudorootdn;
|
|
|
|
op2.o_req_ndn = li->mi_targets[ i ]->mt_pseudorootdn;
|
|
|
|
op2.orb_cred = li->mi_targets[ i ]->mt_pseudorootpw;
|
|
|
|
op2.orb_method = LDAP_AUTH_SIMPLE;
|
2001-05-20 01:02:39 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
lerr = meta_back_single_bind( &op2, rs, mc, i );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( lerr != LDAP_SUCCESS ) {
|
2003-04-06 00:53:57 +08:00
|
|
|
rs->sr_err = lerr;
|
2005-04-16 10:25:41 +08:00
|
|
|
candidates[ i ] = META_NOT_CANDIDATE;
|
2005-01-08 18:59:32 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-20 01:02:39 +08:00
|
|
|
if ( isroot ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
mc->mc_auth_target = META_BOUND_ALL;
|
2001-05-20 01:02:39 +08:00
|
|
|
}
|
|
|
|
|
2001-05-17 07:06:15 +08:00
|
|
|
/*
|
|
|
|
* rc is LDAP_SUCCESS if at least one bind succeeded,
|
|
|
|
* err is the last error that occurred during a bind;
|
|
|
|
* if at least (and at most?) one bind succeedes, fine.
|
|
|
|
*/
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* deal with bind failure ...
|
|
|
|
*/
|
2002-01-07 18:15:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* no target was found within the naming context,
|
|
|
|
* so bind must fail with invalid credentials
|
|
|
|
*/
|
2003-04-06 00:53:57 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS && gotit == 0 ) {
|
|
|
|
rs->sr_err = LDAP_INVALID_CREDENTIALS;
|
2002-01-07 18:15:05 +08:00
|
|
|
}
|
|
|
|
|
2004-04-06 01:32:59 +08:00
|
|
|
rs->sr_err = slap_map_api2result( rs );
|
2003-04-04 05:35:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2005-04-16 10:25:41 +08:00
|
|
|
return rs->sr_err;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
return LDAP_SUCCESS;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-04-21 11:17:31 +08:00
|
|
|
* meta_back_single_bind
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
|
|
|
* attempts to perform a bind with creds
|
|
|
|
*/
|
2002-08-29 22:39:31 +08:00
|
|
|
static int
|
2005-04-21 11:17:31 +08:00
|
|
|
meta_back_single_bind(
|
2002-08-29 22:39:31 +08:00
|
|
|
Operation *op,
|
2003-04-06 00:53:57 +08:00
|
|
|
SlapReply *rs,
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metaconn *mc,
|
2001-05-12 08:51:28 +08:00
|
|
|
int candidate
|
|
|
|
)
|
|
|
|
{
|
2005-01-08 17:20:54 +08:00
|
|
|
struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
|
|
|
|
struct berval mdn = BER_BVNULL;
|
|
|
|
dncookie dc;
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metasingleconn *msc = &mc->mc_conns[ candidate ];
|
2005-01-08 17:20:54 +08:00
|
|
|
int msgid;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Rewrite the bind dn if needed
|
|
|
|
*/
|
2005-04-16 10:25:41 +08:00
|
|
|
dc.rwmap = &li->mi_targets[ candidate ]->mt_rwmap;
|
2003-04-08 01:04:14 +08:00
|
|
|
dc.conn = op->o_conn;
|
|
|
|
dc.rs = rs;
|
2004-03-11 05:11:14 +08:00
|
|
|
dc.ctx = "bindDN";
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2003-04-08 01:04:14 +08:00
|
|
|
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return -1;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2004-02-28 23:20:56 +08:00
|
|
|
/* 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 ... */
|
2005-01-26 17:45:23 +08:00
|
|
|
/* FIXME: should be check if at least some of the op->o_ctrls
|
|
|
|
* can/should be passed? */
|
2005-04-21 11:17:31 +08:00
|
|
|
rs->sr_err = ldap_sasl_bind( msc->msc_ld, mdn.bv_val,
|
2005-01-08 17:20:54 +08:00
|
|
|
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;
|
2005-04-21 11:17:31 +08:00
|
|
|
int nretries = META_BIND_NRETRIES;
|
2005-01-08 17:20:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* handle response!!!
|
|
|
|
*/
|
|
|
|
retry:;
|
2005-04-21 11:17:31 +08:00
|
|
|
switch ( ldap_result( msc->msc_ld, msgid, 0, &tv, &res ) ) {
|
2005-01-08 17:20:54 +08:00
|
|
|
case 0:
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( nretries > 0 ) {
|
2005-01-08 18:59:32 +08:00
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = META_BIND_TIMEOUT;
|
2005-04-21 11:17:31 +08:00
|
|
|
nretries--;
|
2005-01-08 18:59:32 +08:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
rs->sr_err = LDAP_BUSY;
|
|
|
|
break;
|
2005-01-08 17:20:54 +08:00
|
|
|
|
|
|
|
case -1:
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
|
2005-01-08 17:20:54 +08:00
|
|
|
&rs->sr_err );
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( rs->sr_err == LDAP_UNAVAILABLE && nretries > 0 ) {
|
|
|
|
nretries--;
|
|
|
|
if ( meta_back_retry( op, rs, mc, candidate, LDAP_BACK_SENDERR ) ) {
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
2005-01-08 17:20:54 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-04-21 11:17:31 +08:00
|
|
|
rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
|
2005-01-08 17:20:54 +08:00
|
|
|
NULL, NULL, NULL, NULL, 1 );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
rs->sr_err = rc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-06 00:53:57 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2004-04-06 01:32:59 +08:00
|
|
|
rs->sr_err = slap_map_api2result( rs );
|
2004-02-28 23:20:56 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2003-04-04 08:43:40 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
ber_bvreplace( &msc->msc_bound_ndn, &op->o_req_dn );
|
|
|
|
msc->msc_bound = META_BOUND;
|
|
|
|
mc->mc_auth_target = candidate;
|
2004-02-28 23:20:56 +08:00
|
|
|
|
2005-02-05 23:55:27 +08:00
|
|
|
if ( LDAP_BACK_SAVECRED( li ) ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
ber_bvreplace( &msc->msc_cred, &op->orb_cred );
|
|
|
|
ldap_set_rebind_proc( msc->msc_ld, meta_back_rebind, msc );
|
2004-02-28 23:20:56 +08:00
|
|
|
}
|
2003-02-06 06:04:20 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( li->mi_cache.ttl != META_DNCACHE_DISABLED
|
2005-04-21 11:17:31 +08:00
|
|
|
&& op->o_req_ndn.bv_len != 0 )
|
|
|
|
{
|
2005-04-16 10:25:41 +08:00
|
|
|
( void )meta_dncache_update_entry( &li->mi_cache,
|
2004-02-28 23:20:56 +08:00
|
|
|
&op->o_req_ndn, candidate );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2002-08-29 23:07:18 +08:00
|
|
|
|
|
|
|
return_results:;
|
2003-04-04 08:43:40 +08:00
|
|
|
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
|
2002-01-04 00:29:38 +08:00
|
|
|
free( mdn.bv_val );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2003-04-06 00:53:57 +08:00
|
|
|
return rs->sr_err;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
/*
|
|
|
|
* meta_back_single_dobind
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
meta_back_single_dobind(
|
|
|
|
Operation *op,
|
|
|
|
struct metasingleconn *msc,
|
|
|
|
ldap_back_send_t sendok,
|
|
|
|
int retries )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct berval cred = BER_BVC( "" );
|
|
|
|
int msgid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise an anonymous bind is performed
|
|
|
|
* (note: if the target was already bound, the anonymous
|
|
|
|
* bind clears the previous bind).
|
|
|
|
*/
|
|
|
|
if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
|
|
|
|
ber_memfree( msc->msc_bound_ndn.bv_val );
|
|
|
|
BER_BVZERO( &msc->msc_bound_ndn );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( /* FIXME: need li ... li->savecred && */
|
|
|
|
!BER_BVISNULL( &msc->msc_cred ) )
|
|
|
|
{
|
|
|
|
/* destroy sensitive data */
|
|
|
|
memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
|
|
|
|
ber_memfree( msc->msc_cred.bv_val );
|
|
|
|
BER_BVZERO( &msc->msc_cred );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: should we check if at least some of the op->o_ctrls
|
|
|
|
* can/should be passed? */
|
|
|
|
rc = ldap_sasl_bind( msc->msc_ld, "", LDAP_SASL_SIMPLE, &cred,
|
|
|
|
NULL, NULL, &msgid );
|
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
LDAPMessage *res;
|
|
|
|
struct timeval tv = { 0, 0 };
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle response!!!
|
|
|
|
*/
|
|
|
|
retry:;
|
|
|
|
switch ( ldap_result( msc->msc_ld, msgid, 0, &tv, &res ) ) {
|
|
|
|
case 0:
|
|
|
|
if ( retries > 0 ) {
|
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = META_BIND_TIMEOUT;
|
|
|
|
retries--;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = LDAP_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
ldap_get_option( msc->msc_ld,
|
|
|
|
LDAP_OPT_ERROR_NUMBER, &rc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rc = ldap_parse_result( msc->msc_ld, res, &err,
|
|
|
|
NULL, NULL, NULL, NULL, 1 );
|
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
rc = err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* meta_back_dobind
|
|
|
|
*/
|
|
|
|
int
|
2005-04-21 11:17:31 +08:00
|
|
|
meta_back_dobind( struct metaconn *mc, Operation *op, ldap_back_send_t sendok )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metasingleconn *msc;
|
2005-01-08 17:20:54 +08:00
|
|
|
int bound = 0, i;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
char *candidates = meta_back_candidates_get( op );
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &mc->mc_mutex );
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2001-05-20 01:02:39 +08:00
|
|
|
/*
|
|
|
|
* all the targets are bound as pseudoroot
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( mc->mc_auth_target == META_BOUND_ALL ) {
|
|
|
|
bound = 1;
|
|
|
|
goto done;
|
2001-05-20 01:02:39 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
|
2004-03-07 00:47:58 +08:00
|
|
|
int rc;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Not a candidate or something wrong with this target ...
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( msc->msc_ld == NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the target is already bound it is skipped
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( msc->msc_bound == META_BOUND && mc->mc_auth_target == i ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
++bound;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
rc = meta_back_single_dobind( op, msc, sendok, META_BIND_NRETRIES );
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "%s meta_back_dobind[%d]: "
|
|
|
|
"(anonymous) err=%d\n",
|
|
|
|
op->o_log_prefix, i, rc );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* null cred bind should always succeed
|
|
|
|
* as anonymous, so a failure means
|
|
|
|
* the target is no longer candidate possibly
|
|
|
|
* due to technical reasons (remote host down?)
|
|
|
|
* so better clear the handle
|
|
|
|
*/
|
2005-04-16 10:25:41 +08:00
|
|
|
candidates[ i ] = META_NOT_CANDIDATE;
|
|
|
|
#if 0
|
2005-04-21 11:17:31 +08:00
|
|
|
( void )meta_clear_one_candidate( msc );
|
2005-04-16 10:25:41 +08:00
|
|
|
#endif
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
} /* else */
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
candidates[ i ] = META_CANDIDATE;
|
|
|
|
msc->msc_bound = META_ANONYMOUS;
|
2001-05-12 08:51:28 +08:00
|
|
|
++bound;
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
done:;
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
return( bound > 0 );
|
|
|
|
}
|
|
|
|
|
2001-12-27 20:17:54 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
2005-04-21 11:17:31 +08:00
|
|
|
meta_back_is_valid( struct metaconn *mc, int candidate )
|
2001-12-27 20:17:54 +08:00
|
|
|
{
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metasingleconn *msc;
|
2001-12-27 20:17:54 +08:00
|
|
|
int i;
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
assert( mc );
|
2001-12-27 20:17:54 +08:00
|
|
|
|
|
|
|
if ( candidate < 0 ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ) && i < candidate;
|
|
|
|
++i, ++msc );
|
2001-12-27 20:17:54 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( !META_LAST( msc ) ) {
|
|
|
|
return ( msc->msc_ld != NULL );
|
2001-12-27 20:17:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-06 06:04:20 +08:00
|
|
|
/*
|
|
|
|
* meta_back_rebind
|
|
|
|
*
|
|
|
|
* This is a callback used for chasing referrals using the same
|
|
|
|
* credentials as the original user on this session.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
meta_back_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
|
|
|
|
ber_int_t msgid, void *params )
|
|
|
|
{
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metasingleconn *msc = (struct metasingleconn *)params;
|
2003-02-06 06:04:20 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
return ldap_sasl_bind_s( ld, msc->msc_bound_ndn.bv_val,
|
|
|
|
LDAP_SASL_SIMPLE, &msc->msc_cred,
|
2005-01-08 17:20:54 +08:00
|
|
|
NULL, NULL, NULL );
|
2003-02-06 06:04:20 +08:00
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* FIXME: error return must be handled in a cleaner way ...
|
|
|
|
*/
|
|
|
|
int
|
2005-04-16 10:25:41 +08:00
|
|
|
meta_back_op_result(
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metaconn *mc,
|
2005-04-16 10:25:41 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
int candidate )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-01-08 17:20:54 +08:00
|
|
|
int i,
|
|
|
|
rerr = LDAP_SUCCESS;
|
2005-04-21 11:17:31 +08:00
|
|
|
struct metasingleconn *msc;
|
2005-01-08 17:20:54 +08:00
|
|
|
char *rmsg = NULL;
|
|
|
|
char *rmatch = NULL;
|
|
|
|
int free_rmsg = 0,
|
|
|
|
free_rmatch = 0;
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( candidate != META_TARGET_NONE ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
msc = &mc->mc_conns[ candidate ];
|
2001-10-02 00:16:51 +08:00
|
|
|
|
2003-04-06 00:53:57 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
|
2003-04-06 00:53:57 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* better check the type of error. In some cases
|
|
|
|
* (search ?) it might be better to return a
|
|
|
|
* success if at least one of the targets gave
|
|
|
|
* positive result ...
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld,
|
2005-04-16 10:25:41 +08:00
|
|
|
LDAP_OPT_ERROR_STRING, &rmsg );
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld,
|
2005-04-16 10:25:41 +08:00
|
|
|
LDAP_OPT_MATCHED_DN, &rmatch );
|
|
|
|
rerr = rs->sr_err = slap_map_api2result( rs );
|
|
|
|
|
|
|
|
if ( rmsg ) {
|
|
|
|
free_rmsg = 1;
|
|
|
|
}
|
|
|
|
if ( rmatch ) {
|
|
|
|
free_rmatch = 1;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2001-10-02 06:11:37 +08:00
|
|
|
Debug(LDAP_DEBUG_ANY,
|
|
|
|
"==> meta_back_op_result: target"
|
|
|
|
" <%d> sending msg \"%s\""
|
|
|
|
" (matched \"%s\")\n",
|
2005-04-16 10:25:41 +08:00
|
|
|
candidate, ( rmsg ? rmsg : "" ),
|
|
|
|
( rmatch ? rmatch : "" ) );
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
} else {
|
2005-04-21 11:17:31 +08:00
|
|
|
for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
|
2005-04-16 10:25:41 +08:00
|
|
|
char *msg = NULL;
|
|
|
|
char *match = NULL;
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
/*
|
|
|
|
* better check the type of error. In some cases
|
|
|
|
* (search ?) it might be better to return a
|
|
|
|
* success if at least one of the targets gave
|
|
|
|
* positive result ...
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld,
|
2005-04-16 10:25:41 +08:00
|
|
|
LDAP_OPT_ERROR_STRING, &msg );
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_get_option( msc->msc_ld,
|
2005-04-16 10:25:41 +08:00
|
|
|
LDAP_OPT_MATCHED_DN, &match );
|
|
|
|
rs->sr_err = slap_map_api2result( rs );
|
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_ANY,
|
|
|
|
"==> meta_back_op_result: target"
|
|
|
|
" <%d> sending msg \"%s\""
|
|
|
|
" (matched \"%s\")\n",
|
|
|
|
i, ( msg ? msg : "" ),
|
|
|
|
( match ? match : "" ) );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: need to rewrite "match" (need rwinfo)
|
|
|
|
*/
|
|
|
|
switch ( rs->sr_err ) {
|
|
|
|
default:
|
|
|
|
rerr = rs->sr_err;
|
|
|
|
if ( rmsg ) {
|
|
|
|
ber_memfree( rmsg );
|
|
|
|
}
|
|
|
|
rmsg = msg;
|
|
|
|
free_rmsg = 1;
|
|
|
|
msg = NULL;
|
|
|
|
if ( rmatch ) {
|
|
|
|
ber_memfree( rmatch );
|
|
|
|
}
|
|
|
|
rmatch = match;
|
|
|
|
free_rmatch = 1;
|
|
|
|
match = NULL;
|
|
|
|
break;
|
2004-03-06 23:01:16 +08:00
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
/* better test the pointers before freeing? */
|
|
|
|
if ( match ) {
|
|
|
|
free( match );
|
|
|
|
}
|
|
|
|
if ( msg ) {
|
|
|
|
free( msg );
|
2004-03-06 23:01:16 +08:00
|
|
|
}
|
2001-10-02 06:11:37 +08:00
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_err = rerr;
|
|
|
|
rs->sr_text = rmsg;
|
|
|
|
rs->sr_matched = rmatch;
|
|
|
|
send_ldap_result( op, rs );
|
2004-03-06 23:01:16 +08:00
|
|
|
if ( free_rmsg ) {
|
|
|
|
ber_memfree( rmsg );
|
|
|
|
}
|
|
|
|
if ( free_rmatch ) {
|
|
|
|
ber_memfree( rmatch );
|
|
|
|
}
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_text = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2001-10-02 06:11:37 +08:00
|
|
|
|
|
|
|
return ( ( rerr == LDAP_SUCCESS ) ? 0 : -1 );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|