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