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