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