]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
document option '-F'
[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         if ( slapMode & SLAP_SERVER_MODE && bdb->bi_db_has_config ) {
385                 char    buf[SLAP_TEXT_BUFLEN];
386                 FILE *f = fopen( bdb->bi_db_config_path, "r" );
387                 struct berval bv;
388
389                 if ( f ) {
390                         while ( fgets( buf, sizeof(buf), f )) {
391                                 ber_str2bv( buf, 0, 1, &bv );
392                                 if ( bv.bv_val[bv.bv_len-1] == '\n' ) {
393                                         bv.bv_len--;
394                                         bv.bv_val[bv.bv_len] = '\0';
395                                 }
396                                 /* shouldn't need this, but ... */
397                                 if ( bv.bv_val[bv.bv_len-1] == '\r' ) {
398                                         bv.bv_len--;
399                                         bv.bv_val[bv.bv_len] = '\0';
400                                 }
401                                 ber_bvarray_add( &bdb->bi_db_config, &bv );
402                         }
403                         fclose( f );
404                 } else {
405                         /* Eh? It disappeared between config and open?? */
406                         bdb->bi_db_has_config = 0;
407                 }
408
409         }
410         bdb->bi_db_is_open = 1;
411
412         return 0;
413 }
414
415 static int
416 bdb_db_close( BackendDB *be )
417 {
418         int rc;
419         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
420         struct bdb_db_info *db;
421         bdb_idl_cache_entry_t *entry, *next_entry;
422
423         bdb->bi_db_is_open = 0;
424
425         ber_bvarray_free( bdb->bi_db_config );
426
427         while( bdb->bi_ndatabases-- ) {
428                 db = bdb->bi_databases[bdb->bi_ndatabases];
429                 rc = db->bdi_db->close( db->bdi_db, 0 );
430                 /* Lower numbered names are not strdup'd */
431                 if( bdb->bi_ndatabases >= BDB_NDB )
432                         free( db->bdi_name );
433                 free( db );
434         }
435         free( bdb->bi_databases );
436         bdb_attr_index_destroy( bdb->bi_attrs );
437
438         bdb_cache_release_all (&bdb->bi_cache);
439
440         if ( bdb->bi_idl_cache_max_size ) {
441                 ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
442                 avl_free( bdb->bi_idl_tree, NULL );
443                 entry = bdb->bi_idl_lru_head;
444                 while ( entry != NULL ) {
445                         next_entry = entry->idl_lru_next;
446                         if ( entry->idl )
447                                 free( entry->idl );
448                         free( entry->kstr.bv_val );
449                         free( entry );
450                         entry = next_entry;
451                 }
452                 ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
453         }
454
455         if ( !( slapMode & SLAP_TOOL_QUICK )) {
456                 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
457         }
458
459         return 0;
460 }
461
462 static int
463 bdb_db_destroy( BackendDB *be )
464 {
465         int rc;
466         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
467
468         /* close db environment */
469         if( bdb->bi_dbenv ) {
470                 /* force a checkpoint */
471                 if ( !( slapMode & SLAP_TOOL_QUICK )) {
472                         rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
473                         if( rc != 0 ) {
474                                 Debug( LDAP_DEBUG_ANY,
475                                         "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
476                                         db_strerror(rc), rc, 0 );
477                         }
478                 }
479
480                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
481                 bdb->bi_dbenv = NULL;
482                 if( rc != 0 ) {
483                         Debug( LDAP_DEBUG_ANY,
484                                 "bdb_db_destroy: close failed: %s (%d)\n",
485                                 db_strerror(rc), rc, 0 );
486                         return rc;
487                 }
488         }
489
490         rc = alock_close( &bdb->bi_alock_info );
491         if( rc != 0 ) {
492                 Debug( LDAP_DEBUG_ANY,
493                         "bdb_db_destroy: alock_close failed\n", 0, 0, 0 );
494                 return -1;
495         }
496
497         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
498         if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
499
500         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
501         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
502         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
503         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
504         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
505         if ( bdb->bi_idl_cache_max_size ) {
506                 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
507                 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
508         }
509
510         ch_free( bdb );
511         be->be_private = NULL;
512
513         return 0;
514 }
515
516 int
517 bdb_back_initialize(
518         BackendInfo     *bi )
519 {
520         int rc;
521
522         static char *controls[] = {
523                 LDAP_CONTROL_ASSERT,
524                 LDAP_CONTROL_MANAGEDSAIT,
525                 LDAP_CONTROL_NOOP,
526                 LDAP_CONTROL_PAGEDRESULTS,
527 #ifdef LDAP_CONTROL_SUBENTRIES
528                 LDAP_CONTROL_SUBENTRIES,
529 #endif
530 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
531                 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
532 #endif
533                 NULL
534         };
535
536         /* initialize the underlying database system */
537         Debug( LDAP_DEBUG_TRACE,
538                 LDAP_XSTRING(bdb_back_initialize) ": initialize " 
539                 BDB_UCTYPE " backend\n", 0, 0, 0 );
540
541         bi->bi_flags |=
542                 SLAP_BFLAG_INCREMENT |
543 #ifdef BDB_SUBENTRIES
544                 SLAP_BFLAG_SUBENTRIES |
545 #endif
546                 SLAP_BFLAG_ALIASES |
547                 SLAP_BFLAG_REFERRALS;
548
549         bi->bi_controls = controls;
550
551         {       /* version check */
552                 int major, minor, patch, ver;
553                 char *version = db_version( &major, &minor, &patch );
554 #ifdef HAVE_EBCDIC
555                 char v2[1024];
556
557                 /* All our stdio does an ASCII to EBCDIC conversion on
558                  * the output. Strings from the BDB library are already
559                  * in EBCDIC; we have to go back and forth...
560                  */
561                 strcpy( v2, version );
562                 __etoa( v2 );
563                 version = v2;
564 #endif
565
566                 ver = (major << 24) | (minor << 16) | patch;
567                 if( ver != DB_VERSION_FULL ) {
568                         /* fail if a versions don't match */
569                         Debug( LDAP_DEBUG_ANY,
570                                 LDAP_XSTRING(bdb_back_initialize) ": "
571                                 "BDB library version mismatch:"
572                                 " expected " DB_VERSION_STRING ","
573                                 " got %s\n", version, 0, 0 );
574                         return -1;
575                 }
576
577                 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_back_initialize)
578                         ": %s\n", version, 0, 0 );
579         }
580
581         db_env_set_func_free( ber_memfree );
582         db_env_set_func_malloc( (db_malloc *)ber_memalloc );
583         db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
584 #ifndef NO_THREAD
585         /* This is a no-op on a NO_THREAD build. Leave the default
586          * alone so that BDB will sleep on interprocess conflicts.
587          */
588         db_env_set_func_yield( ldap_pvt_thread_yield );
589 #endif
590
591         bi->bi_open = 0;
592         bi->bi_close = 0;
593         bi->bi_config = 0;
594         bi->bi_destroy = 0;
595
596         bi->bi_db_init = bdb_db_init;
597         bi->bi_db_config = config_generic_wrapper;
598         bi->bi_db_open = bdb_db_open;
599         bi->bi_db_close = bdb_db_close;
600         bi->bi_db_destroy = bdb_db_destroy;
601
602         bi->bi_op_add = bdb_add;
603         bi->bi_op_bind = bdb_bind;
604         bi->bi_op_compare = bdb_compare;
605         bi->bi_op_delete = bdb_delete;
606         bi->bi_op_modify = bdb_modify;
607         bi->bi_op_modrdn = bdb_modrdn;
608         bi->bi_op_search = bdb_search;
609
610         bi->bi_op_unbind = 0;
611
612         bi->bi_extended = bdb_extended;
613
614         bi->bi_chk_referrals = bdb_referrals;
615         bi->bi_operational = bdb_operational;
616         bi->bi_has_subordinates = bdb_hasSubordinates;
617         bi->bi_entry_release_rw = bdb_entry_release;
618         bi->bi_entry_get_rw = bdb_entry_get;
619
620         /*
621          * hooks for slap tools
622          */
623         bi->bi_tool_entry_open = bdb_tool_entry_open;
624         bi->bi_tool_entry_close = bdb_tool_entry_close;
625         bi->bi_tool_entry_first = bdb_tool_entry_next;
626         bi->bi_tool_entry_next = bdb_tool_entry_next;
627         bi->bi_tool_entry_get = bdb_tool_entry_get;
628         bi->bi_tool_entry_put = bdb_tool_entry_put;
629         bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
630         bi->bi_tool_sync = 0;
631         bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
632         bi->bi_tool_id2entry_get = bdb_tool_id2entry_get;
633         bi->bi_tool_entry_modify = bdb_tool_entry_modify;
634
635         bi->bi_connection_init = 0;
636         bi->bi_connection_destroy = 0;
637
638         rc = bdb_back_init_cf(bi);
639
640         return rc;
641 }
642
643 #if     (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \
644         (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER))
645
646 /* conditionally define the init_module() function */
647 #ifdef BDB_HIER
648 SLAP_BACKEND_INIT_MODULE( hdb )
649 #else /* !BDB_HIER */
650 SLAP_BACKEND_INIT_MODULE( bdb )
651 #endif /* !BDB_HIER */
652
653 #endif /* SLAPD_[BH]DB == SLAPD_MOD_DYNAMIC */
654