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