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 );
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 );
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Attribute *a;
int depth;
- char **pastAliases;
char *matched;
Entry *origDN = e;
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);
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);
int withDefIDX;
#define BDB2_WITH_DEF_IDX 1
+ /* a handle for the backend's environment */
+ DB_ENV **dbenvH;
+
} BDB2_TXN_HEAD;
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 {
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 );
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;
}
{
send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
NULL, NULL );
+ /* stop front end from sending result */
rc = 1;
goto return_results;
}
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 );
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 );
/* 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 );
}
/* 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 );
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 );
}
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 );
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 );
}
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 );
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 );
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 );
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;
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 );
}
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 );
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 );
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 );
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;
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",
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,
start transaction control */
if ( writer && ( ret == 0 )) {
- ret = bdb2i_start_transction( dbEnv->tx_info );
+ ret = bdb2i_start_transction( bdb2i_dbEnv.tx_info );
}
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 */
}
/* 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 ) {
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,
* 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
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 ));
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 );
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 );
)
{
struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
- DB_ENV *dbEnv = lty->lty_dbenv;
int envFlags;
int err = 0;
char *home;
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 );
)
{
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 );
}
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 */
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",
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 ) {
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 ) {
}
-/* 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 )
{
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 ) {
txn_do_abort = 1;
}
- if ( key.dptr ) free( key.dptr );
+ ldbm_datum_free( ldbm, key );
+ key.flags = 0;
key.dptr = NULL;
key.dsize = 0;
}
{
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 ) {
txn_do_abort = 1;
}
+ key.flags = 0;
key.dptr = NULL;
key.dsize = 0;
}
- if ( oldKey ) free( oldKey );
-
return( key );
}
+/* the DB environment for the backend */
+DB_ENV bdb2i_dbEnv;
+
+
/* variables for transaction support */
DB_TXN *txnid = NULL;
int txn_do_abort = 0;