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