First-cut at manageDSAit-aware backend selection.

This commit is contained in:
Kurt Zeilenga 2000-10-21 03:29:02 +00:00
parent 38cf4a1d82
commit dbdba34972
13 changed files with 57 additions and 23 deletions

View file

@ -44,6 +44,7 @@ do_add( Connection *conn, Operation *op )
Modifications *mods = NULL; Modifications *mods = NULL;
const char *text; const char *text;
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
int manageDSAit;
Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
@ -149,12 +150,15 @@ do_add( Connection *conn, Operation *op )
goto done; goto done;
} }
manageDSAit = get_manageDSAit( op ) &&
is_entry_referral( e );
/* /*
* We could be serving multiple database backends. Select the * We could be serving multiple database backends. Select the
* appropriate one, or send a referral to our "referral server" * appropriate one, or send a referral to our "referral server"
* if we don't hold it. * if we don't hold it.
*/ */
be = select_backend( e->e_ndn ); be = select_backend( e->e_ndn, manageDSAit );
if ( be == NULL ) { if ( be == NULL ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );

View file

@ -433,9 +433,12 @@ be_db_close( void )
} }
Backend * Backend *
select_backend( const char * dn ) select_backend(
const char * dn,
int manageDSAit )
{ {
int i, j, len, dnlen; int i, j, len, dnlen;
Backend *be = NULL;
dnlen = strlen( dn ); dnlen = strlen( dn );
for ( i = 0; i < nbackends; i++ ) { for ( i = 0; i < nbackends; i++ ) {
@ -449,13 +452,23 @@ select_backend( const char * dn )
} }
if ( strcmp( backends[i].be_nsuffix[j], if ( strcmp( backends[i].be_nsuffix[j],
dn + (dnlen - len) ) == 0 ) { dn + (dnlen - len) ) == 0 )
return( &backends[i] ); {
if( be == NULL ) {
be = &backends[i];
if( manageDSAit && len == dnlen ) {
continue;
}
} else {
be = &backends[i];
}
return be;
} }
} }
} }
return( NULL ); return be;
} }
int int
@ -848,7 +861,7 @@ backend_group(
if( strcmp( target->e_ndn, gr_ndn ) != 0 ) { if( strcmp( target->e_ndn, gr_ndn ) != 0 ) {
/* we won't attempt to send it to a different backend */ /* we won't attempt to send it to a different backend */
be = select_backend(gr_ndn); be = select_backend(gr_ndn, 0);
if (be == NULL) { if (be == NULL) {
return LDAP_NO_SUCH_OBJECT; return LDAP_NO_SUCH_OBJECT;
@ -878,7 +891,7 @@ backend_attribute(
if( target == NULL || strcmp( target->e_ndn, e_ndn ) != 0 ) { if( target == NULL || strcmp( target->e_ndn, e_ndn ) != 0 ) {
/* we won't attempt to send it to a different backend */ /* we won't attempt to send it to a different backend */
be = select_backend(e_ndn); be = select_backend(e_ndn, 0);
if (be == NULL) { if (be == NULL) {
return LDAP_NO_SUCH_OBJECT; return LDAP_NO_SUCH_OBJECT;

View file

@ -336,7 +336,7 @@ do_bind(
* if we don't hold it. * if we don't hold it.
*/ */
if ( (be = select_backend( ndn )) == NULL ) { if ( (be = select_backend( ndn, 0 )) == NULL ) {
if ( default_referral ) { if ( default_referral ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );

View file

@ -37,6 +37,7 @@ do_compare(
Backend *be; Backend *be;
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
const char *text = NULL; const char *text = NULL;
int manageDSAit;
ava.aa_desc = NULL; ava.aa_desc = NULL;
desc.bv_val = NULL; desc.bv_val = NULL;
@ -100,12 +101,14 @@ do_compare(
goto cleanup; goto cleanup;
} }
manageDSAit = get_manageDSAit( op );
/* /*
* We could be serving multiple database backends. Select the * We could be serving multiple database backends. Select the
* appropriate one, or send a referral to our "referral server" * appropriate one, or send a referral to our "referral server"
* if we don't hold it. * if we don't hold it.
*/ */
if ( (be = select_backend( ndn )) == NULL ) { if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );
rc = 1; rc = 1;

View file

@ -412,7 +412,7 @@ read_config( const char *fname )
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"%s: line %d: suffix line must appear inside a database definition (ignored)\n", "%s: line %d: suffix line must appear inside a database definition (ignored)\n",
fname, lineno, 0 ); fname, lineno, 0 );
} else if ( ( tmp_be = select_backend( cargv[1] ) ) == be ) { } else if ( ( tmp_be = select_backend( cargv[1], 0 ) ) == be ) {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"%s: line %d: suffix already served by this backend (ignored)\n", "%s: line %d: suffix already served by this backend (ignored)\n",
fname, lineno, 0 ); fname, lineno, 0 );
@ -464,13 +464,13 @@ read_config( const char *fname )
"%s: line %d: suffixAlias line" "%s: line %d: suffixAlias line"
" must appear inside a database definition (ignored)\n", " must appear inside a database definition (ignored)\n",
fname, lineno, 0 ); fname, lineno, 0 );
} else if ( (tmp_be = select_backend( cargv[1] )) != NULL ) { } else if ( (tmp_be = select_backend( cargv[1], 0 )) != NULL ) {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"%s: line %d: suffixAlias served by" "%s: line %d: suffixAlias served by"
" a preceeding backend \"%s\" (ignored)\n", " a preceeding backend \"%s\" (ignored)\n",
fname, lineno, tmp_be->be_suffix[0] ); fname, lineno, tmp_be->be_suffix[0] );
} else if ( (tmp_be = select_backend( cargv[2] )) != NULL ) { } else if ( (tmp_be = select_backend( cargv[2], 0 )) != NULL ) {
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"%s: line %d: suffixAlias derefs to differnet backend" "%s: line %d: suffixAlias derefs to differnet backend"
" a preceeding backend \"%s\" (ignored)\n", " a preceeding backend \"%s\" (ignored)\n",

View file

@ -35,6 +35,7 @@ do_delete(
const char *text; const char *text;
Backend *be; Backend *be;
int rc; int rc;
int manageDSAit;
Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
@ -76,12 +77,14 @@ do_delete(
Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n", Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
op->o_connid, op->o_opid, dn, 0, 0 ); op->o_connid, op->o_opid, dn, 0, 0 );
manageDSAit = get_manageDSAit( op );
/* /*
* We could be serving multiple database backends. Select the * We could be serving multiple database backends. Select the
* appropriate one, or send a referral to our "referral server" * appropriate one, or send a referral to our "referral server"
* if we don't hold it. * if we don't hold it.
*/ */
if ( (be = select_backend( ndn )) == NULL ) { if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );
goto cleanup; goto cleanup;

View file

@ -45,6 +45,7 @@ do_modify(
Backend *be; Backend *be;
int rc; int rc;
const char *text; const char *text;
int manageDSAit;
Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
@ -165,12 +166,14 @@ do_modify(
Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MOD dn=\"%s\"\n", Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MOD dn=\"%s\"\n",
op->o_connid, op->o_opid, dn, 0, 0 ); op->o_connid, op->o_opid, dn, 0, 0 );
manageDSAit = get_manageDSAit( op );
/* /*
* We could be serving multiple database backends. Select the * We could be serving multiple database backends. Select the
* appropriate one, or send a referral to our "referral server" * appropriate one, or send a referral to our "referral server"
* if we don't hold it. * if we don't hold it.
*/ */
if ( (be = select_backend( ndn )) == NULL ) { if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );
goto cleanup; goto cleanup;

View file

@ -54,6 +54,7 @@ do_modrdn(
ber_len_t length; ber_len_t length;
int rc; int rc;
const char *text; const char *text;
int manageDSAit;
Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
@ -160,13 +161,14 @@ do_modrdn(
Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n", Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n",
op->o_connid, op->o_opid, dn, 0, 0 ); op->o_connid, op->o_opid, dn, 0, 0 );
manageDSAit = get_manageDSAit( op );
/* /*
* We could be serving multiple database backends. Select the * We could be serving multiple database backends. Select the
* appropriate one, or send a referral to our "referral server" * appropriate one, or send a referral to our "referral server"
* if we don't hold it. * if we don't hold it.
*/ */
if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
if ( (be = select_backend( ndn )) == NULL ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );
goto cleanup; goto cleanup;
@ -190,7 +192,7 @@ do_modrdn(
* the same backend, otherwise we return an error. * the same backend, otherwise we return an error.
*/ */
if( newSuperior != NULL ) { if( newSuperior != NULL ) {
newSuperior_be = select_backend( nnewSuperior ); newSuperior_be = select_backend( nnewSuperior, 0 );
if ( newSuperior_be != be ) { if ( newSuperior_be != be ) {
/* newSuperior is in same backend */ /* newSuperior is in same backend */

View file

@ -147,7 +147,9 @@ LDAP_SLAPD_F (int) backend_destroy LDAP_P((void));
LDAP_SLAPD_F (BackendInfo *) backend_info LDAP_P(( const char *type )); LDAP_SLAPD_F (BackendInfo *) backend_info LDAP_P(( const char *type ));
LDAP_SLAPD_F (BackendDB *) backend_db_init LDAP_P(( const char *type )); LDAP_SLAPD_F (BackendDB *) backend_db_init LDAP_P(( const char *type ));
LDAP_SLAPD_F (BackendDB *) select_backend LDAP_P(( const char * dn )); LDAP_SLAPD_F (BackendDB *) select_backend LDAP_P((
const char * dn,
int manageDSAit ));
LDAP_SLAPD_F (int) be_issuffix LDAP_P(( Backend *be, const char *suffix )); LDAP_SLAPD_F (int) be_issuffix LDAP_P(( Backend *be, const char *suffix ));
LDAP_SLAPD_F (int) be_isroot LDAP_P(( Backend *be, const char *ndn )); LDAP_SLAPD_F (int) be_isroot LDAP_P(( Backend *be, const char *ndn ));

View file

@ -295,7 +295,7 @@ char *slap_sasl2dn( char *saslname )
"slap_sasl2dn: performing internal search (base=%s, scope=%d)\n", "slap_sasl2dn: performing internal search (base=%s, scope=%d)\n",
searchbase, scope, 0 ); searchbase, scope, 0 );
be = select_backend( searchbase ); be = select_backend( searchbase, 0 );
if(( be == NULL ) || ( be->be_search == NULL)) if(( be == NULL ) || ( be->be_search == NULL))
goto FINISHED; goto FINISHED;
searchbase = suffix_alias( be, searchbase ); searchbase = suffix_alias( be, searchbase );
@ -383,7 +383,7 @@ int slap_sasl_match( char *rule, char *assertDN, char *authc )
"slap_sasl_match: performing internal search (base=%s, scope=%d)\n", "slap_sasl_match: performing internal search (base=%s, scope=%d)\n",
searchbase, scope, 0 ); searchbase, scope, 0 );
be = select_backend( searchbase ); be = select_backend( searchbase, 0 );
if(( be == NULL ) || ( be->be_search == NULL)) { if(( be == NULL ) || ( be->be_search == NULL)) {
rc = LDAP_INAPPROPRIATE_AUTH; rc = LDAP_INAPPROPRIATE_AUTH;
goto CONCLUDED; goto CONCLUDED;

View file

@ -39,6 +39,7 @@ do_search(
Backend *be; Backend *be;
int rc; int rc;
const char *text; const char *text;
int manageDSAit;
Debug( LDAP_DEBUG_TRACE, "do_search\n", 0, 0, 0 ); Debug( LDAP_DEBUG_TRACE, "do_search\n", 0, 0, 0 );
LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY, "conn: %d do_search\n", LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY, "conn: %d do_search\n",
@ -210,12 +211,14 @@ do_search(
nbase = ch_strdup( default_search_nbase ); nbase = ch_strdup( default_search_nbase );
} }
manageDSAit = get_manageDSAit( op );
/* /*
* We could be serving multiple database backends. Select the * We could be serving multiple database backends. Select the
* appropriate one, or send a referral to our "referral server" * appropriate one, or send a referral to our "referral server"
* if we don't hold it. * if we don't hold it.
*/ */
if ( (be = select_backend( nbase )) == NULL ) { if ( (be = select_backend( nbase, manageDSAit )) == NULL ) {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, send_ldap_result( conn, op, rc = LDAP_REFERRAL,
NULL, NULL, default_referral, NULL ); NULL, NULL, default_referral, NULL );

View file

@ -78,7 +78,8 @@ main( int argc, char **argv )
} }
/* check backend */ /* check backend */
if( select_backend( e->e_ndn ) != be ) { if( select_backend( e->e_ndn, is_entry_referral(e) ) != be )
{
fprintf( stderr, "%s: database (%s) not configured to " fprintf( stderr, "%s: database (%s) not configured to "
"hold dn=\"%s\" (line=%d)\n", "hold dn=\"%s\" (line=%d)\n",
progname, progname,

View file

@ -211,7 +211,7 @@ slap_tool_init(
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
be = select_backend( tbase ); be = select_backend( tbase, 0 );
free( tbase ); free( tbase );
if( be == NULL ) { if( be == NULL ) {