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