From 42f6e78dd4e2d481c1bc75b8bc6d38fe9c62bc07 Mon Sep 17 00:00:00 2001 From: Kurt Spanier Date: Mon, 8 Feb 1999 11:42:14 +0000 Subject: [PATCH] Integration of the BDB2 backend into the new init/startup/shutdown schema. Integration into ./configure ( --enable-bdb2 ). Adaptation of the test-suite ( 'make' -> ldbm; 'make bdb2-local' -> bdb2 ). Minor fixes in slapd/libldbm. --- configure | 4 +- include/ldbm.h | 3 + libraries/libldbm/ldbm.c | 5 +- servers/slapd/back-bdb2/abandon.c | 4 +- servers/slapd/back-bdb2/add.c | 12 +- servers/slapd/back-bdb2/alias.c | 4 +- servers/slapd/back-bdb2/back-bdb2.h | 24 +- servers/slapd/back-bdb2/bind.c | 8 +- servers/slapd/back-bdb2/cache.c | 16 +- servers/slapd/back-bdb2/close.c | 13 +- servers/slapd/back-bdb2/compare.c | 8 +- servers/slapd/back-bdb2/config.c | 92 +++++- servers/slapd/back-bdb2/dbcache.c | 41 +-- servers/slapd/back-bdb2/delete.c | 8 +- servers/slapd/back-bdb2/dn2id.c | 12 +- servers/slapd/back-bdb2/external.h | 3 + servers/slapd/back-bdb2/filterindex.c | 26 +- servers/slapd/back-bdb2/group.c | 8 +- servers/slapd/back-bdb2/id2children.c | 6 +- servers/slapd/back-bdb2/id2entry.c | 10 +- servers/slapd/back-bdb2/idl.c | 20 +- servers/slapd/back-bdb2/index.c | 29 +- servers/slapd/back-bdb2/init.c | 66 +++- servers/slapd/back-bdb2/kerberos.c | 2 +- servers/slapd/back-bdb2/modify.c | 10 +- servers/slapd/back-bdb2/modrdn.c | 8 +- servers/slapd/back-bdb2/nextid.c | 12 +- servers/slapd/back-bdb2/porter.c | 12 +- servers/slapd/back-bdb2/proto-back-bdb2.h | 91 +++--- servers/slapd/back-bdb2/search.c | 20 +- servers/slapd/back-bdb2/startup.c | 204 ++++++++---- servers/slapd/back-bdb2/txn.c | 50 +-- servers/slapd/back-bdb2/unbind.c | 4 +- servers/slapd/back-ldbm/config.c | 4 +- servers/slapd/back-ldbm/dbcache.c | 2 +- servers/slapd/back-ldbm/index.c | 3 - servers/slapd/back-ldbm/init.c | 4 +- servers/slapd/backend.c | 72 ++++- servers/slapd/init.c | 6 +- servers/slapd/main.c | 9 +- servers/slapd/slap.h | 4 +- servers/slapd/tools/Makefile.in | 61 +++- servers/slapd/tools/ldif2id2children-bdb2.c | 311 ++++++++++++++++++ servers/slapd/tools/ldif2id2entry-bdb2.c | 206 ++++++++++++ servers/slapd/tools/ldif2index-bdb2.c | 177 +++++++++++ servers/slapd/tools/ldif2ldbm-bdb2.c | 335 ++++++++++++++++++++ tests/Makefile.in | 13 +- tests/data/slapd-bdb2-acl.conf | 41 +++ tests/data/slapd-bdb2-master.conf | 25 ++ tests/data/slapd-bdb2-repl-master.conf | 32 ++ tests/data/slapd-bdb2-repl-slave.conf | 27 ++ tests/scripts/all | 12 +- tests/scripts/defines.sh | 28 +- tests/scripts/test001-ldif2ldbm | 7 +- tests/scripts/test001-slapadd | 7 +- tests/scripts/test002-populate | 5 +- tests/scripts/test003-search | 5 +- tests/scripts/test004-modify | 5 +- tests/scripts/test005-modrdn | 5 +- tests/scripts/test006-acls | 5 +- tests/scripts/test007-replication | 5 +- 61 files changed, 1909 insertions(+), 342 deletions(-) create mode 100644 servers/slapd/tools/ldif2id2children-bdb2.c create mode 100644 servers/slapd/tools/ldif2id2entry-bdb2.c create mode 100644 servers/slapd/tools/ldif2index-bdb2.c create mode 100644 servers/slapd/tools/ldif2ldbm-bdb2.c create mode 100644 tests/data/slapd-bdb2-acl.conf create mode 100644 tests/data/slapd-bdb2-master.conf create mode 100644 tests/data/slapd-bdb2-repl-master.conf create mode 100644 tests/data/slapd-bdb2-repl-slave.conf diff --git a/configure b/configure index 8cf4d6ee31..1afe816bc7 100755 --- a/configure +++ b/configure @@ -1562,7 +1562,7 @@ elif test $ol_enable_ldbm = no ; then echo "configure: warning: LDBM disabled, ignoring --with_ldbm_type argument" 1>&2 fi - if test $ol_enable_ldbm = yes ; then + if test $ol_enable_bdb2 = yes ; then { echo "configure: error: BDB2 requires --enable-ldbm" 1>&2; exit 1; } fi @@ -9600,6 +9600,7 @@ libraries/liblutil/Makefile:build/top.mk:libraries/liblutil/Makefile.in:build/li servers/Makefile:build/top.mk:servers/Makefile.in:build/dir.mk \ servers/ldapd/Makefile:build/top.mk:servers/ldapd/Makefile.in:build/srv.mk \ servers/slapd/Makefile:build/top.mk:servers/slapd/Makefile.in:build/srv.mk \ +servers/slapd/back-bdb2/Makefile:build/top.mk:servers/slapd/back-bdb2/Makefile.in:build/srv.mk \ servers/slapd/back-ldbm/Makefile:build/top.mk:servers/slapd/back-ldbm/Makefile.in:build/srv.mk \ servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/srv.mk \ servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/srv.mk \ @@ -9762,6 +9763,7 @@ libraries/liblutil/Makefile:build/top.mk:libraries/liblutil/Makefile.in:build/li servers/Makefile:build/top.mk:servers/Makefile.in:build/dir.mk \ servers/ldapd/Makefile:build/top.mk:servers/ldapd/Makefile.in:build/srv.mk \ servers/slapd/Makefile:build/top.mk:servers/slapd/Makefile.in:build/srv.mk \ +servers/slapd/back-bdb2/Makefile:build/top.mk:servers/slapd/back-bdb2/Makefile.in:build/srv.mk \ servers/slapd/back-ldbm/Makefile:build/top.mk:servers/slapd/back-ldbm/Makefile.in:build/srv.mk \ servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/srv.mk \ servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/srv.mk \ diff --git a/include/ldbm.h b/include/ldbm.h index ffe8804d6c..0440858bfd 100644 --- a/include/ldbm.h +++ b/include/ldbm.h @@ -204,6 +204,9 @@ LDAP_BEGIN_DECL int ldbm_initialize( void ); int ldbm_shutdown( void ); +#if HAVE_BERKELEY_DB2 +extern DB_ENV ldbm_Env; +#endif int ldbm_errno( LDBM ldbm ); LDBM ldbm_open( char *name, int rw, int mode, int dbcachesize ); diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index 4ca6595350..db5749267d 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -92,7 +92,7 @@ ldbm_db_errcall( const char *prefix, char *message ) } /* a dbEnv for BERKELEYv2 */ -static DB_ENV ldbm_Env; +DB_ENV ldbm_Env; /* Berkeley DB 2.x is reentrant */ #define LDBM_LOCK ((void)0) @@ -158,7 +158,8 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) DB_INFO dbinfo; memset( &dbinfo, 0, sizeof( dbinfo )); - dbinfo.db_cachesize = dbcachesize; + if ( ldbm_Env.mp_info == NULL ) + dbinfo.db_cachesize = dbcachesize; dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE; dbinfo.db_malloc = ldbm_malloc; diff --git a/servers/slapd/back-bdb2/abandon.c b/servers/slapd/back-bdb2/abandon.c index 1d9c1e9daf..b91ce4419b 100644 --- a/servers/slapd/back-bdb2/abandon.c +++ b/servers/slapd/back-bdb2/abandon.c @@ -15,7 +15,7 @@ /*ARGSUSED*/ static int bdb2i_back_abandon_internal( - Backend *be, + BackendDB *be, Connection *c, Operation *o, int msgid ) @@ -26,7 +26,7 @@ bdb2i_back_abandon_internal( int bdb2_back_abandon( - Backend *be, + BackendDB *be, Connection *c, Operation *o, int msgid ) diff --git a/servers/slapd/back-bdb2/add.c b/servers/slapd/back-bdb2/add.c index ef3b1031e7..f7d3274e1e 100644 --- a/servers/slapd/back-bdb2/add.c +++ b/servers/slapd/back-bdb2/add.c @@ -13,7 +13,7 @@ static int bdb2i_back_add_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, Entry *e @@ -242,14 +242,14 @@ return_results:; int bdb2_back_add( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, Entry *e ) { DB_LOCK lock; - struct ldbminfo *li = (struct ldbminfo *) be->be_private; + struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct timeval time1, time2; char *elapsed_time; @@ -257,7 +257,7 @@ bdb2_back_add( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_w( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -266,12 +266,12 @@ bdb2_back_add( /* check, if a new default attribute index will be created, in which case we have to open the index file BEFORE TP */ - if ( bdb2i_with_dbenv ) + if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) bdb2i_check_default_attr_index_add( li, e ); ret = bdb2i_back_add_internal( be, conn, op, e ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/alias.c b/servers/slapd/back-bdb2/alias.c index 984ca5683a..a4fcb985bb 100644 --- a/servers/slapd/back-bdb2/alias.c +++ b/servers/slapd/back-bdb2/alias.c @@ -23,7 +23,7 @@ * given an alias object, dereference it to its end point. * Entry returned has reader lock or is NULL. Starting entry is not released. */ -Entry *bdb2i_derefAlias_r ( Backend *be, +Entry *bdb2i_derefAlias_r ( BackendDB *be, Connection *conn, Operation *op, Entry *e) @@ -161,7 +161,7 @@ Entry *bdb2i_derefAlias_r ( Backend *be, * reconstructed dn is ou=MyOU,o=MyOrg,c=MyCountry * release lock on o=MyOrg,c=MyCountry entry */ -char *bdb2i_derefDN ( Backend *be, +char *bdb2i_derefDN ( BackendDB *be, Connection *conn, Operation *op, char *dn diff --git a/servers/slapd/back-bdb2/back-bdb2.h b/servers/slapd/back-bdb2/back-bdb2.h index 64f9c26c69..31acd5a7ac 100644 --- a/servers/slapd/back-bdb2/back-bdb2.h +++ b/servers/slapd/back-bdb2/back-bdb2.h @@ -15,6 +15,7 @@ LDAP_BEGIN_DECL #define DEFAULT_DBCACHE_SIZE (128 * DEFAULT_DB_PAGE_SIZE) #define DEFAULT_DB_DIRECTORY "/usr/tmp" +#define DEFAULT_DB_HOME "/usr/tmp" #define DEFAULT_MODE 0600 #define SUBLEN 3 @@ -132,8 +133,7 @@ typedef struct _bdb2_txn_head { /* a list of all DB files in use */ BDB2_TXN_FILES *dbFiles; - /* for performance reasons we have pointers to fixed descriptors */ - BDB2_TXN_FILES *dbFileHandle[4]; + /* we have five fixed files */ #define BDB2_DB_DN_FILE 0 #define BDB2_DB_DN2ID_FILE 1 #define BDB2_DB_ID2ENTRY_FILE 2 @@ -149,6 +149,20 @@ typedef struct _bdb2_txn_head { /* end of TP stuff */ + +/* the private description of a backend type */ +struct ldbtype { + char *lty_dbhome; + size_t lty_mpsize; + + /* 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 + + +/* the private description of a database */ struct ldbminfo { ID li_nextid; #if SLAPD_NEXTID_CHUNK > 1 @@ -168,16 +182,12 @@ struct ldbminfo { ldap_pvt_thread_mutex_t li_dbcache_mutex; ldap_pvt_thread_cond_t li_dbcache_cv; - /* Berkeley DB2 Environment */ - DB_ENV li_db_env; - char *li_dbhome; + /* a list of all files of the database */ BDB2_TXN_HEAD li_txn_head; }; -extern int bdb2i_with_dbenv; - #include "proto-back-bdb2.h" LDAP_END_DECL diff --git a/servers/slapd/back-bdb2/bind.c b/servers/slapd/back-bdb2/bind.c index 264c216a6a..9dfc181b40 100644 --- a/servers/slapd/back-bdb2/bind.c +++ b/servers/slapd/back-bdb2/bind.c @@ -59,7 +59,7 @@ crypted_value_find( static int bdb2i_back_bind_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -217,7 +217,7 @@ return_results:; int bdb2_back_bind( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -235,7 +235,7 @@ bdb2_back_bind( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_r( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( 1 ); @@ -244,7 +244,7 @@ bdb2_back_bind( ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/cache.c b/servers/slapd/back-bdb2/cache.c index 8e696e1c88..e7ec725721 100644 --- a/servers/slapd/back-bdb2/cache.c +++ b/servers/slapd/back-bdb2/cache.c @@ -84,7 +84,7 @@ cache_return_entry_rw( struct cache *cache, Entry *e, int rw ) /* set cache mutex */ ldap_pvt_thread_mutex_lock( &cache->c_mutex ); - entry_rdwr_unlock(e, rw);; + entry_rdwr_unlock(e, rw); if ( --e->e_refcnt == 0 && e->e_state == ENTRY_STATE_DELETED ) { entry_free( e ); @@ -213,9 +213,9 @@ bdb2i_cache_add_entry_lock( == 0 && cache->c_cursize > cache->c_maxsize ) { e = cache->c_lrutail; - /* XXX check for writer lock - should also check no readers pending */ + /* check for active readers/writer lock */ #ifdef LDAP_DEBUG - assert(!ldap_pvt_thread_rdwr_active(&e->e_rdwr)); + assert(!ldap_pvt_thread_rdwr_active( &e->e_rdwr )); #endif /* delete from cache and lru q */ @@ -236,7 +236,7 @@ bdb2i_cache_add_entry_lock( ID bdb2i_cache_find_entry_dn2id( - Backend *be, + BackendDB *be, struct cache *cache, char *dn ) @@ -386,14 +386,14 @@ bdb2i_cache_delete_entry( Debug( LDAP_DEBUG_TRACE, "====> cache_delete_entry:\n", 0, 0, 0 ); + /* set cache mutex */ + ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* XXX check for writer lock - should also check no readers pending */ #ifdef LDAP_DEBUG - assert(ldap_pvt_thread_rdwr_writers(&e->e_rdwr)); + assert(ldap_pvt_thread_rdwr_writers( &e->e_rdwr ) == 1); #endif - /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); - rc = cache_delete_entry_internal( cache, e ); /* free cache mutex */ diff --git a/servers/slapd/back-bdb2/close.c b/servers/slapd/back-bdb2/close.c index 90dda95068..647ba757ba 100644 --- a/servers/slapd/back-bdb2/close.c +++ b/servers/slapd/back-bdb2/close.c @@ -1,4 +1,4 @@ -/* close.c - close bdb2 backend */ +/* close.c - close bdb2 backend database */ #include "portable.h" @@ -10,23 +10,24 @@ #include "back-bdb2.h" static int -bdb2i_back_db_close_internal( Backend *be ) +bdb2i_back_db_close_internal( BackendDB *be ) { Debug( LDAP_DEBUG_TRACE, "bdb2 backend saving nextid\n", 0, 0, 0 ); if ( bdb2i_next_id_save( be ) < 0 ) { Debug( LDAP_DEBUG_ANY, "bdb2 backend nextid save failed!\n", 0, 0, 0 ); } - Debug( LDAP_DEBUG_TRACE, "bdb2 backend syncing\n", 0, 0, 0 ); - bdb2i_cache_flush_all( be ); - Debug( LDAP_DEBUG_TRACE, "bdb2 backend done syncing\n", 0, 0, 0 ); + /* close all DB files */ + Debug( LDAP_DEBUG_TRACE, "bdb2 backend closing DB files\n", 0, 0, 0 ); + bdb2i_txn_close_files( be ); + Debug( LDAP_DEBUG_TRACE, "bdb2 backend done closing DB files\n", 0, 0, 0 ); return 0; } int -bdb2_back_db_close( Backend *be ) +bdb2_back_db_close( BackendDB *be ) { struct timeval time1, time2; char *elapsed_time; diff --git a/servers/slapd/back-bdb2/compare.c b/servers/slapd/back-bdb2/compare.c index df38525b29..27a555182d 100644 --- a/servers/slapd/back-bdb2/compare.c +++ b/servers/slapd/back-bdb2/compare.c @@ -13,7 +13,7 @@ static int bdb2i_back_compare_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -64,7 +64,7 @@ return_results:; int bdb2_back_compare( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -80,7 +80,7 @@ bdb2_back_compare( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_r( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( 1 ); @@ -89,7 +89,7 @@ bdb2_back_compare( ret = bdb2i_back_compare_internal( be, conn, op, dn, ava ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/config.c b/servers/slapd/back-bdb2/config.c index 92d2e46db2..7fb2399def 100644 --- a/servers/slapd/back-bdb2/config.c +++ b/servers/slapd/back-bdb2/config.c @@ -10,9 +10,91 @@ #include "slap.h" #include "back-bdb2.h" +static int +bdb2i_back_config_internal( + BackendInfo *bi, + char *fname, + int lineno, + int argc, + char **argv +) +{ + struct ldbtype *lty = (struct ldbtype *) bi->bi_private; + + if ( lty == NULL ) { + fprintf( stderr, "%s: line %d: ldbm backend type info is null!\n", + fname, lineno ); + return( 1 ); + } + + /* directory where DB control files live */ + if ( strcasecmp( argv[0], "home" ) == 0 ) { + if ( argc < 2 ) { + fprintf( stderr, + "%s: line %d: missing dir in \"home \" line\n", + fname, lineno ); + return( 1 ); + } + lty->lty_dbhome = ch_strdup( argv[1] ); + + /* size of the DB memory pool */ + } else if ( strcasecmp( argv[0], "mpoolsize" ) == 0 ) { + if ( argc < 2 ) { + fprintf( stderr, + "%s: line %d: missing size in \"mpoolsize \" line\n", + fname, lineno ); + return( 1 ); + } + lty->lty_mpsize = (size_t) atoi( argv[1] ); + /* we should at least have the suggested 128k */ + if ( lty->lty_mpsize < DEFAULT_DBCACHE_SIZE ) + lty->lty_mpsize = DEFAULT_DBCACHE_SIZE; + + /* anything else */ + } else { + fprintf( stderr, +"%s: line %d: unknown directive \"%s\" in ldbm backend definition (ignored)\n", + fname, lineno, argv[0] ); + } + + return 0; +} + + +int +bdb2_back_config( + BackendInfo *bi, + char *fname, + int lineno, + int argc, + char **argv +) +{ + struct timeval time1, time2; + char *elapsed_time; + int ret; + + gettimeofday( &time1, NULL ); + + ret = bdb2i_back_config_internal( bi, fname, lineno, argc, argv ); + + if ( bdb2i_do_timing ) { + + gettimeofday( &time2, NULL); + elapsed_time = bdb2i_elapsed( time1, time2 ); + Debug( LDAP_DEBUG_TRACE, "BE-CONFIG elapsed=%s\n", + elapsed_time, 0, 0 ); + free( elapsed_time ); + + } + + return( ret ); +} + + static int bdb2i_back_db_config_internal( - Backend *be, + BackendDB *be, char *fname, int lineno, int argc, @@ -22,7 +104,7 @@ bdb2i_back_db_config_internal( struct ldbminfo *li = (struct ldbminfo *) be->be_private; if ( li == NULL ) { - fprintf( stderr, "%s: line %d: ldbm backend info is null!\n", + fprintf( stderr, "%s: line %d: ldbm database info is null!\n", fname, lineno ); return( 1 ); } @@ -38,7 +120,7 @@ bdb2i_back_db_config_internal( li->li_directory = ch_strdup( argv[1] ); li->li_nextid_file = - ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") ); + ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") + 1 ); strcpy(li->li_nextid_file, li->li_directory); strcat(li->li_nextid_file, "/NEXTID"); @@ -107,7 +189,7 @@ bdb2i_back_db_config_internal( int bdb2_back_db_config( - Backend *be, + BackendDB *be, char *fname, int lineno, int argc, @@ -126,7 +208,7 @@ bdb2_back_db_config( gettimeofday( &time2, NULL); elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "CONFIG elapsed=%s\n", + Debug( LDAP_DEBUG_ANY, "DB-CONFIG elapsed=%s\n", elapsed_time, 0, 0 ); free( elapsed_time ); diff --git a/servers/slapd/back-bdb2/dbcache.c b/servers/slapd/back-bdb2/dbcache.c index 259245a7ac..038d4b050e 100644 --- a/servers/slapd/back-bdb2/dbcache.c +++ b/servers/slapd/back-bdb2/dbcache.c @@ -19,12 +19,9 @@ #include "slap.h" #include "back-bdb2.h" -#define ldbm_open_env( buf, flags, mode, dbcachesize, env ) \ - ldbm_open( (buf), (flags), (mode), (dbcachesize) ) - struct dbcache * bdb2i_cache_open( - Backend *be, + BackendDB *be, char *name, char *suffix, int flags @@ -36,15 +33,19 @@ bdb2i_cache_open( char buf[MAXPATHLEN]; LDBM db; struct stat st; - int dbcachesize; - - /* sprintf( buf, "%s%s%s%s", li->li_directory, DEFAULT_DIRSEP, name, suffix ); */ - sprintf( buf, "%s%s", name, suffix ); /* if in slapd, all files are open, so return handle from file cache */ - if ( bdb2i_with_dbenv ) + if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) { + + /* use short name */ + sprintf( buf, "%s%s", name, suffix ); return( bdb2i_get_db_file_cache( li, buf )); + } + + /* use the absolute path */ + sprintf( buf, "%s%s%s%s", li->li_directory, DEFAULT_DIRSEP, name, suffix ); + Debug( LDAP_DEBUG_TRACE, "=> bdb2i_cache_open( \"%s\", %d, %o )\n", buf, flags, li->li_mode ); @@ -100,11 +101,8 @@ bdb2i_cache_open( li->li_dbcache[i].dbc_name = NULL; } - dbcachesize = li->li_dbcachesize; - - if ( bdb2i_with_dbenv ) dbcachesize = 0; - if ( (li->li_dbcache[i].dbc_db = ldbm_open_env( buf, flags, li->li_mode, - dbcachesize, &li->li_db_env )) == NULL ) { + if ( (li->li_dbcache[i].dbc_db = ldbm_open( buf, flags, li->li_mode, + 0 )) == NULL ) { Debug( LDAP_DEBUG_TRACE, "<= bdb2i_cache_open NULL \"%s\" errno %d reason \"%s\")\n", @@ -136,13 +134,14 @@ bdb2i_cache_open( } void -bdb2i_cache_close( Backend *be, struct dbcache *db ) +bdb2i_cache_close( BackendDB *be, struct dbcache *db ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; /* if in slapd, all files stay open and we have only readers or one writer */ - if ( bdb2i_with_dbenv ) return; + if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) + return; ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); if ( --db->dbc_refcnt == 0 ) { @@ -152,13 +151,14 @@ bdb2i_cache_close( Backend *be, struct dbcache *db ) } void -bdb2i_cache_really_close( Backend *be, struct dbcache *db ) +bdb2i_cache_really_close( BackendDB *be, struct dbcache *db ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; /* if in slapd, all files stay open and we have only readers or one writer */ - if ( bdb2i_with_dbenv ) return; + if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) + return; ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); if ( --db->dbc_refcnt == 0 ) { @@ -171,13 +171,14 @@ bdb2i_cache_really_close( Backend *be, struct dbcache *db ) } void -bdb2i_cache_flush_all( Backend *be ) +bdb2i_cache_flush_all( BackendDB *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; int i; /* if in slapd, syncing is done by TP */ - if ( bdb2i_with_dbenv ) return; + if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) + return; ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); for ( i = 0; i < MAXDBCACHE; i++ ) { diff --git a/servers/slapd/back-bdb2/delete.c b/servers/slapd/back-bdb2/delete.c index 241734c4d6..9b5335b149 100644 --- a/servers/slapd/back-bdb2/delete.c +++ b/servers/slapd/back-bdb2/delete.c @@ -13,7 +13,7 @@ static int bdb2i_back_delete_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn @@ -152,7 +152,7 @@ return_results:; int bdb2_back_delete( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn @@ -167,7 +167,7 @@ bdb2_back_delete( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_w( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -176,7 +176,7 @@ bdb2_back_delete( ret = bdb2i_back_delete_internal( be, conn, op, dn ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/dn2id.c b/servers/slapd/back-bdb2/dn2id.c index 5d960e5a1b..49e192ba74 100644 --- a/servers/slapd/back-bdb2/dn2id.c +++ b/servers/slapd/back-bdb2/dn2id.c @@ -13,7 +13,7 @@ int bdb2i_dn2id_add( - Backend *be, + BackendDB *be, char *dn, ID id ) @@ -57,7 +57,7 @@ bdb2i_dn2id_add( ID bdb2i_dn2id( - Backend *be, + BackendDB *be, char *dn ) { @@ -112,7 +112,7 @@ bdb2i_dn2id( int bdb2i_dn2id_delete( - Backend *be, + BackendDB *be, char *dn ) { @@ -155,7 +155,7 @@ bdb2i_dn2id_delete( static Entry * dn2entry( - Backend *be, + BackendDB *be, char *dn, char **matched, int rw @@ -210,7 +210,7 @@ dn2entry( Entry * bdb2i_dn2entry_r( - Backend *be, + BackendDB *be, char *dn, char **matched ) @@ -220,7 +220,7 @@ bdb2i_dn2entry_r( Entry * bdb2i_dn2entry_w( - Backend *be, + BackendDB *be, char *dn, char **matched ) diff --git a/servers/slapd/back-bdb2/external.h b/servers/slapd/back-bdb2/external.h index 0617d482e2..d3f5b535b8 100644 --- a/servers/slapd/back-bdb2/external.h +++ b/servers/slapd/back-bdb2/external.h @@ -8,6 +8,9 @@ extern int bdb2_back_open LDAP_P(( BackendInfo *bi )); extern int bdb2_back_close LDAP_P(( BackendInfo *bi )); extern int bdb2_back_destroy LDAP_P(( BackendInfo *bi )); +extern int bdb2_back_config LDAP_P(( BackendInfo *bt, + char *fname, int lineno, int argc, char **argv )); + extern int bdb2_back_db_init LDAP_P(( BackendDB *bd )); extern int bdb2_back_db_open LDAP_P(( BackendDB *bd )); extern int bdb2_back_db_close LDAP_P(( BackendDB *bd )); diff --git a/servers/slapd/back-bdb2/filterindex.c b/servers/slapd/back-bdb2/filterindex.c index 71b3556c9a..88a854a8b5 100644 --- a/servers/slapd/back-bdb2/filterindex.c +++ b/servers/slapd/back-bdb2/filterindex.c @@ -10,12 +10,12 @@ #include "slap.h" #include "back-bdb2.h" -static ID_BLOCK *ava_candidates( Backend *be, Ava *ava, int type ); -static ID_BLOCK *presence_candidates( Backend *be, char *type ); -static ID_BLOCK *approx_candidates( Backend *be, Ava *ava ); -static ID_BLOCK *list_candidates( Backend *be, Filter *flist, int ftype ); -static ID_BLOCK *substring_candidates( Backend *be, Filter *f ); -static ID_BLOCK *substring_comp_candidates( Backend *be, char *type, char *val, int prepost ); +static ID_BLOCK *ava_candidates( BackendDB *be, Ava *ava, int type ); +static ID_BLOCK *presence_candidates( BackendDB *be, char *type ); +static ID_BLOCK *approx_candidates( BackendDB *be, Ava *ava ); +static ID_BLOCK *list_candidates( BackendDB *be, Filter *flist, int ftype ); +static ID_BLOCK *substring_candidates( BackendDB *be, Filter *f ); +static ID_BLOCK *substring_comp_candidates( BackendDB *be, char *type, char *val, int prepost ); /* * test_filter - test a filter against a single entry. @@ -26,7 +26,7 @@ static ID_BLOCK *substring_comp_candidates( Backend *be, char *type, char *val, ID_BLOCK * bdb2i_filter_candidates( - Backend *be, + BackendDB *be, Filter *f ) { @@ -93,7 +93,7 @@ bdb2i_filter_candidates( static ID_BLOCK * ava_candidates( - Backend *be, + BackendDB *be, Ava *ava, int type ) @@ -124,7 +124,7 @@ ava_candidates( static ID_BLOCK * presence_candidates( - Backend *be, + BackendDB *be, char *type ) { @@ -141,7 +141,7 @@ presence_candidates( static ID_BLOCK * approx_candidates( - Backend *be, + BackendDB *be, Ava *ava ) { @@ -178,7 +178,7 @@ approx_candidates( static ID_BLOCK * list_candidates( - Backend *be, + BackendDB *be, Filter *flist, int ftype ) @@ -219,7 +219,7 @@ list_candidates( static ID_BLOCK * substring_candidates( - Backend *be, + BackendDB *be, Filter *f ) { @@ -286,7 +286,7 @@ substring_candidates( static ID_BLOCK * substring_comp_candidates( - Backend *be, + BackendDB *be, char *type, char *val, int prepost diff --git a/servers/slapd/back-bdb2/group.c b/servers/slapd/back-bdb2/group.c index 959699a259..a5d5fd65d4 100644 --- a/servers/slapd/back-bdb2/group.c +++ b/servers/slapd/back-bdb2/group.c @@ -19,7 +19,7 @@ */ static int bdb2i_back_group_internal( - Backend *be, + BackendDB *be, Entry *target, char *gr_ndn, char *op_ndn, @@ -126,7 +126,7 @@ bdb2i_back_group_internal( int bdb2_back_group( - Backend *be, + BackendDB *be, Entry *target, char *gr_ndn, char *op_ndn, @@ -143,7 +143,7 @@ bdb2_back_group( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_r( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { return( 1 ); @@ -152,7 +152,7 @@ bdb2_back_group( ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn, objectclassValue, groupattrName ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/id2children.c b/servers/slapd/back-bdb2/id2children.c index d404e393da..c1fc26e252 100644 --- a/servers/slapd/back-bdb2/id2children.c +++ b/servers/slapd/back-bdb2/id2children.c @@ -12,7 +12,7 @@ int bdb2i_id2children_add( - Backend *be, + BackendDB *be, Entry *p, Entry *e ) @@ -56,7 +56,7 @@ bdb2i_id2children_add( int bdb2i_id2children_remove( - Backend *be, + BackendDB *be, Entry *p, Entry *e ) @@ -98,7 +98,7 @@ bdb2i_id2children_remove( int bdb2i_has_children( - Backend *be, + BackendDB *be, Entry *p ) { diff --git a/servers/slapd/back-bdb2/id2entry.c b/servers/slapd/back-bdb2/id2entry.c index d999c54ceb..c397e198cd 100644 --- a/servers/slapd/back-bdb2/id2entry.c +++ b/servers/slapd/back-bdb2/id2entry.c @@ -10,7 +10,7 @@ #include "back-bdb2.h" int -bdb2i_id2entry_add( Backend *be, Entry *e ) +bdb2i_id2entry_add( BackendDB *be, Entry *e ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct dbcache *db; @@ -54,7 +54,7 @@ bdb2i_id2entry_add( Backend *be, Entry *e ) } int -bdb2i_id2entry_delete( Backend *be, Entry *e ) +bdb2i_id2entry_delete( BackendDB *be, Entry *e ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct dbcache *db; @@ -96,7 +96,7 @@ bdb2i_id2entry_delete( Backend *be, Entry *e ) /* XXX returns entry with reader/writer lock */ Entry * -bdb2i_id2entry( Backend *be, ID id, int rw ) +bdb2i_id2entry( BackendDB *be, ID id, int rw ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct dbcache *db; @@ -161,13 +161,13 @@ bdb2i_id2entry( Backend *be, ID id, int rw ) } Entry * -bdb2i_id2entry_r( Backend *be, ID id ) +bdb2i_id2entry_r( BackendDB *be, ID id ) { return( bdb2i_id2entry( be, id, 0 ) ); } Entry * -bdb2i_id2entry_w( Backend *be, ID id ) +bdb2i_id2entry_w( BackendDB *be, ID id ) { return( bdb2i_id2entry( be, id, 1 ) ); } diff --git a/servers/slapd/back-bdb2/idl.c b/servers/slapd/back-bdb2/idl.c index d9be424ced..dea359debc 100644 --- a/servers/slapd/back-bdb2/idl.c +++ b/servers/slapd/back-bdb2/idl.c @@ -30,7 +30,7 @@ bdb2i_idl_alloc( int nids ) /* Allocate an empty ALLIDS ID_BLOCK */ ID_BLOCK * -bdb2i_idl_allids( Backend *be ) +bdb2i_idl_allids( BackendDB *be ) { ID_BLOCK *idl; @@ -60,7 +60,7 @@ bdb2i_idl_free( ID_BLOCK *idl ) /* Fetch an single ID_BLOCK from the cache */ static ID_BLOCK * idl_fetch_one( - Backend *be, + BackendDB *be, struct dbcache *db, Datum key ) @@ -96,7 +96,7 @@ idl_fetch_one( */ ID_BLOCK * bdb2i_idl_fetch( - Backend *be, + BackendDB *be, struct dbcache *db, Datum key ) @@ -190,7 +190,7 @@ bdb2i_idl_fetch( /* store a single block */ static int idl_store( - Backend *be, + BackendDB *be, struct dbcache *db, Datum key, ID_BLOCK *idl @@ -276,7 +276,7 @@ idl_split_block( */ static int idl_change_first( - Backend *be, + BackendDB *be, struct dbcache *db, Datum hkey, /* header block key */ ID_BLOCK *h, /* header block */ @@ -320,7 +320,7 @@ idl_change_first( int bdb2i_idl_insert_key( - Backend *be, + BackendDB *be, struct dbcache *db, Datum key, ID id @@ -663,7 +663,7 @@ bdb2i_idl_insert( ID_BLOCK **idl, ID id, int maxids ) int bdb2i_idl_delete_key ( - Backend *be, + BackendDB *be, struct dbcache *db, Datum key, ID id @@ -801,7 +801,7 @@ idl_min( ID_BLOCK *a, ID_BLOCK *b ) */ ID_BLOCK * bdb2i_idl_intersection( - Backend *be, + BackendDB *be, ID_BLOCK *a, ID_BLOCK *b ) @@ -853,7 +853,7 @@ bdb2i_idl_intersection( */ ID_BLOCK * bdb2i_idl_union( - Backend *be, + BackendDB *be, ID_BLOCK *a, ID_BLOCK *b ) @@ -912,7 +912,7 @@ bdb2i_idl_union( */ ID_BLOCK * bdb2i_idl_notin( - Backend *be, + BackendDB *be, ID_BLOCK *a, ID_BLOCK *b ) diff --git a/servers/slapd/back-bdb2/index.c b/servers/slapd/back-bdb2/index.c index 9d99a38d99..e8c0c7a0a9 100644 --- a/servers/slapd/back-bdb2/index.c +++ b/servers/slapd/back-bdb2/index.c @@ -10,12 +10,12 @@ #include "slap.h" #include "back-bdb2.h" -static int add_value(Backend *be, struct dbcache *db, char *type, int indextype, char *val, ID id); +static int add_value(BackendDB *be, struct dbcache *db, char *type, int indextype, char *val, ID id); static int index2prefix(int indextype); int bdb2i_index_add_entry( - Backend *be, + BackendDB *be, Entry *e ) { @@ -55,7 +55,7 @@ bdb2i_index_add_entry( int bdb2i_index_add_mods( - Backend *be, + BackendDB *be, LDAPModList *ml, ID id ) @@ -87,7 +87,7 @@ bdb2i_index_add_mods( ID_BLOCK * bdb2i_index_read( - Backend *be, + BackendDB *be, char *type, int indextype, char *val @@ -158,7 +158,7 @@ bdb2i_index_read( static int add_value( - Backend *be, + BackendDB *be, struct dbcache *db, char *type, int indextype, @@ -168,19 +168,17 @@ add_value( { int rc; Datum key; - ID_BLOCK *idl; - char prefix; - char *realval, *tmpval, *s; + ID_BLOCK *idl = NULL; + char *tmpval = NULL; + char *realval = val; char buf[BUFSIZ]; + char prefix = index2prefix( indextype ); + ldbm_datum_init( key ); - prefix = index2prefix( indextype ); Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 ); - realval = val; - tmpval = NULL; - idl = NULL; if ( prefix != UNKNOWN_PREFIX ) { unsigned int len = strlen( val ); @@ -203,7 +201,10 @@ add_value( if ( tmpval != NULL ) { free( tmpval ); } - bdb2i_idl_free( idl ); + + if( idl != NULL ) { + bdb2i_idl_free( idl ); + } ldap_pvt_thread_yield(); @@ -213,7 +214,7 @@ add_value( int bdb2i_index_add_values( - Backend *be, + BackendDB *be, char *type, struct berval **vals, ID id diff --git a/servers/slapd/back-bdb2/init.c b/servers/slapd/back-bdb2/init.c index 6a3f55eb8e..1bdbda54b2 100644 --- a/servers/slapd/back-bdb2/init.c +++ b/servers/slapd/back-bdb2/init.c @@ -11,13 +11,35 @@ #include "back-bdb2.h" +static int +bdb2i_back_init_private( + BackendInfo *bi +) +{ + struct ldbtype *bt; + + /* allocate backend-type-specific stuff */ + bt = (struct ldbtype *) ch_calloc( 1, sizeof(struct ldbtype) ); + + bt->lty_dbhome = DEFAULT_DB_HOME; + bt->lty_mpsize = DEFAULT_DBCACHE_SIZE; + bt->lty_dbenv = &ldbm_Env; + + bi->bi_private = bt; + + return 0; +} + + int bdb2_back_initialize( BackendInfo *bi ) { + int ret; + bi->bi_open = bdb2_back_open; - bi->bi_config = NULL; + bi->bi_config = bdb2_back_config; bi->bi_close = bdb2_back_close; bi->bi_destroy = bdb2_back_destroy; @@ -37,9 +59,15 @@ bdb2_back_initialize( bi->bi_op_delete = bdb2_back_delete; bi->bi_op_abandon = bdb2_back_abandon; +#ifdef SLAPD_ACLGROUPS bi->bi_acl_group = bdb2_back_group; +#endif - return 0; + ret = bdb2i_back_init_private( bi ); + + Debug( LDAP_DEBUG_TRACE, "bdb2_back_initialize: done (%d).\n", ret, 0, 0 ); + + return( ret ); } int @@ -55,10 +83,19 @@ bdb2_back_open( BackendInfo *bi ) { + static int initialized = 0; int rc; + if ( initialized++ ) { + + Debug( LDAP_DEBUG_TRACE, + "bdb2_back_open: backend already initialized.\n", 0, 0, 0 ); + return 0; + + } + /* initialize the underlying database system */ - rc = bdb2_initialize(); + rc = bdb2i_back_startup( bi ); return rc; } @@ -68,23 +105,25 @@ bdb2_back_close( BackendInfo *bi ) { + int rc; + /* close the underlying database system */ - bdb2_shutdown(); + rc = bdb2i_back_shutdown( bi ); - return 0; + return rc; } /* BDB2 changed */ static int bdb2i_back_db_init_internal( - Backend *be + BackendDB *be ) { struct ldbminfo *li; char *argv[ 4 ]; int i; - /* allocate backend-specific stuff */ + /* allocate backend-database-specific stuff */ li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) ); /* arrange to read nextid later (on first request for it) */ @@ -139,7 +178,8 @@ bdb2i_back_db_init_internal( ldap_pvt_thread_cond_init( &li->li_dbcache_cv ); /* initialize the TP file head */ - bdb2i_txn_head_init( &li->li_txn_head ); + if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 ) + return 1; be->be_private = li; @@ -149,7 +189,7 @@ bdb2i_back_db_init_internal( int bdb2_back_db_init( - Backend *be + BackendDB *be ) { struct timeval time1, time2; @@ -164,7 +204,7 @@ bdb2_back_db_init( gettimeofday( &time2, NULL); elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "INIT elapsed=%s\n", + Debug( LDAP_DEBUG_ANY, "DB-INIT elapsed=%s\n", elapsed_time, 0, 0 ); free( elapsed_time ); @@ -179,7 +219,11 @@ bdb2_back_db_open( BackendDB *be ) { - return 0; + int rc; + + rc = bdb2_back_db_startup( be ); + + return( rc ); } int diff --git a/servers/slapd/back-bdb2/kerberos.c b/servers/slapd/back-bdb2/kerberos.c index c7a917a893..26de882162 100644 --- a/servers/slapd/back-bdb2/kerberos.c +++ b/servers/slapd/back-bdb2/kerberos.c @@ -19,7 +19,7 @@ extern char *ldap_srvtab; extern Attribute *attr_find(); bdb2i_krbv4_ldap_auth( - Backend *be, + BackendDB *be, struct berval *cred, AUTH_DAT *ad ) diff --git a/servers/slapd/back-bdb2/modify.c b/servers/slapd/back-bdb2/modify.c index f36ba6e653..86f319fd86 100644 --- a/servers/slapd/back-bdb2/modify.c +++ b/servers/slapd/back-bdb2/modify.c @@ -17,7 +17,7 @@ static int replace_values(Entry *e, LDAPMod *mod, char *dn); static int bdb2i_back_modify_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -117,7 +117,7 @@ error_return:; int bdb2_back_modify( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -133,7 +133,7 @@ bdb2_back_modify( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_w( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -142,12 +142,12 @@ bdb2_back_modify( /* check, if a new default attribute index will be created, in which case we have to open the index file BEFORE TP */ - if ( bdb2i_with_dbenv ) + if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) bdb2i_check_default_attr_index_mod( li, modlist ); ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/modrdn.c b/servers/slapd/back-bdb2/modrdn.c index b79a429a46..ea49bdd265 100644 --- a/servers/slapd/back-bdb2/modrdn.c +++ b/servers/slapd/back-bdb2/modrdn.c @@ -13,7 +13,7 @@ static int bdb2i_back_modrdn_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -192,7 +192,7 @@ return_results: int bdb2_back_modrdn( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn, @@ -209,7 +209,7 @@ bdb2_back_modrdn( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_w( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -219,7 +219,7 @@ bdb2_back_modrdn( ret = bdb2i_back_modrdn_internal( be, conn, op, dn, newrdn, deleteoldrdn ); - (void) bdb2i_leave_backend( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { diff --git a/servers/slapd/back-bdb2/nextid.c b/servers/slapd/back-bdb2/nextid.c index c4d1eb4719..88013e6d9b 100644 --- a/servers/slapd/back-bdb2/nextid.c +++ b/servers/slapd/back-bdb2/nextid.c @@ -14,7 +14,7 @@ #include "back-bdb2.h" static ID -next_id_read( Backend *be ) +next_id_read( BackendDB *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id; @@ -51,7 +51,7 @@ next_id_read( Backend *be ) } static int -next_id_write( Backend *be, ID id ) +next_id_write( BackendDB *be, ID id ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; char buf[20]; @@ -83,7 +83,7 @@ next_id_write( Backend *be, ID id ) } int -bdb2i_next_id_save( Backend *be ) +bdb2i_next_id_save( BackendDB *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id = next_id_get( be ); @@ -97,7 +97,7 @@ bdb2i_next_id_save( Backend *be ) } ID -bdb2i_next_id( Backend *be ) +bdb2i_next_id( BackendDB *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id; @@ -133,7 +133,7 @@ bdb2i_next_id( Backend *be ) } void -bdb2i_next_id_return( Backend *be, ID id ) +bdb2i_next_id_return( BackendDB *be, ID id ) { #ifdef SLAPD_NEXTID_RETURN struct ldbminfo *li = (struct ldbminfo *) be->be_private; @@ -156,7 +156,7 @@ bdb2i_next_id_return( Backend *be, ID id ) } ID -bdb2i_next_id_get( Backend *be ) +bdb2i_next_id_get( BackendDB *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id; diff --git a/servers/slapd/back-bdb2/porter.c b/servers/slapd/back-bdb2/porter.c index 6047463614..42e2cf9d16 100644 --- a/servers/slapd/back-bdb2/porter.c +++ b/servers/slapd/back-bdb2/porter.c @@ -12,8 +12,6 @@ #define PORTER_OBJ "bdb2_backend" -int bdb2i_with_dbenv = 0; - static int bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) @@ -23,7 +21,8 @@ bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) DBT lock_dbt; int ret; - if ( !bdb2i_with_dbenv ) return( 0 ); + if ( ( slapMode != SLAP_SERVER_MODE ) && ( slapMode != SLAP_TOOL_MODE ) ) + return( 0 ); if ( ( ret = lock_id( dbEnv->lk_info, &locker )) != 0 ) { @@ -42,7 +41,7 @@ bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer ) lock_type, lock ))) { case 0: - Debug( LDAP_DEBUG_ANY, "bdb2i_enter_backend() -- %s lock granted\n", + Debug( LDAP_DEBUG_TRACE, "bdb2i_enter_backend() -- %s lock granted\n", writer ? "write" : "read", 0, 0 ); break; @@ -90,12 +89,13 @@ bdb2i_leave_backend( DB_ENV *dbEnv, DB_LOCK lock ) { int ret; - if ( !bdb2i_with_dbenv ) return( 0 ); + if ( ( slapMode != SLAP_SERVER_MODE ) && ( slapMode != SLAP_TOOL_MODE ) ) + return( 0 ); switch( ( ret = lock_put( dbEnv->lk_info, lock ))) { case 0: - Debug( LDAP_DEBUG_ANY, "bdb2i_leave_backend() -- lock released\n", + Debug( LDAP_DEBUG_TRACE, "bdb2i_leave_backend() -- lock released\n", 0, 0, 0 ); break; diff --git a/servers/slapd/back-bdb2/proto-back-bdb2.h b/servers/slapd/back-bdb2/proto-back-bdb2.h index f85fabc8bb..0a10c2cf1d 100644 --- a/servers/slapd/back-bdb2/proto-back-bdb2.h +++ b/servers/slapd/back-bdb2/proto-back-bdb2.h @@ -11,12 +11,12 @@ LDAP_BEGIN_DECL * alias.c */ Entry *bdb2i_derefAlias_r LDAP_P(( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, Entry *e )); char *bdb2i_derefDN LDAP_P(( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *dn )); @@ -39,7 +39,7 @@ void bdb2i_cache_return_entry_r LDAP_P(( struct cache *cache, Entry *e )); void bdb2i_cache_return_entry_w LDAP_P(( struct cache *cache, Entry *e )); int bdb2i_cache_add_entry_lock LDAP_P(( struct cache *cache, Entry *e, int state )); -ID bdb2i_cache_find_entry_dn2id LDAP_P(( Backend *be, struct cache *cache, +ID bdb2i_cache_find_entry_dn2id LDAP_P(( BackendDB *be, struct cache *cache, char *dn )); Entry * bdb2i_cache_find_entry_id LDAP_P(( struct cache *cache, ID id, int rw )); int bdb2i_cache_delete_entry LDAP_P(( struct cache *cache, Entry *e )); @@ -48,11 +48,11 @@ int bdb2i_cache_delete_entry LDAP_P(( struct cache *cache, Entry *e )); * dbcache.c */ -struct dbcache * bdb2i_cache_open LDAP_P(( Backend *be, char *name, char *suffix, +struct dbcache * bdb2i_cache_open LDAP_P(( BackendDB *be, char *name, char *suffix, int flags )); -void bdb2i_cache_close LDAP_P(( Backend *be, struct dbcache *db )); -void bdb2i_cache_really_close LDAP_P(( Backend *be, struct dbcache *db )); -void bdb2i_cache_flush_all LDAP_P(( Backend *be )); +void bdb2i_cache_close LDAP_P(( BackendDB *be, struct dbcache *db )); +void bdb2i_cache_really_close LDAP_P(( BackendDB *be, struct dbcache *db )); +void bdb2i_cache_flush_all LDAP_P(( BackendDB *be )); Datum bdb2i_cache_fetch LDAP_P(( struct dbcache *db, Datum key )); int bdb2i_cache_store LDAP_P(( struct dbcache *db, Datum key, Datum data, int flags )); int bdb2i_cache_delete LDAP_P(( struct dbcache *db, Datum key )); @@ -61,50 +61,50 @@ int bdb2i_cache_delete LDAP_P(( struct dbcache *db, Datum key )); * dn2id.c */ -int bdb2i_dn2id_add LDAP_P(( Backend *be, char *dn, ID id )); -ID bdb2i_dn2id LDAP_P(( Backend *be, char *dn )); -int bdb2i_dn2id_delete LDAP_P(( Backend *be, char *dn )); -Entry * bdb2i_dn2entry_r LDAP_P(( Backend *be, char *dn, char **matched )); -Entry * bdb2i_dn2entry_w LDAP_P(( Backend *be, char *dn, char **matched )); +int bdb2i_dn2id_add LDAP_P(( BackendDB *be, char *dn, ID id )); +ID bdb2i_dn2id LDAP_P(( BackendDB *be, char *dn )); +int bdb2i_dn2id_delete LDAP_P(( BackendDB *be, char *dn )); +Entry * bdb2i_dn2entry_r LDAP_P(( BackendDB *be, char *dn, char **matched )); +Entry * bdb2i_dn2entry_w LDAP_P(( BackendDB *be, char *dn, char **matched )); /* * filterindex.c */ -ID_BLOCK * bdb2i_filter_candidates LDAP_P(( Backend *be, Filter *f )); +ID_BLOCK * bdb2i_filter_candidates LDAP_P(( BackendDB *be, Filter *f )); /* * id2children.c */ -int bdb2i_id2children_add LDAP_P(( Backend *be, Entry *p, Entry *e )); -int bdb2i_id2children_remove LDAP_P(( Backend *be, Entry *p, Entry *e )); -int bdb2i_has_children LDAP_P(( Backend *be, Entry *p )); +int bdb2i_id2children_add LDAP_P(( BackendDB *be, Entry *p, Entry *e )); +int bdb2i_id2children_remove LDAP_P(( BackendDB *be, Entry *p, Entry *e )); +int bdb2i_has_children LDAP_P(( BackendDB *be, Entry *p )); /* * id2entry.c */ -int bdb2i_id2entry_add LDAP_P(( Backend *be, Entry *e )); -int bdb2i_id2entry_delete LDAP_P(( Backend *be, Entry *e )); -Entry * bdb2i_id2entry LDAP_P(( Backend *be, ID id, int rw )); -Entry * bdb2i_id2entry_r LDAP_P(( Backend *be, ID id )); -Entry * bdb2i_id2entry_w LDAP_P(( Backend *be, ID id )); +int bdb2i_id2entry_add LDAP_P(( BackendDB *be, Entry *e )); +int bdb2i_id2entry_delete LDAP_P(( BackendDB *be, Entry *e )); +Entry * bdb2i_id2entry LDAP_P(( BackendDB *be, ID id, int rw )); +Entry * bdb2i_id2entry_r LDAP_P(( BackendDB *be, ID id )); +Entry * bdb2i_id2entry_w LDAP_P(( BackendDB *be, ID id )); /* * idl.c */ ID_BLOCK * bdb2i_idl_alloc LDAP_P(( int nids )); -ID_BLOCK * bdb2i_idl_allids LDAP_P(( Backend *be )); +ID_BLOCK * bdb2i_idl_allids LDAP_P(( BackendDB *be )); void bdb2i_idl_free LDAP_P(( ID_BLOCK *idl )); -ID_BLOCK * bdb2i_idl_fetch LDAP_P(( Backend *be, struct dbcache *db, Datum key )); -int bdb2i_idl_insert_key LDAP_P(( Backend *be, struct dbcache *db, Datum key, ID id )); +ID_BLOCK * bdb2i_idl_fetch LDAP_P(( BackendDB *be, struct dbcache *db, Datum key )); +int bdb2i_idl_insert_key LDAP_P(( BackendDB *be, struct dbcache *db, Datum key, ID id )); int bdb2i_idl_insert LDAP_P(( ID_BLOCK **idl, ID id, int maxids )); -int bdb2i_idl_delete_key LDAP_P(( Backend *be, struct dbcache *db, Datum key, ID id )); -ID_BLOCK * bdb2i_idl_intersection LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b )); -ID_BLOCK * bdb2i_idl_union LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b )); -ID_BLOCK * bdb2i_idl_notin LDAP_P(( Backend *be, ID_BLOCK *a, ID_BLOCK *b )); +int bdb2i_idl_delete_key LDAP_P(( BackendDB *be, struct dbcache *db, Datum key, ID id )); +ID_BLOCK * bdb2i_idl_intersection LDAP_P(( BackendDB *be, ID_BLOCK *a, ID_BLOCK *b )); +ID_BLOCK * bdb2i_idl_union LDAP_P(( BackendDB *be, ID_BLOCK *a, ID_BLOCK *b )); +ID_BLOCK * bdb2i_idl_notin LDAP_P(( BackendDB *be, ID_BLOCK *a, ID_BLOCK *b )); ID bdb2i_idl_firstid LDAP_P(( ID_BLOCK *idl )); ID bdb2i_idl_nextid LDAP_P(( ID_BLOCK *idl, ID id )); @@ -112,27 +112,36 @@ ID bdb2i_idl_nextid LDAP_P(( ID_BLOCK *idl, ID id )); * index.c */ -int bdb2i_index_add_entry LDAP_P(( Backend *be, Entry *e )); -int bdb2i_index_add_mods LDAP_P(( Backend *be, LDAPModList *ml, ID id )); -ID_BLOCK * bdb2i_index_read LDAP_P(( Backend *be, char *type, int indextype, char *val )); -int bdb2i_index_add_values LDAP_P(( Backend *be, char *type, struct berval **vals, ID id )); +int bdb2i_index_add_entry LDAP_P(( BackendDB *be, Entry *e )); +int bdb2i_index_add_mods LDAP_P(( BackendDB *be, LDAPModList *ml, ID id )); +ID_BLOCK * bdb2i_index_read LDAP_P(( BackendDB *be, char *type, int indextype, char *val )); +int bdb2i_index_add_values LDAP_P(( BackendDB *be, char *type, struct berval **vals, ID id )); /* * kerberos.c */ #ifdef HAVE_KERBEROS -/* bdb2i_krbv4_ldap_auth LDAP_P(( Backend *be, struct berval *cred, AUTH_DAT *ad )); */ +/* bdb2i_krbv4_ldap_auth LDAP_P(( BackendDB *be, struct berval *cred, AUTH_DAT *ad )); */ #endif /* * nextid.c */ -ID bdb2i_next_id LDAP_P(( Backend *be )); -void bdb2i_next_id_return LDAP_P(( Backend *be, ID id )); -ID bdb2i_next_id_get LDAP_P(( Backend *be )); -int bdb2i_next_id_save LDAP_P(( Backend *be )); +ID bdb2i_next_id LDAP_P(( BackendDB *be )); +void bdb2i_next_id_return LDAP_P(( BackendDB *be, ID id )); +ID bdb2i_next_id_get LDAP_P(( BackendDB *be )); +int bdb2i_next_id_save LDAP_P(( BackendDB *be )); + +/* + * startup.c + */ + +int bdb2i_back_startup LDAP_P(( BackendInfo *bi )); +int bdb2i_back_shutdown LDAP_P(( BackendInfo *bi )); +int bdb2i_back_db_startup LDAP_P(( BackendDB *be )); +int bdb2i_back_db_shutdown LDAP_P(( BackendDB *be )); /* * timing.c @@ -153,17 +162,17 @@ int bdb2i_leave_backend LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock )); * txn.c */ -void bdb2i_txn_head_init LDAP_P(( BDB2_TXN_HEAD *head )); +int bdb2i_txn_head_init LDAP_P(( BDB2_TXN_HEAD *head )); void bdb2i_txn_attr_config LDAP_P(( struct ldbminfo *li, char *attr, int open )); -void bdb2i_txn_open_files LDAP_P(( struct ldbminfo *li )); -void bdb2i_txn_close_files LDAP_P(( BDB2_TXN_HEAD *head )); +int bdb2i_txn_open_files LDAP_P(( struct ldbminfo *li )); +void bdb2i_txn_close_files LDAP_P(( BackendDB *be )); BDB2_TXN_FILES *bdb2i_get_db_file_cache LDAP_P(( struct ldbminfo *li, char *name )); -void bdb2i_check_additional_attr_index LDAP_P(( struct ldbminfo *li )); +int bdb2i_check_additional_attr_index LDAP_P(( struct ldbminfo *li )); void bdb2i_check_default_attr_index_add LDAP_P(( struct ldbminfo *li, Entry *e )); diff --git a/servers/slapd/back-bdb2/search.c b/servers/slapd/back-bdb2/search.c index 75afff6edb..073fe951b2 100644 --- a/servers/slapd/back-bdb2/search.c +++ b/servers/slapd/back-bdb2/search.c @@ -11,9 +11,9 @@ #include "back-bdb2.h" #include "proto-back-bdb2.h" -static ID_BLOCK *base_candidates(Backend *be, Connection *conn, Operation *op, char *base, Filter *filter, char **attrs, int attrsonly, char **matched, int *err); -static ID_BLOCK *onelevel_candidates(Backend *be, Connection *conn, Operation *op, char *base, Filter *filter, char **attrs, int attrsonly, char **matched, int *err); -static ID_BLOCK *subtree_candidates(Backend *be, Connection *conn, Operation *op, char *base, Filter *filter, char **attrs, int attrsonly, char **matched, Entry *e, int *err, int lookupbase); +static ID_BLOCK *base_candidates(BackendDB *be, Connection *conn, Operation *op, char *base, Filter *filter, char **attrs, int attrsonly, char **matched, int *err); +static ID_BLOCK *onelevel_candidates(BackendDB *be, Connection *conn, Operation *op, char *base, Filter *filter, char **attrs, int attrsonly, char **matched, int *err); +static ID_BLOCK *subtree_candidates(BackendDB *be, Connection *conn, Operation *op, char *base, Filter *filter, char **attrs, int attrsonly, char **matched, Entry *e, int *err, int lookupbase); #define GRABSIZE BUFSIZ @@ -28,7 +28,7 @@ static ID_BLOCK *subtree_candidates(Backend *be, Connection *conn, Operation *op static int bdb2i_back_search_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *base, @@ -316,7 +316,7 @@ bdb2i_back_search_internal( int bdb2_back_search( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *base, @@ -339,7 +339,7 @@ bdb2_back_search( gettimeofday( &time1, NULL ); - if ( bdb2i_enter_backend_r( &li->li_db_env, &lock ) != 0 ) { + if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) { send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); return( -1 ); @@ -349,7 +349,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( &li->li_db_env, lock ); + (void) bdb2i_leave_backend( get_dbenv( be ), lock ); if ( bdb2i_do_timing ) { @@ -367,7 +367,7 @@ bdb2_back_search( static ID_BLOCK * base_candidates( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *base, @@ -408,7 +408,7 @@ base_candidates( static ID_BLOCK * onelevel_candidates( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *base, @@ -471,7 +471,7 @@ onelevel_candidates( static ID_BLOCK * subtree_candidates( - Backend *be, + BackendDB *be, Connection *conn, Operation *op, char *base, diff --git a/servers/slapd/back-bdb2/startup.c b/servers/slapd/back-bdb2/startup.c index c27f6ad54d..6e526ab88d 100644 --- a/servers/slapd/back-bdb2/startup.c +++ b/servers/slapd/back-bdb2/startup.c @@ -1,4 +1,4 @@ -/* startup.c - startup bdb2 backend */ +/* startup.c - startup/shutdown bdb2 backend */ #include "portable.h" @@ -23,53 +23,30 @@ bdb2i_db_errcall( char *prefix, char *message ) } -void +/* startup/shutdown per backend type */ + +static int bdb2i_back_startup_internal( - Backend *be + BackendInfo *bi ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - DB_ENV *dbEnv = &li->li_db_env; + struct ldbtype *lty = (struct ldbtype *) bi->bi_private; + DB_ENV *dbEnv = lty->lty_dbenv; int envFlags = DB_CREATE | DB_THREAD | DB_INIT_LOCK | DB_INIT_MPOOL; int err = 0; char *home; - char datadir[MAXPATHLEN]; - char *config[2] = { datadir, NULL }; - /* if the data directory is not an absolute path, have it relative - to the current working directory (which should not be configured !) */ - if ( *li->li_directory != *DEFAULT_DIRSEP ) { + /* make sure, dbhome is an absolute path */ + if ( *lty->lty_dbhome != *DEFAULT_DIRSEP ) { char cwd[MAXPATHLEN]; (void) getcwd( cwd, MAXPATHLEN ); - sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory ); - free( li->li_directory ); - li->li_directory = strdup( cwd ); - - } - - /* set the DB home directory to the configured one, or the data dir */ - if ( li->li_dbhome ) { - - if ( *li->li_dbhome != *DEFAULT_DIRSEP ) { - char cwd[MAXPATHLEN]; - - (void) getcwd( cwd, MAXPATHLEN ); - sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_dbhome ); - free( li->li_dbhome ); - li->li_dbhome = strdup( cwd ); - - } - home = li->li_dbhome; - - } else { - - home = li->li_directory; + sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, lty->lty_dbhome ); + free( lty->lty_dbhome ); + lty->lty_dbhome = strdup( cwd ); } - - /* set the DATA_DIR */ - sprintf( datadir, "DB_DATA_DIR %s", li->li_directory ); + home = lty->lty_dbhome; /* general initialization of the environment */ memset( dbEnv, 0, sizeof( DB_ENV )); @@ -83,45 +60,35 @@ bdb2i_back_startup_internal( remove_old_locks( home ); /* initialize the mpool subsystem */ - dbEnv->mp_size = (size_t) li->li_dbcachesize; + dbEnv->mp_size = lty->lty_mpsize; /* now do the db_appinit */ - if ( ( err = db_appinit( home, config, dbEnv, envFlags )) ) { + if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) { char error[BUFSIZ]; if ( err < 0 ) sprintf( error, "%ld\n", (long) err ); else sprintf( error, "%s\n", strerror( err )); - fprintf( stderr, + Debug( LDAP_DEBUG_ANY, "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n", - error ); - exit( 1 ); + error, 0, 0 ); + return( 1 ); } - bdb2i_with_dbenv = 1; - - /* if there are more index files, add them to the DB file list */ - bdb2i_check_additional_attr_index( li ); - - /* now open all DB files */ - bdb2i_txn_open_files( li ); - + return 0; } -static void +static int bdb2i_back_shutdown_internal( - Backend *be + BackendInfo *bi ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - DB_ENV *dbEnv = &li->li_db_env; + struct ldbtype *lty = (struct ldbtype *) bi->bi_private; + DB_ENV *dbEnv = lty->lty_dbenv; int err; - /* close all DB files */ - bdb2i_txn_close_files( &li->li_txn_head ); - /* remove old locking tables */ dbEnv->db_errpfx = "bdb2i_back_shutdown(): lock_unlink:"; if ( ( err = lock_unlink( NULL, 1, dbEnv )) != 0 ) @@ -134,56 +101,159 @@ bdb2i_back_shutdown_internal( Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n", strerror( err ), 0, 0); - (void) db_appexit( &li->li_db_env ); + (void) db_appexit( dbEnv ); + + return( 0 ); +} + + +int +bdb2i_back_startup( + BackendInfo *bi +) +{ + struct timeval time1, time2; + char *elapsed_time; + int ret; + + gettimeofday( &time1, NULL ); + + ret = bdb2i_back_startup_internal( bi ); + + if ( bdb2i_do_timing ) { + + gettimeofday( &time2, NULL); + elapsed_time = bdb2i_elapsed( time1, time2 ); + Debug( LDAP_DEBUG_ANY, "BE-START elapsed=%s\n", + elapsed_time, 0, 0 ); + free( elapsed_time ); + + } + + return( ret ); +} + +int +bdb2i_back_shutdown( + BackendInfo *bi +) +{ + struct timeval time1, time2; + char *elapsed_time; + int ret; + + gettimeofday( &time1, NULL ); + + ret = bdb2i_back_shutdown_internal( bi ); + + if ( bdb2i_do_timing ) { + + gettimeofday( &time2, NULL); + elapsed_time = bdb2i_elapsed( time1, time2 ); + Debug( LDAP_DEBUG_ANY, "BE-SHUTDOWN elapsed=%s\n", + elapsed_time, 0, 0 ); + free( elapsed_time ); + + } + + return( ret ); +} + + +/* startup/shutdown per backend database */ + +static int +bdb2i_back_db_startup_internal( + BackendDB *be +) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + + /* if the data directory is not an absolute path, have it relative + to the current working directory (which should not be configured !) */ + if ( *li->li_directory != *DEFAULT_DIRSEP ) { + char cwd[MAXPATHLEN]; + + (void) getcwd( cwd, MAXPATHLEN ); + sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory ); + free( li->li_directory ); + li->li_directory = strdup( cwd ); + + } + + /* if there are more index files, add them to the DB file list */ + if ( bdb2i_check_additional_attr_index( li ) != 0 ) + return 1; + + /* now open all DB files */ + if ( bdb2i_txn_open_files( li ) != 0 ) + return 1; + + return 0; +} + + +static int +bdb2i_back_db_shutdown_internal( + BackendDB *be +) +{ + return 0; } -void -bdb2_back_startup( - Backend *be +int +bdb2_back_db_startup( + BackendDB *be ) { struct timeval time1, time2; char *elapsed_time; + int ret; gettimeofday( &time1, NULL ); - bdb2i_back_startup_internal( be ); + ret = bdb2i_back_db_startup_internal( be ); if ( bdb2i_do_timing ) { gettimeofday( &time2, NULL); elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "START elapsed=%s\n", + Debug( LDAP_DEBUG_ANY, "DB-START elapsed=%s\n", elapsed_time, 0, 0 ); free( elapsed_time ); } + + return( ret ); } -void -bdb2_back_shutdown( - Backend *be +int +bdb2_back_db_shutdown( + BackendDB *be ) { struct timeval time1, time2; char *elapsed_time; + int ret; gettimeofday( &time1, NULL ); - bdb2i_back_shutdown_internal( be ); + ret = bdb2i_back_db_shutdown_internal( be ); if ( bdb2i_do_timing ) { gettimeofday( &time2, NULL); elapsed_time = bdb2i_elapsed( time1, time2 ); - Debug( LDAP_DEBUG_ANY, "SHUTDOWN elapsed=%s\n", + Debug( LDAP_DEBUG_ANY, "DB-SHUTDOWN elapsed=%s\n", elapsed_time, 0, 0 ); free( elapsed_time ); } + + return( ret ); } diff --git a/servers/slapd/back-bdb2/txn.c b/servers/slapd/back-bdb2/txn.c index 335f9c549f..a5df7a9724 100644 --- a/servers/slapd/back-bdb2/txn.c +++ b/servers/slapd/back-bdb2/txn.c @@ -3,7 +3,7 @@ #include "txn.h" -void +int bdb2i_txn_head_init( BDB2_TXN_HEAD *head ) { int dbFile; @@ -16,13 +16,12 @@ bdb2i_txn_head_init( BDB2_TXN_HEAD *head ) char fileName[MAXPATHLEN]; - *fileNodeH = head->dbFileHandle[dbFile] = - (BDB2_TXN_FILES *) ch_calloc( 1, sizeof( BDB2_TXN_FILES )); + *fileNodeH = (BDB2_TXN_FILES *) ch_calloc( 1, sizeof( BDB2_TXN_FILES )); if ( *fileNodeH == NULL ) { Debug( LDAP_DEBUG_ANY, "bdb2i_txn_head_init(): out of memory!\n", 0, 0, 0 ); - exit( 1 ); + return( 1 ); } @@ -33,6 +32,7 @@ bdb2i_txn_head_init( BDB2_TXN_HEAD *head ) } + return 0; } @@ -43,9 +43,9 @@ bdb2i_init_db_file_cache( struct ldbminfo *li, BDB2_TXN_FILES *fileinfo ) struct stat st; char buf[MAXPATHLEN]; - pthread_mutex_lock( ¤ttime_mutex ); + ldap_pvt_thread_mutex_lock( ¤ttime_mutex ); curtime = currenttime; - pthread_mutex_unlock( ¤ttime_mutex ); + ldap_pvt_thread_mutex_unlock( ¤ttime_mutex ); fileinfo->dbc_refcnt = 1; fileinfo->dbc_lastref = curtime; @@ -58,7 +58,8 @@ bdb2i_init_db_file_cache( struct ldbminfo *li, BDB2_TXN_FILES *fileinfo ) fileinfo->dbc_blksize = DEFAULT_BLOCKSIZE; } - fileinfo->dbc_maxids = ( fileinfo->dbc_blksize / sizeof( ID )) - 2; + fileinfo->dbc_maxids = ( fileinfo->dbc_blksize / sizeof( ID )) - + ID_BLOCK_IDS_OFFSET; fileinfo->dbc_maxindirect = ( SLAPD_LDBM_MIN_MAXIDS / fileinfo->dbc_maxids ) + 1; @@ -122,9 +123,12 @@ bdb2i_txn_attr_config( /* BUT NOT "objectclass", 'cause that's a default index ! */ if ( open && strcasecmp( fileName, "objectclass" )) { + /* re-use filename to get the complete path */ + sprintf( fileName, "%s%s%s", + 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_env( p->dbc_name, LDBM_WRCREAT, - li->li_mode, 0, &li->li_db_env ); + p->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 ); /* if the files could not be opened, something is wrong; complain */ @@ -154,17 +158,20 @@ bdb2i_txn_attr_config( } -void +int bdb2i_txn_open_files( struct ldbminfo *li ) { BDB2_TXN_HEAD *head = &li->li_txn_head; BDB2_TXN_FILES *dbFile; for ( dbFile = head->dbFiles; dbFile; dbFile = dbFile->next ) { + char fileName[MAXPATHLEN]; + + sprintf( fileName, "%s%s%s", + 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_env( dbFile->dbc_name, LDBM_WRCREAT, - li->li_mode, 0, &li->li_db_env ); + dbFile->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 ); /* if the files could not be opened, something is wrong; complain */ if ( dbFile->dbc_db == NULL ) { @@ -172,7 +179,7 @@ bdb2i_txn_open_files( struct ldbminfo *li ) Debug( LDAP_DEBUG_ANY, "bdb2i_txn_open_files(): couldn't open file \"%s\" -- FATAL.\n", dbFile->dbc_name, 0, 0 ); - exit( 1 ); + return( 1 ); } @@ -184,13 +191,16 @@ bdb2i_txn_open_files( struct ldbminfo *li ) } + return 0; } void -bdb2i_txn_close_files( BDB2_TXN_HEAD *head) +bdb2i_txn_close_files( BackendDB *be ) { - BDB2_TXN_FILES *dbFile; + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + BDB2_TXN_HEAD *head = &li->li_txn_head; + BDB2_TXN_FILES *dbFile; for ( dbFile = head->dbFiles; dbFile; dbFile = dbFile->next ) { @@ -207,8 +217,12 @@ bdb2i_get_db_file_cache( struct ldbminfo *li, char *name ) BDB2_TXN_FILES *dbFile; int dbFileNum; + Debug( LDAP_DEBUG_TRACE, "bdb2i_get_db_file_cache(): looking for file %s\n", + name, 0, 0 ); + for ( dbFile = head->dbFiles; dbFile; dbFile = dbFile->next ) { + /* we've got it */ if ( !strcasecmp( dbFile->dbc_name, name )) return( dbFile ); } @@ -225,19 +239,18 @@ bdb2i_get_db_file_cache( struct ldbminfo *li, char *name ) /* check for new attribute indexes, that might have been created during former runs of slapd */ /* this is called during startup of the slapd server */ -void +int bdb2i_check_additional_attr_index( struct ldbminfo *li ) { DIR *datadir; struct dirent *file; if ( ( datadir = opendir( li->li_directory ) ) == NULL ) { - /* if ( ( datadir = opendir( "/tmp" ) ) == NULL ) { */ Debug( LDAP_DEBUG_ANY, "bdb2i_check_additional_attr_index(): ERROR while opening datadir: %s\n", strerror( errno ), 0, 0 ); - exit( 1 ); + return( 1 ); } @@ -266,6 +279,7 @@ bdb2i_check_additional_attr_index( struct ldbminfo *li ) closedir( datadir ); + return 0; } diff --git a/servers/slapd/back-bdb2/unbind.c b/servers/slapd/back-bdb2/unbind.c index f183765317..6d74cbb87b 100644 --- a/servers/slapd/back-bdb2/unbind.c +++ b/servers/slapd/back-bdb2/unbind.c @@ -10,7 +10,7 @@ static int bdb2i_back_unbind_internal( - Backend *be, + BackendDB *be, Connection *conn, Operation *op ) @@ -21,7 +21,7 @@ bdb2i_back_unbind_internal( int bdb2_back_unbind( - Backend *be, + BackendDB *be, Connection *conn, Operation *op ) diff --git a/servers/slapd/back-ldbm/config.c b/servers/slapd/back-ldbm/config.c index 808aa4f4a7..44a38c7bac 100644 --- a/servers/slapd/back-ldbm/config.c +++ b/servers/slapd/back-ldbm/config.c @@ -22,7 +22,7 @@ ldbm_back_db_config( struct ldbminfo *li = (struct ldbminfo *) be->be_private; if ( li == NULL ) { - fprintf( stderr, "%s: line %d: ldbm backend info is null!\n", + fprintf( stderr, "%s: line %d: ldbm database info is null!\n", fname, lineno ); return( 1 ); } @@ -38,7 +38,7 @@ ldbm_back_db_config( li->li_directory = ch_strdup( argv[1] ); li->li_nextid_file = - ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") ); + ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") + 1 ); strcpy(li->li_nextid_file, li->li_directory); strcat(li->li_nextid_file, "/NEXTID"); diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 5e3549ff34..7d044c34a8 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -34,7 +34,7 @@ ldbm_cache_open( LDBM db; struct stat st; - sprintf( buf, "%s/%s%s", li->li_directory, name, suffix ); + sprintf( buf, "%s%s%s%s", li->li_directory, DEFAULT_DIRSEP, name, suffix ); Debug( LDAP_DEBUG_TRACE, "=> ldbm_cache_open( \"%s\", %d, %o )\n", buf, flags, li->li_mode ); diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index 18279f2143..3a785fd215 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -179,9 +179,6 @@ add_value( Debug( LDAP_DEBUG_TRACE, "=> add_value( \"%c%s\" )\n", prefix, val, 0 ); - realval = val; - tmpval = NULL; - if ( prefix != UNKNOWN_PREFIX ) { unsigned int len = strlen( val ); diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 7f65cf8dd5..d2666cee2b 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -36,7 +36,9 @@ ldbm_back_initialize( bi->bi_op_delete = ldbm_back_delete; bi->bi_op_abandon = ldbm_back_abandon; +#ifdef SLAPD_ACLGROUPS bi->bi_acl_group = ldbm_back_group; +#endif return 0; } @@ -82,7 +84,7 @@ ldbm_back_db_init( char *argv[ 4 ]; int i; - /* allocate backend-specific stuff */ + /* allocate backend-database-specific stuff */ li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) ); /* arrange to read nextid later (on first request for it) */ diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 8680ff8cf8..d6c7727220 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -15,6 +15,9 @@ #ifdef SLAPD_LDBM #include "back-ldbm/external.h" #endif +#ifdef SLAPD_BDB2 +#include "back-bdb2/external.h" +#endif #ifdef SLAPD_PASSWD #include "back-passwd/external.h" #endif @@ -29,6 +32,9 @@ static BackendInfo binfo[] = { #ifdef SLAPD_LDBM {"ldbm", ldbm_back_initialize}, #endif +#ifdef SLAPD_BDB2 + {"bdb2", bdb2_back_initialize}, +#endif #ifdef SLAPD_PASSWD {"passwd", passwd_back_initialize}, #endif @@ -49,7 +55,7 @@ BackendDB *backendDB = NULL; int backend_init(void) { - int rc = 0; + int rc = -1; if((nBackendInfo != 0) || (backendInfo != NULL)) { /* already initialized */ @@ -93,7 +99,7 @@ int backend_init(void) "backend_init: failed\n", 0, 0, 0 ); - return rc ? rc : -1; + return rc; } int backend_startup(int n) @@ -115,13 +121,22 @@ int backend_startup(int n) "backend_startup: starting database %d\n", n, 0, 0 ); + /* make sure, n does not exceed the number of backend databases */ + if ( n >= nbackends ) { + + Debug( LDAP_DEBUG_ANY, + "backend_startup: database number %d exceeding maximum (%d)\n", + n, nbackends, 0 ); + return 1; + } + if ( backendDB[n].bd_info->bi_open ) { rc = backendDB[n].bd_info->bi_open( backendDB[n].bd_info ); } if(rc != 0) { - Debug( LDAP_DEBUG_TRACE, + Debug( LDAP_DEBUG_ANY, "backend_startup: bi_open failed!\n", 0, 0, 0 ); return rc; @@ -133,7 +148,7 @@ int backend_startup(int n) } if(rc != 0) { - Debug( LDAP_DEBUG_TRACE, + Debug( LDAP_DEBUG_ANY, "backend_startup: bi_db_open failed!\n", 0, 0, 0 ); return rc; @@ -143,6 +158,7 @@ int backend_startup(int n) } /* open each backend type */ +/* for( i = 0; i < nBackendInfo; i++ ) { if( backendInfo[i].bi_open ) { rc = backendInfo[i].bi_open( @@ -150,22 +166,38 @@ int backend_startup(int n) } if(rc != 0) { - Debug( LDAP_DEBUG_TRACE, + Debug( LDAP_DEBUG_ANY, "backend_startup: bi_open %d failed!\n", i, 0, 0 ); return rc; } } +*/ /* open each backend database */ for( i = 0; i < nBackendDB; i++ ) { + BackendInfo *bi; + + /* open the backend type, if not done already */ + bi = backendDB[i].bd_info; + if( bi->bi_open ) { + rc = bi->bi_open( bi ); + } + + if(rc != 0) { + Debug( LDAP_DEBUG_ANY, + "backend_startup: bi_open %s failed!\n", + bi->bi_type, 0, 0 ); + return rc; + } + if ( backendDB[i].bd_info->bi_db_open ) { rc = backendDB[i].bd_info->bi_db_open( &backendDB[i] ); } if(rc != 0) { - Debug( LDAP_DEBUG_TRACE, + Debug( LDAP_DEBUG_ANY, "backend_startup: bi_db_open %d failed!\n", i, 0, 0 ); return rc; @@ -178,10 +210,20 @@ int backend_startup(int n) int backend_shutdown(int n) { int i; + int rc = 0; if(n >= 0) { /* shutdown a specific backend database */ + /* make sure, n does not exceed the number of backend databases */ + if ( n >= nbackends ) { + + Debug( LDAP_DEBUG_ANY, + "backend_startup: database number %d exceeding maximum (%d)\n", + n, nbackends, 0 ); + return 1; + } + if ( backendDB[n].bd_info->bi_db_close ) { backendDB[n].bd_info->bi_db_close( &backendDB[n] ); @@ -197,19 +239,35 @@ int backend_shutdown(int n) /* close each backend database */ for( i = 0; i < nBackendDB; i++ ) { + BackendInfo *bi; + if ( backendDB[i].bd_info->bi_db_close ) { backendDB[i].bd_info->bi_db_close( &backendDB[i] ); } + + /* close the backend type, if not done already */ + bi = backendDB[i].bd_info; + if( bi->bi_close ) { + rc = bi->bi_close( bi ); + } + + if(rc != 0) { + Debug( LDAP_DEBUG_ANY, + "backend_close: bi_close %s failed!\n", + bi->bi_type, 0, 0 ); + } } /* close each backend type */ +/* for( i = 0; i < nBackendInfo; i++ ) { if( backendInfo[i].bi_close ) { backendInfo[i].bi_close( &backendInfo[i] ); } } +*/ return 0; } @@ -227,12 +285,14 @@ int backend_destroy(void) } /* destroy each backend type */ +/* for( i = 0; i < nBackendInfo; i++ ) { if( backendInfo[i].bi_destroy ) { backendInfo[i].bi_destroy( &backendInfo[i] ); } } +*/ return 0; } diff --git a/servers/slapd/init.c b/servers/slapd/init.c index 5f7e6a3ef8..f90cb6ba58 100644 --- a/servers/slapd/init.c +++ b/servers/slapd/init.c @@ -62,14 +62,14 @@ ldap_pvt_thread_mutex_t entry2str_mutex; ldap_pvt_thread_mutex_t replog_mutex; static char* slap_name; -int slapMode = 0; +int slapMode = SLAP_UNDEFINED_MODE; int slap_init( int mode, char *name ) { int rc; - if( slapMode ) { + if( slapMode != SLAP_UNDEFINED_MODE ) { Debug( LDAP_DEBUG_ANY, "%s init: init called twice (old=%d, new=%d)\n", name, slapMode, mode ); @@ -78,7 +78,7 @@ slap_init( int mode, char *name ) slapMode = mode; - if(!slapMode) { + if( ( slapMode != SLAP_SERVER_MODE ) && ( slapMode != SLAP_TOOL_MODE ) ) { Debug( LDAP_DEBUG_ANY, "%s init: undefined mode (%d).\n", name, mode, 0 ); diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 894f834a9f..eb320394b8 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -304,9 +304,14 @@ main( int argc, char **argv ) } shutdown: - slap_shutdown(-1); + /* remember an error during shutdown */ + rc |= slap_shutdown(-1); destroy: - slap_destroy(); + /* remember an error during destroy */ + rc |= slap_destroy(); + + Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 ); + return rc; } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 5dabb215c6..17f67a30a5 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -289,7 +289,7 @@ struct backend_db { char *be_update_ndn; /* allowed to make changes (in replicas) */ int be_lastmod; /* keep track of lastmodified{by,time} */ - void *be_private; /* anything the backend needs */ + void *be_private; /* anything the backend database needs */ }; struct backend_info { @@ -387,7 +387,7 @@ struct backend_info { char *objectclassValue, char *groupattrName )); #endif - void *bi_private; /* anything the backend needs */ + void *bi_private; /* anything the backend type needs */ }; /* diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index 788994b27d..f53ed41629 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -14,6 +14,7 @@ #----------------------------------------------------------------------------- HAVE_ISODE = @HAVE_ISODE@ BUILD_LDBM = @BUILD_LDBM@ +BUILD_BDB2 = @BUILD_BDB2@ LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries @@ -23,12 +24,18 @@ XXLIBS = $(LDAPD_LIBS) $(SLAPD_LIBS) \ $(PERL_LDFLAGS) $(LDBM_LIBS) $(KRB_LIBS) $(LUTIL_LIBS) XXXLIBS = $(LTHREAD_LIBS) -PROGRAMS=ldif2index ldif2ldbm ldbmcat ldif2id2entry \ - ldif2id2children centipede ldbmtest ldif +PROGRAMS=ldif2index ldif2ldbm ldbmcat ldif2id2entry ldif2id2children \ + centipede ldbmtest ldif + +PROGRAMS2=ldif2index-bdb2 ldif2ldbm-bdb2 \ + ldif2id2entry-bdb2 ldif2id2children-bdb2 SRCS = centipede.c ldbmcat.c ldbmtest.c sizecount.c \ ldif.c ldif2id2children.c ldif2id2entry.c ldif2index.c ldif2ldbm.c +SRCS2 = ldif2id2children-bdb2.c ldif2id2entry-bdb2.c \ + ldif2index-bdb2.c ldif2ldbm-bdb2.c + XSRCS = edb2-vers.c EDB2LDIFSRCS = edb2ldif.c ldapsyntax.c @@ -40,7 +47,7 @@ OBJS2 = ../config.o ../ch_malloc.o ../backend.o ../charray.o \ ../dn.o ../filter.o ../str2filter.o ../ava.o ../init.o \ ../schemaparse.o -all-local: build-ldbm build-edb2ldif build-chlog2replog +all-local: build-ldbm build-bdb2 build-edb2ldif build-chlog2replog build-ldbm: FORCE @if [ "$(BUILD_LDBM)" = "yes" ]; then \ @@ -49,8 +56,17 @@ build-ldbm: FORCE echo "run configure with --with-ldbm to build LDBM tools"; \ fi +build-bdb2: FORCE + @if [ "$(BUILD_BDB2)" = "yes" ]; then \ + $(MAKE) $(MFLAGS) bdb2-tools; \ + else \ + echo "run configure with --enable-bdb2 to build BDB2 tools"; \ + fi + ldbm-tools: $(PROGRAMS) +bdb2-tools: $(PROGRAMS2) + build-edb2ldif: FORCE @if [ "$(HAVE_ISODE)" = "yes" ]; then \ $(MAKE) $(MFLAGS) edb2ldif; \ @@ -82,16 +98,31 @@ chlog2replog: chlog2replog.o ../lock.o ../ch_malloc.o $(SLAPD_LIBDEPEND) ldif2index: ldif2index.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ ldif2index.o $(OBJS2) ../libbackends.a $(LIBS) +ldif2index-bdb2: ldif2index-bdb2.o ../libbackends.a \ + $(OBJS2) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ ldif2index-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) + ldif2ldbm: ldif2ldbm.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ ldif2ldbm.o $(OBJS2) ../libbackends.a $(LIBS) +ldif2ldbm-bdb2: ldif2ldbm-bdb2.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ ldif2ldbm-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) + ldif2id2entry: ldif2id2entry.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ ldif2id2entry.o $(OBJS2) ../libbackends.a $(LIBS) +ldif2id2entry-bdb2: ldif2id2entry-bdb2.o ../libbackends.a \ + $(OBJS2) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ ldif2id2entry-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) + ldif2id2children: ldif2id2children.o ../libbackends.a \ $(OBJS2) $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ ldif2id2children.o $(OBJS2) ../libbackends.a $(LIBS) +ldif2id2children-bdb2: ldif2id2children-bdb2.o ../libbackends.a \ + $(OBJS2) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ ldif2id2children-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) + ldbmcat: ldbmcat.o $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ ldbmcat.o $(LIBS) @@ -108,26 +139,31 @@ ldbmtest: ldbmtest.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) $(LTLINK) -o ldbmtest ldbmtest.o $(OBJS2) ../libbackends.a $(LIBS) clean-local: FORCE - $(RM) $(PROGRAMS) $(XPROGRAMS) $(XSRCS) edb2-vers.c \ + $(RM) $(PROGRAMS) $(PROGRAMS2) $(XPROGRAMS) $(XSRCS) edb2-vers.c \ *.o core .libs/* depend-local: FORCE - @DEPEND=no ; DEPEND_LDBM= ; DEPEND_ISODE= ; \ + @DEPEND=no ; DEPEND_LDBM= ; DEPEND_BDB2= ; DEPEND_ISODE= ; \ if [ "$(BUILD_LDBM)" = "yes" ]; then \ DEPEND_LDBM="$(SRCS)"; \ DEPEND=yes ; \ + fi; \ + if [ "$(BUILD_BDB2)" = "yes" ]; then \ + DEPEND_BDB2="$(SRCS2)"; \ + DEPEND=yes ; \ fi; \ if [ "$(HAVE_ISODE)" = "yes" ]; then \ DEPEND_ISODE="$(ISODEINCLUDEFLAG) chlog2replog.c $(EDB2LDIFSRCS)"; \ DEPEND=yes ; \ fi; \ if [ "$$DEPEND" = "yes" ]; then \ - $(MKDEP) $(DEFS) $(DEFINES) $$DEPEND_ISODE $$DEPEND_LDBM; \ + $(MKDEP) $(DEFS) $(DEFINES) $$DEPEND_ISODE \ + $$DEPEND_LDBM $$DEPEND_BDB2; \ else \ echo "slapd-tools: no dependencies to make"; \ fi -install-local: install-ldbm install-isode FORCE +install-local: install-ldbm install-bdb2 install-isode FORCE install-ldbm: FORCE @-$(MKDIR) $(sbindir) @@ -144,6 +180,17 @@ install-ldbm: FORCE exit 0 ; \ fi +install-bdb2: FORCE + @-$(MKDIR) $(sbindir) + @if [ "$(BUILD_BDB2)" = "yes" ]; then \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2ldbm-bdb2 $(sbindir) ; \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2index-bdb2 $(sbindir) ; \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2id2entry-bdb2 $(sbindir) ; \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2id2children-bdb2 $(sbindir) ; \ + else \ + exit 0 ; \ + fi + install-isode: FORCE @-$(MKDIR) $(sbindir) @if [ "$(HAVE_ISODE)" = "yes" ]; then \ diff --git a/servers/slapd/tools/ldif2id2children-bdb2.c b/servers/slapd/tools/ldif2id2children-bdb2.c new file mode 100644 index 0000000000..be5a435bef --- /dev/null +++ b/servers/slapd/tools/ldif2id2children-bdb2.c @@ -0,0 +1,311 @@ +#include "portable.h" + +#include +#include + +#include +#include +#include +#include + +#include "ldapconfig.h" +#include "../slap.h" +#include "../back-bdb2/back-bdb2.h" + +#include "ldif.h" + +#define MAXARGS 100 + +static char *tailorfile; +static char *inputfile; + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, cargc, indb, stop, status; + char *cargv[MAXARGS]; + char *defargv[MAXARGS]; + char *linep, *buf; + char line[BUFSIZ]; + int lineno, elineno; + int lmax, lcur; + int dbnum; + ID id; + struct dbcache *db, *db2; + Backend *be = NULL; + struct ldbminfo *li; + struct berval bv; + struct berval *vals[2]; + Avlnode *avltypes = NULL; + + tailorfile = SLAPD_DEFAULT_CONFIGFILE; + dbnum = -1; + while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) { + switch ( i ) { + case 'd': /* turn on debugging */ + ldap_debug = atoi( optarg ); + break; + + case 'f': /* specify a tailor file */ + tailorfile = strdup( optarg ); + break; + + case 'i': /* input file */ + inputfile = strdup( optarg ); + break; + + case 'n': /* which config file db to index */ + dbnum = atoi( optarg ) - 1; + break; + + default: + usage( argv[0] ); + break; + } + } + if ( inputfile == NULL ) { + usage( argv[0] ); + } else { + if ( freopen( inputfile, "r", stdin ) == NULL ) { + perror( inputfile ); + exit( 1 ); + } + } + + /* + * initialize stuff and figure out which backend we're dealing with + */ + + slap_init(SLAP_TOOL_MODE, "ldif2id2children"); + read_config( tailorfile ); + + if ( dbnum == -1 ) { + for ( dbnum = 0; dbnum < nbackends; dbnum++ ) { + if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) + == 0 ) { + break; + } + } + if ( dbnum == nbackends ) { + fprintf( stderr, "No bdb2 database found in config file\n" ); + exit( 1 ); + } + } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { + fprintf( stderr, "Database number selected via -n is out of range\n" ); + fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends ); + exit( 1 ); + } else if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) != 0 ) { + fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum ); + exit( 1 ); + } + + slap_startup(dbnum); + be = &backends[dbnum]; + + /* disable write sync'ing */ + li = (struct ldbminfo *) be->be_private; + li->li_dbcachewsync = 0; + + /* + * first, make the dn2id index + */ + + if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB )) + == NULL ) { + perror( "dn2id file" ); + exit( 1 ); + } + + id = 0; + stop = 0; + lineno = 0; + buf = NULL; + lcur = lmax = 0; + vals[0] = &bv; + vals[1] = NULL; + while ( ! stop ) { + char *type, *val, *s; + int vlen; + Datum key, data; + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + if ( fgets( line, sizeof(line), stdin ) != NULL ) { + int len; + + lineno++; + len = strlen( line ); + while ( lcur + len + 1 > lmax ) { + lmax += BUFSIZ; + buf = (char *) ch_realloc( buf, lmax ); + } + strcpy( buf + lcur, line ); + lcur += len; + } else { + stop = 1; + } + if ( line[0] == '\n' || stop && buf && *buf ) { + if ( *buf != '\n' ) { + if (isdigit(*buf)) { + id = atol(buf); + } else { + id++; + } + s = buf; + elineno = 0; + while ( (linep = ldif_getline( &s )) != NULL ) { + elineno++; + if ( ldif_parse_line( linep, &type, &val, + &vlen ) != 0 ) { + Debug( LDAP_DEBUG_PARSE, + "bad line %d in entry ending at line %d ignored\n", + elineno, lineno, 0 ); + continue; + } + + if ( strcmp( type, "dn" ) == 0 ) + break; + } + + if ( linep == NULL ) { + fprintf( stderr, "entry %lu has no dn\n", + id ); + } else { + key.dptr = dn_normalize_case( val ); + key.dsize = strlen( val ) + 1; + data.dptr = (char *) &id; + data.dsize = sizeof(ID); + if ( ldbm_store( db->dbc_db, key, data, + LDBM_REPLACE ) != 0 ) { + perror( "dn2id ldbm_store..." ); + exit( 1 ); + } + } + } + *buf = '\0'; + lcur = 0; + line[0] = '\0'; + } + } + if ( buf ) + free( buf ); + + /* + * next, make the id2children index + */ + + if ( (db2 = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX, + LDBM_NEWDB )) == NULL ) { + perror( "id2children file" ); + exit( 1 ); + } + + rewind( stdin ); + id = 0; + stop = 0; + buf = NULL; + lineno = 0; + lcur = lmax = 0; + vals[0] = &bv; + vals[1] = NULL; + while ( ! stop ) { + char *type, *val, *s, *dn; + int vlen; + ID pid; + char buf2[20]; + Datum key, data; + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + if ( fgets( line, sizeof(line), stdin ) != NULL ) { + int len; + + len = strlen( line ); + while ( lcur + len + 1 > lmax ) { + lmax += BUFSIZ; + buf = (char *) ch_realloc( buf, lmax ); + } + strcpy( buf + lcur, line ); + lcur += len; + } else { + stop = 1; + } + if ( line[0] == '\n' || stop && buf && *buf ) { + if ( * buf != '\n' ) { + id++; + s = buf; + while ( (linep = ldif_getline( &s )) != NULL ) { + if ( ldif_parse_line( linep, &type, &val, + &vlen ) != 0 ) { + Debug( LDAP_DEBUG_PARSE, + "bad line %d ignored\n", + lineno, 0, 0 ); + continue; + } + + if ( strcmp( type, "dn" ) == 0 ) + break; + } + + if ( linep == NULL ) { + fprintf( stderr, "entry %lu has no dn\n", + id ); + } else { + if ( (dn = dn_parent( be, val )) + == NULL ) { + pid = 0; + } else { + key.dptr = + dn_normalize_case( dn ); + key.dsize = strlen( dn ) + 1; + + data = ldbm_fetch( db->dbc_db, + key ); + free( dn ); + if ( data.dptr == NULL ) { + dn_normalize_case( val ); + if ( ! be_issuffix( be, + val ) ) { + Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 ); + } + *buf = '\0'; + lcur = 0; + line[0] = '\0'; + continue; + } + (void) memcpy( (char *) &pid, + data.dptr, sizeof(ID) ); + + ldbm_datum_free( db->dbc_db, data); + } + + sprintf( buf2, "%c%ld", EQ_PREFIX, pid ); + key.dptr = buf2; + key.dsize = strlen( buf2 ) + 1; + if ( idl_insert_key( be, db2, key, id ) + != 0 ) { + perror( "idl_insert_key" ); + exit( 1 ); + } + } + } + *buf = '\0'; + lcur = 0; + line[0] = '\0'; + } + } + + slap_shutdown(dbnum); + slap_destroy(); + + exit( 0 ); +} diff --git a/servers/slapd/tools/ldif2id2entry-bdb2.c b/servers/slapd/tools/ldif2id2entry-bdb2.c new file mode 100644 index 0000000000..5ca1120621 --- /dev/null +++ b/servers/slapd/tools/ldif2id2entry-bdb2.c @@ -0,0 +1,206 @@ +#include "portable.h" + +#include +#include + +#include +#include +#include +#include + +#include "ldapconfig.h" +#include "../slap.h" +#include "../back-bdb2/back-bdb2.h" + +#define MAXARGS 100 + +static char *tailorfile; +static char *inputfile; + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, cargc, indb, stop, status; + char *cargv[MAXARGS]; + char *defargv[MAXARGS]; + char *linep, *buf; + char line[BUFSIZ], idbuf[BUFSIZ]; + int lmax, lcur; + int dbnum; + ID id; + struct dbcache *db; + Backend *be = NULL; + struct ldbminfo *li; + struct berval bv; + struct berval *vals[2]; + Avlnode *avltypes = NULL; + FILE *fp; + + tailorfile = SLAPD_DEFAULT_CONFIGFILE; + dbnum = -1; + while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) { + switch ( i ) { + case 'd': /* turn on debugging */ + ldap_debug = atoi( optarg ); + break; + + case 'f': /* specify a tailor file */ + tailorfile = strdup( optarg ); + break; + + case 'i': /* input file */ + inputfile = strdup( optarg ); + break; + + case 'n': /* which config file db to index */ + dbnum = atoi( optarg ) - 1; + break; + + default: + usage( argv[0] ); + break; + } + } + if ( inputfile == NULL ) { + usage( argv[0] ); + } else { + if ( freopen( inputfile, "r", stdin ) == NULL ) { + perror( inputfile ); + exit( 1 ); + } + } + + /* + * initialize stuff and figure out which backend we're dealing with + */ + + slap_init(SLAP_TOOL_MODE, "ldif2id2entry"); + read_config( tailorfile ); + + if ( dbnum == -1 ) { + for ( dbnum = 0; dbnum < nbackends; dbnum++ ) { + if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) + == 0 ) { + break; + } + } + if ( dbnum == nbackends ) { + fprintf( stderr, "No bdb2 database found in config file\n" ); + exit( 1 ); + } + } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { + fprintf( stderr, "Database number selected via -n is out of range\n" ); + fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends ); + exit( 1 ); + } else if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) != 0 ) { + fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum ); + exit( 1 ); + } + + slap_startup(dbnum); + + be = &backends[dbnum]; + + /* disable write sync'ing */ + li = (struct ldbminfo *) be->be_private; + li->li_dbcachewsync = 0; + + if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB )) + == NULL ) { + perror( "id2entry file" ); + exit( 1 ); + } + + id = 0; + stop = 0; + buf = NULL; + lcur = lmax = 0; + vals[0] = &bv; + vals[1] = NULL; + while ( ! stop ) { + char *type, *val, *s; + int vlen; + Datum key, data; + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + if ( fgets( line, sizeof(line), stdin ) != NULL ) { + int len, idlen; + + len = strlen( line ); + if ( buf == NULL || *buf == '\0' ) { + if (!isdigit(line[0])) { + sprintf( idbuf, "%d\n", id + 1 ); + idlen = strlen( idbuf ); + } else { + id = atol(line) - 1; + idlen = 0; + } + } else { + idlen = 0; + } + + while ( lcur + len + idlen + 1 > lmax ) { + lmax += BUFSIZ; + buf = (char *) ch_realloc( buf, lmax ); + } + + if ( idlen > 0 ) { + strcpy( buf + lcur, idbuf ); + lcur += idlen; + } + strcpy( buf + lcur, line ); + lcur += len; + } else { + stop = 1; + } + if ( line[0] == '\n' || stop && buf && *buf ) { + if ( *buf != '\n' ) { + int len; + + id++; + key.dptr = (char *) &id; + key.dsize = sizeof(ID); + data.dptr = buf; + len = strlen(buf); + if (buf[len - 1] == '\n') + buf[--len] = '\0'; + data.dsize = len + 1; + if ( ldbm_store( db->dbc_db, key, data, + LDBM_INSERT ) != 0 ) { + fputs("id2entry ldbm_store failed\n", + stderr); + exit( 1 ); + } + } + *buf = '\0'; + lcur = 0; + line[0] = '\0'; + } + } + + slap_shutdown(dbnum); + + id++; + sprintf( line, "%s/NEXTID", + ((struct ldbminfo *) be->be_private)->li_directory ); + if ( (fp = fopen( line, "w" )) == NULL ) { + perror( line ); + fprintf( stderr, "Could not write next id %ld\n", id ); + } else { + fprintf( fp, "%ld\n", id ); + fclose( fp ); + } + + slap_destroy(); + + exit( 0 ); +} diff --git a/servers/slapd/tools/ldif2index-bdb2.c b/servers/slapd/tools/ldif2index-bdb2.c new file mode 100644 index 0000000000..1c7f5331b2 --- /dev/null +++ b/servers/slapd/tools/ldif2index-bdb2.c @@ -0,0 +1,177 @@ +#include "portable.h" + +#include +#include + +#include +#include +#include +#include + +#include "../slap.h" +#include "../back-bdb2/back-bdb2.h" + +#include "ldapconfig.h" +#include "ldif.h" + +#define MAXARGS 100 + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, cargc, indb, stop; + char *cargv[MAXARGS]; + char *defargv[MAXARGS]; + char *tailorfile, *inputfile; + char *linep, *buf, *attr; + char line[BUFSIZ]; + int lineno, elineno; + int lmax, lcur, indexmask, syntaxmask; + int dbnum; + unsigned long id; + Backend *be = NULL; + struct ldbminfo *li; + struct berval bv; + struct berval *vals[2]; + + inputfile = NULL; + tailorfile = SLAPD_DEFAULT_CONFIGFILE; + dbnum = -1; + while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) { + switch ( i ) { + case 'd': /* turn on debugging */ + ldap_debug = atoi( optarg ); + break; + + case 'f': /* specify a tailor file */ + tailorfile = strdup( optarg ); + break; + + case 'i': /* input file */ + inputfile = strdup( optarg ); + break; + + case 'n': /* which config file db to index */ + dbnum = atoi( optarg ) - 1; + break; + + default: + usage( argv[0] ); + break; + } + } + attr = attr_normalize( argv[argc - 1] ); + if ( inputfile == NULL ) { + usage( argv[0] ); + } else { + if ( freopen( inputfile, "r", stdin ) == NULL ) { + perror( inputfile ); + exit( 1 ); + } + } + + slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0])); + read_config( tailorfile ); + + if ( dbnum == -1 ) { + for ( dbnum = 0; dbnum < nbackends; dbnum++ ) { + if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) + == 0 ) { + break; + } + } + if ( dbnum == nbackends ) { + fprintf( stderr, "No bdb2 database found in config file\n" ); + exit( 1 ); + } + } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { + fprintf( stderr, "Database number selected via -n is out of range\n" ); + fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends ); + exit( 1 ); + } else if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) != 0 ) { + fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum ); + exit( 1 ); + } + + slap_startup(dbnum); + + be = &backends[dbnum]; + + /* disable write sync'ing */ + li = (struct ldbminfo *) be->be_private; + li->li_dbcachewsync = 0; + + attr_masks( be->be_private, attr, &indexmask, &syntaxmask ); + if ( indexmask == 0 ) { + exit( 0 ); + } + + id = 0; + stop = 0; + lineno = 0; + buf = NULL; + lcur = lmax = 0; + vals[0] = &bv; + vals[1] = NULL; + while ( ! stop ) { + char *type, *val, *s; + int vlen; + + if ( fgets( line, sizeof(line), stdin ) != NULL ) { + int len; + + lineno++; + len = strlen( line ); + while ( lcur + len + 1 > lmax ) { + lmax += BUFSIZ; + buf = (char *) ch_realloc( buf, lmax ); + } + strcpy( buf + lcur, line ); + lcur += len; + } else { + stop = 1; + } + if ( line[0] == '\n' || stop && buf && *buf ) { + if ( *buf != '\n' ) { + if (isdigit(*buf)) { + id = atol(buf); + } else { + id++; + } + s = buf; + elineno = 0; + while ( (linep = ldif_getline( &s )) != NULL ) { + elineno++; + if ( ldif_parse_line( linep, &type, &val, + &vlen ) != 0 ) { + Debug( LDAP_DEBUG_PARSE, + "bad line %d in entry ending at line %d ignored\n", + elineno, elineno, 0 ); + continue; + } + + if ( strcasecmp( type, attr ) == 0 ) { + bv.bv_val = val; + bv.bv_len = vlen; + index_add_values( be, attr, + vals, id ); + } + } + } + *buf = '\0'; + lcur = 0; + } + } + + slap_shutdown(dbnum); + slap_destroy(); + + exit( 0 ); +} diff --git a/servers/slapd/tools/ldif2ldbm-bdb2.c b/servers/slapd/tools/ldif2ldbm-bdb2.c new file mode 100644 index 0000000000..2e0ef1f8dd --- /dev/null +++ b/servers/slapd/tools/ldif2ldbm-bdb2.c @@ -0,0 +1,335 @@ +#include "portable.h" + +#include + +#include +#include +#include +#include +#include + +#include + +#include "ldapconfig.h" +#include "../slap.h" +#include "../back-bdb2/back-bdb2.h" +#include "ldif.h" + +#define INDEXCMD "ldif2index-bdb2" +#define ID2ENTRYCMD "ldif2id2entry-bdb2" +#define ID2CHILDRENCMD "ldif2id2children-bdb2" +#define MAXARGS 100 + +static void fork_child( char *prog, char *args[] ); +static void wait4kids( int nkidval ); + +static char *indexcmd; +static char *tailorfile; +static char *inputfile; +static int maxkids = 1; +static int nkids; + +static void +usage( char *name ) +{ + fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-j #jobs] [-n databasenumber] [-s sbindir]\n", name ); + exit( 1 ); +} + +int +main( int argc, char **argv ) +{ + int i, stop, status; + char *linep, *buf, *sbindir; + char *args[MAXARGS]; + char buf2[20], buf3[20]; + char line[BUFSIZ]; + char cmd[MAXPATHLEN]; + int lineno, elineno; + int lmax, lcur; + int dbnum; + ID id; + int rc; + Backend *be = NULL; + struct ldbminfo *li; + struct berval bv; + struct berval *vals[2]; + Avlnode *avltypes = NULL; + + sbindir = DEFAULT_SBINDIR; + tailorfile = SLAPD_DEFAULT_CONFIGFILE; + dbnum = -1; + while ( (i = getopt( argc, argv, "d:e:s:f:i:j:n:" )) != EOF ) { + switch ( i ) { + case 'd': /* turn on debugging */ + ldap_debug = atoi( optarg ); + break; + + case 's': /* alternate sbindir (index cmd location) */ + case 'e': /* accept -e for backwards compatibility */ + sbindir = strdup( optarg ); + break; + + case 'f': /* specify a tailor file */ + tailorfile = strdup( optarg ); + break; + + case 'i': /* input file */ + inputfile = strdup( optarg ); + break; + + case 'j': /* number of parallel index procs */ + maxkids = atoi( optarg ); + break; + + case 'n': /* which config file db to index */ + dbnum = atoi( optarg ) - 1; + break; + + default: + usage( argv[0] ); + break; + } + } + if ( inputfile == NULL ) { + usage( argv[0] ); + } else { + if ( freopen( inputfile, "r", stdin ) == NULL ) { + perror( inputfile ); + exit( 1 ); + } + } + + /* + * initialize stuff and figure out which backend we're dealing with + */ + + rc = slap_init(SLAP_TOOL_MODE, "ldif2ldbm"); + if (rc != 0 ) { + fprintf( stderr, "ldif2ldbm: slap_init failed!\n"); + exit(1); + } + + read_config( tailorfile ); + + if ( dbnum == -1 ) { + for ( dbnum = 0; dbnum < nbackends; dbnum++ ) { + if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) + == 0 ) { + break; + } + } + if ( dbnum == nbackends ) { + fprintf( stderr, "No bdb2 database found in config file\n" ); + exit( 1 ); + } + } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { + fprintf( stderr, "Database number selected via -n is out of range\n" ); + fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends ); + exit( 1 ); + } else if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) != 0 ) { + fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum ); + exit( 1 ); + } + + slap_startup(dbnum); + + be = &backends[dbnum]; + + /* disable write sync'ing */ + li = (struct ldbminfo *) be->be_private; + li->li_dbcachewsync = 0; + + /* + * generate the id2entry index + */ + + i = 0; + sprintf( cmd, "%s/%s", sbindir, ID2ENTRYCMD ); + args[i++] = cmd; + args[i++] = "-i"; + args[i++] = inputfile; + args[i++] = "-f"; + args[i++] = tailorfile; + args[i++] = "-n"; + sprintf( buf2, "%d", dbnum+1 ); + args[i++] = buf2; + if ( ldap_debug ) { + sprintf( buf3, "%d", ldap_debug ); + args[i++] = "-d"; + args[i++] = buf3; + } + args[i++] = NULL; + fork_child( cmd, args ); + + /* + * generate the dn2id and id2children indexes + */ + + i = 0; + sprintf( cmd, "%s/%s", sbindir, ID2CHILDRENCMD ); + args[i++] = cmd; + args[i++] = "-i"; + args[i++] = inputfile; + args[i++] = "-f"; + args[i++] = tailorfile; + args[i++] = "-n"; + sprintf( buf2, "%d", dbnum+1 ); + args[i++] = buf2; + if ( ldap_debug ) { + sprintf( buf3, "%d", ldap_debug ); + args[i++] = "-d"; + args[i++] = buf3; + } + args[i++] = NULL; + fork_child( cmd, args ); + + /* + * generate the attribute indexes + */ + + i = 0; + sprintf( cmd, "%s/%s", sbindir, INDEXCMD ); + args[i++] = cmd; + args[i++] = "-i"; + args[i++] = inputfile; + args[i++] = "-f"; + args[i++] = tailorfile; + args[i++] = "-n"; + sprintf( buf2, "%d", dbnum+1 ); + args[i++] = buf2; + if ( ldap_debug ) { + sprintf( buf3, "%d", ldap_debug ); + args[i++] = "-d"; + args[i++] = buf3; + } + args[i++] = NULL; /* will hold the attribute name */ + args[i++] = NULL; + + id = 0; + stop = 0; + buf = NULL; + lineno = 0; + lcur = lmax = 0; + vals[0] = &bv; + vals[1] = NULL; + while ( ! stop ) { + char *type, *val, *s; + int vlen, indexmask, syntaxmask; + Datum key, data; + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + if ( fgets( line, sizeof(line), stdin ) != NULL ) { + int len; + + lineno++; + len = strlen( line ); + while ( lcur + len + 1 > lmax ) { + lmax += BUFSIZ; + buf = (char *) ch_realloc( buf, lmax ); + } + strcpy( buf + lcur, line ); + lcur += len; + } else { + stop = 1; + } + if ( line[0] == '\n' || stop && buf && *buf ) { + id++; + s = buf; + elineno = 0; + while ( (linep = ldif_getline( &s )) != NULL ) { + elineno++; + if ( ldif_parse_line( linep, &type, &val, &vlen ) + != 0 ) { + Debug( LDAP_DEBUG_PARSE, + "bad line %d in entry ending at line %d ignored\n", + elineno, lineno, 0 ); + continue; + } + + if ( !isascii( *type ) || isdigit( *type ) ) + continue; + + type = strdup( type ); + if ( avl_insert( &avltypes, type, strcasecmp, + avl_dup_error ) != 0 ) { + free( type ); + } else { + attr_masks( be->be_private, type, + &indexmask, &syntaxmask ); + if ( indexmask ) { + args[i - 2] = type; + fork_child( cmd, args ); + } + } + } + *buf = '\0'; + lcur = 0; + } + } + + slap_shutdown(dbnum); + + wait4kids( -1 ); + + slap_destroy(); + + exit( 0 ); +} + +static void +fork_child( char *prog, char *args[] ) +{ + int status, pid; + + wait4kids( maxkids ); + + switch ( pid = fork() ) { + case 0: /* child */ + execvp( prog, args ); + fprintf( stderr, "%s: ", prog ); + perror( "execv" ); + exit( -1 ); + break; + + case -1: /* trouble */ + fprintf( stderr, "Could not fork to run %s\n", prog ); + perror( "fork" ); + break; + + default: /* parent */ + nkids++; + break; + } +} + +static void +wait4kids( int nkidval ) +{ + int status; + unsigned char *p; + + while ( nkids >= nkidval ) { + wait( &status ); + p = (unsigned char *) &status; + if ( p[sizeof(int) - 1] == 0177 ) { + fprintf( stderr, + "stopping: child stopped with signal %d\n", + p[sizeof(int) - 2] ); + } else if ( p[sizeof(int) - 1] != 0 ) { + fprintf( stderr, + "stopping: child terminated with signal %d\n", + p[sizeof(int) - 1] ); + exit( p[sizeof(int) - 1] ); + } else if ( p[sizeof(int) - 2] != 0 ) { + fprintf( stderr, + "stopping: child exited with status %d\n", + p[sizeof(int) - 2] ); + exit( p[sizeof(int) - 2] ); + } else { + nkids--; + } + } +} diff --git a/tests/Makefile.in b/tests/Makefile.in index fda33ec0b4..70b0433fd2 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -2,12 +2,23 @@ ## COPYING RESTRICTIONS APPLY, see COPYRIGHT file ## ## tests Makefile.in for OpenLDAP +BUILD_BDB2 = @BUILD_BDB2@ + +bdb2-local: FORCE + @if [ "$(BUILD_BDB2)" = "yes" ]; then \ + @-$(LN_S) $(srcdir)/data .; \ + echo "Initiating LDAP tests..."; \ + $(MKDIR) test-db test-repl ; \ + $(srcdir)/scripts/all $(srcdir) bdb2;\ + else \ + echo "run configure with --enable-bdb2"; \ + fi all-local: FORCE @-$(LN_S) $(srcdir)/data . @echo "Initiating LDAP tests..."; \ $(MKDIR) test-db test-repl ; \ - $(srcdir)/scripts/all $(srcdir) + $(srcdir)/scripts/all $(srcdir) ldbm clean-local: FORCE $(RM) test-db/[!C]* test-repl/[!C]* *core diff --git a/tests/data/slapd-bdb2-acl.conf b/tests/data/slapd-bdb2-acl.conf new file mode 100644 index 0000000000..31a47805e3 --- /dev/null +++ b/tests/data/slapd-bdb2-acl.conf @@ -0,0 +1,41 @@ +# +# master slapd config -- for testing +# +include ./data/slapd.at.conf +include ./data/slapd.oc.conf +schemacheck off +pidfile ./test-db/slapd.pid +argsfile ./test-db/slapd.args + +####################################################################### +# ldbm database definitions +####################################################################### + +backend bdb2 +home ./test-db + +database bdb2 +suffix "o=University of Michigan, c=US" +directory ./test-db +rootdn "cn=Manager, o=University of Michigan, c=US" +rootpw secret +index cn,sn,uid pres,eq,approx +index default none +lastmod on +defaultaccess none +access to attr=objectclass + by * read +access to attr=userpassword + by self write + by * compare +access to dn=".*,ou=Alumni Association,ou=People,o=University of Michigan,c=US" + by dn=".*,o=University of Michigan,c=US" + read + by * none +access to attr=member + by dnattr=member selfwrite + by * read +access to filter="objectclass=rfc822mailgroup" + by dn="Bjorn Jensen,ou=Information Technology Division,ou=People,o=University of Michigan,c=US" write + by * read +access to * by * read diff --git a/tests/data/slapd-bdb2-master.conf b/tests/data/slapd-bdb2-master.conf new file mode 100644 index 0000000000..53e6a91f2d --- /dev/null +++ b/tests/data/slapd-bdb2-master.conf @@ -0,0 +1,25 @@ +# +# master slapd config -- for testing +# +include ./data/slapd.at.conf +include ./data/slapd.oc.conf +schemacheck on +pidfile ./test-db/slapd.pid +argsfile ./test-db/slapd.args + +####################################################################### +# ldbm database definitions +####################################################################### + +backend bdb2 +home ./test-db + +database bdb2 +cachesize 4 +suffix "o=University of Michigan, c=US" +directory ./test-db +rootdn "cn=Manager, o=University of Michigan, c=US" +rootpw secret +index cn,sn,uid pres,eq,approx +index default none +lastmod on diff --git a/tests/data/slapd-bdb2-repl-master.conf b/tests/data/slapd-bdb2-repl-master.conf new file mode 100644 index 0000000000..a212901936 --- /dev/null +++ b/tests/data/slapd-bdb2-repl-master.conf @@ -0,0 +1,32 @@ +# +# master slapd config -- for testing of replication +# +include ./data/slapd.at.conf +include ./data/slapd.oc.conf +schemacheck off +pidfile ./test-db/slapd.pid +argsfile ./test-db/slapd.args + +####################################################################### +# ldbm database definitions +####################################################################### + +backend bdb2 +home ./test-db + +database bdb2 +suffix "o=University of Michigan, c=US" +directory ./test-db +rootdn "cn=Manager, o=University of Michigan, c=US" +rootpw secret +index cn,sn,uid pres,eq,approx +index default none +# index default pres,eq,approx +lastmod on + +replogfile ./test-db/slapd.replog + +replica host=localhost:9010 + binddn="cn=Manager, o=University of Michigan, c=US" + bindmethod=simple + credentials=secret diff --git a/tests/data/slapd-bdb2-repl-slave.conf b/tests/data/slapd-bdb2-repl-slave.conf new file mode 100644 index 0000000000..81f7caaba3 --- /dev/null +++ b/tests/data/slapd-bdb2-repl-slave.conf @@ -0,0 +1,27 @@ +# +# master slapd config -- for testing of replication +# +include ./data/slapd.at.conf +include ./data/slapd.oc.conf +schemacheck off +pidfile ./test-repl/slapd.pid +argsfile ./test-repl/slapd.args + +####################################################################### +# ldbm database definitions +####################################################################### + +backend bdb2 +home ./test-db + +database bdb2 +suffix "o=University of Michigan, c=US" +directory ./test-repl +rootdn "cn=Manager, o=University of Michigan, c=US" +rootpw secret +updatedn "cn=Manager, o=University of Michigan, c=US" +index cn,sn,uid pres,eq,approx +index default none +# index default pres,eq,approx +lastmod on +dbcachenowsync diff --git a/tests/scripts/all b/tests/scripts/all index 2af48bcc4d..c582f20e0b 100755 --- a/tests/scripts/all +++ b/tests/scripts/all @@ -10,12 +10,20 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi - echo ">>>>> Test Directory: $SRCDIR" +if [ $# -eq 1 ]; then + BDB2=$1; shift + if [ "$BDB2" == "ldbm" ]; then + echo ">>>>> LDBM mode" + else + echo ">>>>> BDB2 mode" + fi +fi + for CMD in $SRCDIR/scripts/test*; do echo ">>>>> Starting `basename $CMD` ..." - $CMD $SRCDIR + $CMD $SRCDIR $BDB2 RC=$? if [ $RC -eq 0 ]; then echo ">>>>> $CMD completed OK." diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh index 49a6656fb7..4e138e5920 100755 --- a/tests/scripts/defines.sh +++ b/tests/scripts/defines.sh @@ -1,6 +1,28 @@ +if [ $# -eq 0 ]; then + SRCDIR="." +else + SRCDIR=$1; shift +fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi + DATADIR=$SRCDIR/data -LDIF2LDBM=../servers/slapd/tools/ldif2ldbm +if [ $BDB2 == "bdb2" ]; then + LDIF2LDBM=../servers/slapd/tools/ldif2ldbm-bdb2 + CONF=$DATADIR/slapd-bdb2-master.conf + ACLCONF=$DATADIR/slapd-bdb2-acl.conf + MASTERCONF=$DATADIR/slapd-bdb2-repl-master.conf + SLAVECONF=$DATADIR/slapd-bdb2-repl-slave.conf +else + LDIF2LDBM=../servers/slapd/tools/ldif2ldbm + CONF=$DATADIR/slapd-master.conf + ACLCONF=$DATADIR/slapd-acl.conf + MASTERCONF=$DATADIR/slapd-repl-master.conf + SLAVECONF=$DATADIR/slapd-repl-slave.conf +fi + SLAPD=../servers/slapd/slapd SLURPD=../servers/slurpd/slurpd LDAPSEARCH=../clients/tools/ldapsearch @@ -11,10 +33,6 @@ PORT=9009 SLAVEPORT=9010 DBDIR=./test-db REPLDIR=./test-repl -CONF=$DATADIR/slapd-master.conf -ACLCONF=$DATADIR/slapd-acl.conf -MASTERCONF=$DATADIR/slapd-repl-master.conf -SLAVECONF=$DATADIR/slapd-repl-slave.conf LDIF=$DATADIR/test.ldif LDIFORDERED=$DATADIR/test-ordered.ldif BASEDN="o=University of Michigan, c=US" diff --git a/tests/scripts/test001-ldif2ldbm b/tests/scripts/test001-ldif2ldbm index 64deb66b87..2c9ea80826 100755 --- a/tests/scripts/test001-ldif2ldbm +++ b/tests/scripts/test001-ldif2ldbm @@ -5,10 +5,13 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -echo "running defines.sh $SRCDIR" +echo "running defines.sh $SRCDIR $BDB2" -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "Datadir is $DATADIR" diff --git a/tests/scripts/test001-slapadd b/tests/scripts/test001-slapadd index 64deb66b87..2c9ea80826 100755 --- a/tests/scripts/test001-slapadd +++ b/tests/scripts/test001-slapadd @@ -5,10 +5,13 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -echo "running defines.sh $SRCDIR" +echo "running defines.sh $SRCDIR $BDB2" -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "Datadir is $DATADIR" diff --git a/tests/scripts/test002-populate b/tests/scripts/test002-populate index cc7fc7debd..afc71f45ad 100755 --- a/tests/scripts/test002-populate +++ b/tests/scripts/test002-populate @@ -5,8 +5,11 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "Cleaning up in $DBDIR..." diff --git a/tests/scripts/test003-search b/tests/scripts/test003-search index e6d2d6ac9d..e5b5a2ab81 100755 --- a/tests/scripts/test003-search +++ b/tests/scripts/test003-search @@ -5,8 +5,11 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "Cleaning up in $DBDIR..." diff --git a/tests/scripts/test004-modify b/tests/scripts/test004-modify index bea606e7a3..352c66c35f 100755 --- a/tests/scripts/test004-modify +++ b/tests/scripts/test004-modify @@ -5,8 +5,11 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "Cleaning up in $DBDIR..." diff --git a/tests/scripts/test005-modrdn b/tests/scripts/test005-modrdn index 510f898554..af654c4a2e 100755 --- a/tests/scripts/test005-modrdn +++ b/tests/scripts/test005-modrdn @@ -5,8 +5,11 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "modrdn test not yet written" exit 0 diff --git a/tests/scripts/test006-acls b/tests/scripts/test006-acls index 7a1f0f84f5..6d03e68422 100755 --- a/tests/scripts/test006-acls +++ b/tests/scripts/test006-acls @@ -5,8 +5,11 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 echo "Cleaning up in $DBDIR..." diff --git a/tests/scripts/test007-replication b/tests/scripts/test007-replication index 472d257678..b66f03a1e1 100755 --- a/tests/scripts/test007-replication +++ b/tests/scripts/test007-replication @@ -15,8 +15,11 @@ if [ $# -eq 0 ]; then else SRCDIR=$1; shift fi +if [ $# -eq 1 ]; then + BDB2=$1; shift +fi -. $SRCDIR/scripts/defines.sh $SRCDIR +. $SRCDIR/scripts/defines.sh $SRCDIR $BDB2 if test ! -x $SLURPD ; then echo ">>>>> $SLURPD is not executable or do not exist." -- 2.39.5