1 /* init.c - initialize bdb backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
21 #include <ac/unistd.h>
22 #include <ac/stdlib.h>
31 static const struct bdbi_database {
36 } bdbi_databases[] = {
37 { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
38 { "dn2id" BDB_SUFFIX, "dn2id", DB_BTREE, 0 },
42 typedef void * db_malloc(size_t);
43 typedef void * db_realloc(void *, size_t);
45 #define bdb_db_init BDB_SYMBOL(db_init)
46 #define bdb_db_open BDB_SYMBOL(db_open)
47 #define bdb_db_close BDB_SYMBOL(db_close)
50 bdb_db_init( BackendDB *be, ConfigReply *cr )
55 Debug( LDAP_DEBUG_TRACE,
56 LDAP_XSTRING(bdb_db_init) ": Initializing " BDB_UCTYPE " database\n",
59 /* allocate backend-database-specific stuff */
60 bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
62 /* DBEnv parameters */
63 bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
64 bdb->bi_dbenv_xflags = 0;
65 bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
67 bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
68 bdb->bi_cache.c_minfree = 1;
70 bdb->bi_lock_detect = DB_LOCK_DEFAULT;
71 bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
72 bdb->bi_search_stack = NULL;
74 ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
75 ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
77 ldap_pvt_thread_mutex_init( &bdb->bi_modrdns_mutex );
79 ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_lru_mutex );
80 ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_count_mutex );
81 ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_eifree_mutex );
82 ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
83 ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
84 ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
85 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_lrulock );
88 be->be_cf_ocs = be->bd_info->bi_cf_ocs;
90 rc = bdb_monitor_db_init( be );
96 bdb_db_close( BackendDB *be, ConfigReply *cr );
99 bdb_db_open( BackendDB *be, ConfigReply *cr )
102 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
103 struct stat stat1, stat2;
105 char path[MAXPATHLEN];
108 int do_recover = 0, do_alock_recover = 0;
109 int alockt, quick = 0;
111 if ( be->be_suffix == NULL ) {
112 Debug( LDAP_DEBUG_ANY,
113 LDAP_XSTRING(bdb_db_open) ": need suffix.\n",
118 Debug( LDAP_DEBUG_ARGS,
119 LDAP_XSTRING(bdb_db_open) ": \"%s\"\n",
120 be->be_suffix[0].bv_val, 0, 0 );
122 #ifndef BDB_MULTIPLE_SUFFIXES
123 if ( be->be_suffix[1].bv_val ) {
125 snprintf(cr->msg, sizeof(cr->msg),
126 "database \"%s\": only one suffix allowed.",
127 be->be_suffix[0].bv_val);
128 Debug( LDAP_DEBUG_ANY,
129 LDAP_XSTRING(bdb_db_open) ": %s\n", cr->msg, 0, 0 );
135 /* Check existence of dbenv_home. Any error means trouble */
136 rc = stat( bdb->bi_dbenv_home, &stat1 );
138 Debug( LDAP_DEBUG_ANY,
139 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
140 "cannot access database directory \"%s\" (%d).\n",
141 be->be_suffix[0].bv_val, bdb->bi_dbenv_home, errno );
145 /* Perform database use arbitration/recovery logic */
146 alockt = (slapMode & SLAP_TOOL_READONLY) ? ALOCK_LOCKED : ALOCK_UNIQUE;
147 if ( slapMode & SLAP_TOOL_QUICK ) {
148 alockt |= ALOCK_NOSAVE;
152 rc = alock_open( &bdb->bi_alock_info,
154 bdb->bi_dbenv_home, alockt );
156 /* alockt is TRUE if the existing environment was created in Quick mode */
157 alockt = (rc & ALOCK_NOSAVE) ? 1 : 0;
160 if( rc == ALOCK_RECOVER ) {
161 Debug( LDAP_DEBUG_ANY,
162 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
163 "unclean shutdown detected; attempting recovery.\n",
164 be->be_suffix[0].bv_val, 0, 0 );
165 do_alock_recover = 1;
166 do_recover = DB_RECOVER;
167 } else if( rc == ALOCK_BUSY ) {
168 Debug( LDAP_DEBUG_ANY,
169 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
170 "database already in use.\n",
171 be->be_suffix[0].bv_val, 0, 0 );
173 } else if( rc != ALOCK_CLEAN ) {
174 Debug( LDAP_DEBUG_ANY,
175 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
176 "alock package is unstable.\n",
177 be->be_suffix[0].bv_val, 0, 0 );
182 * The DB_CONFIG file may have changed. If so, recover the
183 * database so that new settings are put into effect. Also
184 * note the possible absence of DB_CONFIG in the log.
186 if( stat( bdb->bi_db_config_path, &stat1 ) == 0 ) {
188 char *ptr = lutil_strcopy(path, bdb->bi_dbenv_home);
189 *ptr++ = LDAP_DIRSEP[0];
190 strcpy( ptr, "__db.001" );
191 if( stat( path, &stat2 ) == 0 ) {
192 if( stat2.st_mtime < stat1.st_mtime ) {
193 Debug( LDAP_DEBUG_ANY,
194 LDAP_XSTRING(bdb_db_open) ": DB_CONFIG for suffix \"%s\" has changed.\n",
195 be->be_suffix[0].bv_val, 0, 0 );
197 Debug( LDAP_DEBUG_ANY,
198 "Cannot use Quick mode; perform manual recovery first.\n",
200 slapMode ^= SLAP_TOOL_QUICK;
204 Debug( LDAP_DEBUG_ANY,
205 "Performing database recovery to activate new settings.\n",
208 do_recover = DB_RECOVER;
214 Debug( LDAP_DEBUG_ANY,
215 LDAP_XSTRING(bdb_db_open) ": warning - no DB_CONFIG file found "
216 "in directory %s: (%d).\n"
217 "Expect poor performance for suffix \"%s\".\n",
218 bdb->bi_dbenv_home, errno, be->be_suffix[0].bv_val );
221 /* Always let slapcat run, regardless of environment state.
222 * This can be used to cause a cache flush after an unclean
225 if ( do_recover && ( slapMode & SLAP_TOOL_READONLY )) {
226 Debug( LDAP_DEBUG_ANY,
227 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
228 "recovery skipped in read-only mode. "
229 "Run manual recovery if errors are encountered.\n",
230 be->be_suffix[0].bv_val, 0, 0 );
235 /* An existing environment in Quick mode has nothing to recover. */
236 if ( alockt && do_recover ) {
237 Debug( LDAP_DEBUG_ANY,
238 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
239 "cannot recover, database must be reinitialized.\n",
240 be->be_suffix[0].bv_val, 0, 0 );
245 rc = db_env_create( &bdb->bi_dbenv, 0 );
247 Debug( LDAP_DEBUG_ANY,
248 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
249 "db_env_create failed: %s (%d).\n",
250 be->be_suffix[0].bv_val, db_strerror(rc), rc );
255 strcpy( path, bdb->bi_dbenv_home );
259 dbhome = bdb->bi_dbenv_home;
262 /* If existing environment is clean but doesn't support
263 * currently requested modes, remove it.
265 if ( !do_recover && ( alockt ^ quick )) {
267 rc = bdb->bi_dbenv->remove( bdb->bi_dbenv, dbhome, DB_FORCE );
269 Debug( LDAP_DEBUG_ANY,
270 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
271 "dbenv remove failed: %s (%d).\n",
272 be->be_suffix[0].bv_val, db_strerror(rc), rc );
273 bdb->bi_dbenv = NULL;
276 rc = db_env_create( &bdb->bi_dbenv, 0 );
278 Debug( LDAP_DEBUG_ANY,
279 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
280 "db_env_create failed: %s (%d).\n",
281 be->be_suffix[0].bv_val, db_strerror(rc), rc );
286 bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
287 bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
289 bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
291 /* One long-lived TXN per thread, two TXNs per write op */
292 bdb->bi_dbenv->set_tx_max( bdb->bi_dbenv, connection_pool_max * 3 );
294 if( bdb->bi_dbenv_xflags != 0 ) {
295 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
296 bdb->bi_dbenv_xflags, 1);
298 Debug( LDAP_DEBUG_ANY,
299 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
300 "dbenv_set_flags failed: %s (%d).\n",
301 be->be_suffix[0].bv_val, db_strerror(rc), rc );
306 #define BDB_TXN_FLAGS (DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN)
308 Debug( LDAP_DEBUG_TRACE,
309 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
311 be->be_suffix[0].bv_val, bdb->bi_dbenv_home, 0);
313 flags = DB_INIT_MPOOL | DB_CREATE | DB_THREAD;
316 flags |= BDB_TXN_FLAGS;
318 /* If a key was set, use shared memory for the BDB environment */
319 if ( bdb->bi_shm_key ) {
320 bdb->bi_dbenv->set_shm_key( bdb->bi_dbenv, bdb->bi_shm_key );
321 flags |= DB_SYSTEM_MEM;
323 rc = (bdb->bi_dbenv->open)( bdb->bi_dbenv, dbhome,
324 flags | do_recover, bdb->bi_dbenv_mode );
327 /* Regular open failed, probably a missing shm environment.
328 * Start over, do a recovery.
330 if ( !do_recover && bdb->bi_shm_key ) {
331 bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
332 rc = db_env_create( &bdb->bi_dbenv, 0 );
334 Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_db_open)
335 ": database \"%s\": "
336 "shared memory env open failed, assuming stale env.\n",
337 be->be_suffix[0].bv_val, 0, 0 );
341 Debug( LDAP_DEBUG_ANY,
342 LDAP_XSTRING(bdb_db_open) ": database \"%s\" cannot be %s, err %d. "
343 "Restore from backup!\n",
344 be->be_suffix[0].bv_val, do_recover ? "recovered" : "opened", rc );
348 if ( do_alock_recover && alock_recover (&bdb->bi_alock_info) != 0 ) {
349 Debug( LDAP_DEBUG_ANY,
350 LDAP_XSTRING(bdb_db_open) ": database \"%s\": alock_recover failed\n",
351 be->be_suffix[0].bv_val, 0, 0 );
356 #ifdef SLAP_ZONE_ALLOC
357 if ( bdb->bi_cache.c_maxsize ) {
358 bdb->bi_cache.c_zctx = slap_zn_mem_create(
359 SLAP_ZONE_INITSIZE, SLAP_ZONE_MAXSIZE,
360 SLAP_ZONE_DELTA, SLAP_ZONE_SIZE);
364 /* Default dncache to 2x entrycache */
365 if ( bdb->bi_cache.c_maxsize && !bdb->bi_cache.c_eimax ) {
366 bdb->bi_cache.c_eimax = bdb->bi_cache.c_maxsize * 2;
369 if ( bdb->bi_idl_cache_max_size ) {
370 bdb->bi_idl_tree = NULL;
371 bdb->bi_idl_cache_size = 0;
374 flags = DB_THREAD | bdb->bi_db_opflags;
376 #ifdef DB_AUTO_COMMIT
378 flags |= DB_AUTO_COMMIT;
381 bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
382 BDB_INDICES * sizeof(struct bdb_db_info *) );
384 /* open (and create) main database */
385 for( i = 0; bdbi_databases[i].name; i++ ) {
386 struct bdb_db_info *db;
388 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
390 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
392 snprintf(cr->msg, sizeof(cr->msg),
393 "database \"%s\": db_create(%s) failed: %s (%d).",
394 be->be_suffix[0].bv_val,
395 bdb->bi_dbenv_home, db_strerror(rc), rc );
396 Debug( LDAP_DEBUG_ANY,
397 LDAP_XSTRING(bdb_db_open) ": %s\n",
402 if( i == BDB_ID2ENTRY ) {
403 if ( slapMode & SLAP_TOOL_MODE )
404 db->bdi_db->mpf->set_priority( db->bdi_db->mpf,
405 DB_PRIORITY_VERY_LOW );
407 rc = db->bdi_db->set_pagesize( db->bdi_db,
408 BDB_ID2ENTRY_PAGESIZE );
409 if ( slapMode & SLAP_TOOL_READMAIN ) {
415 rc = db->bdi_db->set_flags( db->bdi_db,
416 DB_DUP | DB_DUPSORT );
418 if ( slapMode & SLAP_TOOL_READONLY ) {
424 if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
430 rc = db->bdi_db->set_pagesize( db->bdi_db,
435 strcpy( path, bdbi_databases[i].file );
437 rc = DB_OPEN( db->bdi_db,
439 /* bdbi_databases[i].name, */ NULL,
440 bdbi_databases[i].type,
441 bdbi_databases[i].flags | flags,
442 bdb->bi_dbenv_mode );
444 rc = DB_OPEN( db->bdi_db,
445 bdbi_databases[i].file,
446 /* bdbi_databases[i].name, */ NULL,
447 bdbi_databases[i].type,
448 bdbi_databases[i].flags | flags,
449 bdb->bi_dbenv_mode );
453 snprintf( cr->msg, sizeof(cr->msg), "database \"%s\": "
454 "db_open(%s/%s) failed: %s (%d).",
455 be->be_suffix[0].bv_val,
456 bdb->bi_dbenv_home, bdbi_databases[i].file,
457 db_strerror(rc), rc );
458 Debug( LDAP_DEBUG_ANY,
459 LDAP_XSTRING(bdb_db_open) ": %s\n",
461 db->bdi_db->close( db->bdi_db, 0 );
465 flags &= ~(DB_CREATE | DB_RDONLY);
466 db->bdi_name = bdbi_databases[i].name;
467 bdb->bi_databases[i] = db;
470 bdb->bi_databases[i] = NULL;
471 bdb->bi_ndatabases = i;
474 rc = bdb_last_id( be, NULL );
476 snprintf( cr->msg, sizeof(cr->msg), "database \"%s\": "
477 "last_id(%s) failed: %s (%d).",
478 be->be_suffix[0].bv_val, bdb->bi_dbenv_home,
479 db_strerror(rc), rc );
480 Debug( LDAP_DEBUG_ANY,
481 LDAP_XSTRING(bdb_db_open) ": %s\n",
487 #if DB_VERSION_FULL >= 0x04060012
489 XLOCK_ID(bdb->bi_dbenv, &lid);
490 __lock_getlocker(bdb->bi_dbenv->lk_handle, lid, 0, &bdb->bi_cache.c_locker);
492 XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
496 entry_prealloc( bdb->bi_cache.c_maxsize );
497 attr_prealloc( bdb->bi_cache.c_maxsize * 20 );
499 /* setup for empty-DN contexts */
500 if ( BER_BVISEMPTY( &be->be_nsuffix[0] )) {
501 rc = bdb_id2entry( be, NULL, 0, 0, &e );
506 ber_dupbv( &e->e_name, (struct berval *)&slap_empty_bv );
507 ber_dupbv( &e->e_nname, (struct berval *)&slap_empty_bv );
509 e->e_ocflags = SLAP_OC_GLUE|SLAP_OC__END;
510 e->e_private = &bdb->bi_cache.c_dntree;
511 bdb->bi_cache.c_dntree.bei_e = e;
514 rc = bdb_monitor_db_open( be );
519 bdb->bi_flags |= BDB_IS_OPEN;
524 bdb_db_close( be, NULL );
529 bdb_db_close( BackendDB *be, ConfigReply *cr )
532 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
533 struct bdb_db_info *db;
534 bdb_idl_cache_entry_t *entry, *next_entry;
536 /* monitor handling */
537 (void)bdb_monitor_db_close( be );
540 Entry *e = bdb->bi_cache.c_dntree.bei_e;
542 bdb->bi_cache.c_dntree.bei_e = NULL;
544 bdb_entry_return( e );
548 bdb->bi_flags &= ~BDB_IS_OPEN;
550 ber_bvarray_free( bdb->bi_db_config );
551 bdb->bi_db_config = NULL;
553 while( bdb->bi_databases && bdb->bi_ndatabases-- ) {
554 db = bdb->bi_databases[bdb->bi_ndatabases];
555 rc = db->bdi_db->close( db->bdi_db, 0 );
556 /* Lower numbered names are not strdup'd */
557 if( bdb->bi_ndatabases >= BDB_NDB )
558 free( db->bdi_name );
561 free( bdb->bi_databases );
562 bdb->bi_databases = NULL;
564 bdb_cache_release_all (&bdb->bi_cache);
566 if ( bdb->bi_idl_cache_size ) {
567 avl_free( bdb->bi_idl_tree, NULL );
568 bdb->bi_idl_tree = NULL;
569 entry = bdb->bi_idl_lru_head;
571 next_entry = entry->idl_lru_next;
574 free( entry->kstr.bv_val );
577 } while ( entry != bdb->bi_idl_lru_head );
578 bdb->bi_idl_lru_head = bdb->bi_idl_lru_tail = NULL;
581 /* close db environment */
582 if( bdb->bi_dbenv ) {
583 /* Free cache locker if we enabled locking */
584 if ( !( slapMode & SLAP_TOOL_QUICK )) {
585 #if DB_VERSION_FULL >= 0x04060012
586 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker->id);
588 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
590 bdb->bi_cache.c_locker = 0;
592 #ifdef BDB_REUSE_LOCKERS
593 bdb_locker_flush( bdb->bi_dbenv );
595 /* force a checkpoint, but not if we were ReadOnly,
596 * and not in Quick mode since there are no transactions there.
598 if ( !( slapMode & ( SLAP_TOOL_QUICK|SLAP_TOOL_READONLY ))) {
599 rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
601 Debug( LDAP_DEBUG_ANY,
602 "bdb_db_close: database \"%s\": "
603 "txn_checkpoint failed: %s (%d).\n",
604 be->be_suffix[0].bv_val, db_strerror(rc), rc );
608 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
609 bdb->bi_dbenv = NULL;
611 Debug( LDAP_DEBUG_ANY,
612 "bdb_db_close: database \"%s\": "
613 "close failed: %s (%d)\n",
614 be->be_suffix[0].bv_val, db_strerror(rc), rc );
619 rc = alock_close( &bdb->bi_alock_info, slapMode & SLAP_TOOL_QUICK );
621 Debug( LDAP_DEBUG_ANY,
622 "bdb_db_close: database \"%s\": alock_close failed\n",
623 be->be_suffix[0].bv_val, 0, 0 );
631 bdb_db_destroy( BackendDB *be, ConfigReply *cr )
633 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
635 /* monitor handling */
636 (void)bdb_monitor_db_destroy( be );
638 if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
639 if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
641 bdb_attr_index_destroy( bdb );
643 ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
644 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_lru_mutex );
645 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_count_mutex );
646 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_eifree_mutex );
647 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
649 ldap_pvt_thread_mutex_destroy( &bdb->bi_modrdns_mutex );
651 ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
652 ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
653 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
654 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
657 be->be_private = NULL;
668 static char *controls[] = {
670 LDAP_CONTROL_MANAGEDSAIT,
672 LDAP_CONTROL_PAGEDRESULTS,
673 LDAP_CONTROL_PRE_READ,
674 LDAP_CONTROL_POST_READ,
675 LDAP_CONTROL_SUBENTRIES,
676 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
678 LDAP_CONTROL_X_TXN_SPEC,
683 /* initialize the underlying database system */
684 Debug( LDAP_DEBUG_TRACE,
685 LDAP_XSTRING(bdb_back_initialize) ": initialize "
686 BDB_UCTYPE " backend\n", 0, 0, 0 );
689 SLAP_BFLAG_INCREMENT |
690 SLAP_BFLAG_SUBENTRIES |
692 SLAP_BFLAG_REFERRALS;
694 bi->bi_controls = controls;
696 { /* version check */
697 int major, minor, patch, ver;
698 char *version = db_version( &major, &minor, &patch );
702 /* All our stdio does an ASCII to EBCDIC conversion on
703 * the output. Strings from the BDB library are already
704 * in EBCDIC; we have to go back and forth...
706 strcpy( v2, version );
711 ver = (major << 24) | (minor << 16) | patch;
712 if( ver != DB_VERSION_FULL ) {
713 /* fail if a versions don't match */
714 Debug( LDAP_DEBUG_ANY,
715 LDAP_XSTRING(bdb_back_initialize) ": "
716 "BDB library version mismatch:"
717 " expected " DB_VERSION_STRING ","
718 " got %s\n", version, 0, 0 );
722 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_back_initialize)
723 ": %s\n", version, 0, 0 );
726 db_env_set_func_free( ber_memfree );
727 db_env_set_func_malloc( (db_malloc *)ber_memalloc );
728 db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
730 /* This is a no-op on a NO_THREAD build. Leave the default
731 * alone so that BDB will sleep on interprocess conflicts.
733 db_env_set_func_yield( ldap_pvt_thread_yield );
741 bi->bi_db_init = bdb_db_init;
742 bi->bi_db_config = config_generic_wrapper;
743 bi->bi_db_open = bdb_db_open;
744 bi->bi_db_close = bdb_db_close;
745 bi->bi_db_destroy = bdb_db_destroy;
747 bi->bi_op_add = bdb_add;
748 bi->bi_op_bind = bdb_bind;
749 bi->bi_op_compare = bdb_compare;
750 bi->bi_op_delete = bdb_delete;
751 bi->bi_op_modify = bdb_modify;
752 bi->bi_op_modrdn = bdb_modrdn;
753 bi->bi_op_search = bdb_search;
755 bi->bi_op_unbind = 0;
757 bi->bi_extended = bdb_extended;
759 bi->bi_chk_referrals = bdb_referrals;
760 bi->bi_operational = bdb_operational;
761 bi->bi_has_subordinates = bdb_hasSubordinates;
762 bi->bi_entry_release_rw = bdb_entry_release;
763 bi->bi_entry_get_rw = bdb_entry_get;
766 * hooks for slap tools
768 bi->bi_tool_entry_open = bdb_tool_entry_open;
769 bi->bi_tool_entry_close = bdb_tool_entry_close;
770 bi->bi_tool_entry_first = bdb_tool_entry_next;
771 bi->bi_tool_entry_next = bdb_tool_entry_next;
772 bi->bi_tool_entry_get = bdb_tool_entry_get;
773 bi->bi_tool_entry_put = bdb_tool_entry_put;
774 bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
775 bi->bi_tool_sync = 0;
776 bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
777 bi->bi_tool_entry_modify = bdb_tool_entry_modify;
779 bi->bi_connection_init = 0;
780 bi->bi_connection_destroy = 0;
782 rc = bdb_back_init_cf( bi );
787 #if (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \
788 (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER))
790 /* conditionally define the init_module() function */
792 SLAP_BACKEND_INIT_MODULE( hdb )
793 #else /* !BDB_HIER */
794 SLAP_BACKEND_INIT_MODULE( bdb )
795 #endif /* !BDB_HIER */
797 #endif /* SLAPD_[BH]DB == SLAPD_MOD_DYNAMIC */