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, BER_BVC("id2entry"), DB_BTREE, 0 },
38 { "dn2id" BDB_SUFFIX, BER_BVC("dn2id"), DB_BTREE, 0 },
39 { NULL, BER_BVNULL, 0, 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 #ifndef BDB_MULTIPLE_SUFFIXES
91 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_ONE_SUFFIX;
94 rc = bdb_monitor_db_init( be );
100 bdb_db_close( BackendDB *be, ConfigReply *cr );
103 bdb_db_open( BackendDB *be, ConfigReply *cr )
106 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
107 struct stat stat1, stat2;
109 char path[MAXPATHLEN];
112 int do_recover = 0, do_alock_recover = 0;
113 int alockt, quick = 0;
115 if ( be->be_suffix == NULL ) {
116 Debug( LDAP_DEBUG_ANY,
117 LDAP_XSTRING(bdb_db_open) ": need suffix.\n",
122 Debug( LDAP_DEBUG_ARGS,
123 LDAP_XSTRING(bdb_db_open) ": \"%s\"\n",
124 be->be_suffix[0].bv_val, 0, 0 );
126 /* Check existence of dbenv_home. Any error means trouble */
127 rc = stat( bdb->bi_dbenv_home, &stat1 );
129 Debug( LDAP_DEBUG_ANY,
130 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
131 "cannot access database directory \"%s\" (%d).\n",
132 be->be_suffix[0].bv_val, bdb->bi_dbenv_home, errno );
136 /* Perform database use arbitration/recovery logic */
137 alockt = (slapMode & SLAP_TOOL_READONLY) ? ALOCK_LOCKED : ALOCK_UNIQUE;
138 if ( slapMode & SLAP_TOOL_QUICK ) {
139 alockt |= ALOCK_NOSAVE;
143 rc = alock_open( &bdb->bi_alock_info,
145 bdb->bi_dbenv_home, alockt );
147 /* alockt is TRUE if the existing environment was created in Quick mode */
148 alockt = (rc & ALOCK_NOSAVE) ? 1 : 0;
151 if( rc == ALOCK_RECOVER ) {
152 Debug( LDAP_DEBUG_ANY,
153 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
154 "unclean shutdown detected; attempting recovery.\n",
155 be->be_suffix[0].bv_val, 0, 0 );
156 do_alock_recover = 1;
157 do_recover = DB_RECOVER;
158 } else if( rc == ALOCK_BUSY ) {
159 Debug( LDAP_DEBUG_ANY,
160 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
161 "database already in use.\n",
162 be->be_suffix[0].bv_val, 0, 0 );
164 } else if( rc != ALOCK_CLEAN ) {
165 Debug( LDAP_DEBUG_ANY,
166 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
167 "alock package is unstable.\n",
168 be->be_suffix[0].bv_val, 0, 0 );
173 * The DB_CONFIG file may have changed. If so, recover the
174 * database so that new settings are put into effect. Also
175 * note the possible absence of DB_CONFIG in the log.
177 if( stat( bdb->bi_db_config_path, &stat1 ) == 0 ) {
179 char *ptr = lutil_strcopy(path, bdb->bi_dbenv_home);
180 *ptr++ = LDAP_DIRSEP[0];
181 strcpy( ptr, "__db.001" );
182 if( stat( path, &stat2 ) == 0 ) {
183 if( stat2.st_mtime < stat1.st_mtime ) {
184 Debug( LDAP_DEBUG_ANY,
185 LDAP_XSTRING(bdb_db_open) ": DB_CONFIG for suffix \"%s\" has changed.\n",
186 be->be_suffix[0].bv_val, 0, 0 );
188 Debug( LDAP_DEBUG_ANY,
189 "Cannot use Quick mode; perform manual recovery first.\n",
191 slapMode ^= SLAP_TOOL_QUICK;
195 Debug( LDAP_DEBUG_ANY,
196 "Performing database recovery to activate new settings.\n",
199 do_recover = DB_RECOVER;
205 Debug( LDAP_DEBUG_ANY,
206 LDAP_XSTRING(bdb_db_open) ": warning - no DB_CONFIG file found "
207 "in directory %s: (%d).\n"
208 "Expect poor performance for suffix \"%s\".\n",
209 bdb->bi_dbenv_home, errno, be->be_suffix[0].bv_val );
212 /* Always let slapcat run, regardless of environment state.
213 * This can be used to cause a cache flush after an unclean
216 if ( do_recover && ( slapMode & SLAP_TOOL_READONLY )) {
217 Debug( LDAP_DEBUG_ANY,
218 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
219 "recovery skipped in read-only mode. "
220 "Run manual recovery if errors are encountered.\n",
221 be->be_suffix[0].bv_val, 0, 0 );
226 /* An existing environment in Quick mode has nothing to recover. */
227 if ( alockt && do_recover ) {
228 Debug( LDAP_DEBUG_ANY,
229 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
230 "cannot recover, database must be reinitialized.\n",
231 be->be_suffix[0].bv_val, 0, 0 );
236 rc = db_env_create( &bdb->bi_dbenv, 0 );
238 Debug( LDAP_DEBUG_ANY,
239 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
240 "db_env_create failed: %s (%d).\n",
241 be->be_suffix[0].bv_val, db_strerror(rc), rc );
246 strcpy( path, bdb->bi_dbenv_home );
250 dbhome = bdb->bi_dbenv_home;
253 /* If existing environment is clean but doesn't support
254 * currently requested modes, remove it.
256 if ( !do_recover && ( alockt ^ quick )) {
258 rc = bdb->bi_dbenv->remove( bdb->bi_dbenv, dbhome, DB_FORCE );
260 Debug( LDAP_DEBUG_ANY,
261 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
262 "dbenv remove failed: %s (%d).\n",
263 be->be_suffix[0].bv_val, db_strerror(rc), rc );
264 bdb->bi_dbenv = NULL;
267 rc = db_env_create( &bdb->bi_dbenv, 0 );
269 Debug( LDAP_DEBUG_ANY,
270 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
271 "db_env_create failed: %s (%d).\n",
272 be->be_suffix[0].bv_val, db_strerror(rc), rc );
277 bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
278 bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
280 bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
282 /* One long-lived TXN per thread, two TXNs per write op */
283 bdb->bi_dbenv->set_tx_max( bdb->bi_dbenv, connection_pool_max * 3 );
285 if( bdb->bi_dbenv_xflags != 0 ) {
286 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
287 bdb->bi_dbenv_xflags, 1);
289 Debug( LDAP_DEBUG_ANY,
290 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
291 "dbenv_set_flags failed: %s (%d).\n",
292 be->be_suffix[0].bv_val, db_strerror(rc), rc );
297 #define BDB_TXN_FLAGS (DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN)
299 Debug( LDAP_DEBUG_TRACE,
300 LDAP_XSTRING(bdb_db_open) ": database \"%s\": "
302 be->be_suffix[0].bv_val, bdb->bi_dbenv_home, 0);
304 flags = DB_INIT_MPOOL | DB_CREATE | DB_THREAD;
307 flags |= BDB_TXN_FLAGS;
309 /* If a key was set, use shared memory for the BDB environment */
310 if ( bdb->bi_shm_key ) {
311 bdb->bi_dbenv->set_shm_key( bdb->bi_dbenv, bdb->bi_shm_key );
312 flags |= DB_SYSTEM_MEM;
314 rc = (bdb->bi_dbenv->open)( bdb->bi_dbenv, dbhome,
315 flags | do_recover, bdb->bi_dbenv_mode );
318 /* Regular open failed, probably a missing shm environment.
319 * Start over, do a recovery.
321 if ( !do_recover && bdb->bi_shm_key ) {
322 bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
323 rc = db_env_create( &bdb->bi_dbenv, 0 );
325 Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_db_open)
326 ": database \"%s\": "
327 "shared memory env open failed, assuming stale env.\n",
328 be->be_suffix[0].bv_val, 0, 0 );
332 Debug( LDAP_DEBUG_ANY,
333 LDAP_XSTRING(bdb_db_open) ": database \"%s\" cannot be %s, err %d. "
334 "Restore from backup!\n",
335 be->be_suffix[0].bv_val, do_recover ? "recovered" : "opened", rc );
339 if ( do_alock_recover && alock_recover (&bdb->bi_alock_info) != 0 ) {
340 Debug( LDAP_DEBUG_ANY,
341 LDAP_XSTRING(bdb_db_open) ": database \"%s\": alock_recover failed\n",
342 be->be_suffix[0].bv_val, 0, 0 );
347 #ifdef SLAP_ZONE_ALLOC
348 if ( bdb->bi_cache.c_maxsize ) {
349 bdb->bi_cache.c_zctx = slap_zn_mem_create(
350 SLAP_ZONE_INITSIZE, SLAP_ZONE_MAXSIZE,
351 SLAP_ZONE_DELTA, SLAP_ZONE_SIZE);
355 /* Default dncache to 2x entrycache */
356 if ( bdb->bi_cache.c_maxsize && !bdb->bi_cache.c_eimax ) {
357 bdb->bi_cache.c_eimax = bdb->bi_cache.c_maxsize * 2;
360 if ( bdb->bi_idl_cache_max_size ) {
361 bdb->bi_idl_tree = NULL;
362 bdb->bi_idl_cache_size = 0;
365 flags = DB_THREAD | bdb->bi_db_opflags;
367 #ifdef DB_AUTO_COMMIT
369 flags |= DB_AUTO_COMMIT;
372 bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
373 BDB_INDICES * sizeof(struct bdb_db_info *) );
375 /* open (and create) main database */
376 for( i = 0; bdbi_databases[i].name.bv_val; i++ ) {
377 struct bdb_db_info *db;
379 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
381 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
383 snprintf(cr->msg, sizeof(cr->msg),
384 "database \"%s\": db_create(%s) failed: %s (%d).",
385 be->be_suffix[0].bv_val,
386 bdb->bi_dbenv_home, db_strerror(rc), rc );
387 Debug( LDAP_DEBUG_ANY,
388 LDAP_XSTRING(bdb_db_open) ": %s\n",
393 if( i == BDB_ID2ENTRY ) {
394 if ( slapMode & SLAP_TOOL_MODE )
395 db->bdi_db->mpf->set_priority( db->bdi_db->mpf,
396 DB_PRIORITY_VERY_LOW );
398 rc = db->bdi_db->set_pagesize( db->bdi_db,
399 BDB_ID2ENTRY_PAGESIZE );
400 if ( slapMode & SLAP_TOOL_READMAIN ) {
406 rc = db->bdi_db->set_flags( db->bdi_db,
407 DB_DUP | DB_DUPSORT );
409 if ( slapMode & SLAP_TOOL_READONLY ) {
415 rc = db->bdi_db->set_dup_compare( db->bdi_db,
417 if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
423 rc = db->bdi_db->set_pagesize( db->bdi_db,
428 strcpy( path, bdbi_databases[i].file );
430 rc = DB_OPEN( db->bdi_db,
432 /* bdbi_databases[i].name, */ NULL,
433 bdbi_databases[i].type,
434 bdbi_databases[i].flags | flags,
435 bdb->bi_dbenv_mode );
437 rc = DB_OPEN( db->bdi_db,
438 bdbi_databases[i].file,
439 /* bdbi_databases[i].name, */ NULL,
440 bdbi_databases[i].type,
441 bdbi_databases[i].flags | flags,
442 bdb->bi_dbenv_mode );
446 snprintf( cr->msg, sizeof(cr->msg), "database \"%s\": "
447 "db_open(%s/%s) failed: %s (%d).",
448 be->be_suffix[0].bv_val,
449 bdb->bi_dbenv_home, bdbi_databases[i].file,
450 db_strerror(rc), rc );
451 Debug( LDAP_DEBUG_ANY,
452 LDAP_XSTRING(bdb_db_open) ": %s\n",
454 db->bdi_db->close( db->bdi_db, 0 );
458 flags &= ~(DB_CREATE | DB_RDONLY);
459 db->bdi_name = bdbi_databases[i].name;
460 bdb->bi_databases[i] = db;
463 bdb->bi_databases[i] = NULL;
464 bdb->bi_ndatabases = i;
467 rc = bdb_last_id( be, NULL );
469 snprintf( cr->msg, sizeof(cr->msg), "database \"%s\": "
470 "last_id(%s) failed: %s (%d).",
471 be->be_suffix[0].bv_val, bdb->bi_dbenv_home,
472 db_strerror(rc), rc );
473 Debug( LDAP_DEBUG_ANY,
474 LDAP_XSTRING(bdb_db_open) ": %s\n",
480 #if DB_VERSION_FULL >= 0x04060012
482 XLOCK_ID(bdb->bi_dbenv, &lid);
483 __lock_getlocker(bdb->bi_dbenv->lk_handle, lid, 0, &bdb->bi_cache.c_locker);
485 XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
489 entry_prealloc( bdb->bi_cache.c_maxsize );
490 attr_prealloc( bdb->bi_cache.c_maxsize * 20 );
492 /* setup for empty-DN contexts */
493 if ( BER_BVISEMPTY( &be->be_nsuffix[0] )) {
494 rc = bdb_id2entry( be, NULL, 0, 0, &e );
499 ber_dupbv( &e->e_name, (struct berval *)&slap_empty_bv );
500 ber_dupbv( &e->e_nname, (struct berval *)&slap_empty_bv );
502 e->e_ocflags = SLAP_OC_GLUE|SLAP_OC__END;
503 e->e_private = &bdb->bi_cache.c_dntree;
504 bdb->bi_cache.c_dntree.bei_e = e;
507 rc = bdb_monitor_db_open( be );
512 bdb->bi_flags |= BDB_IS_OPEN;
517 bdb_db_close( be, NULL );
522 bdb_db_close( BackendDB *be, ConfigReply *cr )
525 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
526 struct bdb_db_info *db;
527 bdb_idl_cache_entry_t *entry, *next_entry;
529 /* monitor handling */
530 (void)bdb_monitor_db_close( be );
533 Entry *e = bdb->bi_cache.c_dntree.bei_e;
535 bdb->bi_cache.c_dntree.bei_e = NULL;
537 bdb_entry_return( e );
541 bdb->bi_flags &= ~BDB_IS_OPEN;
543 ber_bvarray_free( bdb->bi_db_config );
544 bdb->bi_db_config = NULL;
546 while( bdb->bi_databases && bdb->bi_ndatabases-- ) {
547 db = bdb->bi_databases[bdb->bi_ndatabases];
548 rc = db->bdi_db->close( db->bdi_db, 0 );
549 /* Lower numbered names are not strdup'd */
550 if( bdb->bi_ndatabases >= BDB_NDB )
551 free( db->bdi_name.bv_val );
554 free( bdb->bi_databases );
555 bdb->bi_databases = NULL;
557 bdb_cache_release_all (&bdb->bi_cache);
559 if ( bdb->bi_idl_cache_size ) {
560 avl_free( bdb->bi_idl_tree, NULL );
561 bdb->bi_idl_tree = NULL;
562 entry = bdb->bi_idl_lru_head;
564 next_entry = entry->idl_lru_next;
567 free( entry->kstr.bv_val );
570 } while ( entry != bdb->bi_idl_lru_head );
571 bdb->bi_idl_lru_head = bdb->bi_idl_lru_tail = NULL;
574 /* close db environment */
575 if( bdb->bi_dbenv ) {
576 /* Free cache locker if we enabled locking */
577 if ( !( slapMode & SLAP_TOOL_QUICK )) {
578 #if DB_VERSION_FULL >= 0x04060012
579 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker->id);
581 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
583 bdb->bi_cache.c_locker = 0;
585 #ifdef BDB_REUSE_LOCKERS
586 bdb_locker_flush( bdb->bi_dbenv );
588 /* force a checkpoint, but not if we were ReadOnly,
589 * and not in Quick mode since there are no transactions there.
591 if ( !( slapMode & ( SLAP_TOOL_QUICK|SLAP_TOOL_READONLY ))) {
592 rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
594 Debug( LDAP_DEBUG_ANY,
595 "bdb_db_close: database \"%s\": "
596 "txn_checkpoint failed: %s (%d).\n",
597 be->be_suffix[0].bv_val, db_strerror(rc), rc );
601 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
602 bdb->bi_dbenv = NULL;
604 Debug( LDAP_DEBUG_ANY,
605 "bdb_db_close: database \"%s\": "
606 "close failed: %s (%d)\n",
607 be->be_suffix[0].bv_val, db_strerror(rc), rc );
612 rc = alock_close( &bdb->bi_alock_info, slapMode & SLAP_TOOL_QUICK );
614 Debug( LDAP_DEBUG_ANY,
615 "bdb_db_close: database \"%s\": alock_close failed\n",
616 be->be_suffix[0].bv_val, 0, 0 );
624 bdb_db_destroy( BackendDB *be, ConfigReply *cr )
626 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
628 /* monitor handling */
629 (void)bdb_monitor_db_destroy( be );
631 if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
632 if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
634 bdb_attr_index_destroy( bdb );
636 ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
637 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_lru_mutex );
638 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_count_mutex );
639 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_eifree_mutex );
640 ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
642 ldap_pvt_thread_mutex_destroy( &bdb->bi_modrdns_mutex );
644 ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
645 ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
646 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
647 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
650 be->be_private = NULL;
661 static char *controls[] = {
663 LDAP_CONTROL_MANAGEDSAIT,
665 LDAP_CONTROL_PAGEDRESULTS,
666 LDAP_CONTROL_PRE_READ,
667 LDAP_CONTROL_POST_READ,
668 LDAP_CONTROL_SUBENTRIES,
669 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
671 LDAP_CONTROL_X_TXN_SPEC,
676 /* initialize the underlying database system */
677 Debug( LDAP_DEBUG_TRACE,
678 LDAP_XSTRING(bdb_back_initialize) ": initialize "
679 BDB_UCTYPE " backend\n", 0, 0, 0 );
682 SLAP_BFLAG_INCREMENT |
683 SLAP_BFLAG_SUBENTRIES |
685 SLAP_BFLAG_REFERRALS;
687 bi->bi_controls = controls;
689 { /* version check */
690 int major, minor, patch, ver;
691 char *version = db_version( &major, &minor, &patch );
695 /* All our stdio does an ASCII to EBCDIC conversion on
696 * the output. Strings from the BDB library are already
697 * in EBCDIC; we have to go back and forth...
699 strcpy( v2, version );
704 ver = (major << 24) | (minor << 16) | patch;
705 if( ver != DB_VERSION_FULL ) {
706 /* fail if a versions don't match */
707 Debug( LDAP_DEBUG_ANY,
708 LDAP_XSTRING(bdb_back_initialize) ": "
709 "BDB library version mismatch:"
710 " expected " DB_VERSION_STRING ","
711 " got %s\n", version, 0, 0 );
715 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_back_initialize)
716 ": %s\n", version, 0, 0 );
719 db_env_set_func_free( ber_memfree );
720 db_env_set_func_malloc( (db_malloc *)ber_memalloc );
721 db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
723 /* This is a no-op on a NO_THREAD build. Leave the default
724 * alone so that BDB will sleep on interprocess conflicts.
726 db_env_set_func_yield( ldap_pvt_thread_yield );
734 bi->bi_db_init = bdb_db_init;
735 bi->bi_db_config = config_generic_wrapper;
736 bi->bi_db_open = bdb_db_open;
737 bi->bi_db_close = bdb_db_close;
738 bi->bi_db_destroy = bdb_db_destroy;
740 bi->bi_op_add = bdb_add;
741 bi->bi_op_bind = bdb_bind;
742 bi->bi_op_compare = bdb_compare;
743 bi->bi_op_delete = bdb_delete;
744 bi->bi_op_modify = bdb_modify;
745 bi->bi_op_modrdn = bdb_modrdn;
746 bi->bi_op_search = bdb_search;
748 bi->bi_op_unbind = 0;
750 bi->bi_extended = bdb_extended;
752 bi->bi_chk_referrals = bdb_referrals;
753 bi->bi_operational = bdb_operational;
754 bi->bi_has_subordinates = bdb_hasSubordinates;
755 bi->bi_entry_release_rw = bdb_entry_release;
756 bi->bi_entry_get_rw = bdb_entry_get;
759 * hooks for slap tools
761 bi->bi_tool_entry_open = bdb_tool_entry_open;
762 bi->bi_tool_entry_close = bdb_tool_entry_close;
763 bi->bi_tool_entry_first = bdb_tool_entry_next;
764 bi->bi_tool_entry_next = bdb_tool_entry_next;
765 bi->bi_tool_entry_get = bdb_tool_entry_get;
766 bi->bi_tool_entry_put = bdb_tool_entry_put;
767 bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
768 bi->bi_tool_sync = 0;
769 bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
770 bi->bi_tool_entry_modify = bdb_tool_entry_modify;
772 bi->bi_connection_init = 0;
773 bi->bi_connection_destroy = 0;
775 rc = bdb_back_init_cf( bi );
780 #if (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \
781 (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER))
783 /* conditionally define the init_module() function */
785 SLAP_BACKEND_INIT_MODULE( hdb )
786 #else /* !BDB_HIER */
787 SLAP_BACKEND_INIT_MODULE( bdb )
788 #endif /* !BDB_HIER */
790 #endif /* SLAPD_[BH]DB == SLAPD_MOD_DYNAMIC */