]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
5337dcd19177744901b2fba950c1b39a4e9080e5
[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 = BER_BVNULL;
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         /* allocate backend-database-specific stuff */
79         bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
80
81         /* DBEnv parameters */
82         bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
83         bdb->bi_dbenv_xflags = 0;
84         bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
85
86         bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
87
88         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
89         bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
90         bdb->bi_search_stack = NULL;
91
92         LDAP_LIST_INIT (&bdb->bi_psearch_list);
93
94         ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
95         ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
96         ldap_pvt_thread_rdwr_init ( &bdb->bi_pslist_rwlock );
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         unsigned char *u, *c;
113         int i, x;
114
115         u = usrkey->data;
116         c = curkey->data;
117
118 #ifdef WORDS_BIGENDIAN
119         for( i = 0; i < (int)sizeof(ID); i++)
120 #else
121         for( i = sizeof(ID)-1; i >= 0; i--)
122 #endif
123         {
124                 x = u[i] - c[i];
125                 if( x ) return x;
126         }
127
128         return 0;
129 }
130
131 static int
132 bdb_db_open( BackendDB *be )
133 {
134         int rc, i;
135         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
136         u_int32_t flags;
137 #ifdef HAVE_EBCDIC
138         char path[MAXPATHLEN];
139 #endif
140
141 #ifdef NEW_LOGGING
142         LDAP_LOG( BACK_BDB, ARGS, 
143                 "bdb_db_open: %s\n", be->be_suffix[0].bv_val, 0, 0 );
144 #else
145         Debug( LDAP_DEBUG_ARGS,
146                 "bdb_db_open: %s\n",
147                 be->be_suffix[0].bv_val, 0, 0 );
148 #endif
149
150 #ifndef BDB_MULTIPLE_SUFFIXES
151         if ( be->be_suffix[1].bv_val ) {
152 #ifdef NEW_LOGGING
153         LDAP_LOG( BACK_BDB, ERR, 
154                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
155 #else
156         Debug( LDAP_DEBUG_ANY,
157                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
158 #endif
159                 return -1;
160         }
161 #endif
162         /* we should check existance of dbenv_home and db_directory */
163
164         rc = db_env_create( &bdb->bi_dbenv, 0 );
165         if( rc != 0 ) {
166 #ifdef NEW_LOGGING
167                 LDAP_LOG( BACK_BDB, ERR, 
168                         "bdb_db_open: db_env_create failed: %s (%d)\n", 
169                         db_strerror(rc), rc, 0 );
170 #else
171                 Debug( LDAP_DEBUG_ANY,
172                         "bdb_db_open: db_env_create failed: %s (%d)\n",
173                         db_strerror(rc), rc, 0 );
174 #endif
175                 return rc;
176         }
177
178         flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE
179                 | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
180         
181 #if 0
182         /* Never do automatic recovery, must perform it manually.
183          * Otherwise restarting with gentlehup will corrupt the
184          * database.
185          */
186         if( !(slapMode & SLAP_TOOL_MODE) ) flags |= DB_RECOVER;
187 #endif
188
189         /* If a key was set, use shared memory for the BDB environment */
190         if ( bdb->bi_shm_key ) {
191                 bdb->bi_dbenv->set_shm_key( bdb->bi_dbenv, bdb->bi_shm_key );
192                 flags |= DB_SYSTEM_MEM;
193         }
194
195         bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
196         bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
197         bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
198
199         if ( bdb->bi_idl_cache_max_size ) {
200                 bdb->bi_idl_tree = NULL;
201                 ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
202                 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_lrulock );
203                 bdb->bi_idl_cache_size = 0;
204         }
205
206 #ifdef BDB_SUBDIRS
207         {
208                 char dir[MAXPATHLEN], *ptr;
209                 
210                 if (bdb->bi_dbenv_home[0] == '.') {
211                         /* If home is a relative path, relative subdirs
212                          * are just concat'd by BDB. We don't want the
213                          * path to be concat'd twice, e.g.
214                          * ./test-db/./test-db/tmp
215                          */
216                         ptr = dir;
217                 } else {
218                         ptr = lutil_strcopy( dir, bdb->bi_dbenv_home );
219                         *ptr++ = LDAP_DIRSEP[0];
220 #ifdef HAVE_EBCDIC
221                         __atoe( dir );
222 #endif
223                 }
224
225                 strcpy( ptr, BDB_TMP_SUBDIR );
226 #ifdef HAVE_EBCDIC
227                 __atoe( ptr );
228 #endif
229                 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
230                 if( rc != 0 ) {
231 #ifdef NEW_LOGGING
232                         LDAP_LOG( BACK_BDB, ERR, 
233                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n", 
234                                 dir, db_strerror(rc), rc );
235 #else
236                         Debug( LDAP_DEBUG_ANY,
237                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
238                                 dir, db_strerror(rc), rc );
239 #endif
240                         return rc;
241                 }
242
243                 strcpy( ptr, BDB_LG_SUBDIR );
244 #ifdef HAVE_EBCDIC
245                 __atoe( ptr );
246 #endif
247                 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
248                 if( rc != 0 ) {
249 #ifdef NEW_LOGGING
250                         LDAP_LOG( BACK_BDB, ERR, 
251                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n", 
252                                 dir, db_strerror(rc), rc );
253 #else
254                         Debug( LDAP_DEBUG_ANY,
255                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
256                                 dir, db_strerror(rc), rc );
257 #endif
258                         return rc;
259                 }
260
261                 strcpy( ptr, BDB_DATA_SUBDIR );
262 #ifdef HAVE_EBCDIC
263                 __atoe( ptr );
264 #endif
265                 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
266                 if( rc != 0 ) {
267 #ifdef NEW_LOGGING
268                         LDAP_LOG( BACK_BDB, ERR, 
269                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
270                                 dir, db_strerror(rc), rc );
271 #else
272                         Debug( LDAP_DEBUG_ANY,
273                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
274                                 dir, db_strerror(rc), rc );
275 #endif
276                         return rc;
277                 }
278         }
279 #endif
280
281 #ifdef NEW_LOGGING
282         LDAP_LOG( BACK_BDB, DETAIL1, 
283                 "bdb_db_open: dbenv_open %s\n", bdb->bi_dbenv_home, 0, 0 );
284 #else
285         Debug( LDAP_DEBUG_TRACE,
286                 "bdb_db_open: dbenv_open(%s)\n",
287                 bdb->bi_dbenv_home, 0, 0);
288 #endif
289
290 #ifdef HAVE_EBCDIC
291         strcpy( path, bdb->bi_dbenv_home );
292         __atoe( path );
293         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
294                 path,
295                 flags,
296                 bdb->bi_dbenv_mode );
297 #else
298         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
299                 bdb->bi_dbenv_home,
300                 flags,
301                 bdb->bi_dbenv_mode );
302 #endif
303         if( rc != 0 ) {
304 #ifdef NEW_LOGGING
305                 LDAP_LOG( BACK_BDB, ERR, 
306                         "bdb_db_open: dbenv_open failed: %s (%d)\n", 
307                         db_strerror(rc), rc, 0 );
308 #else
309                 Debug( LDAP_DEBUG_ANY,
310                         "bdb_db_open: dbenv_open failed: %s (%d)\n",
311                         db_strerror(rc), rc, 0 );
312 #endif
313                 return rc;
314         }
315
316         if( bdb->bi_dbenv_xflags != 0 ) {
317                 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
318                         bdb->bi_dbenv_xflags, 1);
319                 if( rc != 0 ) {
320 #ifdef NEW_LOGGING
321                         LDAP_LOG( BACK_BDB, ERR, 
322                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n", 
323                                 db_strerror(rc), rc, 0 );
324 #else
325                         Debug( LDAP_DEBUG_ANY,
326                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
327                                 db_strerror(rc), rc, 0 );
328 #endif
329                         return rc;
330                 }
331         }
332
333         flags = DB_THREAD | bdb->bi_db_opflags;
334
335         bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
336                 BDB_INDICES * sizeof(struct bdb_db_info *) );
337
338         /* open (and create) main database */
339         for( i = 0; bdbi_databases[i].name; i++ ) {
340                 struct bdb_db_info *db;
341
342                 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
343
344                 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
345                 if( rc != 0 ) {
346 #ifdef NEW_LOGGING
347                         LDAP_LOG( BACK_BDB, ERR, 
348                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
349                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
350 #else
351                         Debug( LDAP_DEBUG_ANY,
352                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n",
353                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
354 #endif
355                         return rc;
356                 }
357
358                 if( i == BDB_ID2ENTRY ) {
359                         rc = db->bdi_db->set_bt_compare( db->bdi_db,
360                                 bdb_bt_compare );
361                         rc = db->bdi_db->set_pagesize( db->bdi_db,
362                                 BDB_ID2ENTRY_PAGESIZE );
363                         if ( slapMode & SLAP_TOOL_READMAIN ) {
364                                 flags |= DB_RDONLY;
365                         } else {
366                                 flags |= DB_CREATE;
367                         }
368                 } else {
369                         rc = db->bdi_db->set_flags( db->bdi_db, 
370                                 DB_DUP | DB_DUPSORT );
371 #ifndef BDB_HIER
372                         rc = db->bdi_db->set_dup_compare( db->bdi_db,
373                                 bdb_bt_compare );
374                         if ( slapMode & SLAP_TOOL_READONLY ) {
375                                 flags |= DB_RDONLY;
376                         } else {
377                                 flags |= DB_CREATE;
378                         }
379 #else
380                         rc = db->bdi_db->set_dup_compare( db->bdi_db,
381                                 bdb_dup_compare );
382                         rc = db->bdi_db->set_bt_compare( db->bdi_db,
383                                 bdb_bt_compare );
384                         if ( slapMode & (SLAP_TOOL_READONLY|SLAP_TOOL_READMAIN) ) {
385                                 flags |= DB_RDONLY;
386                         } else {
387                                 flags |= DB_CREATE;
388                         }
389 #endif
390                         rc = db->bdi_db->set_pagesize( db->bdi_db,
391                                 BDB_PAGESIZE );
392                 }
393
394 #ifdef HAVE_EBCDIC
395                 strcpy( path, bdbi_databases[i].file );
396                 __atoe( path );
397                 rc = DB_OPEN( db->bdi_db,
398                         path,
399                 /*      bdbi_databases[i].name, */ NULL,
400                         bdbi_databases[i].type,
401                         bdbi_databases[i].flags | flags,
402                         bdb->bi_dbenv_mode );
403 #else
404                 rc = DB_OPEN( db->bdi_db,
405                         bdbi_databases[i].file,
406                 /*      bdbi_databases[i].name, */ NULL,
407                         bdbi_databases[i].type,
408                         bdbi_databases[i].flags | flags,
409                         bdb->bi_dbenv_mode );
410 #endif
411
412                 if( rc != 0 ) {
413 #ifdef NEW_LOGGING
414                         LDAP_LOG( BACK_BDB, ERR, 
415                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
416                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
417 #else
418                         Debug( LDAP_DEBUG_ANY,
419                                 "bdb_db_open: db_open(%s) failed: %s (%d)\n",
420                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
421 #endif
422                         return rc;
423                 }
424
425                 flags &= ~(DB_CREATE | DB_RDONLY);
426                 db->bdi_name = bdbi_databases[i].name;
427                 bdb->bi_databases[i] = db;
428         }
429
430         bdb->bi_databases[i] = NULL;
431         bdb->bi_ndatabases = i;
432
433         /* get nextid */
434         rc = bdb_last_id( be, NULL );
435         if( rc != 0 ) {
436 #ifdef NEW_LOGGING
437                         LDAP_LOG( BACK_BDB, ERR, 
438                                 "bdb_db_open: last_id(%s) failed: %s (%d)\n", 
439                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
440 #else
441                 Debug( LDAP_DEBUG_ANY,
442                         "bdb_db_open: last_id(%s) failed: %s (%d)\n",
443                         bdb->bi_dbenv_home, db_strerror(rc), rc );
444 #endif
445                 return rc;
446         }
447
448         bdb->bi_dbenv->lock_id(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
449
450         /* <insert> open (and create) index databases */
451         return 0;
452 }
453
454 static int
455 bdb_db_close( BackendDB *be )
456 {
457         int rc;
458         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
459         struct bdb_db_info *db;
460         bdb_idl_cache_entry_t *entry, *next_entry;
461
462         while( bdb->bi_ndatabases-- ) {
463                 db = bdb->bi_databases[bdb->bi_ndatabases];
464                 rc = db->bdi_db->close( db->bdi_db, 0 );
465                 /* Lower numbered names are not strdup'd */
466                 if( bdb->bi_ndatabases >= BDB_NDB )
467                         free( db->bdi_name );
468                 free( db );
469         }
470         free( bdb->bi_databases );
471         bdb_attr_index_destroy( bdb->bi_attrs );
472
473         bdb_cache_release_all (&bdb->bi_cache);
474
475         if ( bdb->bi_idl_cache_max_size ) {
476                 ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
477                 avl_free( bdb->bi_idl_tree, NULL );
478                 entry = bdb->bi_idl_lru_head;
479                 while ( entry != NULL ) {
480                         next_entry = entry->idl_lru_next;
481                         if ( entry->idl )
482                                 free( entry->idl );
483                         free( entry->kstr.bv_val );
484                         free( entry );
485                         entry = next_entry;
486                 }
487                 ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
488         }
489
490         return 0;
491 }
492
493 static int
494 bdb_db_destroy( BackendDB *be )
495 {
496         int rc;
497         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
498
499         /* close db environment */
500         if( bdb->bi_dbenv ) {
501                 /* force a checkpoint */
502                 rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
503                 if( rc != 0 ) {
504 #ifdef NEW_LOGGING
505                         LDAP_LOG( BACK_BDB, ERR, 
506                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
507                                 db_strerror(rc), rc, 0 );
508 #else
509                         Debug( LDAP_DEBUG_ANY,
510                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
511                                 db_strerror(rc), rc, 0 );
512 #endif
513                 }
514
515                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
516                 bdb->bi_dbenv = NULL;
517                 if( rc != 0 ) {
518 #ifdef NEW_LOGGING
519                         LDAP_LOG( BACK_BDB, ERR, 
520                                 "bdb_db_destroy: close failed: %s (%d)\n", 
521                                 db_strerror(rc), rc, 0 );
522 #else
523                         Debug( LDAP_DEBUG_ANY,
524                                 "bdb_db_destroy: close failed: %s (%d)\n",
525                                 db_strerror(rc), rc, 0 );
526 #endif
527                         return rc;
528                 }
529         }
530
531         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
532
533         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
534         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
535         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
536         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_pslist_rwlock );
537         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
538         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
539         if ( bdb->bi_idl_cache_max_size ) {
540                 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
541                 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
542         }
543
544         ch_free( bdb );
545         be->be_private = NULL;
546
547         return 0;
548 }
549
550 #if     (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \
551         (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER))
552 int init_module( int argc, char *argv[] ) {
553         BackendInfo bi;
554
555         memset( &bi, '\0', sizeof(bi) );
556 #ifdef BDB_HIER
557         bi.bi_type = "hdb";
558 #else
559         bi.bi_type = "bdb";
560 #endif
561         bi.bi_init = bdb_initialize;
562
563         backend_add( &bi );
564         return 0;
565 }
566 #endif /* SLAPD_BDB */
567
568 int
569 bdb_initialize(
570         BackendInfo     *bi )
571 {
572         static char *controls[] = {
573                 LDAP_CONTROL_ASSERT,
574                 LDAP_CONTROL_MANAGEDSAIT,
575                 LDAP_CONTROL_NOOP,
576                 LDAP_CONTROL_PAGEDRESULTS,
577 #ifdef LDAP_CONTROL_SUBENTRIES
578                 LDAP_CONTROL_SUBENTRIES,
579 #endif
580                 LDAP_CONTROL_VALUESRETURNFILTER,
581                 NULL
582         };
583
584         /* initialize the underlying database system */
585 #ifdef NEW_LOGGING
586         LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_initialize\n", 0, 0, 0 );
587 #else
588         Debug( LDAP_DEBUG_TRACE, "bdb_initialize: initialize BDB backend\n",
589                 0, 0, 0 );
590 #endif
591
592         bi->bi_flags |=
593                 SLAP_BFLAG_INCREMENT |
594 #ifdef BDB_SUBENTRIES
595                 SLAP_BFLAG_SUBENTRIES |
596 #endif
597 #ifdef BDB_ALIASES
598                 SLAP_BFLAG_ALIASES |
599 #endif
600                 SLAP_BFLAG_REFERRALS;
601
602         bi->bi_controls = controls;
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 }