]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
Happy new year
[openldap] / servers / slapd / back-bdb / init.c
1 /* init.c - initialize bdb backend */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12 #include <ac/unistd.h>
13 #include <ac/stdlib.h>
14
15 #include <lutil.h>
16
17 #include "back-bdb.h"
18 #include "external.h"
19
20 static struct bdbi_database {
21         char *file;
22         char *name;
23         int type;
24         int flags;
25 } bdbi_databases[] = {
26         { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
27 #ifdef BDB_HIER
28         { "id2parent" BDB_SUFFIX, "id2parent", DB_BTREE, 0 },
29 #else
30         { "dn2id" BDB_SUFFIX, "dn2id", DB_BTREE, 0 },
31 #endif
32         { NULL, NULL, 0, 0 }
33 };
34
35 struct berval bdb_uuid = { 0, NULL };
36
37 typedef void * db_malloc(size_t);
38 typedef void * db_realloc(void *, size_t);
39
40 #if 0
41 static int
42 bdb_open( BackendInfo *bi )
43 {
44         return 0;
45 }
46
47 static int
48 bdb_destroy( BackendInfo *bi )
49 {
50         return 0;
51 }
52
53 static int
54 bdb_close( BackendInfo *bi )
55 {
56         /* terminate the underlying database system */
57         return 0;
58 }
59 #endif
60
61 static int
62 bdb_db_init( BackendDB *be )
63 {
64         struct bdb_info *bdb;
65
66 #ifdef NEW_LOGGING
67         LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_init", 0, 0, 0 );
68 #else
69         Debug( LDAP_DEBUG_ANY,
70                 "bdb_db_init: Initializing BDB database\n",
71                 0, 0, 0 );
72 #endif
73
74         /* indicate system schema supported */
75         be->be_flags |=
76 #ifdef BDB_SUBENTRIES
77                 SLAP_BFLAG_SUBENTRIES |
78 #endif
79 #ifdef BDB_ALIASES
80                 SLAP_BFLAG_ALIASES |
81 #endif
82                 SLAP_BFLAG_REFERRALS;
83
84         /* allocate backend-database-specific stuff */
85         bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
86
87         /* DBEnv parameters */
88         bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
89         bdb->bi_dbenv_xflags = 0;
90         bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
91
92         bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
93
94         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
95         bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
96         bdb->bi_search_stack = NULL;
97
98 #ifdef LDAP_CLIENT_UPDATE
99         LDAP_LIST_INIT (&bdb->psearch_list);
100 #endif
101
102         ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
103         ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
104         ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
105         ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
106 #ifdef BDB_HIER
107         ldap_pvt_thread_rdwr_init( &bdb->bi_tree_rdwr );
108 #endif
109
110         be->be_private = bdb;
111
112         return 0;
113 }
114
115 int
116 bdb_bt_compare(
117         DB *db, 
118         const DBT *usrkey,
119         const DBT *curkey
120 )
121 {
122         unsigned char *u, *c;
123         int i, x;
124
125         u = usrkey->data;
126         c = curkey->data;
127
128 #ifdef WORDS_BIGENDIAN
129         for( i = 0; i < sizeof(ID); i++)
130 #else
131         for( i = sizeof(ID)-1; i >= 0; i--)
132 #endif
133         {
134                 x = u[i] - c[i];
135                 if( x ) return x;
136         }
137
138         return 0;
139 }
140
141 static int
142 bdb_db_open( BackendDB *be )
143 {
144         int rc, i;
145         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
146         u_int32_t flags;
147 #ifdef HAVE_EBCDIC
148         char path[MAXPATHLEN];
149 #endif
150
151 #ifdef NEW_LOGGING
152         LDAP_LOG( BACK_BDB, ARGS, 
153                 "bdb_db_open: %s\n", be->be_suffix[0].bv_val, 0, 0 );
154 #else
155         Debug( LDAP_DEBUG_ARGS,
156                 "bdb_db_open: %s\n",
157                 be->be_suffix[0].bv_val, 0, 0 );
158 #endif
159
160         /* we should check existance of dbenv_home and db_directory */
161
162         rc = db_env_create( &bdb->bi_dbenv, 0 );
163         if( rc != 0 ) {
164 #ifdef NEW_LOGGING
165                 LDAP_LOG( BACK_BDB, ERR, 
166                         "bdb_db_open: db_env_create failed: %s (%d)\n", 
167                         db_strerror(rc), rc, 0 );
168 #else
169                 Debug( LDAP_DEBUG_ANY,
170                         "bdb_db_open: db_env_create failed: %s (%d)\n",
171                         db_strerror(rc), rc, 0 );
172 #endif
173                 return rc;
174         }
175
176         flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE
177                 | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
178         
179 #if 0
180         /* Never do automatic recovery, must perform it manually.
181          * Otherwise restarting with gentlehup will corrupt the
182          * database.
183          */
184         if( !(slapMode & SLAP_TOOL_MODE) ) flags |= DB_RECOVER;
185 #endif
186
187         bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
188         bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
189         bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
190
191 #ifdef SLAP_IDL_CACHE
192         if ( bdb->bi_idl_cache_max_size ) {
193                 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_mutex );
194                 bdb->bi_idl_cache_size = 0;
195         }
196 #endif
197
198 #ifdef BDB_SUBDIRS
199         {
200                 char dir[MAXPATHLEN];
201                 size_t len = strlen( bdb->bi_dbenv_home );
202
203                 strcpy( dir, bdb->bi_dbenv_home );
204                 strcat( &dir[len], BDB_TMP_SUBDIR );
205                 
206                 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
207                 if( rc != 0 ) {
208 #ifdef NEW_LOGGING
209                         LDAP_LOG( BACK_BDB, ERR, 
210                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n", 
211                                 dir, db_strerror(rc), rc );
212 #else
213                         Debug( LDAP_DEBUG_ANY,
214                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
215                                 dir, db_strerror(rc), rc );
216 #endif
217                         return rc;
218                 }
219
220                 strcat( &dir[len], BDB_LG_SUBDIR );
221
222                 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
223                 if( rc != 0 ) {
224 #ifdef NEW_LOGGING
225                         LDAP_LOG( BACK_BDB, ERR, 
226                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n", 
227                                 dir, db_strerror(rc), rc );
228 #else
229                         Debug( LDAP_DEBUG_ANY,
230                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
231                                 dir, db_strerror(rc), rc );
232 #endif
233                         return rc;
234                 }
235
236                 strcat( &dir[len], BDB_DATA_SUBDIR );
237
238                 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
239                 if( rc != 0 ) {
240 #ifdef NEW_LOGGING
241                         LDAP_LOG( BACK_BDB, ERR, 
242                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
243                                 dir, db_strerror(rc), rc );
244 #else
245                         Debug( LDAP_DEBUG_ANY,
246                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
247                                 dir, db_strerror(rc), rc );
248 #endif
249                         return rc;
250                 }
251         }
252 #endif
253
254 #ifdef NEW_LOGGING
255         LDAP_LOG( BACK_BDB, DETAIL1, 
256                 "bdb_db_open: dbenv_open %s\n", bdb->bi_dbenv_home, 0, 0 );
257 #else
258         Debug( LDAP_DEBUG_TRACE,
259                 "bdb_db_open: dbenv_open(%s)\n",
260                 bdb->bi_dbenv_home, 0, 0);
261 #endif
262
263 #ifdef HAVE_EBCDIC
264         strcpy( path, bdb->bi_dbenv_home );
265         __atoe( path );
266         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
267                 path,
268                 flags,
269                 bdb->bi_dbenv_mode );
270 #else
271         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
272                 bdb->bi_dbenv_home,
273                 flags,
274                 bdb->bi_dbenv_mode );
275 #endif
276         if( rc != 0 ) {
277 #ifdef NEW_LOGGING
278                 LDAP_LOG( BACK_BDB, ERR, 
279                         "bdb_db_open: dbenv_open failed: %s (%d)\n", 
280                         db_strerror(rc), rc, 0 );
281 #else
282                 Debug( LDAP_DEBUG_ANY,
283                         "bdb_db_open: dbenv_open failed: %s (%d)\n",
284                         db_strerror(rc), rc, 0 );
285 #endif
286                 return rc;
287         }
288
289         if( bdb->bi_dbenv_xflags != 0 ) {
290                 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
291                         bdb->bi_dbenv_xflags, 1);
292                 if( rc != 0 ) {
293 #ifdef NEW_LOGGING
294                         LDAP_LOG( BACK_BDB, ERR, 
295                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n", 
296                                 db_strerror(rc), rc, 0 );
297 #else
298                         Debug( LDAP_DEBUG_ANY,
299                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
300                                 db_strerror(rc), rc, 0 );
301 #endif
302                         return rc;
303                 }
304         }
305
306         flags = DB_THREAD | DB_CREATE | bdb->bi_db_opflags;
307
308         bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
309                 BDB_INDICES * sizeof(struct bdb_db_info *) );
310
311         /* open (and create) main database */
312         for( i = 0; bdbi_databases[i].name; i++ ) {
313                 struct bdb_db_info *db;
314
315                 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
316
317                 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
318                 if( rc != 0 ) {
319 #ifdef NEW_LOGGING
320                         LDAP_LOG( BACK_BDB, ERR, 
321                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
322                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
323 #else
324                         Debug( LDAP_DEBUG_ANY,
325                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n",
326                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
327 #endif
328                         return rc;
329                 }
330
331                 if( i == BDB_ID2ENTRY ) {
332                         rc = db->bdi_db->set_bt_compare( db->bdi_db,
333                                 bdb_bt_compare );
334                         rc = db->bdi_db->set_pagesize( db->bdi_db,
335                                 BDB_ID2ENTRY_PAGESIZE );
336                 } else {
337 #ifdef BDB_HIER
338                         rc = db->bdi_db->set_bt_compare( db->bdi_db,
339                                 bdb_bt_compare );
340 #else
341                         rc = db->bdi_db->set_flags( db->bdi_db, 
342                                 DB_DUP | DB_DUPSORT );
343                         rc = db->bdi_db->set_dup_compare( db->bdi_db,
344                                 bdb_bt_compare );
345 #endif
346                         rc = db->bdi_db->set_pagesize( db->bdi_db,
347                                 BDB_PAGESIZE );
348                 }
349
350 #ifdef HAVE_EBCDIC
351                 strcpy( path, bdbi_databases[i].file );
352                 __atoe( path );
353                 rc = DB_OPEN( db->bdi_db, 
354                         path,
355                 /*      bdbi_databases[i].name, */ NULL,
356                         bdbi_databases[i].type,
357                         bdbi_databases[i].flags | flags,
358                         bdb->bi_dbenv_mode );
359 #else
360                 rc = DB_OPEN( db->bdi_db, 
361                         bdbi_databases[i].file,
362                 /*      bdbi_databases[i].name, */ NULL,
363                         bdbi_databases[i].type,
364                         bdbi_databases[i].flags | flags,
365                         bdb->bi_dbenv_mode );
366 #endif
367
368                 if( rc != 0 ) {
369 #ifdef NEW_LOGGING
370                         LDAP_LOG( BACK_BDB, ERR, 
371                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
372                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
373 #else
374                         Debug( LDAP_DEBUG_ANY,
375                                 "bdb_db_open: db_open(%s) failed: %s (%d)\n",
376                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
377 #endif
378                         return rc;
379                 }
380
381                 db->bdi_name = bdbi_databases[i].name;
382                 bdb->bi_databases[i] = db;
383         }
384
385         bdb->bi_databases[i] = NULL;
386         bdb->bi_ndatabases = i;
387
388         /* get nextid */
389         rc = bdb_last_id( be, NULL );
390         if( rc != 0 ) {
391 #ifdef NEW_LOGGING
392                         LDAP_LOG( BACK_BDB, ERR, 
393                                 "bdb_db_open: last_id(%s) failed: %s (%d)\n", 
394                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
395 #else
396                 Debug( LDAP_DEBUG_ANY,
397                         "bdb_db_open: last_id(%s) failed: %s (%d)\n",
398                         bdb->bi_dbenv_home, db_strerror(rc), rc );
399 #endif
400                 return rc;
401         }
402
403         /* <insert> open (and create) index databases */
404 #ifdef BDB_HIER
405         rc = bdb_build_tree( be );
406 #endif
407         return 0;
408 }
409
410 static int
411 bdb_db_close( BackendDB *be )
412 {
413         int rc;
414         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
415         struct bdb_db_info *db;
416 #ifdef SLAP_IDL_CACHE
417         bdb_idl_cache_entry_t *entry, *next_entry;
418 #endif
419
420         while( bdb->bi_ndatabases-- ) {
421                 db = bdb->bi_databases[bdb->bi_ndatabases];
422                 rc = db->bdi_db->close( db->bdi_db, 0 );
423                 /* Lower numbered names are not strdup'd */
424                 if( bdb->bi_ndatabases >= BDB_NDB )
425                         free( db->bdi_name );
426                 free( db );
427         }
428         free( bdb->bi_databases );
429         bdb_attr_index_destroy( bdb->bi_attrs );
430
431         bdb_cache_release_all (&bdb->bi_cache);
432
433 #ifdef SLAP_IDL_CACHE
434         ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
435         entry = bdb->bi_idl_lru_head;
436         while ( entry != NULL ) {
437                 next_entry = entry->idl_lru_next;
438                 free( entry->idl );
439                 free( entry->kstr.bv_val );
440                 free( entry );
441                 entry = next_entry;
442         }
443         ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
444 #endif
445
446         return 0;
447 }
448
449 static int
450 bdb_db_destroy( BackendDB *be )
451 {
452         int rc;
453         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
454
455         /* close db environment */
456         if( bdb->bi_dbenv ) {
457                 /* force a checkpoint */
458                 rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
459                 if( rc != 0 ) {
460 #ifdef NEW_LOGGING
461                         LDAP_LOG( BACK_BDB, ERR, 
462                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
463                                 db_strerror(rc), rc, 0 );
464 #else
465                         Debug( LDAP_DEBUG_ANY,
466                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
467                                 db_strerror(rc), rc, 0 );
468 #endif
469                 }
470
471                 bdb_cache_release_all (&bdb->bi_cache);
472
473                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
474                 bdb->bi_dbenv = NULL;
475                 if( rc != 0 ) {
476 #ifdef NEW_LOGGING
477                         LDAP_LOG( BACK_BDB, ERR, 
478                                 "bdb_db_destroy: close failed: %s (%d)\n", 
479                                 db_strerror(rc), rc, 0 );
480 #else
481                         Debug( LDAP_DEBUG_ANY,
482                                 "bdb_db_destroy: close failed: %s (%d)\n",
483                                 db_strerror(rc), rc, 0 );
484 #endif
485                         return rc;
486                 }
487         }
488
489         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
490
491 #ifdef BDB_HIER
492         ldap_pvt_thread_rdwr_destroy( &bdb->bi_tree_rdwr );
493 #endif
494         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
495         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
496         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
497         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
498
499         ch_free( bdb );
500         be->be_private = NULL;
501
502         return 0;
503 }
504
505 #ifdef SLAPD_BDB_DYNAMIC
506 int back_bdb_LTX_init_module( int argc, char *argv[] ) {
507         BackendInfo bi;
508
509         memset( &bi, '\0', sizeof(bi) );
510         bi.bi_type = "bdb";
511         bi.bi_init = bdb_initialize;
512
513         backend_add( &bi );
514         return 0;
515 }
516 #endif /* SLAPD_BDB_DYNAMIC */
517
518 int
519 bdb_initialize(
520         BackendInfo     *bi
521 )
522 {
523         static char *controls[] = {
524                 LDAP_CONTROL_MANAGEDSAIT,
525                 LDAP_CONTROL_NOOP,
526                 LDAP_CONTROL_PAGEDRESULTS,
527                 LDAP_CONTROL_VALUESRETURNFILTER,
528 #ifdef LDAP_CONTROL_SUBENTRIES
529                 LDAP_CONTROL_SUBENTRIES,
530 #endif
531 #ifdef LDAP_CLIENT_UPDATE
532                 LDAP_CONTROL_CLIENT_UPDATE,
533 #endif
534                 NULL
535         };
536
537         bi->bi_controls = controls;
538
539         /* initialize the underlying database system */
540 #ifdef NEW_LOGGING
541         LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_initialize\n", 0, 0, 0 );
542 #else
543         Debug( LDAP_DEBUG_TRACE, "bdb_initialize: initialize BDB backend\n",
544                 0, 0, 0 );
545 #endif
546
547         {       /* version check */
548                 int major, minor, patch;
549                 char *version = db_version( &major, &minor, &patch );
550 #ifdef HAVE_EBCDIC
551                 char v2[1024];
552
553                 /* All our stdio does an ASCII to EBCDIC conversion on
554                  * the output. Strings from the BDB library are already
555                  * in EBCDIC; we have to go back and forth...
556                  */
557                 strcpy( v2, version );
558                 __etoa( v2 );
559                 version = v2;
560 #endif
561
562                 if( major != DB_VERSION_MAJOR ||
563                         minor != DB_VERSION_MINOR ||
564                         patch < DB_VERSION_PATCH )
565                 {
566 #ifdef NEW_LOGGING
567                         LDAP_LOG( BACK_BDB, ERR, 
568                                 "bdb_db_initialize: version mismatch: "
569                                 "\texpected: %s \tgot: %s\n", DB_VERSION_STRING, version, 0 );
570 #else
571                         Debug( LDAP_DEBUG_ANY,
572                                 "bdb_initialize: version mismatch\n"
573                                 "\texpected: " DB_VERSION_STRING "\n"
574                                 "\tgot: %s \n", version, 0, 0 );
575 #endif
576                 }
577
578 #ifdef NEW_LOGGING
579                 LDAP_LOG( BACK_BDB, DETAIL1, 
580                         "bdb_db_initialize: %s\n", version, 0, 0 );
581 #else
582                 Debug( LDAP_DEBUG_ANY, "bdb_initialize: %s\n",
583                         version, 0, 0 );
584 #endif
585         }
586
587         db_env_set_func_free( ber_memfree );
588         db_env_set_func_malloc( (db_malloc *)ber_memalloc );
589         db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
590 #ifndef NO_THREAD
591         /* This is a no-op on a NO_THREAD build. Leave the default
592          * alone so that BDB will sleep on interprocess conflicts.
593          */
594         db_env_set_func_yield( ldap_pvt_thread_yield );
595 #endif
596
597         {
598                 static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
599
600                 bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ));
601                 bdb_uuid.bv_val = uuidbuf;
602         }
603
604         bi->bi_open = 0;
605         bi->bi_close = 0;
606         bi->bi_config = 0;
607         bi->bi_destroy = 0;
608
609         bi->bi_db_init = bdb_db_init;
610         bi->bi_db_config = bdb_db_config;
611         bi->bi_db_open = bdb_db_open;
612         bi->bi_db_close = bdb_db_close;
613         bi->bi_db_destroy = bdb_db_destroy;
614
615         bi->bi_op_add = bdb_add;
616         bi->bi_op_bind = bdb_bind;
617         bi->bi_op_compare = bdb_compare;
618         bi->bi_op_delete = bdb_delete;
619         bi->bi_op_modify = bdb_modify;
620         bi->bi_op_modrdn = bdb_modrdn;
621         bi->bi_op_search = bdb_search;
622
623         bi->bi_op_unbind = 0;
624         bi->bi_op_abandon = 0;
625
626         bi->bi_extended = bdb_extended;
627
628 #if 1
629         /*
630          * these routines (and their callers) are not yet designed
631          * to work with transaction.  Using them may cause deadlock.
632          */
633         bi->bi_acl_group = bdb_group;
634         bi->bi_acl_attribute = bdb_attribute;
635 #else
636         bi->bi_acl_group = 0;
637         bi->bi_acl_attribute = 0;
638 #endif
639
640         bi->bi_chk_referrals = bdb_referrals;
641         bi->bi_operational = bdb_operational;
642         bi->bi_has_subordinates = bdb_hasSubordinates;
643         bi->bi_entry_release_rw = bdb_entry_release;
644
645         /*
646          * hooks for slap tools
647          */
648         bi->bi_tool_entry_open = bdb_tool_entry_open;
649         bi->bi_tool_entry_close = bdb_tool_entry_close;
650         bi->bi_tool_entry_first = bdb_tool_entry_next;
651         bi->bi_tool_entry_next = bdb_tool_entry_next;
652         bi->bi_tool_entry_get = bdb_tool_entry_get;
653         bi->bi_tool_entry_put = bdb_tool_entry_put;
654         bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
655         bi->bi_tool_sync = 0;
656
657         bi->bi_connection_init = 0;
658         bi->bi_connection_destroy = 0;
659
660         return 0;
661 }