]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
f037eaf6ee15e26af193aba65d43251f2a9495e4
[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 = { 0, NULL };
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 #ifdef NEW_LOGGING
71         LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_init", 0, 0, 0 );
72 #else
73         Debug( LDAP_DEBUG_ANY,
74                 "bdb_db_init: Initializing BDB database\n",
75                 0, 0, 0 );
76 #endif
77
78         /* indicate system schema supported */
79         be->be_flags |=
80                 SLAP_BFLAG_INCREMENT |
81 #ifdef BDB_SUBENTRIES
82                 SLAP_BFLAG_SUBENTRIES |
83 #endif
84 #ifdef BDB_ALIASES
85                 SLAP_BFLAG_ALIASES |
86 #endif
87                 SLAP_BFLAG_REFERRALS;
88
89         /* allocate backend-database-specific stuff */
90         bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
91
92         /* DBEnv parameters */
93         bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
94         bdb->bi_dbenv_xflags = 0;
95         bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
96
97         bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
98
99         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
100         bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
101         bdb->bi_search_stack = NULL;
102
103         LDAP_LIST_INIT (&bdb->bi_psearch_list);
104
105         ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
106         ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
107         ldap_pvt_thread_rdwr_init ( &bdb->bi_pslist_rwlock );
108         ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
109         ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
110         ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
111
112         be->be_private = bdb;
113
114         return 0;
115 }
116
117 static int
118 bdb_db_open( BackendDB *be )
119 {
120         int rc, i;
121         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
122         u_int32_t flags;
123 #ifdef HAVE_EBCDIC
124         char path[MAXPATHLEN];
125 #endif
126
127 #ifdef NEW_LOGGING
128         LDAP_LOG( BACK_BDB, ARGS, 
129                 "bdb_db_open: %s\n", be->be_suffix[0].bv_val, 0, 0 );
130 #else
131         Debug( LDAP_DEBUG_ARGS,
132                 "bdb_db_open: %s\n",
133                 be->be_suffix[0].bv_val, 0, 0 );
134 #endif
135
136 #ifndef BDB_MULTIPLE_SUFFIXES
137         if ( be->be_suffix[1].bv_val ) {
138 #ifdef NEW_LOGGING
139         LDAP_LOG( BACK_BDB, ERR, 
140                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
141 #else
142         Debug( LDAP_DEBUG_ANY,
143                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
144 #endif
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 #ifdef NEW_LOGGING
153                 LDAP_LOG( BACK_BDB, ERR, 
154                         "bdb_db_open: db_env_create failed: %s (%d)\n", 
155                         db_strerror(rc), rc, 0 );
156 #else
157                 Debug( LDAP_DEBUG_ANY,
158                         "bdb_db_open: db_env_create failed: %s (%d)\n",
159                         db_strerror(rc), rc, 0 );
160 #endif
161                 return rc;
162         }
163
164         flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE
165                 | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
166         
167 #if 0
168         /* Never do automatic recovery, must perform it manually.
169          * Otherwise restarting with gentlehup will corrupt the
170          * database.
171          */
172         if( !(slapMode & SLAP_TOOL_MODE) ) flags |= DB_RECOVER;
173 #endif
174
175         /* If a key was set, use shared memory for the BDB environment */
176         if ( bdb->bi_shm_key ) {
177                 bdb->bi_dbenv->set_shm_key( bdb->bi_dbenv, bdb->bi_shm_key );
178                 flags |= DB_SYSTEM_MEM;
179         }
180
181         bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
182         bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
183         bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
184
185         /* default IDL cache to 10x entry cache */
186         if ( bdb->bi_idl_cache_max_size == 0 )
187                 bdb->bi_idl_cache_max_size = 10 * bdb->bi_cache.c_maxsize;
188
189         if ( bdb->bi_idl_cache_max_size ) {
190                 bdb->bi_idl_tree = NULL;
191                 ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
192                 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_lrulock );
193                 bdb->bi_idl_cache_size = 0;
194         }
195
196 #ifdef BDB_SUBDIRS
197         {
198                 char dir[MAXPATHLEN], *ptr;
199                 
200                 if (bdb->bi_dbenv_home[0] == '.') {
201                         /* If home is a relative path, relative subdirs
202                          * are just concat'd by BDB. We don't want the
203                          * path to be concat'd twice, e.g.
204                          * ./test-db/./test-db/tmp
205                          */
206                         ptr = dir;
207                 } else {
208                         ptr = lutil_strcopy( dir, bdb->bi_dbenv_home );
209                         *ptr++ = LDAP_DIRSEP[0];
210 #ifdef HAVE_EBCDIC
211                         __atoe( dir );
212 #endif
213                 }
214
215                 strcpy( ptr, BDB_TMP_SUBDIR );
216 #ifdef HAVE_EBCDIC
217                 __atoe( ptr );
218 #endif
219                 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
220                 if( rc != 0 ) {
221 #ifdef NEW_LOGGING
222                         LDAP_LOG( BACK_BDB, ERR, 
223                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n", 
224                                 dir, db_strerror(rc), rc );
225 #else
226                         Debug( LDAP_DEBUG_ANY,
227                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
228                                 dir, db_strerror(rc), rc );
229 #endif
230                         return rc;
231                 }
232
233                 strcpy( ptr, BDB_LG_SUBDIR );
234 #ifdef HAVE_EBCDIC
235                 __atoe( ptr );
236 #endif
237                 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
238                 if( rc != 0 ) {
239 #ifdef NEW_LOGGING
240                         LDAP_LOG( BACK_BDB, ERR, 
241                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n", 
242                                 dir, db_strerror(rc), rc );
243 #else
244                         Debug( LDAP_DEBUG_ANY,
245                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
246                                 dir, db_strerror(rc), rc );
247 #endif
248                         return rc;
249                 }
250
251                 strcpy( ptr, BDB_DATA_SUBDIR );
252 #ifdef HAVE_EBCDIC
253                 __atoe( ptr );
254 #endif
255                 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
256                 if( rc != 0 ) {
257 #ifdef NEW_LOGGING
258                         LDAP_LOG( BACK_BDB, ERR, 
259                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
260                                 dir, db_strerror(rc), rc );
261 #else
262                         Debug( LDAP_DEBUG_ANY,
263                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
264                                 dir, db_strerror(rc), rc );
265 #endif
266                         return rc;
267                 }
268         }
269 #endif
270
271 #ifdef NEW_LOGGING
272         LDAP_LOG( BACK_BDB, DETAIL1, 
273                 "bdb_db_open: dbenv_open %s\n", bdb->bi_dbenv_home, 0, 0 );
274 #else
275         Debug( LDAP_DEBUG_TRACE,
276                 "bdb_db_open: dbenv_open(%s)\n",
277                 bdb->bi_dbenv_home, 0, 0);
278 #endif
279
280 #ifdef HAVE_EBCDIC
281         strcpy( path, bdb->bi_dbenv_home );
282         __atoe( path );
283         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
284                 path,
285                 flags,
286                 bdb->bi_dbenv_mode );
287 #else
288         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
289                 bdb->bi_dbenv_home,
290                 flags,
291                 bdb->bi_dbenv_mode );
292 #endif
293         if( rc != 0 ) {
294 #ifdef NEW_LOGGING
295                 LDAP_LOG( BACK_BDB, ERR, 
296                         "bdb_db_open: dbenv_open failed: %s (%d)\n", 
297                         db_strerror(rc), rc, 0 );
298 #else
299                 Debug( LDAP_DEBUG_ANY,
300                         "bdb_db_open: dbenv_open failed: %s (%d)\n",
301                         db_strerror(rc), rc, 0 );
302 #endif
303                 return rc;
304         }
305
306         if( bdb->bi_dbenv_xflags != 0 ) {
307                 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
308                         bdb->bi_dbenv_xflags, 1);
309                 if( rc != 0 ) {
310 #ifdef NEW_LOGGING
311                         LDAP_LOG( BACK_BDB, ERR, 
312                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n", 
313                                 db_strerror(rc), rc, 0 );
314 #else
315                         Debug( LDAP_DEBUG_ANY,
316                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
317                                 db_strerror(rc), rc, 0 );
318 #endif
319                         return rc;
320                 }
321         }
322
323         flags = DB_THREAD | bdb->bi_db_opflags;
324
325         bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
326                 BDB_INDICES * sizeof(struct bdb_db_info *) );
327
328         /* open (and create) main database */
329         for( i = 0; bdbi_databases[i].name; i++ ) {
330                 struct bdb_db_info *db;
331
332                 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
333
334                 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
335                 if( rc != 0 ) {
336 #ifdef NEW_LOGGING
337                         LDAP_LOG( BACK_BDB, ERR, 
338                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
339                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
340 #else
341                         Debug( LDAP_DEBUG_ANY,
342                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n",
343                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
344 #endif
345                         return rc;
346                 }
347
348                 if( i == BDB_ID2ENTRY ) {
349                         rc = db->bdi_db->set_pagesize( db->bdi_db,
350                                 BDB_ID2ENTRY_PAGESIZE );
351                         if ( slapMode & SLAP_TOOL_READMAIN ) {
352                                 flags |= DB_RDONLY;
353                         } else {
354                                 flags |= DB_CREATE;
355                         }
356                 } else {
357                         rc = db->bdi_db->set_flags( db->bdi_db, 
358                                 DB_DUP | DB_DUPSORT );
359 #ifndef BDB_HIER
360                         if ( slapMode & SLAP_TOOL_READONLY ) {
361                                 flags |= DB_RDONLY;
362                         } else {
363                                 flags |= DB_CREATE;
364                         }
365 #else
366                         rc = db->bdi_db->set_dup_compare( db->bdi_db,
367                                 bdb_dup_compare );
368                         if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
369                                 flags |= DB_RDONLY;
370                         } else {
371                                 flags |= DB_CREATE;
372                         }
373 #endif
374                         rc = db->bdi_db->set_pagesize( db->bdi_db,
375                                 BDB_PAGESIZE );
376                 }
377
378 #ifdef HAVE_EBCDIC
379                 strcpy( path, bdbi_databases[i].file );
380                 __atoe( path );
381                 rc = DB_OPEN( db->bdi_db,
382                         path,
383                 /*      bdbi_databases[i].name, */ NULL,
384                         bdbi_databases[i].type,
385                         bdbi_databases[i].flags | flags,
386                         bdb->bi_dbenv_mode );
387 #else
388                 rc = DB_OPEN( db->bdi_db,
389                         bdbi_databases[i].file,
390                 /*      bdbi_databases[i].name, */ NULL,
391                         bdbi_databases[i].type,
392                         bdbi_databases[i].flags | flags,
393                         bdb->bi_dbenv_mode );
394 #endif
395
396                 if( rc != 0 ) {
397 #ifdef NEW_LOGGING
398                         LDAP_LOG( BACK_BDB, ERR, 
399                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
400                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
401 #else
402                         Debug( LDAP_DEBUG_ANY,
403                                 "bdb_db_open: db_open(%s) failed: %s (%d)\n",
404                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
405 #endif
406                         return rc;
407                 }
408
409                 flags &= ~(DB_CREATE | DB_RDONLY);
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         return 0;
434 }
435
436 static int
437 bdb_db_close( BackendDB *be )
438 {
439         int rc;
440         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
441         struct bdb_db_info *db;
442         bdb_idl_cache_entry_t *entry, *next_entry;
443
444         while( bdb->bi_ndatabases-- ) {
445                 db = bdb->bi_databases[bdb->bi_ndatabases];
446                 rc = db->bdi_db->close( db->bdi_db, 0 );
447                 /* Lower numbered names are not strdup'd */
448                 if( bdb->bi_ndatabases >= BDB_NDB )
449                         free( db->bdi_name );
450                 free( db );
451         }
452         free( bdb->bi_databases );
453         bdb_attr_index_destroy( bdb->bi_attrs );
454
455         bdb_cache_release_all (&bdb->bi_cache);
456
457         if ( bdb->bi_idl_cache_max_size ) {
458                 ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
459                 avl_free( bdb->bi_idl_tree, NULL );
460                 entry = bdb->bi_idl_lru_head;
461                 while ( entry != NULL ) {
462                         next_entry = entry->idl_lru_next;
463                         if ( entry->idl )
464                                 free( entry->idl );
465                         free( entry->kstr.bv_val );
466                         free( entry );
467                         entry = next_entry;
468                 }
469                 ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
470         }
471
472         return 0;
473 }
474
475 static int
476 bdb_db_destroy( BackendDB *be )
477 {
478         int rc;
479         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
480
481         /* close db environment */
482         if( bdb->bi_dbenv ) {
483                 /* force a checkpoint */
484                 rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
485                 if( rc != 0 ) {
486 #ifdef NEW_LOGGING
487                         LDAP_LOG( BACK_BDB, ERR, 
488                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
489                                 db_strerror(rc), rc, 0 );
490 #else
491                         Debug( LDAP_DEBUG_ANY,
492                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
493                                 db_strerror(rc), rc, 0 );
494 #endif
495                 }
496
497                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
498                 bdb->bi_dbenv = NULL;
499                 if( rc != 0 ) {
500 #ifdef NEW_LOGGING
501                         LDAP_LOG( BACK_BDB, ERR, 
502                                 "bdb_db_destroy: close failed: %s (%d)\n", 
503                                 db_strerror(rc), rc, 0 );
504 #else
505                         Debug( LDAP_DEBUG_ANY,
506                                 "bdb_db_destroy: close failed: %s (%d)\n",
507                                 db_strerror(rc), rc, 0 );
508 #endif
509                         return rc;
510                 }
511         }
512
513         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
514
515         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
516         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
517         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
518         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_pslist_rwlock );
519         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
520         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
521
522         if ( bdb->bi_idl_cache_max_size ) {
523                 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
524                 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
525         }
526
527         ch_free( bdb );
528         be->be_private = NULL;
529
530         return 0;
531 }
532
533 #if     (defined(SLAPD_BDB_DYNAMIC) && !defined(BDB_HIER)) || \
534         (defined(SLAPD_HDB_DYNAMIC) && defined(BDB_HIER))
535 int init_module( int argc, char *argv[] ) {
536         BackendInfo bi;
537
538         memset( &bi, '\0', sizeof(bi) );
539 #ifdef BDB_HIER
540         bi.bi_type = "hdb";
541 #else
542         bi.bi_type = "bdb";
543 #endif
544         bi.bi_init = bdb_initialize;
545
546         backend_add( &bi );
547         return 0;
548 }
549 #endif /* SLAPD_BDB_DYNAMIC */
550
551 int
552 bdb_initialize(
553         BackendInfo     *bi
554 )
555 {
556         static char *controls[] = {
557                 LDAP_CONTROL_ASSERT,
558                 LDAP_CONTROL_MANAGEDSAIT,
559                 LDAP_CONTROL_NOOP,
560                 LDAP_CONTROL_PAGEDRESULTS,
561 #ifdef LDAP_CONTROL_SUBENTRIES
562                 LDAP_CONTROL_SUBENTRIES,
563 #endif
564                 LDAP_CONTROL_VALUESRETURNFILTER,
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_initialize: BDB library version mismatch:"
600                                 " expected " DB_VERSION_STRING ","
601                                 " got %s\n", version, 0, 0 );
602 #else
603                         Debug( LDAP_DEBUG_ANY,
604                                 "bdb_initialize: BDB library version mismatch:"
605                                 " expected " DB_VERSION_STRING ","
606                                 " got %s\n", version, 0, 0 );
607 #endif
608                 }
609
610 #ifdef NEW_LOGGING
611                 LDAP_LOG( BACK_BDB, DETAIL1, 
612                         "bdb_db_initialize: %s\n", version, 0, 0 );
613 #else
614                 Debug( LDAP_DEBUG_ANY, "bdb_initialize: %s\n",
615                         version, 0, 0 );
616 #endif
617         }
618
619         db_env_set_func_free( ber_memfree );
620         db_env_set_func_malloc( (db_malloc *)ber_memalloc );
621         db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
622 #ifndef NO_THREAD
623         /* This is a no-op on a NO_THREAD build. Leave the default
624          * alone so that BDB will sleep on interprocess conflicts.
625          */
626         db_env_set_func_yield( ldap_pvt_thread_yield );
627 #endif
628
629         {
630                 static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
631
632                 bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ));
633                 bdb_uuid.bv_val = uuidbuf;
634         }
635
636         bi->bi_open = 0;
637         bi->bi_close = 0;
638         bi->bi_config = 0;
639         bi->bi_destroy = 0;
640
641         bi->bi_db_init = bdb_db_init;
642         bi->bi_db_config = bdb_db_config;
643         bi->bi_db_open = bdb_db_open;
644         bi->bi_db_close = bdb_db_close;
645         bi->bi_db_destroy = bdb_db_destroy;
646
647         bi->bi_op_add = bdb_add;
648         bi->bi_op_bind = bdb_bind;
649         bi->bi_op_compare = bdb_compare;
650         bi->bi_op_delete = bdb_delete;
651         bi->bi_op_modify = bdb_modify;
652         bi->bi_op_modrdn = bdb_modrdn;
653         bi->bi_op_search = bdb_search;
654
655         bi->bi_op_unbind = 0;
656
657         bi->bi_op_abandon = bdb_abandon;
658         bi->bi_op_cancel = bdb_cancel;
659
660         bi->bi_extended = bdb_extended;
661
662         bi->bi_chk_referrals = bdb_referrals;
663         bi->bi_operational = bdb_operational;
664         bi->bi_has_subordinates = bdb_hasSubordinates;
665         bi->bi_entry_release_rw = bdb_entry_release;
666         bi->bi_entry_get_rw = bdb_entry_get;
667
668         /*
669          * hooks for slap tools
670          */
671         bi->bi_tool_entry_open = bdb_tool_entry_open;
672         bi->bi_tool_entry_close = bdb_tool_entry_close;
673         bi->bi_tool_entry_first = bdb_tool_entry_next;
674         bi->bi_tool_entry_next = bdb_tool_entry_next;
675         bi->bi_tool_entry_get = bdb_tool_entry_get;
676         bi->bi_tool_entry_put = bdb_tool_entry_put;
677         bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
678         bi->bi_tool_sync = 0;
679         bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
680         bi->bi_tool_id2entry_get = bdb_tool_id2entry_get;
681         bi->bi_tool_entry_modify = bdb_tool_entry_modify;
682
683         bi->bi_connection_init = 0;
684         bi->bi_connection_destroy = 0;
685
686         return 0;
687 }