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