From 0076b40c329936cf8fc788ca109d1d39e5422c5e Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 24 Mar 2005 05:13:31 +0000 Subject: [PATCH] Convert backendInfo/backendDB to STAILQs --- servers/slapd/abandon.c | 5 +- servers/slapd/acl.c | 4 +- servers/slapd/back-monitor/backend.c | 14 +- servers/slapd/back-monitor/database.c | 18 ++- servers/slapd/back-monitor/overlay.c | 6 +- servers/slapd/backend.c | 222 +++++++++++--------------- servers/slapd/backover.c | 6 +- servers/slapd/bconfig.c | 13 +- servers/slapd/cancel.c | 3 +- servers/slapd/config.h | 6 + servers/slapd/overlays/glue.c | 21 +-- servers/slapd/root_dse.c | 27 ++-- servers/slapd/slap.h | 11 +- servers/slapd/slapcommon.c | 22 ++- 14 files changed, 177 insertions(+), 201 deletions(-) diff --git a/servers/slapd/abandon.c b/servers/slapd/abandon.c index efc3ba7c8e..95df80c2a5 100644 --- a/servers/slapd/abandon.c +++ b/servers/slapd/abandon.c @@ -108,10 +108,7 @@ do_abandon( Operation *op, SlapReply *rs ) int fe_op_abandon( Operation *op, SlapReply *rs ) { - int i; - - for ( i = 0; i < nbackends; i++ ) { - op->o_bd = &backends[i]; + LDAP_STAILQ_FOREACH( op->o_bd, &backendDB, be_next ) { if ( op->o_bd->be_abandon ) { (void)op->o_bd->be_abandon( op, rs ); } diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index fdb2b9156f..2c5551cc3f 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -223,7 +223,7 @@ access_allowed_mask( be = op->o_bd; if ( be == NULL ) { - be = &backends[0]; + be = LDAP_STAILQ_FIRST(&backendDB); be_null = 1; #ifdef LDAP_DEVEL /* @@ -1725,7 +1725,7 @@ acl_check_modlist( be = op->o_bd; if ( be == NULL ) { - be = &backends[0]; + be = LDAP_STAILQ_FIRST(&backendDB); be_null = 1; op->o_bd = be; } diff --git a/servers/slapd/back-monitor/backend.c b/servers/slapd/back-monitor/backend.c index d215821791..b9e6084358 100644 --- a/servers/slapd/back-monitor/backend.c +++ b/servers/slapd/back-monitor/backend.c @@ -42,6 +42,7 @@ monitor_subsys_backend_init( int i; monitor_entry_t *mp; monitor_subsys_t *ms_database; + BackendInfo *bi; mi = ( monitor_info_t * )be->be_private; @@ -69,14 +70,15 @@ monitor_subsys_backend_init( mp->mp_children = NULL; ep = &mp->mp_children; - for ( i = 0; i < nBackendInfo; i++ ) { + i = -1; + LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) { char buf[ BACKMONITOR_BUFSIZE ]; - BackendInfo *bi; + BackendDB *be; struct berval bv; int j; Entry *e; - bi = &backendInfo[ i ]; + i++; snprintf( buf, sizeof( buf ), "dn: cn=Backend %d,%s\n" @@ -124,11 +126,13 @@ monitor_subsys_backend_init( } } - for ( j = 0; j < nBackendDB; j++ ) { - BackendDB *be = &backendDB[ j ]; + j = -1; + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { char buf[ SLAP_LDAPDN_MAXLEN ]; struct berval dn; + j++; + if ( be->bd_info != bi ) { continue; } diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index 5acedec8ca..1deed07e7d 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -166,14 +166,15 @@ monitor_subsys_database_init( mp->mp_children = NULL; ep = &mp->mp_children; - for ( i = 0; i < nBackendDB; i++ ) { + i = -1; + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { char buf[ BACKMONITOR_BUFSIZE ]; int j; slap_overinfo *oi = NULL; - BackendInfo *bi; + BackendInfo *bi, *bi2; Entry *e; - be = &backendDB[ i ]; + i++; bi = be->bd_info; @@ -356,8 +357,10 @@ monitor_subsys_database_init( } #endif /* defined(SLAPD_LDAP) */ - for ( j = 0; j < nBackendInfo; j++ ) { - if ( backendInfo[ j ].bi_type == bi->bi_type ) { + j = -1; + LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) { + j++; + if ( bi2->bi_type == bi->bi_type ) { struct berval bv; snprintf( buf, sizeof( buf ), @@ -550,8 +553,11 @@ monitor_subsys_database_modify( if ( n < 0 || n >= nBackendDB ) return LDAP_NO_SUCH_OBJECT; + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( n == 0 ) break; + n--; + } /* do not allow some changes on back-monitor (needs work)... */ - be = &backendDB[ n ]; if ( SLAP_MONITOR( be ) ) return LDAP_UNWILLING_TO_PERFORM; diff --git a/servers/slapd/back-monitor/overlay.c b/servers/slapd/back-monitor/overlay.c index b90fc8a2b0..c68d5152cd 100644 --- a/servers/slapd/back-monitor/overlay.c +++ b/servers/slapd/back-monitor/overlay.c @@ -73,6 +73,7 @@ monitor_subsys_overlay_init( struct berval bv; int j; Entry *e; + BackendDB *be; snprintf( buf, sizeof( buf ), "dn: cn=Overlay %d,%s\n" @@ -110,11 +111,12 @@ monitor_subsys_overlay_init( attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL ); - for ( j = 0; j < nBackendDB; j++ ) { - BackendDB *be = &backendDB[ j ]; + j = -1; + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { char buf[ SLAP_LDAPDN_MAXLEN ]; struct berval dn; + j++; if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) { continue; } diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 1a0277f25c..ea42a39d0a 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -57,10 +57,10 @@ static void call_group_postop_plugins( Operation *op ); */ int nBackendInfo = 0; -BackendInfo *backendInfo = NULL; +slap_bi_head backendInfo = LDAP_STAILQ_HEAD_INITIALIZER(backendInfo); int nBackendDB = 0; -BackendDB *backendDB = NULL; +slap_be_head backendDB = LDAP_STAILQ_HEAD_INITIALIZER(backendDB); static int backend_init_controls( BackendInfo *bi ) @@ -91,26 +91,25 @@ backend_init_controls( BackendInfo *bi ) int backend_init(void) { int rc = -1; + BackendInfo *bi; - if((nBackendInfo != 0) || (backendInfo != NULL)) { + if((nBackendInfo != 0) || !LDAP_STAILQ_EMPTY(&backendInfo)) { /* already initialized */ Debug( LDAP_DEBUG_ANY, "backend_init: already initialized\n", 0, 0, 0 ); return -1; } - for( ; - slap_binfo[nBackendInfo].bi_type != NULL; - nBackendInfo++ ) + for( bi=slap_binfo; bi->bi_type != NULL; bi++,nBackendInfo++ ) { - assert( slap_binfo[nBackendInfo].bi_init ); + assert( bi->bi_init ); - rc = slap_binfo[nBackendInfo].bi_init( &slap_binfo[nBackendInfo] ); + rc = bi->bi_init( bi ); if(rc != 0) { Debug( LDAP_DEBUG_ANY, "backend_init: initialized for type \"%s\"\n", - slap_binfo[nBackendInfo].bi_type, 0, 0 ); + bi->bi_type, 0, 0 ); /* destroy those we've already inited */ for( nBackendInfo--; nBackendInfo >= 0 ; @@ -123,10 +122,10 @@ int backend_init(void) } return rc; } + LDAP_STAILQ_INSERT_TAIL(&backendInfo, bi, bi_next); } if ( nBackendInfo > 0) { - backendInfo = slap_binfo; return 0; } @@ -164,25 +163,9 @@ int backend_add(BackendInfo *aBackendInfo) (void)backend_init_controls( aBackendInfo ); /* now add the backend type to the Backend Info List */ - { - BackendInfo *newBackendInfo = 0; - - /* if backendInfo == slap_binfo no deallocation of old backendInfo */ - if (backendInfo == slap_binfo) { - newBackendInfo = ch_calloc(nBackendInfo + 1, sizeof(BackendInfo)); - AC_MEMCPY(newBackendInfo, backendInfo, - sizeof(BackendInfo) * nBackendInfo); - } else { - newBackendInfo = ch_realloc(backendInfo, - sizeof(BackendInfo) * (nBackendInfo + 1)); - } - - AC_MEMCPY(&newBackendInfo[nBackendInfo], aBackendInfo, - sizeof(BackendInfo)); - backendInfo = newBackendInfo; - nBackendInfo++; - return 0; - } + LDAP_STAILQ_INSERT_TAIL( &backendInfo, aBackendInfo, bi_next ); + nBackendInfo++; + return 0; } static int @@ -255,6 +238,7 @@ int backend_startup(Backend *be) { int i; int rc = 0; + BackendInfo *bi; if( ! ( nBackendDB > 0 ) ) { /* no databases */ @@ -291,23 +275,25 @@ int backend_startup(Backend *be) } /* open each backend type */ - for( i = 0; i < nBackendInfo; i++ ) { - if( backendInfo[i].bi_nDB == 0) { + i = -1; + LDAP_STAILQ_FOREACH(bi, &backendInfo, bi_next) { + i++; + if( bi->bi_nDB == 0) { /* no database of this type, don't open */ continue; } - if( backendInfo[i].bi_open ) { - rc = backendInfo[i].bi_open( &backendInfo[i] ); + if( bi->bi_open ) { + rc = bi->bi_open( bi ); if ( rc != 0 ) { Debug( LDAP_DEBUG_ANY, - "backend_startup: bi_open %d failed!\n", - i, 0, 0 ); + "backend_startup: bi_open %d (%s) failed!\n", + i, bi->bi_type, 0 ); return rc; } } - (void)backend_init_controls( &backendInfo[i] ); + (void)backend_init_controls( bi ); } ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex ); @@ -315,26 +301,28 @@ int backend_startup(Backend *be) LDAP_STAILQ_INIT( &slapd_rq.run_list ); /* open each backend database */ - for( i = 0; i < nBackendDB; i++ ) { - if ( backendDB[i].be_suffix == NULL ) { + i = -1; + LDAP_STAILQ_FOREACH(be, &backendDB, be_next) { + i++; + if ( be->be_suffix == NULL ) { Debug( LDAP_DEBUG_ANY, "backend_startup: warning, database %d (%s) " "has no suffix\n", - i, backendDB[i].bd_info->bi_type, 0 ); + i, be->bd_info->bi_type, 0 ); } /* append global access controls */ - acl_append( &backendDB[i].be_acl, frontendDB->be_acl ); + acl_append( &be->be_acl, frontendDB->be_acl ); - rc = backend_startup_one( &backendDB[i] ); + rc = backend_startup_one( be ); if ( rc ) return rc; - if ( backendDB[i].be_syncinfo ) { + if ( be->be_syncinfo ) { syncinfo_t *si; - if ( !( backendDB[i].be_search && backendDB[i].be_add && - backendDB[i].be_modify && backendDB[i].be_delete )) { + if ( !( be->be_search && be->be_add && + be->be_modify && be->be_delete )) { Debug( LDAP_DEBUG_ANY, "backend_startup: database(%d) does not support " "operations required for syncrepl", i, 0, 0 ); @@ -342,8 +330,8 @@ int backend_startup(Backend *be) } { - si = backendDB[i].be_syncinfo; - si->si_be = &backendDB[i]; + si = be->be_syncinfo; + si->si_be = be; init_syncrepl( si ); ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); ldap_pvt_runqueue_insert( &slapd_rq, @@ -358,12 +346,14 @@ int backend_startup(Backend *be) int backend_num( Backend *be ) { - int i; + int i = 0; + BackendDB *b2; if( be == NULL ) return -1; - for( i = 0; i < nBackendDB; i++ ) { - if( be == &backendDB[i] ) return i; + LDAP_STAILQ_FOREACH( b2, &backendDB, be_next ) { + if( be == b2 ) return i; + i++; } return -1; } @@ -372,6 +362,7 @@ int backend_shutdown( Backend *be ) { int i; int rc = 0; + BackendInfo *bi; if( be != NULL ) { /* shutdown a specific backend database */ @@ -393,29 +384,27 @@ int backend_shutdown( Backend *be ) } /* close each backend database */ - for( i = 0; i < nBackendDB; i++ ) { - if ( backendDB[i].bd_info->bi_db_close ) { - backendDB[i].bd_info->bi_db_close( - &backendDB[i] ); + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( be->bd_info->bi_db_close ) { + be->bd_info->bi_db_close( be ); } if(rc != 0) { Debug( LDAP_DEBUG_ANY, "backend_close: bi_db_close %s failed!\n", - backendDB[i].be_type, 0, 0 ); + be->be_type, 0, 0 ); } } /* close each backend type */ - for( i = 0; i < nBackendInfo; i++ ) { - if( backendInfo[i].bi_nDB == 0 ) { + LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) { + if( bi->bi_nDB == 0 ) { /* no database of this type */ continue; } - if( backendInfo[i].bi_close ) { - backendInfo[i].bi_close( - &backendInfo[i] ); + if( bi->bi_close ) { + bi->bi_close( bi ); } } @@ -436,10 +425,12 @@ int backend_destroy(void) { int i; BackendDB *bd; + BackendInfo *bi; struct slap_csn_entry *csne; /* destroy each backend database */ - for( i = 0, bd = backendDB; i < nBackendDB; i++, bd++ ) { + while (( bd = LDAP_STAILQ_FIRST(&backendDB))) { + LDAP_STAILQ_REMOVE_HEAD(&backendDB, be_next); if ( bd->be_syncinfo ) { syncinfo_free( bd->be_syncinfo ); @@ -472,25 +463,18 @@ int backend_destroy(void) free( bd->be_rootpw.bv_val ); } acl_destroy( bd->be_acl, frontendDB->be_acl ); + free( bd ); } - free( backendDB ); /* destroy each backend type */ - for( i = 0; i < nBackendInfo; i++ ) { - if( backendInfo[i].bi_destroy ) { - backendInfo[i].bi_destroy( - &backendInfo[i] ); + LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) { + if( bi->bi_destroy ) { + bi->bi_destroy( bi ); } } -#ifdef SLAPD_MODULES - if (backendInfo != slap_binfo) { - free(backendInfo); - } -#endif /* SLAPD_MODULES */ - nBackendInfo = 0; - backendInfo = NULL; + LDAP_STAILQ_INIT(&backendInfo); /* destroy frontend database */ bd = frontendDB; @@ -517,12 +501,12 @@ int backend_destroy(void) BackendInfo* backend_info(const char *type) { - int i; + BackendInfo *bi; /* search for the backend type */ - for( i = 0; i < nBackendInfo; i++ ) { - if( strcasecmp(backendInfo[i].bi_type, type) == 0 ) { - return &backendInfo[i]; + LDAP_STAILQ_FOREACH(bi,&backendInfo,bi_next) { + if( strcasecmp(bi->bi_type, type) == 0 ) { + return bi; } } @@ -543,23 +527,9 @@ backend_db_init( return NULL; } - be = backendDB; - - backendDB = (BackendDB *) ch_realloc( - (char *) backendDB, - (nBackendDB + 1) * sizeof(Backend) ); - - memset( &backendDB[nbackends], '\0', sizeof(Backend) ); - - /* did realloc move our table? if so, fix up dependent pointers */ - if ( be != backendDB ) { - int i; - for ( i=0, be=backendDB; ibe_pcl_mutexp = &be->be_pcl_mutex; - } - } - - be = &backends[nbackends++]; + be = ch_calloc( 1, sizeof(Backend) ); + nbackends++; + LDAP_STAILQ_INSERT_TAIL(&backendDB, be, be_next); be->bd_info = bi; @@ -593,11 +563,12 @@ backend_db_init( void be_db_close( void ) { + BackendDB *be; int i; - for ( i = 0; i < nbackends; i++ ) { - if ( backends[i].bd_info->bi_db_close ) { - (*backends[i].bd_info->bi_db_close)( &backends[i] ); + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( be->bd_info->bi_db_close ) { + be->bd_info->bi_db_close( be ); } } @@ -615,22 +586,21 @@ select_backend( { int i, j; ber_len_t len, dnlen = dn->bv_len; - Backend *be = NULL; + Backend *be, *b2; - for ( i = 0; i < nbackends; i++ ) { - if ( backends[i].be_nsuffix == NULL ) { + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( be->be_nsuffix == NULL ) { continue; } - for ( j = 0; !BER_BVISNULL( &backends[i].be_nsuffix[j] ); j++ ) + for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[j] ); j++ ) { - if ( ( SLAP_GLUE_SUBORDINATE( &backends[i] ) ) - && noSubs ) + if ( ( SLAP_GLUE_SUBORDINATE( be ) ) && noSubs ) { continue; } - len = backends[i].be_nsuffix[j].bv_len; + len = be->be_nsuffix[j].bv_len; if ( len > dnlen ) { /* suffix is longer than DN */ @@ -647,25 +617,25 @@ select_backend( continue; } - if ( strcmp( backends[i].be_nsuffix[j].bv_val, + if ( strcmp( be->be_nsuffix[j].bv_val, &dn->bv_val[dnlen-len] ) == 0 ) { - if( be == NULL ) { - be = &backends[i]; + if( b2 == NULL ) { + b2 = be; if( manageDSAit && len == dnlen && !SLAP_GLUE_SUBORDINATE( be ) ) { continue; } } else { - be = &backends[i]; + b2 = be; } - return be; + return b2; } } } - return be; + return b2; } int @@ -780,15 +750,16 @@ be_entry_release_rw( int backend_unbind( Operation *op, SlapReply *rs ) { - int i; + int i = 0; + BackendDB *be; - for ( i = 0; i < nbackends; i++ ) { + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { #if defined( LDAP_SLAPI ) if ( op->o_pb ) { int rc; if ( i == 0 ) slapi_int_pblock_set_operation( op->o_pb, op ); - slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)&backends[i] ); - rc = slapi_int_call_plugins( &backends[i], + slapi_pblock_set( op->o_pb, SLAPI_BACKEND, (void *)be ); + rc = slapi_int_call_plugins( be, SLAPI_PLUGIN_PRE_UNBIND_FN, (Slapi_PBlock *)op->o_pb ); if ( rc < 0 ) { /* @@ -803,13 +774,13 @@ backend_unbind( Operation *op, SlapReply *rs ) } #endif /* defined( LDAP_SLAPI ) */ - if ( backends[i].be_unbind ) { - op->o_bd = &backends[i]; - (*backends[i].be_unbind)( op, rs ); + if ( be->be_unbind ) { + op->o_bd = be; + be->be_unbind( op, rs ); } #if defined( LDAP_SLAPI ) - if ( op->o_pb != NULL && slapi_int_call_plugins( &backends[i], + if ( op->o_pb != NULL && slapi_int_call_plugins( be, SLAPI_PLUGIN_POST_UNBIND_FN, (Slapi_PBlock *)op->o_pb ) < 0 ) { Debug(LDAP_DEBUG_TRACE, @@ -817,6 +788,7 @@ backend_unbind( Operation *op, SlapReply *rs ) 0, 0, 0); } #endif /* defined( LDAP_SLAPI ) */ + i++; } return 0; @@ -826,11 +798,11 @@ int backend_connection_init( Connection *conn ) { - int i; + BackendDB *be; - for ( i = 0; i < nbackends; i++ ) { - if ( backends[i].be_connection_init ) { - (*backends[i].be_connection_init)( &backends[i], conn); + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( be->be_connection_init ) { + be->be_connection_init( be, conn); } } @@ -841,11 +813,11 @@ int backend_connection_destroy( Connection *conn ) { - int i; + BackendDB *be; - for ( i = 0; i < nbackends; i++ ) { - if ( backends[i].be_connection_destroy ) { - (*backends[i].be_connection_destroy)( &backends[i], conn); + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( be->be_connection_destroy ) { + be->be_connection_destroy( be, conn); } } diff --git a/servers/slapd/backover.c b/servers/slapd/backover.c index e1b31a50c1..f4b82dc0be 100644 --- a/servers/slapd/backover.c +++ b/servers/slapd/backover.c @@ -545,12 +545,10 @@ overlay_register_control( BackendDB *be, const char *oid ) } if ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_GLOBAL_OVERLAY ) { - int i; + BackendDB *bd; /* add to all backends... */ - for ( i = 0; i < nBackendDB; i++ ) { - BackendDB *bd = &backendDB[i]; - + LDAP_STAILQ_FOREACH( bd, &backendDB, be_next ) { if ( be == bd ) { gotit = 1; } diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index b09b3afb2f..f208a5d033 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -893,7 +893,7 @@ config_generic(ConfigArgs *c) { /* NOTE: config is always the first backend! */ if ( !strcasecmp( c->argv[1], "config" )) { - c->be = backendDB; + c->be = LDAP_STAILQ_FIRST(&backendDB); } else if ( !strcasecmp( c->argv[1], "frontend" )) { c->be = frontendDB; } else if(!(c->be = backend_db_init(c->argv[1]))) { @@ -3166,7 +3166,7 @@ config_add_internal( CfBackInfo *cfb, Entry *e, SlapReply *rs, int *renum ) goto ok; /* FALLTHRU */ case Cft_Global: - ca.be = backendDB; + ca.be = LDAP_STAILQ_FIRST(&backendDB); break; case Cft_Backend: @@ -3764,8 +3764,7 @@ config_back_db_open( BackendDB *be ) */ c.line = 0; - bi = backendInfo; - for (i=0; ibi_cf_table) continue; if (!bi->bi_private) continue; @@ -3788,12 +3787,14 @@ config_back_db_open( BackendDB *be ) } /* Create database nodes... */ - for (i=0; ibd_info->bi_private; diff --git a/servers/slapd/cancel.c b/servers/slapd/cancel.c index e1256de909..141229b874 100644 --- a/servers/slapd/cancel.c +++ b/servers/slapd/cancel.c @@ -90,8 +90,7 @@ int cancel_extop( Operation *op, SlapReply *rs ) o->o_cancel = SLAP_CANCEL_REQ; - for ( i = 0; i < nbackends; i++ ) { - op->o_bd = &backends[i]; + LDAP_STAILQ_FOREACH( op->o_bd, &backendDB, be_next ) { if( !op->o_bd->be_cancel ) continue; op->oq_cancel.rs_msgid = opid; diff --git a/servers/slapd/config.h b/servers/slapd/config.h index 15d41f2349..be90c5c2d3 100644 --- a/servers/slapd/config.h +++ b/servers/slapd/config.h @@ -72,6 +72,12 @@ typedef struct ConfigOCs { char *def; ConfigType cft; ObjectClass **oc; +#if 0 + BI_op_add *add; /* optional, add-specific processing */ + BI_op_delete *del; /* mandatory, delete implementation */ + BI_op_modify *mod; /* optional, mod-specific */ + BI_op_modrdn *ren; /* optional, modrdn... */ +#endif } ConfigOCs; typedef struct config_args_s { diff --git a/servers/slapd/overlays/glue.c b/servers/slapd/overlays/glue.c index 13da05a952..957a45655d 100644 --- a/servers/slapd/overlays/glue.c +++ b/servers/slapd/overlays/glue.c @@ -40,7 +40,6 @@ typedef struct gluenode { BackendDB *gn_be; - int gn_bx; struct berval gn_pdn; int gn_async; } gluenode; @@ -730,23 +729,6 @@ glue_db_destroy ( return SLAP_CB_CONTINUE; } -static int -glue_db_open ( - BackendDB *be -) -{ - slap_overinst *on = (slap_overinst *)be->bd_info; - glueinfo *gi = (glueinfo *)on->on_bi.bi_private; - int i; - - for ( i=0; igi_nodes; i++ ) { - int j; - - gi->gi_n[i].gn_be = backendDB + gi->gi_n[i].gn_bx; - } - return 0; -} - static int glue_db_close( BackendDB *be @@ -813,7 +795,7 @@ glue_db_config( } gi = (glueinfo *)ch_realloc( gi, sizeof(glueinfo) + gi->gi_nodes * sizeof(gluenode)); - gi->gi_n[gi->gi_nodes].gn_bx = b2 - backendDB; + gi->gi_n[gi->gi_nodes].gn_be = b2; dnParent( &b2->be_nsuffix[0], &gi->gi_n[gi->gi_nodes].gn_pdn ); gi->gi_n[gi->gi_nodes].gn_async = async; gi->gi_nodes++; @@ -830,7 +812,6 @@ glue_init() glue.on_bi.bi_db_init = glue_db_init; glue.on_bi.bi_db_config = glue_db_config; - glue.on_bi.bi_db_open = glue_db_open; glue.on_bi.bi_db_close = glue_db_close; glue.on_bi.bi_db_destroy = glue_db_destroy; diff --git a/servers/slapd/root_dse.c b/servers/slapd/root_dse.c index dbe4f371c6..057b9061e9 100644 --- a/servers/slapd/root_dse.c +++ b/servers/slapd/root_dse.c @@ -56,6 +56,7 @@ root_dse_info( struct berval nvals[2]; int i, j; char ** supportedSASLMechanisms; + BackendDB *be; AttributeDescription *ad_structuralObjectClass = slap_schema.si_ad_structuralObjectClass; @@ -116,34 +117,34 @@ root_dse_info( return LDAP_OTHER; } - for ( i = 0; i < nbackends; i++ ) { - if ( backends[i].be_suffix == NULL - || backends[i].be_nsuffix == NULL ) { + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( be->be_suffix == NULL + || be->be_nsuffix == NULL ) { /* no suffix! */ continue; } - if ( SLAP_MONITOR( &backends[i] )) { - vals[0] = backends[i].be_suffix[0]; - nvals[0] = backends[i].be_nsuffix[0]; + if ( SLAP_MONITOR( be )) { + vals[0] = be->be_suffix[0]; + nvals[0] = be->be_nsuffix[0]; if( attr_merge( e, ad_monitorContext, vals, nvals ) ) { return LDAP_OTHER; } continue; } - if ( SLAP_CONFIG( &backends[i] )) { - vals[0] = backends[i].be_suffix[0]; - nvals[0] = backends[i].be_nsuffix[0]; + if ( SLAP_CONFIG( be )) { + vals[0] = be->be_suffix[0]; + nvals[0] = be->be_nsuffix[0]; if( attr_merge( e, ad_configContext, vals, nvals ) ) { return LDAP_OTHER; } continue; } - if ( SLAP_GLUE_SUBORDINATE( &backends[i] ) && !SLAP_GLUE_ADVERTISE( &backends[i] ) ) { + if ( SLAP_GLUE_SUBORDINATE( be ) && !SLAP_GLUE_ADVERTISE( be ) ) { continue; } - for ( j = 0; backends[i].be_suffix[j].bv_val != NULL; j++ ) { - vals[0] = backends[i].be_suffix[j]; - nvals[0] = backends[i].be_nsuffix[0]; + for ( j = 0; be->be_suffix[j].bv_val != NULL; j++ ) { + vals[0] = be->be_suffix[j]; + nvals[0] = be->be_nsuffix[0]; if( attr_merge( e, ad_namingContexts, vals, nvals ) ) { return LDAP_OTHER; } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index a419a94103..28b63a4c9c 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1389,11 +1389,13 @@ typedef struct slap_acl_state { typedef struct slap_backend_info BackendInfo; /* per backend type */ typedef struct slap_backend_db BackendDB; /* per backend database */ +typedef LDAP_STAILQ_HEAD(BeI, slap_backend_info) slap_bi_head; +typedef LDAP_STAILQ_HEAD(BeDB, slap_backend_db) slap_be_head; LDAP_SLAPD_V (int) nBackendInfo; LDAP_SLAPD_V (int) nBackendDB; -LDAP_SLAPD_V (BackendInfo *) backendInfo; -LDAP_SLAPD_V (BackendDB *) backendDB; +LDAP_SLAPD_V (slap_bi_head) backendInfo; +LDAP_SLAPD_V (slap_be_head) backendDB; LDAP_SLAPD_V (BackendDB *) frontendDB; LDAP_SLAPD_V (int) slapMode; @@ -1736,6 +1738,7 @@ struct slap_backend_db { struct ConfigTable *be_cf_table; void *be_private; /* anything the backend database needs */ + LDAP_STAILQ_ENTRY(slap_backend_db) be_next; }; struct slap_conn; @@ -2068,6 +2071,7 @@ struct slap_backend_info { unsigned int bi_nDB; /* number of databases of this type */ struct ConfigTable *bi_cf_table; void *bi_private; /* anything the backend type needs */ + LDAP_STAILQ_ENTRY(slap_backend_info) bi_next ; }; #define c_authtype c_authz.sai_method @@ -2921,11 +2925,10 @@ struct zone_heap { #endif #define SLAP_BACKEND_INIT_MODULE(b) \ + static BackendInfo bi; \ int \ init_module( int argc, char *argv[] ) \ { \ - BackendInfo bi; \ - memset( &bi, '\0', sizeof( bi ) ); \ bi.bi_type = #b ; \ bi.bi_init = b ## _back_initialize; \ backend_add( &bi ); \ diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 4a0c55a600..ab0048db05 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -446,21 +446,24 @@ slap_tool_init( fprintf( stderr, "No available databases\n" ); exit( EXIT_FAILURE ); } + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + dbnum++; + if ( dbnum < 1 ) continue; - be = &backends[dbnum=1]; + if ( SLAP_MONITOR(be)) + continue; + /* If just doing the first by default and it is a * glue subordinate, find the master. */ - while (SLAP_GLUE_SUBORDINATE(be) || SLAP_MONITOR(be)) { - if (SLAP_GLUE_SUBORDINATE(be)) { + if ( SLAP_GLUE_SUBORDINATE(be) ) { nosubordinates = 1; + continue; } - be++; - dbnum++; + break; } - - if ( dbnum >= nbackends ) { + if ( !be ) { fprintf( stderr, "Available database(s) " "do not allow %s\n", progname ); exit( EXIT_FAILURE ); @@ -482,7 +485,10 @@ slap_tool_init( exit( EXIT_FAILURE ); } else { - be = &backends[dbnum]; + LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) { + if ( dbnum == 0 ) break; + dbnum--; + } } startup:; -- 2.39.5