X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Finit.c;h=4b5f012335680ce0b15eeeceaa1501cfab4fa4db;hb=3a9310431e4e90005c1d7573c2b8f492cbf0cd0d;hp=3a0ed89e666ab8822dce9f39381cf92dcbc6d309;hpb=4ae77ae2662449eb58a530d7e5aee97efc6bd249;p=openldap diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 3a0ed89e66..4b5f012335 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -26,6 +26,7 @@ #include #include #include "alock.h" +#include "config.h" static const struct bdbi_database { char *file; @@ -46,7 +47,7 @@ typedef void * db_realloc(void *, size_t); #define bdb_db_close BDB_SYMBOL(db_close) static int -bdb_db_init( BackendDB *be ) +bdb_db_init( BackendDB *be, ConfigReply *cr ) { struct bdb_info *bdb; int rc; @@ -83,14 +84,6 @@ bdb_db_init( BackendDB *be ) ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock ); ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_lrulock ); - { - Entry *e = entry_alloc(); - e->e_id = 0; - e->e_private = &bdb->bi_cache.c_dntree; - BER_BVSTR( &e->e_name, "" ); - BER_BVSTR( &e->e_nname, "" ); - bdb->bi_cache.c_dntree.bei_e = e; - } be->be_private = bdb; be->be_cf_ocs = be->bd_info->bi_cf_ocs; @@ -101,10 +94,10 @@ bdb_db_init( BackendDB *be ) } static int -bdb_db_close( BackendDB *be ); +bdb_db_close( BackendDB *be, ConfigReply *cr ); static int -bdb_db_open( BackendDB *be ) +bdb_db_open( BackendDB *be, ConfigReply *cr ) { int rc, i; struct bdb_info *bdb = (struct bdb_info *) be->be_private; @@ -112,13 +105,14 @@ bdb_db_open( BackendDB *be ) u_int32_t flags; char path[MAXPATHLEN]; char *dbhome; + Entry *e = NULL; int do_recover = 0, do_alock_recover = 0; int alockt, quick = 0; if ( be->be_suffix == NULL ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_db_open) ": need suffix\n", - 0, 0, 0 ); + 1, 0, 0 ); return -1; } @@ -128,8 +122,11 @@ bdb_db_open( BackendDB *be ) #ifndef BDB_MULTIPLE_SUFFIXES if ( be->be_suffix[1].bv_val ) { - Debug( LDAP_DEBUG_ANY, - LDAP_XSTRING(bdb_db_open) ": only one suffix allowed\n", 0, 0, 0 ); + if (cr) { + snprintf(cr->msg, sizeof(cr->msg), "only one suffix allowed"); + Debug( LDAP_DEBUG_ANY, + LDAP_XSTRING(bdb_db_open) ": %s\n", cr->msg, 0, 0 ); + } return -1; } #endif @@ -140,7 +137,7 @@ bdb_db_open( BackendDB *be ) Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_db_open) ": Cannot access database directory %s (%d)\n", bdb->bi_dbenv_home, errno, 0 ); - return -1; + return -1; } /* Perform database use arbitration/recovery logic */ @@ -453,6 +450,23 @@ shm_retry: XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker); } + entry_prealloc( bdb->bi_cache.c_maxsize ); + attr_prealloc( bdb->bi_cache.c_maxsize * 20 ); + + /* setup for empty-DN contexts */ + if ( BER_BVISEMPTY( &be->be_nsuffix[0] )) { + rc = bdb_id2entry( be, NULL, 0, 0, &e ); + } + if ( !e ) { + e = entry_alloc(); + e->e_id = 0; + ber_dupbv( &e->e_name, (struct berval *)&slap_empty_bv ); + ber_dupbv( &e->e_nname, (struct berval *)&slap_empty_bv ); + } + e->e_ocflags = SLAP_OC_GLUE|SLAP_OC__END; + e->e_private = &bdb->bi_cache.c_dntree; + bdb->bi_cache.c_dntree.bei_e = e; + /* monitor setup */ rc = bdb_monitor_db_open( be ); if ( rc != 0 ) { @@ -461,17 +475,15 @@ shm_retry: bdb->bi_flags |= BDB_IS_OPEN; - entry_prealloc( bdb->bi_cache.c_maxsize ); - attr_prealloc( bdb->bi_cache.c_maxsize * 20 ); return 0; fail: - bdb_db_close( be ); + bdb_db_close( be, NULL ); return rc; } static int -bdb_db_close( BackendDB *be ) +bdb_db_close( BackendDB *be, ConfigReply *cr ) { int rc; struct bdb_info *bdb = (struct bdb_info *) be->be_private; @@ -481,6 +493,15 @@ bdb_db_close( BackendDB *be ) /* monitor handling */ (void)bdb_monitor_db_close( be ); + { + Entry *e = bdb->bi_cache.c_dntree.bei_e; + if ( e ) { + bdb->bi_cache.c_dntree.bei_e = NULL; + e->e_private = NULL; + bdb_entry_return( e ); + } + } + bdb->bi_flags &= ~BDB_IS_OPEN; ber_bvarray_free( bdb->bi_db_config ); @@ -557,7 +578,7 @@ bdb_db_close( BackendDB *be ) } static int -bdb_db_destroy( BackendDB *be ) +bdb_db_destroy( BackendDB *be, ConfigReply *cr ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; @@ -582,16 +603,6 @@ bdb_db_destroy( BackendDB *be ) ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock ); ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock ); - { - Entry *e; - e = bdb->bi_cache.c_dntree.bei_e; - bdb->bi_cache.c_dntree.bei_e = NULL; - e->e_private = NULL; - BER_BVZERO( &e->e_name ); - BER_BVZERO( &e->e_nname ); - entry_free( e ); - } - ch_free( bdb ); be->be_private = NULL;