]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
ed7b84dab2fcd02be1760d14d6453a030b4a25b7
[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 #include "alock.h"
28
29 static const struct bdbi_database {
30         char *file;
31         char *name;
32         int type;
33         int flags;
34 } bdbi_databases[] = {
35         { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
36         { "dn2id" BDB_SUFFIX, "dn2id", DB_BTREE, 0 },
37         { NULL, NULL, 0, 0 }
38 };
39
40 typedef void * db_malloc(size_t);
41 typedef void * db_realloc(void *, size_t);
42
43 static int
44 bdb_db_init( BackendDB *be )
45 {
46         struct bdb_info *bdb;
47
48         Debug( LDAP_DEBUG_TRACE,
49                 LDAP_XSTRING(bdb_db_init) ": Initializing " BDB_UCTYPE " database\n",
50                 0, 0, 0 );
51
52         /* allocate backend-database-specific stuff */
53         bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
54
55         /* DBEnv parameters */
56         bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
57         bdb->bi_dbenv_xflags = 0;
58         bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
59
60         bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
61
62         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
63         bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
64         bdb->bi_search_stack = NULL;
65
66         ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
67         ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
68         ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
69         ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
70         ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
71
72         be->be_private = bdb;
73         be->be_cf_table = be->bd_info->bi_cf_table;
74
75         return 0;
76 }
77
78 static void *
79 bdb_checkpoint( void *ctx, void *arg )
80 {
81         struct re_s *rtask = arg;
82         struct bdb_info *bdb = rtask->arg;
83         
84         TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
85                 bdb->bi_txn_cp_min, 0 );
86         ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
87         ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
88         ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
89         return NULL;
90 }
91
92 static int
93 bdb_db_open( BackendDB *be )
94 {
95         int rc, i;
96         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
97         u_int32_t flags;
98 #ifdef HAVE_EBCDIC
99         char path[MAXPATHLEN];
100 #endif
101
102         Debug( LDAP_DEBUG_ARGS,
103                 "bdb_db_open: %s\n",
104                 be->be_suffix[0].bv_val, 0, 0 );
105
106 #ifndef BDB_MULTIPLE_SUFFIXES
107         if ( be->be_suffix[1].bv_val ) {
108         Debug( LDAP_DEBUG_ANY,
109                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
110                 return -1;
111         }
112 #endif
113         /* we should check existance of dbenv_home and db_directory */
114
115         rc = db_env_create( &bdb->bi_dbenv, 0 );
116         if( rc != 0 ) {
117                 Debug( LDAP_DEBUG_ANY,
118                         "bdb_db_open: db_env_create failed: %s (%d)\n",
119                         db_strerror(rc), rc, 0 );
120                 return rc;
121         }
122
123         flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE;
124
125         if ( !( slapMode & SLAP_TOOL_QUICK ))
126                 flags |= DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
127         
128         rc = alock_open( &bdb->bi_alock_info, "slapd", bdb->bi_dbenv_home,
129                 slapMode & SLAP_TOOL_READONLY ?  ALOCK_LOCKED : ALOCK_UNIQUE );
130         if( rc == ALOCK_RECOVER ) {
131                 Debug( LDAP_DEBUG_ANY,
132                         "bdb_db_open: alock_open: recovery required\n", 0, 0, 0 );
133                 flags |= DB_RECOVER;
134         } else if( rc == ALOCK_BUSY ) {
135                 Debug( LDAP_DEBUG_ANY,
136                    "bdb_db_open: alock_open: database in use\n", 0, 0, 0 );
137                 return -1;
138         } else if( rc != ALOCK_CLEAN ) {
139                 Debug( LDAP_DEBUG_ANY,
140                    "bdb_db_open: alock_open: database unstable\n", 0, 0, 0 );
141                 return -1;
142         }
143
144         /* If a key was set, use shared memory for the BDB environment */
145         if ( bdb->bi_shm_key ) {
146                 bdb->bi_dbenv->set_shm_key( bdb->bi_dbenv, bdb->bi_shm_key );
147                 flags |= DB_SYSTEM_MEM;
148         }
149
150         bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
151         bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
152         bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
153
154         /* One long-lived TXN per thread, two TXNs per write op */
155         bdb->bi_dbenv->set_tx_max( bdb->bi_dbenv, connection_pool_max * 3 );
156
157 #ifdef SLAP_ZONE_ALLOC
158         if ( bdb->bi_cache.c_maxsize ) {
159                 bdb->bi_cache.c_zctx = slap_zn_mem_create(
160                                                                 SLAP_ZONE_INITSIZE,
161                                                                 SLAP_ZONE_MAXSIZE,
162                                                                 SLAP_ZONE_DELTA,
163                                                                 SLAP_ZONE_SIZE);
164         }
165 #endif
166
167         if ( bdb->bi_idl_cache_max_size ) {
168                 bdb->bi_idl_tree = NULL;
169                 ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
170                 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_lrulock );
171                 bdb->bi_idl_cache_size = 0;
172         }
173
174 #ifdef BDB_SUBDIRS
175         {
176                 char dir[MAXPATHLEN], *ptr;
177                 
178                 if (bdb->bi_dbenv_home[0] == '.') {
179                         /* If home is a relative path, relative subdirs
180                          * are just concat'd by BDB. We don't want the
181                          * path to be concat'd twice, e.g.
182                          * ./test-db/./test-db/tmp
183                          */
184                         ptr = dir;
185                 } else {
186                         ptr = lutil_strcopy( dir, bdb->bi_dbenv_home );
187                         *ptr++ = LDAP_DIRSEP[0];
188 #ifdef HAVE_EBCDIC
189                         __atoe( dir );
190 #endif
191                 }
192
193                 strcpy( ptr, BDB_TMP_SUBDIR );
194 #ifdef HAVE_EBCDIC
195                 __atoe( ptr );
196 #endif
197                 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
198                 if( rc != 0 ) {
199                         Debug( LDAP_DEBUG_ANY,
200                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
201                                 dir, db_strerror(rc), rc );
202                         return rc;
203                 }
204
205                 strcpy( ptr, BDB_LG_SUBDIR );
206 #ifdef HAVE_EBCDIC
207                 __atoe( ptr );
208 #endif
209                 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
210                 if( rc != 0 ) {
211                         Debug( LDAP_DEBUG_ANY,
212                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
213                                 dir, db_strerror(rc), rc );
214                         return rc;
215                 }
216
217                 strcpy( ptr, BDB_DATA_SUBDIR );
218 #ifdef HAVE_EBCDIC
219                 __atoe( ptr );
220 #endif
221                 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
222                 if( rc != 0 ) {
223                         Debug( LDAP_DEBUG_ANY,
224                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
225                                 dir, db_strerror(rc), rc );
226                         return rc;
227                 }
228         }
229 #endif
230
231         if( bdb->bi_dbenv_xflags != 0 ) {
232                 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
233                         bdb->bi_dbenv_xflags, 1);
234                 if( rc != 0 ) {
235                         Debug( LDAP_DEBUG_ANY,
236                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
237                                 db_strerror(rc), rc, 0 );
238                         return rc;
239                 }
240         }
241
242         Debug( LDAP_DEBUG_TRACE,
243                 "bdb_db_open: dbenv_open(%s)\n",
244                 bdb->bi_dbenv_home, 0, 0);
245
246 #ifdef HAVE_EBCDIC
247         strcpy( path, bdb->bi_dbenv_home );
248         __atoe( path );
249         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
250                 path,
251                 flags,
252                 bdb->bi_dbenv_mode );
253 #else
254         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
255                 bdb->bi_dbenv_home,
256                 flags,
257                 bdb->bi_dbenv_mode );
258 #endif
259         if( rc != 0 ) {
260                 Debug( LDAP_DEBUG_ANY,
261                         "bdb_db_open: dbenv_open failed: %s (%d)\n",
262                         db_strerror(rc), rc, 0 );
263                 return rc;
264         }
265         if( flags & DB_RECOVER ) {
266                 rc = alock_recover (&bdb->bi_alock_info);
267                 if( rc != 0 ) {
268                         Debug( LDAP_DEBUG_ANY,
269                            "bdb_db_open: unable to alock_recover\n", 0, 0, 0 );
270                         return -1;
271                 }
272         }
273
274         flags = DB_THREAD | bdb->bi_db_opflags;
275
276 #ifdef DB_AUTO_COMMIT
277         if ( !( slapMode & SLAP_TOOL_QUICK ))
278                 flags |= DB_AUTO_COMMIT;
279 #endif
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         if ( !( slapMode & SLAP_TOOL_QUICK )) {
373                 XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
374         }
375
376         /* If we're in server mode and time-based checkpointing is enabled,
377          * submit a task to perform periodic checkpoints.
378          */
379         if (( slapMode & SLAP_SERVER_MODE ) && bdb->bi_txn_cp &&
380                 bdb->bi_txn_cp_min )  {
381                 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
382                 ldap_pvt_runqueue_insert( &slapd_rq, bdb->bi_txn_cp_min*60,
383                         bdb_checkpoint, bdb );
384                 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
385         }
386
387         if ( slapMode & SLAP_SERVER_MODE && bdb->bi_db_has_config ) {
388                 char    buf[SLAP_TEXT_BUFLEN];
389                 FILE *f = fopen( bdb->bi_db_config_path, "r" );
390                 struct berval bv;
391
392                 if ( f ) {
393                         while ( fgets( buf, sizeof(buf), f )) {
394                                 ber_str2bv( buf, 0, 1, &bv );
395                                 if ( bv.bv_val[bv.bv_len-1] == '\n' ) {
396                                         bv.bv_len--;
397                                         bv.bv_val[bv.bv_len] = '\0';
398                                 }
399                                 /* shouldn't need this, but ... */
400                                 if ( bv.bv_val[bv.bv_len-1] == '\r' ) {
401                                         bv.bv_len--;
402                                         bv.bv_val[bv.bv_len] = '\0';
403                                 }
404                                 ber_bvarray_add( &bdb->bi_db_config, &bv );
405                         }
406                         fclose( f );
407                 } else {
408                         /* Eh? It disappeared between config and open?? */
409                         bdb->bi_db_has_config = 0;
410                 }
411
412         }
413         bdb->bi_db_is_open = 1;
414
415         return 0;
416 }
417
418 static int
419 bdb_db_close( BackendDB *be )
420 {
421         int rc;
422         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
423         struct bdb_db_info *db;
424         bdb_idl_cache_entry_t *entry, *next_entry;
425
426         bdb->bi_db_is_open = 0;
427
428         ber_bvarray_free( bdb->bi_db_config );
429
430         while( bdb->bi_ndatabases-- ) {
431                 db = bdb->bi_databases[bdb->bi_ndatabases];
432                 rc = db->bdi_db->close( db->bdi_db, 0 );
433                 /* Lower numbered names are not strdup'd */
434                 if( bdb->bi_ndatabases >= BDB_NDB )
435                         free( db->bdi_name );
436                 free( db );
437         }
438         free( bdb->bi_databases );
439         bdb_attr_index_destroy( bdb->bi_attrs );
440
441         bdb_cache_release_all (&bdb->bi_cache);
442
443         if ( bdb->bi_idl_cache_max_size ) {
444                 ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
445                 avl_free( bdb->bi_idl_tree, NULL );
446                 entry = bdb->bi_idl_lru_head;
447                 while ( entry != NULL ) {
448                         next_entry = entry->idl_lru_next;
449                         if ( entry->idl )
450                                 free( entry->idl );
451                         free( entry->kstr.bv_val );
452                         free( entry );
453                         entry = next_entry;
454                 }
455                 ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
456         }
457
458         if ( !( slapMode & SLAP_TOOL_QUICK )) {
459                 XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
460         }
461
462         return 0;
463 }
464
465 static int
466 bdb_db_destroy( BackendDB *be )
467 {
468         int rc;
469         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
470
471         /* close db environment */
472         if( bdb->bi_dbenv ) {
473                 /* force a checkpoint */
474                 if ( !( slapMode & SLAP_TOOL_QUICK )) {
475                         rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
476                         if( rc != 0 ) {
477                                 Debug( LDAP_DEBUG_ANY,
478                                         "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
479                                         db_strerror(rc), rc, 0 );
480                         }
481                 }
482
483                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
484                 bdb->bi_dbenv = NULL;
485                 if( rc != 0 ) {
486                         Debug( LDAP_DEBUG_ANY,
487                                 "bdb_db_destroy: close failed: %s (%d)\n",
488                                 db_strerror(rc), rc, 0 );
489                         return rc;
490                 }
491         }
492
493         rc = alock_close( &bdb->bi_alock_info );
494         if( rc != 0 ) {
495                 Debug( LDAP_DEBUG_ANY,
496                         "bdb_db_destroy: alock_close failed\n", 0, 0, 0 );
497                 return -1;
498         }
499
500         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
501         if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
502
503         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
504         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
505         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
506         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
507         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
508         if ( bdb->bi_idl_cache_max_size ) {
509                 ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
510                 ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
511         }
512
513         ch_free( bdb );
514         be->be_private = NULL;
515
516         return 0;
517 }
518
519 int
520 bdb_back_initialize(
521         BackendInfo     *bi )
522 {
523         int rc;
524
525         static char *controls[] = {
526                 LDAP_CONTROL_ASSERT,
527                 LDAP_CONTROL_MANAGEDSAIT,
528                 LDAP_CONTROL_NOOP,
529                 LDAP_CONTROL_PAGEDRESULTS,
530 #ifdef LDAP_CONTROL_SUBENTRIES
531                 LDAP_CONTROL_SUBENTRIES,
532 #endif
533 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
534                 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
535 #endif
536                 NULL
537         };
538
539         /* initialize the underlying database system */
540         Debug( LDAP_DEBUG_TRACE,
541                 LDAP_XSTRING(bdb_back_initialize) ": initialize " 
542                 BDB_UCTYPE " backend\n", 0, 0, 0 );
543
544         bi->bi_flags |=
545                 SLAP_BFLAG_INCREMENT |
546 #ifdef BDB_SUBENTRIES
547                 SLAP_BFLAG_SUBENTRIES |
548 #endif
549                 SLAP_BFLAG_ALIASES |
550                 SLAP_BFLAG_REFERRALS;
551
552         bi->bi_controls = controls;
553
554         {       /* version check */
555                 int major, minor, patch, ver;
556                 char *version = db_version( &major, &minor, &patch );
557 #ifdef HAVE_EBCDIC
558                 char v2[1024];
559
560                 /* All our stdio does an ASCII to EBCDIC conversion on
561                  * the output. Strings from the BDB library are already
562                  * in EBCDIC; we have to go back and forth...
563                  */
564                 strcpy( v2, version );
565                 __etoa( v2 );
566                 version = v2;
567 #endif
568
569                 ver = (major << 24) | (minor << 16) | patch;
570                 if( ver != DB_VERSION_FULL ) {
571                         /* fail if a versions don't match */
572                         Debug( LDAP_DEBUG_ANY,
573                                 LDAP_XSTRING(bdb_back_initialize) ": "
574                                 "BDB library version mismatch:"
575                                 " expected " DB_VERSION_STRING ","
576                                 " got %s\n", version, 0, 0 );
577                         return -1;
578                 }
579
580                 Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_back_initialize)
581                         ": %s\n", version, 0, 0 );
582         }
583
584         db_env_set_func_free( ber_memfree );
585         db_env_set_func_malloc( (db_malloc *)ber_memalloc );
586         db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
587 #ifndef NO_THREAD
588         /* This is a no-op on a NO_THREAD build. Leave the default
589          * alone so that BDB will sleep on interprocess conflicts.
590          */
591         db_env_set_func_yield( ldap_pvt_thread_yield );
592 #endif
593
594         bi->bi_open = 0;
595         bi->bi_close = 0;
596         bi->bi_config = 0;
597         bi->bi_destroy = 0;
598
599         bi->bi_db_init = bdb_db_init;
600         bi->bi_db_config = config_generic_wrapper;
601         bi->bi_db_open = bdb_db_open;
602         bi->bi_db_close = bdb_db_close;
603         bi->bi_db_destroy = bdb_db_destroy;
604
605         bi->bi_op_add = bdb_add;
606         bi->bi_op_bind = bdb_bind;
607         bi->bi_op_compare = bdb_compare;
608         bi->bi_op_delete = bdb_delete;
609         bi->bi_op_modify = bdb_modify;
610         bi->bi_op_modrdn = bdb_modrdn;
611         bi->bi_op_search = bdb_search;
612
613         bi->bi_op_unbind = 0;
614
615         bi->bi_extended = bdb_extended;
616
617         bi->bi_chk_referrals = bdb_referrals;
618         bi->bi_operational = bdb_operational;
619         bi->bi_has_subordinates = bdb_hasSubordinates;
620         bi->bi_entry_release_rw = bdb_entry_release;
621         bi->bi_entry_get_rw = bdb_entry_get;
622
623         /*
624          * hooks for slap tools
625          */
626         bi->bi_tool_entry_open = bdb_tool_entry_open;
627         bi->bi_tool_entry_close = bdb_tool_entry_close;
628         bi->bi_tool_entry_first = bdb_tool_entry_next;
629         bi->bi_tool_entry_next = bdb_tool_entry_next;
630         bi->bi_tool_entry_get = bdb_tool_entry_get;
631         bi->bi_tool_entry_put = bdb_tool_entry_put;
632         bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
633         bi->bi_tool_sync = 0;
634         bi->bi_tool_dn2id_get = bdb_tool_dn2id_get;
635         bi->bi_tool_id2entry_get = bdb_tool_id2entry_get;
636         bi->bi_tool_entry_modify = bdb_tool_entry_modify;
637
638         bi->bi_connection_init = 0;
639         bi->bi_connection_destroy = 0;
640
641         rc = bdb_back_init_cf( bi );
642
643         return rc;
644 }
645
646 #if     (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \
647         (SLAPD_HDB == SLAPD_MOD_DYNAMIC && defined(BDB_HIER))
648
649 /* conditionally define the init_module() function */
650 #ifdef BDB_HIER
651 SLAP_BACKEND_INIT_MODULE( hdb )
652 #else /* !BDB_HIER */
653 SLAP_BACKEND_INIT_MODULE( bdb )
654 #endif /* !BDB_HIER */
655
656 #endif /* SLAPD_[BH]DB == SLAPD_MOD_DYNAMIC */
657