From dbdba34972665507f2ea4088764002d3b1eeb9f7 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 21 Oct 2000 03:29:02 +0000 Subject: [PATCH] First-cut at manageDSAit-aware backend selection. --- servers/slapd/add.c | 6 +++++- servers/slapd/backend.c | 25 +++++++++++++++++++------ servers/slapd/bind.c | 2 +- servers/slapd/compare.c | 5 ++++- servers/slapd/config.c | 6 +++--- servers/slapd/delete.c | 5 ++++- servers/slapd/modify.c | 5 ++++- servers/slapd/modrdn.c | 8 +++++--- servers/slapd/proto-slap.h | 4 +++- servers/slapd/saslauthz.c | 4 ++-- servers/slapd/search.c | 5 ++++- servers/slapd/tools/slapadd.c | 3 ++- servers/slapd/tools/slapcommon.c | 2 +- 13 files changed, 57 insertions(+), 23 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 86030d638e..c0c5a920a1 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -44,6 +44,7 @@ do_add( Connection *conn, Operation *op ) Modifications *mods = NULL; const char *text; int rc = LDAP_SUCCESS; + int manageDSAit; Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 ); @@ -149,12 +150,15 @@ do_add( Connection *conn, Operation *op ) goto done; } + manageDSAit = get_manageDSAit( op ) && + is_entry_referral( e ); + /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * if we don't hold it. */ - be = select_backend( e->e_ndn ); + be = select_backend( e->e_ndn, manageDSAit ); if ( be == NULL ) { send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL, default_referral, NULL ); diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 8aca7e0e1e..d05df37075 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -433,9 +433,12 @@ be_db_close( void ) } Backend * -select_backend( const char * dn ) +select_backend( + const char * dn, + int manageDSAit ) { int i, j, len, dnlen; + Backend *be = NULL; dnlen = strlen( dn ); for ( i = 0; i < nbackends; i++ ) { @@ -449,13 +452,23 @@ select_backend( const char * dn ) } if ( strcmp( backends[i].be_nsuffix[j], - dn + (dnlen - len) ) == 0 ) { - return( &backends[i] ); + dn + (dnlen - len) ) == 0 ) + { + if( be == NULL ) { + be = &backends[i]; + + if( manageDSAit && len == dnlen ) { + continue; + } + } else { + be = &backends[i]; + } + return be; } } } - return( NULL ); + return be; } int @@ -848,7 +861,7 @@ backend_group( if( strcmp( target->e_ndn, gr_ndn ) != 0 ) { /* 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) { return LDAP_NO_SUCH_OBJECT; @@ -878,7 +891,7 @@ backend_attribute( if( target == NULL || strcmp( target->e_ndn, e_ndn ) != 0 ) { /* 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) { return LDAP_NO_SUCH_OBJECT; diff --git a/servers/slapd/bind.c b/servers/slapd/bind.c index b22de77f7c..9f3f5427b2 100644 --- a/servers/slapd/bind.c +++ b/servers/slapd/bind.c @@ -336,7 +336,7 @@ do_bind( * if we don't hold it. */ - if ( (be = select_backend( ndn )) == NULL ) { + if ( (be = select_backend( ndn, 0 )) == NULL ) { if ( default_referral ) { send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL, default_referral, NULL ); diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index cb291b073d..262304a514 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -37,6 +37,7 @@ do_compare( Backend *be; int rc = LDAP_SUCCESS; const char *text = NULL; + int manageDSAit; ava.aa_desc = NULL; desc.bv_val = NULL; @@ -100,12 +101,14 @@ do_compare( goto cleanup; } + manageDSAit = get_manageDSAit( op ); + /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * 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, NULL, NULL, default_referral, NULL ); rc = 1; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 41088400ec..51fef27f45 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -412,7 +412,7 @@ read_config( const char *fname ) Debug( LDAP_DEBUG_ANY, "%s: line %d: suffix line must appear inside a database definition (ignored)\n", 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, "%s: line %d: suffix already served by this backend (ignored)\n", fname, lineno, 0 ); @@ -464,13 +464,13 @@ read_config( const char *fname ) "%s: line %d: suffixAlias line" " must appear inside a database definition (ignored)\n", 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, "%s: line %d: suffixAlias served by" " a preceeding backend \"%s\" (ignored)\n", 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, "%s: line %d: suffixAlias derefs to differnet backend" " a preceeding backend \"%s\" (ignored)\n", diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 140e825152..c253949f7b 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -35,6 +35,7 @@ do_delete( const char *text; Backend *be; int rc; + int manageDSAit; 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", op->o_connid, op->o_opid, dn, 0, 0 ); + manageDSAit = get_manageDSAit( op ); + /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * 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, NULL, NULL, default_referral, NULL ); goto cleanup; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index faa0973246..99e31fe033 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -45,6 +45,7 @@ do_modify( Backend *be; int rc; const char *text; + int manageDSAit; 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", op->o_connid, op->o_opid, dn, 0, 0 ); + manageDSAit = get_manageDSAit( op ); + /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * 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, NULL, NULL, default_referral, NULL ); goto cleanup; diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 84808e97d9..7bcf98ecf6 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -54,6 +54,7 @@ do_modrdn( ber_len_t length; int rc; const char *text; + int manageDSAit; 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", op->o_connid, op->o_opid, dn, 0, 0 ); + manageDSAit = get_manageDSAit( op ); + /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * 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, NULL, NULL, default_referral, NULL ); goto cleanup; @@ -190,7 +192,7 @@ do_modrdn( * the same backend, otherwise we return an error. */ if( newSuperior != NULL ) { - newSuperior_be = select_backend( nnewSuperior ); + newSuperior_be = select_backend( nnewSuperior, 0 ); if ( newSuperior_be != be ) { /* newSuperior is in same backend */ diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 84498e24b9..f97adc5482 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 (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_isroot LDAP_P(( Backend *be, const char *ndn )); diff --git a/servers/slapd/saslauthz.c b/servers/slapd/saslauthz.c index 9599f8a973..e4bcdb7c0e 100644 --- a/servers/slapd/saslauthz.c +++ b/servers/slapd/saslauthz.c @@ -295,7 +295,7 @@ char *slap_sasl2dn( char *saslname ) "slap_sasl2dn: performing internal search (base=%s, scope=%d)\n", searchbase, scope, 0 ); - be = select_backend( searchbase ); + be = select_backend( searchbase, 0 ); if(( be == NULL ) || ( be->be_search == NULL)) goto FINISHED; 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", searchbase, scope, 0 ); - be = select_backend( searchbase ); + be = select_backend( searchbase, 0 ); if(( be == NULL ) || ( be->be_search == NULL)) { rc = LDAP_INAPPROPRIATE_AUTH; goto CONCLUDED; diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 5ae5439ab0..e197f28ffd 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -39,6 +39,7 @@ do_search( Backend *be; int rc; const char *text; + int manageDSAit; Debug( LDAP_DEBUG_TRACE, "do_search\n", 0, 0, 0 ); LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY, "conn: %d do_search\n", @@ -210,12 +211,14 @@ do_search( nbase = ch_strdup( default_search_nbase ); } + manageDSAit = get_manageDSAit( op ); + /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * 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, NULL, NULL, default_referral, NULL ); diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 8ce9f1a534..0e16f60749 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -78,7 +78,8 @@ main( int argc, char **argv ) } /* 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 " "hold dn=\"%s\" (line=%d)\n", progname, diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index 67793bb368..9c583c964d 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -211,7 +211,7 @@ slap_tool_init( exit( EXIT_FAILURE ); } - be = select_backend( tbase ); + be = select_backend( tbase, 0 ); free( tbase ); if( be == NULL ) { -- 2.39.5