]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
962aa47f3930c1296422ad6a6a100792d5723f7c
[openldap] / servers / slapd / back-bdb / init.c
1 /* init.c - initialize bdb backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21 #include <ac/unistd.h>
22 #include <ac/stdlib.h>
23
24 #include "back-bdb.h"
25 #include <lutil.h>
26 #include <ldap_rq.h>
27 #include "alock.h"
28
29 static const struct bdbi_database {
30         char *file;
31         char *name;
32         int type;
33         int flags;
34 } bdbi_databases[] = {
35         { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
36         { "dn2id" BDB_SUFFIX, "dn2id", DB_BTREE, 0 },
37         { NULL, NULL, 0, 0 }
38 };
39
40 typedef void * db_malloc(size_t);
41 typedef void * db_realloc(void *, size_t);
42
43 static int
44 bdb_db_init( BackendDB *be )
45 {
46         struct bdb_info *bdb;
47
48         Debug( LDAP_DEBUG_TRACE,
49                 LDAP_XSTRING(bdb_db_init) ": Initializing " BDB_UCTYPE " database\n",
50                 0, 0, 0 );
51
52         /* allocate backend-database-specific stuff */
53         bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
54
55         /* DBEnv parameters */
56         bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
57         bdb->bi_dbenv_xflags = 0;
58         bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
59
60         bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
61
62         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
63         bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
64         bdb->bi_search_stack = NULL;
65
66         ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
67         ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
68         ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
69         ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
70         ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
71
72         be->be_private = bdb;
73         be->be_cf_table = be->bd_info->bi_cf_table;
74
75         return 0;
76 }
77
78 static void *
79 bdb_checkpoint( void *ctx, void *arg )
80 {
81         struct re_s *rtask = arg;
82         struct bdb_info *bdb = rtask->arg;
83         
84         TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
85                 bdb->bi_txn_cp_min, 0 );
86         return NULL;
87 }
88
89 static int
90 bdb_db_open( BackendDB *be )
91 {
92         int rc, i;
93         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
94         u_int32_t flags;
95 #ifdef HAVE_EBCDIC
96         char path[MAXPATHLEN];
97 #endif
98
99         Debug( LDAP_DEBUG_ARGS,
100                 "bdb_db_open: %s\n",
101                 be->be_suffix[0].bv_val, 0, 0 );
102
103 #ifndef BDB_MULTIPLE_SUFFIXES
104         if ( be->be_suffix[1].bv_val ) {
105         Debug( LDAP_DEBUG_ANY,
106                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
107                 return -1;
108         }
109 #endif
110         /* we should check existance of dbenv_home and db_directory */
111
112         rc = db_env_create( &bdb->bi_dbenv, 0 );
113         if( rc != 0 ) {
114                 Debug( LDAP_DEBUG_ANY,
115                         "bdb_db_open: db_env_create failed: %s (%d)\n",
116                         db_strerror(rc), rc, 0 );
117                 return rc;
118         }
119
120         flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE;
121
122         if ( !( slapMode & SLAP_TOOL_QUICK ))
123                 flags |= DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
124         
125         rc = alock_open( &bdb->bi_alock_info, "slapd", bdb->bi_dbenv_home,
126                 slapMode & SLAP_TOOL_READONLY ?  ALOCK_LOCKED : ALOCK_UNIQUE );
127         if( rc == ALOCK_RECOVER ) {
128                 Debug( LDAP_DEBUG_ANY,
129                         "bdb_db_open: alock_open: recovery required\n", 0, 0, 0 );
130                 flags |= DB_RECOVER;
131         } else if( rc == ALOCK_BUSY ) {
132                 Debug( LDAP_DEBUG_ANY,
133                    "bdb_db_open: alock_open: database in use\n", 0, 0, 0 );
134                 return -1;
135         } else if( rc != ALOCK_CLEAN ) {
136                 Debug( LDAP_DEBUG_ANY,
137                    "bdb_db_open: alock_open: database unstable\n", 0, 0, 0 );
138                 return -1;
139         }
140
141         /* If a key was set, use shared memory for the BDB environment */
142         if ( bdb->bi_shm_key ) {
143                 bdb->bi_dbenv->set_shm_key( bdb->bi_dbenv, bdb->bi_shm_key );
144                 flags |= DB_SYSTEM_MEM;
145         }
146
147         bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
148         bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
149         bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
150
151         /* One long-lived TXN per thread, two TXNs per write op */
152         bdb->bi_dbenv->set_tx_max( bdb->bi_dbenv, connection_pool_max * 3 );
153
154 #ifdef SLAP_ZONE_ALLOC
155         if ( bdb->bi_cache.c_maxsize ) {
156                 bdb->bi_cache.c_zctx = slap_zn_mem_create(
157                                                                 SLAP_ZONE_INITSIZE,
158                                                                 SLAP_ZONE_MAXSIZE,
159                                                                 SLAP_ZONE_DELTA,
160                                                                 SLAP_ZONE_SIZE);
161         }
162 #endif
163
164         if ( bdb->bi_idl_cache_max_size ) {
165                 bdb->bi_idl_tree = NULL;
166                 ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
167                 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_lrulock );
168                 bdb->bi_idl_cache_size = 0;
169         }
170
171 #ifdef BDB_SUBDIRS
172         {
173                 char dir[MAXPATHLEN], *ptr;
174                 
175                 if (bdb->bi_dbenv_home[0] == '.') {
176                         /* If home is a relative path, relative subdirs
177                          * are just concat'd by BDB. We don't want the
178                          * path to be concat'd twice, e.g.
179                          * ./test-db/./test-db/tmp
180                          */
181                         ptr = dir;
182                 } else {
183                         ptr = lutil_strcopy( dir, bdb->bi_dbenv_home );
184                         *ptr++ = LDAP_DIRSEP[0];
185 #ifdef HAVE_EBCDIC
186                         __atoe( dir );
187 #endif
188                 }
189
190                 strcpy( ptr, BDB_TMP_SUBDIR );
191 #ifdef HAVE_EBCDIC
192                 __atoe( ptr );
193 #endif
194                 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
195                 if( rc != 0 ) {
196                         Debug( LDAP_DEBUG_ANY,
197                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
198                                 dir, db_strerror(rc), rc );
199                         return rc;
200                 }
201
202                 strcpy( ptr, BDB_LG_SUBDIR );
203 #ifdef HAVE_EBCDIC
204                 __atoe( ptr );
205 #endif
206                 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
207                 if( rc != 0 ) {
208                         Debug( LDAP_DEBUG_ANY,
209                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
210                                 dir, db_strerror(rc), rc );
211                         return rc;
212                 }
213
214                 strcpy( ptr, BDB_DATA_SUBDIR );
215 #ifdef HAVE_EBCDIC
216                 __atoe( ptr );
217 #endif
218                 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
219                 if( rc != 0 ) {
220                         Debug( LDAP_DEBUG_ANY,
221                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
222                                 dir, db_strerror(rc), rc );
223                         return rc;
224                 }
225         }
226 #endif
227
228         if( bdb->bi_dbenv_xflags != 0 ) {
229                 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
230                         bdb->bi_dbenv_xflags, 1);
231                 if( rc != 0 ) {
232                         Debug( LDAP_DEBUG_ANY,
233                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
234                                 db_strerror(rc), rc, 0 );
235                         return rc;
236                 }
237         }
238
239         Debug( LDAP_DEBUG_TRACE,
240                 "bdb_db_open: dbenv_open(%s)\n",
241                 bdb->bi_dbenv_home, 0, 0);
242
243 #ifdef HAVE_EBCDIC
244         strcpy( path, bdb->bi_dbenv_home );
245         __atoe( path );
246         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
247                 path,
248                 flags,
249                 bdb->bi_dbenv_mode );
250 #else
251         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
252                 bdb->bi_dbenv_home,
253                 flags,
254                 bdb->bi_dbenv_mode );
255 #endif
256         if( rc != 0 ) {
257                 Debug( LDAP_DEBUG_ANY,
258                         "bdb_db_open: dbenv_open failed: %s (%d)\n",
259                         db_strerror(rc), rc, 0 );
260                 return rc;
261         }
262         if( flags & DB_RECOVER ) {
263                 rc = alock_recover (&bdb->bi_alock_info);
264                 if( rc != 0 ) {
265                         Debug( LDAP_DEBUG_ANY,
266                            "bdb_db_open: unable to alock_recover\n", 0, 0, 0 );
267                         return -1;
268                 }
269         }
270
271         flags = DB_THREAD | bdb->bi_db_opflags;
272
273 #ifdef DB_AUTO_COMMIT
274         if ( !( slapMode & SLAP_TOOL_QUICK ))
275                 flags |= DB_AUTO_COMMIT;
276 #endif
277
278         bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
279                 BDB_INDICES * sizeof(struct bdb_db_info *) );
280
281         /* open (and create) main database */
282         for( i = 0; bdbi_databases[i].name; i++ ) {
283                 struct bdb_db_info *db;
284
285                 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
286
287                 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
288                 if( rc != 0 ) {
289                         Debug( LDAP_DEBUG_ANY,
290                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n",
291                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
292                         return rc;
293                 }
294
295                 if( i == BDB_ID2ENTRY ) {
296                         rc = db->bdi_db->set_pagesize( db->bdi_db,
297                                 BDB_ID2ENTRY_PAGESIZE );
298                         if ( slapMode & SLAP_TOOL_READMAIN ) {
299                                 flags |= DB_RDONLY;
300                         } else {
301                                 flags |= DB_CREATE;
302                         }
303                 } else {
304                         rc = db->bdi_db->set_flags( db->bdi_db, 
305                                 DB_DUP | DB_DUPSORT );
306 #ifndef BDB_HIER
307                         if ( slapMode & SLAP_TOOL_READONLY ) {
308                                 flags |= DB_RDONLY;
309                         } else {
310                                 flags |= DB_CREATE;
311                         }
312 #else
313                         if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
314                                 flags |= DB_RDONLY;
315                         } else {
316                                 flags |= DB_CREATE;
317                         }
318 #endif
319                         rc = db->bdi_db->set_pagesize( db->bdi_db,
320                                 BDB_PAGESIZE );
321                 }
322
323 #ifdef HAVE_EBCDIC
324                 strcpy( path, bdbi_databases[i].file );
325                 __atoe( path );
326                 rc = DB_OPEN( db->bdi_db,
327                         path,
328                 /*      bdbi_databases[i].name, */ NULL,
329                         bdbi_databases[i].type,
330                         bdbi_databases[i].flags | flags,
331                         bdb->bi_dbenv_mode );
332 #else
333                 rc = DB_OPEN( db->bdi_db,
334                         bdbi_databases[i].file,
335                 /*      bdbi_databases[i].name, */ NULL,
336                         bdbi_databases[i].type,
337                         bdbi_databases[i].flags | flags,
338                         bdb->bi_dbenv_mode );
339 #endif
340
341                 if ( rc != 0 ) {
342                         char    buf[SLAP_TEXT_BUFLEN];
343
344                         snprintf( buf, sizeof(buf), "%s/%s", 
345                                 bdb->bi_dbenv_home, bdbi_databases[i].file );
346                         Debug( LDAP_DEBUG_ANY,
347                                 "bdb_db_open: db_open(%s) failed: %s (%d)\n",
348                                 buf, db_strerror(rc), rc );
349                         return rc;
350                 }
351
352                 flags &= ~(DB_CREATE | DB_RDONLY);
353                 db->bdi_name = bdbi_databases[i].name;
354                 bdb->bi_databases[i] = db;
355         }
356
357         bdb->bi_databases[i] = NULL;
358         bdb->bi_ndatabases = i;
359
360         /* get nextid */
361         rc = bdb_last_id( be, NULL );
362         if( rc != 0 ) {
363                 Debug( LDAP_DEBUG_ANY,
364                         "bdb_db_open: last_id(%s) failed: %s (%d)\n",
365                         bdb->bi_dbenv_home, db_strerror(rc), rc );
366                 return rc;
367         }
368
369         if ( !( slapMode & SLAP_TOOL_QUICK )) {
370                 XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
371         }
372
373         /* If we're in server mode and time-based checkpointing is enabled,
374          * submit a task to perform periodic checkpoints.
375          */
376         if ( slapMode & SLAP_SERVER_MODE && bdb->bi_txn_cp &&
377                 bdb->bi_txn_cp_min )  {
378                 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
379                 ldap_pvt_runqueue_insert( &slapd_rq, bdb->bi_txn_cp_min*60,
380                         bdb_checkpoint, bdb );
381                 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
382         }
383
384         return 0;
385 }
386
387 static int
388 bdb_db_close( BackendDB *be )
389 {
390         int rc;
391         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
392         struct bdb_db_info *db;
393         bdb_idl_cache_entry_t *entry, *next_entry;
394
395         while( bdb->bi_ndatabases-- ) {
396                 db = bdb->bi_databases[bdb->bi_ndatabases];
397                 rc = db->bdi_db->close( db->bdi_db, 0 );
398                 /* Lower numbered names are not strdup'd */
399                 if( bdb->bi_ndatabases >= BDB_NDB )
400                         free( db->bdi_name );
401                 free( db );
402         }
403         free( bdb->bi_databases );
404         bdb_attr_index_destroy( bdb->bi_attrs );
405
406         bdb_cache_release_all (&bdb->bi_cache);
407
408         if ( bdb->bi_idl_cache_max_size ) {
409                 ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
410                 avl_free( bdb->bi_idl_tree, NULL );
411                 entry = bdb->bi_idl_lru_head;
412                 while ( entry != NULL ) {
413                         next_entry = entry->idl_lru_next;
414                         if ( entry->idl )
415                                 free( entry->idl );
416                         free( entry->kstr.bv_val );
417                         free( entry );
418                         entry = next_entry;
419                 }
420                 ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
421         }
422
423         if ( !( slapMode & SLAP_TOOL_QUICK )) {
424                 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
425         }
426
427         return 0;
428 }
429
430 static int
431 bdb_db_destroy( BackendDB *be )
432 {
433         int rc;
434         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
435
436         /* close db environment */
437         if( bdb->bi_dbenv ) {
438                 /* force a checkpoint */
439                 if ( !( slapMode & SLAP_TOOL_QUICK )) {
440                         rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
441                         if( rc != 0 ) {
442                                 Debug( LDAP_DEBUG_ANY,
443                                         "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
444                                         db_strerror(rc), rc, 0 );
445                         }
446                 }
447
448                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
449                 bdb->bi_dbenv = NULL;
450                 if( rc != 0 ) {
451                         Debug( LDAP_DEBUG_ANY,
452                                 "bdb_db_destroy: close failed: %s (%d)\n",
453                                 db_strerror(rc), rc, 0 );
454                         return rc;
455                 }
456         }
457
458         rc = alock_close( &bdb->bi_alock_info );
459         if( rc != 0 ) {
460                 Debug( LDAP_DEBUG_ANY,
461                         "bdb_db_destroy: alock_close failed\n", 0, 0, 0 );
462                 return -1;
463         }
464
465         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
466
467         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
468         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
469         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
470         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
471         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
472         if ( bdb->bi_idl_cache_max_size ) {
473                 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
474                 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
475         }
476
477         ch_free( bdb );
478         be->be_private = NULL;
479
480         return 0;
481 }
482
483 int
484 bdb_back_initialize(
485         BackendInfo     *bi )
486 {
487         int rc;
488
489         static char *controls[] = {
490                 LDAP_CONTROL_ASSERT,
491                 LDAP_CONTROL_MANAGEDSAIT,
492                 LDAP_CONTROL_NOOP,
493                 LDAP_CONTROL_PAGEDRESULTS,
494 #ifdef LDAP_CONTROL_SUBENTRIES
495                 LDAP_CONTROL_SUBENTRIES,
496 #endif
497 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
498                 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
499 #endif
500                 NULL
501         };
502
503         /* initialize the underlying database system */
504         Debug( LDAP_DEBUG_TRACE,
505                 LDAP_XSTRING(bdb_back_initialize) ": initialize " 
506                 BDB_UCTYPE " backend\n", 0, 0, 0 );
507
508         bi->bi_flags |=
509                 SLAP_BFLAG_INCREMENT |
510 #ifdef BDB_SUBENTRIES
511                 SLAP_BFLAG_SUBENTRIES |
512 #endif
513                 SLAP_BFLAG_ALIASES |
514                 SLAP_BFLAG_REFERRALS;
515
516         bi->bi_controls = controls;
517
518         {       /* version check */
519                 int major, minor, patch, ver;
520                 char *version = db_version( &major, &minor, &patch );
521 #ifdef HAVE_EBCDIC
522                 char v2[1024];
523
524                 /* All our stdio does an ASCII to EBCDIC conversion on
525                  * the output. Strings from the BDB library are already
526                  * in EBCDIC; we have to go back and forth...
527                  */
528                 strcpy( v2, version );
529                 __etoa( v2 );
530                 version = v2;
531 #endif
532
533                 ver = (major << 24) | (minor << 16) | patch;
534                 if( ver != DB_VERSION_FULL ) {
535                         /* fail if a versions don't match */
536                         Debug( LDAP_DEBUG_ANY,
537                                 LDAP_XSTRING(bdb_back_initialize) ": "
538                                 "BDB library version mismatch:"
539                                 " expected " DB_VERSION_STRING ","
540                                 " got %s\n", version, 0, 0 );
541                         return -1;
542                 }
543
544                 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_back_initialize)
545                         ": %s\n", version, 0, 0 );
546         }
547
548         db_env_set_func_free( ber_memfree );
549         db_env_set_func_malloc( (db_malloc *)ber_memalloc );
550         db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
551 #ifndef NO_THREAD
552         /* This is a no-op on a NO_THREAD build. Leave the default
553          * alone so that BDB will sleep on interprocess conflicts.
554          */
555         db_env_set_func_yield( ldap_pvt_thread_yield );
556 #endif
557
558         bi->bi_open = 0;
559         bi->bi_close = 0;
560         bi->bi_config = 0;
561         bi->bi_destroy = 0;
562
563         bi->bi_db_init = bdb_db_init;
564         bi->bi_db_config = config_generic_wrapper;
565         bi->bi_db_open = bdb_db_open;
566         bi->bi_db_close = bdb_db_close;
567         bi->bi_db_destroy = bdb_db_destroy;
568
569         bi->bi_op_add = bdb_add;
570         bi->bi_op_bind = bdb_bind;
571         bi->bi_op_compare = bdb_compare;
572         bi->bi_op_delete = bdb_delete;
573         bi->bi_op_modify = bdb_modify;
574         bi->bi_op_modrdn = bdb_modrdn;
575         bi->bi_op_search = bdb_search;
576
577         bi->bi_op_unbind = 0;
578
579         bi->bi_extended = bdb_extended;
580
581         bi->bi_chk_referrals = bdb_referrals;
582         bi->bi_operational = bdb_operational;
583         bi->bi_has_subordinates = bdb_hasSubordinates;
584         bi->bi_entry_release_rw = bdb_entry_release;
585         bi->bi_entry_get_rw = bdb_entry_get;
586
587         /*
588          * hooks for slap tools
589          */
590         bi->bi_tool_entry_open = bdb_tool_entry_open;
591         bi->bi_tool_entry_close = bdb_tool_entry_close;
592         bi->bi_tool_entry_first = bdb_tool_entry_next;
593         bi->bi_tool_entry_next = bdb_tool_entry_next;
594         bi->bi_tool_entry_get = bdb_tool_entry_get;
595         bi->bi_tool_entry_put = bdb_tool_entry_put;
596         bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
597         bi->bi_tool_sync = 0;
598         bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
599         bi->bi_tool_id2entry_get = bdb_tool_id2entry_get;
600         bi->bi_tool_entry_modify = bdb_tool_entry_modify;
601
602         bi->bi_connection_init = 0;
603         bi->bi_connection_destroy = 0;
604
605         rc = bdb_back_init_cf(bi);
606
607         return rc;
608 }
609
610 #if     (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \
611         (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER))
612
613 /* conditionally define the init_module() function */
614 #ifdef BDB_HIER
615 SLAP_BACKEND_INIT_MODULE( hdb )
616 #else /* !BDB_HIER */
617 SLAP_BACKEND_INIT_MODULE( bdb )
618 #endif /* !BDB_HIER */
619
620 #endif /* SLAPD_[BH]DB == SLAPD_MOD_DYNAMIC */
621