From 3f76ee7a0ba1e91aa4200625b08d583da36ae18a Mon Sep 17 00:00:00 2001 From: Kurt Spanier Date: Fri, 5 Mar 1999 10:25:55 +0000 Subject: [PATCH] Make dbEnv a private toy of back-bdb2. --- servers/slapd/back-bdb2/add.c | 4 +- servers/slapd/back-bdb2/alias.c | 5 +-- servers/slapd/back-bdb2/back-bdb2.h | 10 +++-- servers/slapd/back-bdb2/bind.c | 8 +++- servers/slapd/back-bdb2/close.c | 6 +-- servers/slapd/back-bdb2/compare.c | 4 +- servers/slapd/back-bdb2/delete.c | 4 +- servers/slapd/back-bdb2/group.c | 4 +- servers/slapd/back-bdb2/init.c | 1 - servers/slapd/back-bdb2/modify.c | 4 +- servers/slapd/back-bdb2/modrdn.c | 4 +- servers/slapd/back-bdb2/porter.c | 16 ++++---- servers/slapd/back-bdb2/proto-back-bdb2.h | 14 ++++--- servers/slapd/back-bdb2/search.c | 4 +- servers/slapd/back-bdb2/startup.c | 24 ++++++------ servers/slapd/back-bdb2/txn.c | 48 +++++++++++++++++------ servers/slapd/back-bdb2/txn.h | 4 ++ 17 files changed, 98 insertions(+), 66 deletions(-) diff --git a/servers/slapd/back-bdb2/add.c b/servers/slapd/back-bdb2/add.c index 2383e5979f..6edf1f636d 100644 --- a/servers/slapd/back-bdb2/add.c +++ b/servers/slapd/back-bdb2/add.c @@ -239,7 +239,7 @@ bdb2_back_add( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -261,7 +261,7 @@ bdb2_back_add( ret = bdb2i_back_add_internal( be, conn, op, e ); bdb2i_stop_timing( be->bd_info, time2, "ADD-INTERN", conn, op ); - (void) bdb2i_leave_backend_w( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_w( lock ); bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op ); return( ret ); diff --git a/servers/slapd/back-bdb2/alias.c b/servers/slapd/back-bdb2/alias.c index a4fcb985bb..1d66b27732 100644 --- a/servers/slapd/back-bdb2/alias.c +++ b/servers/slapd/back-bdb2/alias.c @@ -32,7 +32,6 @@ Entry *bdb2i_derefAlias_r ( BackendDB *be, struct ldbminfo *li = (struct ldbminfo *) be->be_private; Attribute *a; int depth; - char **pastAliases; char *matched; Entry *origDN = e; @@ -76,7 +75,7 @@ Entry *bdb2i_derefAlias_r ( BackendDB *be, Debug( LDAP_DEBUG_TRACE, "<= %s alias is same as current %s\n", oldDN, newDN, 0 ); - send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "", + send_ldap_result( conn, op, LDAP_ALIAS_DEREF_PROBLEM, "", "Circular alias" ); free (newDN); free (oldDN); @@ -88,7 +87,7 @@ Entry *bdb2i_derefAlias_r ( BackendDB *be, Debug( LDAP_DEBUG_TRACE, "<= %s alias is same as original %s\n", oldDN, origDN->e_ndn, 0 ); - send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "", + send_ldap_result( conn, op, LDAP_ALIAS_DEREF_PROBLEM, "", "Circular alias" ); free (newDN); free (oldDN); diff --git a/servers/slapd/back-bdb2/back-bdb2.h b/servers/slapd/back-bdb2/back-bdb2.h index a40c4f5195..a8785037d2 100644 --- a/servers/slapd/back-bdb2/back-bdb2.h +++ b/servers/slapd/back-bdb2/back-bdb2.h @@ -154,6 +154,9 @@ typedef struct _bdb2_txn_head { int withDefIDX; #define BDB2_WITH_DEF_IDX 1 + /* a handle for the backend's environment */ + DB_ENV **dbenvH; + } BDB2_TXN_HEAD; @@ -165,15 +168,14 @@ struct ldbtype { char *lty_dbhome; size_t lty_mpsize; int lty_betiming; - - /* XXX do we need a private DB_ENV for all DB2 backend types ? */ - DB_ENV *lty_dbenv; }; -#define get_dbenv(be) ((struct ldbtype *) (be)->bd_info->bi_private)->lty_dbenv #define with_timing(bi) (((struct ldbtype *) \ (bi)->bi_private)->lty_betiming == 1) +/* The DB environment */ +extern DB_ENV bdb2i_dbEnv; + /* the private description of a database */ struct ldbminfo { diff --git a/servers/slapd/back-bdb2/bind.c b/servers/slapd/back-bdb2/bind.c index 7e759c5cde..b51d9ea136 100644 --- a/servers/slapd/back-bdb2/bind.c +++ b/servers/slapd/back-bdb2/bind.c @@ -120,6 +120,7 @@ bdb2i_back_bind_internal( goto return_results; } + /* check for root dn/passwd */ if ( be_isroot_pw( be, dn, cred ) ) { /* front end will send result */ if( *edn != NULL ) free( *edn ); @@ -131,6 +132,8 @@ bdb2i_back_bind_internal( if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) { send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH, NULL, NULL ); + + /* stop front end from sending result */ rc = 1; goto return_results; } @@ -139,6 +142,7 @@ bdb2i_back_bind_internal( { send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS, NULL, NULL ); + /* stop front end from sending result */ rc = 1; goto return_results; } @@ -224,7 +228,7 @@ bdb2_back_bind( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( 1 ); @@ -233,7 +237,7 @@ bdb2_back_bind( ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn ); - (void) bdb2i_leave_backend_r( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_r( lock ); bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op ); diff --git a/servers/slapd/back-bdb2/close.c b/servers/slapd/back-bdb2/close.c index 2d573533b6..eafdf164f4 100644 --- a/servers/slapd/back-bdb2/close.c +++ b/servers/slapd/back-bdb2/close.c @@ -16,7 +16,7 @@ bdb2i_back_db_close_internal( BackendDB *be ) /* since close will probably write the NEXTID file, wee need transaction control */ - if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( &lock ) != 0 ) { return( -1 ); } @@ -31,8 +31,8 @@ bdb2i_back_db_close_internal( BackendDB *be ) /* before closing all files, leave the backend (thus commiting all writes) and set a last checkpoint */ - (void) bdb2i_leave_backend_w( get_dbenv( be ), lock ); - (void) bdb2i_set_txn_checkpoint( get_dbenv( be )->tx_info, 1 ); + (void) bdb2i_leave_backend_w( lock ); + (void) bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 1 ); /* close all DB files */ Debug( LDAP_DEBUG_TRACE, "bdb2 backend closing DB files\n", 0, 0, 0 ); diff --git a/servers/slapd/back-bdb2/compare.c b/servers/slapd/back-bdb2/compare.c index 6ea93d5203..2c07093416 100644 --- a/servers/slapd/back-bdb2/compare.c +++ b/servers/slapd/back-bdb2/compare.c @@ -78,7 +78,7 @@ bdb2_back_compare( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( 1 ); @@ -86,7 +86,7 @@ bdb2_back_compare( } ret = bdb2i_back_compare_internal( be, conn, op, dn, ava ); - (void) bdb2i_leave_backend_r( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_r( lock ); bdb2i_stop_timing( be->bd_info, time1, "CMP", conn, op ); return( ret ); diff --git a/servers/slapd/back-bdb2/delete.c b/servers/slapd/back-bdb2/delete.c index 2affa8db85..f0344009fd 100644 --- a/servers/slapd/back-bdb2/delete.c +++ b/servers/slapd/back-bdb2/delete.c @@ -156,7 +156,7 @@ bdb2_back_delete( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -164,7 +164,7 @@ bdb2_back_delete( } ret = bdb2i_back_delete_internal( be, conn, op, dn ); - (void) bdb2i_leave_backend_w( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_w( lock ); bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op ); return( ret ); diff --git a/servers/slapd/back-bdb2/group.c b/servers/slapd/back-bdb2/group.c index 60a829e7d3..4634107ba4 100644 --- a/servers/slapd/back-bdb2/group.c +++ b/servers/slapd/back-bdb2/group.c @@ -141,7 +141,7 @@ bdb2_back_group( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( &lock ) != 0 ) { return( 1 ); @@ -150,7 +150,7 @@ bdb2_back_group( ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn, objectclassValue, groupattrName ); - (void) bdb2i_leave_backend_r( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_r( lock ); bdb2i_stop_timing( be->bd_info, time1, "GRP", NULL, NULL ); return( ret ); diff --git a/servers/slapd/back-bdb2/init.c b/servers/slapd/back-bdb2/init.c index e64eb998ea..c540e2a609 100644 --- a/servers/slapd/back-bdb2/init.c +++ b/servers/slapd/back-bdb2/init.c @@ -23,7 +23,6 @@ bdb2i_back_init_private( bt->lty_dbhome = DEFAULT_DB_HOME; bt->lty_mpsize = DEFAULT_DBCACHE_SIZE; - bt->lty_dbenv = &ldbm_Env; if ( slapMode == SLAP_TIMEDSERVER_MODE ) bt->lty_betiming = 1; diff --git a/servers/slapd/back-bdb2/modify.c b/servers/slapd/back-bdb2/modify.c index cbf5defe59..749955329f 100644 --- a/servers/slapd/back-bdb2/modify.c +++ b/servers/slapd/back-bdb2/modify.c @@ -128,7 +128,7 @@ bdb2_back_modify( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -147,7 +147,7 @@ bdb2_back_modify( } ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist ); - (void) bdb2i_leave_backend_w( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_w( lock ); bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op ); return( ret ); diff --git a/servers/slapd/back-bdb2/modrdn.c b/servers/slapd/back-bdb2/modrdn.c index 6e71e6b915..6d64d8a1e9 100644 --- a/servers/slapd/back-bdb2/modrdn.c +++ b/servers/slapd/back-bdb2/modrdn.c @@ -214,7 +214,7 @@ bdb2_back_modrdn( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -225,7 +225,7 @@ bdb2_back_modrdn( newrdn, deleteoldrdn, newSuperior ); - (void) bdb2i_leave_backend_w( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_w( lock ); bdb2i_stop_timing( be->bd_info, time1, "MODRDN", conn, op ); return( ret ); diff --git a/servers/slapd/back-bdb2/porter.c b/servers/slapd/back-bdb2/porter.c index d28e0f9ed9..ce1518f239 100644 --- a/servers/slapd/back-bdb2/porter.c +++ b/servers/slapd/back-bdb2/porter.c @@ -14,7 +14,7 @@ int -bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) +bdb2i_enter_backend_rw( DB_LOCK *lock, int writer ) { u_int32_t locker; db_lockmode_t lock_type; @@ -27,7 +27,7 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: case SLAP_TOOLID_MODE: - if ( ( ret = lock_id( dbEnv->lk_info, &locker )) != 0 ) { + if ( ( ret = lock_id( bdb2i_dbEnv.lk_info, &locker )) != 0 ) { Debug( LDAP_DEBUG_ANY, "bdb2i_enter_backend(): unable to get locker id -- %s\n", @@ -40,8 +40,8 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) lock_dbt.data = PORTER_OBJ; lock_dbt.size = strlen( PORTER_OBJ ); - switch ( ( ret = lock_get( dbEnv->lk_info, locker, 0, &lock_dbt, - lock_type, lock ))) { + switch ( ( ret = lock_get( bdb2i_dbEnv.lk_info, locker, 0, + &lock_dbt, lock_type, lock ))) { case 0: Debug( LDAP_DEBUG_TRACE, @@ -76,7 +76,7 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) start transaction control */ if ( writer && ( ret == 0 )) { - ret = bdb2i_start_transction( dbEnv->tx_info ); + ret = bdb2i_start_transction( bdb2i_dbEnv.tx_info ); } @@ -85,7 +85,7 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) int -bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer ) +bdb2i_leave_backend_rw( DB_LOCK lock, int writer ) { /* since one or more error can occure, we must have several return codes that are or'ed at the end */ @@ -101,7 +101,7 @@ bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer ) } /* check whether checkpointing is needed */ - ret_transaction |= bdb2i_set_txn_checkpoint( dbEnv->tx_info, 0 ); + ret_transaction |= bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 0 ); /* now release the lock */ switch ( slapMode ) { @@ -110,7 +110,7 @@ bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer ) case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: case SLAP_TOOLID_MODE: - switch( ( ret_lock = lock_put( dbEnv->lk_info, lock ))) { + switch( ( ret_lock = lock_put( bdb2i_dbEnv.lk_info, lock ))) { case 0: Debug( LDAP_DEBUG_TRACE, diff --git a/servers/slapd/back-bdb2/proto-back-bdb2.h b/servers/slapd/back-bdb2/proto-back-bdb2.h index e8e3b6f425..83974b96e6 100644 --- a/servers/slapd/back-bdb2/proto-back-bdb2.h +++ b/servers/slapd/back-bdb2/proto-back-bdb2.h @@ -173,12 +173,12 @@ void bdb2i_uncond_stop_timing LDAP_P(( struct timeval time1, * porter.c */ -int bdb2i_enter_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock, int writer )); -#define bdb2i_enter_backend_r(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 0 ) -#define bdb2i_enter_backend_w(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 1 ) -int bdb2i_leave_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock, int writer )); -#define bdb2i_leave_backend_r(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 0 ) -#define bdb2i_leave_backend_w(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 1 ) +int bdb2i_enter_backend_rw LDAP_P(( DB_LOCK *lock, int writer )); +#define bdb2i_enter_backend_r(lock) bdb2i_enter_backend_rw((lock), 0 ) +#define bdb2i_enter_backend_w(lock) bdb2i_enter_backend_rw((lock), 1 ) +int bdb2i_leave_backend_rw LDAP_P(( DB_LOCK lock, int writer )); +#define bdb2i_leave_backend_r(lock) bdb2i_leave_backend_rw((lock), 0 ) +#define bdb2i_leave_backend_w(lock) bdb2i_leave_backend_rw((lock), 1 ) /* * txn.c @@ -203,6 +203,8 @@ void bdb2i_check_default_attr_index_mod LDAP_P(( LDAPModList *modlist )); ID bdb2i_get_nextid LDAP_P(( BackendDB *be )); int bdb2i_put_nextid LDAP_P(( BackendDB *be, ID id )); +LDBM bdb2i_db_open LDAP_P(( char *name, int type, int rw, int mode, + int dbcachesize )); int bdb2i_db_store LDAP_P(( LDBM ldbm, Datum key, Datum data, int flags )); int bdb2i_db_delete LDAP_P(( LDBM ldbm, Datum key )); Datum bdb2i_db_fetch LDAP_P(( LDBM ldbm, Datum key )); diff --git a/servers/slapd/back-bdb2/search.c b/servers/slapd/back-bdb2/search.c index 04e68498d4..d2523da41e 100644 --- a/servers/slapd/back-bdb2/search.c +++ b/servers/slapd/back-bdb2/search.c @@ -337,7 +337,7 @@ bdb2_back_search( bdb2i_start_timing( be->bd_info, &time1 ); - if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -347,7 +347,7 @@ bdb2_back_search( ret = bdb2i_back_search_internal( be, conn, op, base, scope, deref, slimit, tlimit, filter, filterstr, attrs, attrsonly ); - (void) bdb2i_leave_backend_r( get_dbenv( be ), lock ); + (void) bdb2i_leave_backend_r( lock ); bdb2i_stop_timing( be->bd_info, time1, "SRCH", conn, op ); return( ret ); diff --git a/servers/slapd/back-bdb2/startup.c b/servers/slapd/back-bdb2/startup.c index f678f64e74..e3c48e70d2 100644 --- a/servers/slapd/back-bdb2/startup.c +++ b/servers/slapd/back-bdb2/startup.c @@ -31,7 +31,6 @@ bdb2i_back_startup_internal( ) { struct ldbtype *lty = (struct ldbtype *) bi->bi_private; - DB_ENV *dbEnv = lty->lty_dbenv; int envFlags; int err = 0; char *home; @@ -53,21 +52,21 @@ bdb2i_back_startup_internal( home = lty->lty_dbhome; /* general initialization of the environment */ - memset( dbEnv, 0, sizeof( DB_ENV )); - dbEnv->db_errcall = bdb2i_db_errcall; - dbEnv->db_errpfx = "==>"; + memset( &bdb2i_dbEnv, 0, sizeof( DB_ENV )); + bdb2i_dbEnv.db_errcall = bdb2i_db_errcall; + bdb2i_dbEnv.db_errpfx = "==>"; /* initialize the lock subsystem */ - dbEnv->lk_max = 0; + bdb2i_dbEnv.lk_max = 0; /* remove old locking tables */ remove_old_locks( home ); /* initialize the mpool subsystem */ - dbEnv->mp_size = lty->lty_mpsize; + bdb2i_dbEnv.mp_size = lty->lty_mpsize; /* now do the db_appinit */ - if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) { + if ( ( err = db_appinit( home, NULL, &bdb2i_dbEnv, envFlags )) ) { char error[BUFSIZ]; if ( err < 0 ) sprintf( error, "%ld\n", (long) err ); @@ -90,22 +89,21 @@ bdb2i_back_shutdown_internal( ) { struct ldbtype *lty = (struct ldbtype *) bi->bi_private; - DB_ENV *dbEnv = lty->lty_dbenv; int err; /* remove old locking tables */ - dbEnv->db_errpfx = "bdb2i_back_shutdown(): lock_unlink:"; - if ( ( err = lock_unlink( NULL, 1, dbEnv )) != 0 ) + bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): lock_unlink:"; + if ( ( err = lock_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 ) Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n", strerror( err ), 0, 0); /* remove old memory pool */ - dbEnv->db_errpfx = "bdb2i_back_shutdown(): memp_unlink:"; - if ( ( err = memp_unlink( NULL, 1, dbEnv )) != 0 ) + bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): memp_unlink:"; + if ( ( err = memp_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 ) Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n", strerror( err ), 0, 0); - (void) db_appexit( dbEnv ); + (void) db_appexit( &bdb2i_dbEnv ); return( 0 ); } diff --git a/servers/slapd/back-bdb2/txn.c b/servers/slapd/back-bdb2/txn.c index 7d1ced6b34..cc389deb79 100644 --- a/servers/slapd/back-bdb2/txn.c +++ b/servers/slapd/back-bdb2/txn.c @@ -137,7 +137,8 @@ bdb2i_txn_attr_config( li->li_directory, DEFAULT_DIRSEP, p->dbc_name ); /* since we have an mpool, we should not define a cache size */ - p->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 ); + p->dbc_db = bdb2i_db_open( fileName, DB_TYPE, + LDBM_WRCREAT, li->li_mode, 0 ); /* if the files could not be opened, something is wrong; complain */ @@ -177,7 +178,6 @@ bdb2i_open_nextid( BackendDB *be ) BDB2_TXN_HEAD *head = &li->li_txn_head; LDBM db = NULL; DB_INFO dbinfo; - DB_ENV *dbenv = get_dbenv( be ); char fileName[MAXPATHLEN]; sprintf( fileName, "%s%s%s", @@ -189,7 +189,7 @@ bdb2i_open_nextid( BackendDB *be ) dbinfo.db_malloc = ldbm_malloc; (void) db_open( fileName, DB_RECNO, DB_CREATE | DB_THREAD, - li->li_mode, dbenv, &dbinfo, &db ); + li->li_mode, &bdb2i_dbEnv, &dbinfo, &db ); if ( db == NULL ) { @@ -228,7 +228,8 @@ bdb2i_txn_open_files( BackendDB *be ) li->li_directory, DEFAULT_DIRSEP, dbFile->dbc_name ); /* since we have an mpool, we should not define a cache size */ - dbFile->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 ); + dbFile->dbc_db = bdb2i_db_open( fileName, DB_TYPE, + LDBM_WRCREAT, li->li_mode, 0 ); /* if the files could not be opened, something is wrong; complain */ if ( dbFile->dbc_db == NULL ) { @@ -476,7 +477,30 @@ bdb2i_put_nextid( BackendDB *be, ID id ) } -/* BDB2 backend-private functions of ldbm_store and ldbm_delete */ +/* BDB2 backend-private functions of libldbm */ +LDBM +bdb2i_db_open( + char *name, + int type, + int rw, + int mode, + int dbcachesize ) +{ + LDBM ret = NULL; + DB_INFO dbinfo; + + memset( &dbinfo, 0, sizeof( dbinfo )); + if ( bdb2i_dbEnv.mp_info == NULL ) + dbinfo.db_cachesize = dbcachesize; + dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE; + dbinfo.db_malloc = ldbm_malloc; + + (void) db_open( name, type, rw, mode, &bdb2i_dbEnv, &dbinfo, &ret ); + + return( ret ); +} + + int bdb2i_db_store( LDBM ldbm, Datum key, Datum data, int flags ) { @@ -595,11 +619,12 @@ bdb2i_db_firstkey( LDBM ldbm, DBC **dbch ) txn_do_abort = 1; } + key.flags = 0; return( key ); } else { *dbch = dbci; if ( (*dbci->c_get)( dbci, &key, &data, DB_NEXT ) == 0 ) { - if ( data.dptr ) free( data.dptr ); + ldbm_datum_free( ldbm, data ); } else { if ( txnid != NULL ) { @@ -609,7 +634,8 @@ bdb2i_db_firstkey( LDBM ldbm, DBC **dbch ) txn_do_abort = 1; } - if ( key.dptr ) free( key.dptr ); + ldbm_datum_free( ldbm, key ); + key.flags = 0; key.dptr = NULL; key.dsize = 0; } @@ -624,13 +650,12 @@ bdb2i_db_nextkey( LDBM ldbm, Datum key, DBC *dbcp ) { Datum data; int rc; - void *oldKey = key.dptr; ldbm_datum_init( data ); - data.flags = DB_DBT_MALLOC; + key.flags = data.flags = DB_DBT_MALLOC; if ( (*dbcp->c_get)( dbcp, &key, &data, DB_NEXT ) == 0 ) { - if ( data.dptr ) free( data.dptr ); + ldbm_datum_free( ldbm, data ); } else { if ( txnid != NULL ) { @@ -640,12 +665,11 @@ bdb2i_db_nextkey( LDBM ldbm, Datum key, DBC *dbcp ) txn_do_abort = 1; } + key.flags = 0; key.dptr = NULL; key.dsize = 0; } - if ( oldKey ) free( oldKey ); - return( key ); } diff --git a/servers/slapd/back-bdb2/txn.h b/servers/slapd/back-bdb2/txn.h index 37414e222b..1068f238e9 100644 --- a/servers/slapd/back-bdb2/txn.h +++ b/servers/slapd/back-bdb2/txn.h @@ -22,6 +22,10 @@ +/* the DB environment for the backend */ +DB_ENV bdb2i_dbEnv; + + /* variables for transaction support */ DB_TXN *txnid = NULL; int txn_do_abort = 0; -- 2.39.5