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