]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
ITS#2917 don't try to use uninit'd mutex
[openldap] / servers / slapd / back-bdb / init.c
1 /* init.c - initialize bdb backend */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12 #include <ac/unistd.h>
13 #include <ac/stdlib.h>
14
15 #include "back-bdb.h"
16 #include "external.h"
17 #include <lutil.h>
18
19 static struct bdbi_database {
20         char *file;
21         char *name;
22         int type;
23         int flags;
24 } bdbi_databases[] = {
25         { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
26 #ifdef BDB_HIER
27         { "id2parent" BDB_SUFFIX, "id2parent", DB_BTREE, 0 },
28 #else
29         { "dn2id" BDB_SUFFIX, "dn2id", DB_BTREE, 0 },
30 #endif
31         { NULL, NULL, 0, 0 }
32 };
33
34 struct berval bdb_uuid = { 0, NULL };
35
36 typedef void * db_malloc(size_t);
37 typedef void * db_realloc(void *, size_t);
38
39 #if 0
40 static int
41 bdb_open( BackendInfo *bi )
42 {
43         return 0;
44 }
45
46 static int
47 bdb_destroy( BackendInfo *bi )
48 {
49         return 0;
50 }
51
52 static int
53 bdb_close( BackendInfo *bi )
54 {
55         /* terminate the underlying database system */
56         return 0;
57 }
58 #endif
59
60 static int
61 bdb_db_init( BackendDB *be )
62 {
63         struct bdb_info *bdb;
64
65 #ifdef NEW_LOGGING
66         LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_init", 0, 0, 0 );
67 #else
68         Debug( LDAP_DEBUG_ANY,
69                 "bdb_db_init: Initializing BDB database\n",
70                 0, 0, 0 );
71 #endif
72
73         /* indicate system schema supported */
74         be->be_flags |=
75 #ifdef BDB_SUBENTRIES
76                 SLAP_BFLAG_SUBENTRIES |
77 #endif
78 #ifdef BDB_ALIASES
79                 SLAP_BFLAG_ALIASES |
80 #endif
81                 SLAP_BFLAG_REFERRALS;
82
83         /* allocate backend-database-specific stuff */
84         bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
85
86         /* DBEnv parameters */
87         bdb->bi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
88         bdb->bi_dbenv_xflags = 0;
89         bdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
90
91         bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
92
93         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
94         bdb->bi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
95         bdb->bi_search_stack = NULL;
96
97 #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC)
98         LDAP_LIST_INIT (&bdb->psearch_list);
99 #endif
100
101         ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
102         ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
103         ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
104         ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
105 #ifdef BDB_HIER
106         ldap_pvt_thread_rdwr_init( &bdb->bi_tree_rdwr );
107 #endif
108
109         be->be_private = bdb;
110
111         return 0;
112 }
113
114 int
115 bdb_bt_compare(
116         DB *db, 
117         const DBT *usrkey,
118         const DBT *curkey
119 )
120 {
121         unsigned char *u, *c;
122         int i, x;
123
124         u = usrkey->data;
125         c = curkey->data;
126
127 #ifdef WORDS_BIGENDIAN
128         for( i = 0; i < (int)sizeof(ID); i++)
129 #else
130         for( i = sizeof(ID)-1; i >= 0; i--)
131 #endif
132         {
133                 x = u[i] - c[i];
134                 if( x ) return x;
135         }
136
137         return 0;
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 #ifdef NEW_LOGGING
151         LDAP_LOG( BACK_BDB, ARGS, 
152                 "bdb_db_open: %s\n", be->be_suffix[0].bv_val, 0, 0 );
153 #else
154         Debug( LDAP_DEBUG_ARGS,
155                 "bdb_db_open: %s\n",
156                 be->be_suffix[0].bv_val, 0, 0 );
157 #endif
158
159 #ifndef BDB_MULTIPLE_SUFFIXES
160         if ( be->be_suffix[1].bv_val ) {
161 #ifdef NEW_LOGGING
162         LDAP_LOG( BACK_BDB, ERR, 
163                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
164 #else
165         Debug( LDAP_DEBUG_ANY,
166                 "bdb_db_open: only one suffix allowed\n", 0, 0, 0 );
167 #endif
168                 return -1;
169         }
170 #endif
171         /* we should check existance of dbenv_home and db_directory */
172
173         rc = db_env_create( &bdb->bi_dbenv, 0 );
174         if( rc != 0 ) {
175 #ifdef NEW_LOGGING
176                 LDAP_LOG( BACK_BDB, ERR, 
177                         "bdb_db_open: db_env_create failed: %s (%d)\n", 
178                         db_strerror(rc), rc, 0 );
179 #else
180                 Debug( LDAP_DEBUG_ANY,
181                         "bdb_db_open: db_env_create failed: %s (%d)\n",
182                         db_strerror(rc), rc, 0 );
183 #endif
184                 return rc;
185         }
186
187         flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE
188                 | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN;
189         
190 #if 0
191         /* Never do automatic recovery, must perform it manually.
192          * Otherwise restarting with gentlehup will corrupt the
193          * database.
194          */
195         if( !(slapMode & SLAP_TOOL_MODE) ) flags |= DB_RECOVER;
196 #endif
197
198         bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
199         bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
200         bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
201
202 #ifdef SLAP_IDL_CACHE
203         if ( bdb->bi_idl_cache_max_size ) {
204                 ldap_pvt_thread_mutex_init( &bdb->bi_idl_tree_mutex );
205                 bdb->bi_idl_cache_size = 0;
206         }
207 #endif
208
209 #ifdef BDB_SUBDIRS
210         {
211                 char dir[MAXPATHLEN], *ptr;
212                 
213                 if (bdb->bi_dbenv_home[0] == '.') {
214                         /* If home is a relative path, relative subdirs
215                          * are just concat'd by BDB. We don't want the
216                          * path to be concat'd twice, e.g.
217                          * ./test-db/./test-db/tmp
218                          */
219                         ptr = dir;
220                 } else {
221                         ptr = lutil_strcopy( dir, bdb->bi_dbenv_home );
222                         *ptr++ = LDAP_DIRSEP[0];
223 #ifdef HAVE_EBCDIC
224                         __atoe( dir );
225 #endif
226                 }
227
228                 strcpy( ptr, BDB_TMP_SUBDIR );
229 #ifdef HAVE_EBCDIC
230                 __atoe( ptr );
231 #endif
232                 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
233                 if( rc != 0 ) {
234 #ifdef NEW_LOGGING
235                         LDAP_LOG( BACK_BDB, ERR, 
236                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n", 
237                                 dir, db_strerror(rc), rc );
238 #else
239                         Debug( LDAP_DEBUG_ANY,
240                                 "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
241                                 dir, db_strerror(rc), rc );
242 #endif
243                         return rc;
244                 }
245
246                 strcpy( ptr, BDB_LG_SUBDIR );
247 #ifdef HAVE_EBCDIC
248                 __atoe( ptr );
249 #endif
250                 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
251                 if( rc != 0 ) {
252 #ifdef NEW_LOGGING
253                         LDAP_LOG( BACK_BDB, ERR, 
254                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n", 
255                                 dir, db_strerror(rc), rc );
256 #else
257                         Debug( LDAP_DEBUG_ANY,
258                                 "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
259                                 dir, db_strerror(rc), rc );
260 #endif
261                         return rc;
262                 }
263
264                 strcpy( ptr, BDB_DATA_SUBDIR );
265 #ifdef HAVE_EBCDIC
266                 __atoe( ptr );
267 #endif
268                 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
269                 if( rc != 0 ) {
270 #ifdef NEW_LOGGING
271                         LDAP_LOG( BACK_BDB, ERR, 
272                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
273                                 dir, db_strerror(rc), rc );
274 #else
275                         Debug( LDAP_DEBUG_ANY,
276                                 "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
277                                 dir, db_strerror(rc), rc );
278 #endif
279                         return rc;
280                 }
281         }
282 #endif
283
284 #ifdef NEW_LOGGING
285         LDAP_LOG( BACK_BDB, DETAIL1, 
286                 "bdb_db_open: dbenv_open %s\n", bdb->bi_dbenv_home, 0, 0 );
287 #else
288         Debug( LDAP_DEBUG_TRACE,
289                 "bdb_db_open: dbenv_open(%s)\n",
290                 bdb->bi_dbenv_home, 0, 0);
291 #endif
292
293 #ifdef HAVE_EBCDIC
294         strcpy( path, bdb->bi_dbenv_home );
295         __atoe( path );
296         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
297                 path,
298                 flags,
299                 bdb->bi_dbenv_mode );
300 #else
301         rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
302                 bdb->bi_dbenv_home,
303                 flags,
304                 bdb->bi_dbenv_mode );
305 #endif
306         if( rc != 0 ) {
307 #ifdef NEW_LOGGING
308                 LDAP_LOG( BACK_BDB, ERR, 
309                         "bdb_db_open: dbenv_open failed: %s (%d)\n", 
310                         db_strerror(rc), rc, 0 );
311 #else
312                 Debug( LDAP_DEBUG_ANY,
313                         "bdb_db_open: dbenv_open failed: %s (%d)\n",
314                         db_strerror(rc), rc, 0 );
315 #endif
316                 return rc;
317         }
318
319         if( bdb->bi_dbenv_xflags != 0 ) {
320                 rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
321                         bdb->bi_dbenv_xflags, 1);
322                 if( rc != 0 ) {
323 #ifdef NEW_LOGGING
324                         LDAP_LOG( BACK_BDB, ERR, 
325                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n", 
326                                 db_strerror(rc), rc, 0 );
327 #else
328                         Debug( LDAP_DEBUG_ANY,
329                                 "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
330                                 db_strerror(rc), rc, 0 );
331 #endif
332                         return rc;
333                 }
334         }
335
336         flags = DB_THREAD | DB_CREATE | bdb->bi_db_opflags;
337
338         bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
339                 BDB_INDICES * sizeof(struct bdb_db_info *) );
340
341         /* open (and create) main database */
342         for( i = 0; bdbi_databases[i].name; i++ ) {
343                 struct bdb_db_info *db;
344
345                 db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
346
347                 rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
348                 if( rc != 0 ) {
349 #ifdef NEW_LOGGING
350                         LDAP_LOG( BACK_BDB, ERR, 
351                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
352                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
353 #else
354                         Debug( LDAP_DEBUG_ANY,
355                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n",
356                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
357 #endif
358                         return rc;
359                 }
360
361                 if( i == BDB_ID2ENTRY ) {
362                         rc = db->bdi_db->set_bt_compare( db->bdi_db,
363                                 bdb_bt_compare );
364                         rc = db->bdi_db->set_pagesize( db->bdi_db,
365                                 BDB_ID2ENTRY_PAGESIZE );
366                 } else {
367 #ifdef BDB_HIER
368                         rc = db->bdi_db->set_bt_compare( db->bdi_db,
369                                 bdb_bt_compare );
370 #else
371                         rc = db->bdi_db->set_flags( db->bdi_db, 
372                                 DB_DUP | DB_DUPSORT );
373                         rc = db->bdi_db->set_dup_compare( db->bdi_db,
374                                 bdb_bt_compare );
375 #endif
376                         rc = db->bdi_db->set_pagesize( db->bdi_db,
377                                 BDB_PAGESIZE );
378                 }
379
380 #ifdef HAVE_EBCDIC
381                 strcpy( path, bdbi_databases[i].file );
382                 __atoe( path );
383                 rc = DB_OPEN( db->bdi_db,
384                         path,
385                 /*      bdbi_databases[i].name, */ NULL,
386                         bdbi_databases[i].type,
387                         bdbi_databases[i].flags | flags | DB_AUTO_COMMIT,
388                         bdb->bi_dbenv_mode );
389 #else
390                 rc = DB_OPEN( db->bdi_db,
391                         bdbi_databases[i].file,
392                 /*      bdbi_databases[i].name, */ NULL,
393                         bdbi_databases[i].type,
394                         bdbi_databases[i].flags | flags | DB_AUTO_COMMIT,
395                         bdb->bi_dbenv_mode );
396 #endif
397
398                 if( rc != 0 ) {
399 #ifdef NEW_LOGGING
400                         LDAP_LOG( BACK_BDB, ERR, 
401                                 "bdb_db_open: db_create(%s) failed: %s (%d)\n", 
402                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
403 #else
404                         Debug( LDAP_DEBUG_ANY,
405                                 "bdb_db_open: db_open(%s) failed: %s (%d)\n",
406                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
407 #endif
408                         return rc;
409                 }
410
411                 db->bdi_name = bdbi_databases[i].name;
412                 bdb->bi_databases[i] = db;
413         }
414
415         bdb->bi_databases[i] = NULL;
416         bdb->bi_ndatabases = i;
417
418         /* get nextid */
419         rc = bdb_last_id( be, NULL );
420         if( rc != 0 ) {
421 #ifdef NEW_LOGGING
422                         LDAP_LOG( BACK_BDB, ERR, 
423                                 "bdb_db_open: last_id(%s) failed: %s (%d)\n", 
424                                 bdb->bi_dbenv_home, db_strerror(rc), rc );
425 #else
426                 Debug( LDAP_DEBUG_ANY,
427                         "bdb_db_open: last_id(%s) failed: %s (%d)\n",
428                         bdb->bi_dbenv_home, db_strerror(rc), rc );
429 #endif
430                 return rc;
431         }
432
433         /* <insert> open (and create) index databases */
434 #ifdef BDB_HIER
435         rc = bdb_build_tree( be );
436 #endif
437         return 0;
438 }
439
440 static int
441 bdb_db_close( BackendDB *be )
442 {
443         int rc;
444         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
445         struct bdb_db_info *db;
446 #ifdef SLAP_IDL_CACHE
447         bdb_idl_cache_entry_t *entry, *next_entry;
448 #endif
449
450         while( bdb->bi_ndatabases-- ) {
451                 db = bdb->bi_databases[bdb->bi_ndatabases];
452                 rc = db->bdi_db->close( db->bdi_db, 0 );
453                 /* Lower numbered names are not strdup'd */
454                 if( bdb->bi_ndatabases >= BDB_NDB )
455                         free( db->bdi_name );
456                 free( db );
457         }
458         free( bdb->bi_databases );
459         bdb_attr_index_destroy( bdb->bi_attrs );
460
461         bdb_cache_release_all (&bdb->bi_cache);
462
463 #ifdef SLAP_IDL_CACHE
464         if ( bdb->bi_idl_cache_max_size ) {
465                 ldap_pvt_thread_mutex_lock ( &bdb->bi_idl_tree_mutex );
466                 entry = bdb->bi_idl_lru_head;
467                 while ( entry != NULL ) {
468                         next_entry = entry->idl_lru_next;
469                         avl_delete( &bdb->bi_idl_tree, (caddr_t) entry, bdb_idl_entry_cmp );
470                         free( entry->idl );
471                         free( entry->kstr.bv_val );
472                         free( entry );
473                         entry = next_entry;
474                 }
475                 ldap_pvt_thread_mutex_unlock ( &bdb->bi_idl_tree_mutex );
476         }
477 #endif
478
479         return 0;
480 }
481
482 static int
483 bdb_db_destroy( BackendDB *be )
484 {
485         int rc;
486         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
487
488         /* close db environment */
489         if( bdb->bi_dbenv ) {
490                 /* force a checkpoint */
491                 rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE );
492                 if( rc != 0 ) {
493 #ifdef NEW_LOGGING
494                         LDAP_LOG( BACK_BDB, ERR, 
495                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
496                                 db_strerror(rc), rc, 0 );
497 #else
498                         Debug( LDAP_DEBUG_ANY,
499                                 "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
500                                 db_strerror(rc), rc, 0 );
501 #endif
502                 }
503
504                 bdb_cache_release_all (&bdb->bi_cache);
505
506                 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
507                 bdb->bi_dbenv = NULL;
508                 if( rc != 0 ) {
509 #ifdef NEW_LOGGING
510                         LDAP_LOG( BACK_BDB, ERR, 
511                                 "bdb_db_destroy: close failed: %s (%d)\n", 
512                                 db_strerror(rc), rc, 0 );
513 #else
514                         Debug( LDAP_DEBUG_ANY,
515                                 "bdb_db_destroy: close failed: %s (%d)\n",
516                                 db_strerror(rc), rc, 0 );
517 #endif
518                         return rc;
519                 }
520         }
521
522         if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
523
524 #ifdef BDB_HIER
525         ldap_pvt_thread_rdwr_destroy( &bdb->bi_tree_rdwr );
526 #endif
527         ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
528         ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
529         ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
530         ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
531
532         ch_free( bdb );
533         be->be_private = NULL;
534
535         return 0;
536 }
537
538 #ifdef SLAPD_BDB_DYNAMIC
539 int back_bdb_LTX_init_module( int argc, char *argv[] ) {
540         BackendInfo bi;
541
542         memset( &bi, '\0', sizeof(bi) );
543         bi.bi_type = "bdb";
544         bi.bi_init = bdb_initialize;
545
546         backend_add( &bi );
547         return 0;
548 }
549 #endif /* SLAPD_BDB_DYNAMIC */
550
551 int
552 bdb_initialize(
553         BackendInfo     *bi
554 )
555 {
556         static char *controls[] = {
557                 LDAP_CONTROL_MANAGEDSAIT,
558                 LDAP_CONTROL_NOOP,
559 #ifdef LDAP_CONTROL_PAGEDRESULTS
560                 LDAP_CONTROL_PAGEDRESULTS,
561 #endif
562                 LDAP_CONTROL_VALUESRETURNFILTER,
563 #ifdef LDAP_CONTROL_SUBENTRIES
564                 LDAP_CONTROL_SUBENTRIES,
565 #endif
566 #ifdef LDAP_CLIENT_UPDATE
567                 LDAP_CONTROL_CLIENT_UPDATE,
568 #endif
569                 NULL
570         };
571
572         bi->bi_controls = controls;
573
574         /* initialize the underlying database system */
575 #ifdef NEW_LOGGING
576         LDAP_LOG( BACK_BDB, ENTRY, "bdb_db_initialize\n", 0, 0, 0 );
577 #else
578         Debug( LDAP_DEBUG_TRACE, "bdb_initialize: initialize BDB backend\n",
579                 0, 0, 0 );
580 #endif
581
582         {       /* version check */
583                 int major, minor, patch;
584                 char *version = db_version( &major, &minor, &patch );
585 #ifdef HAVE_EBCDIC
586                 char v2[1024];
587
588                 /* All our stdio does an ASCII to EBCDIC conversion on
589                  * the output. Strings from the BDB library are already
590                  * in EBCDIC; we have to go back and forth...
591                  */
592                 strcpy( v2, version );
593                 __etoa( v2 );
594                 version = v2;
595 #endif
596
597                 if( major != DB_VERSION_MAJOR ||
598                         minor != DB_VERSION_MINOR ||
599                         patch < DB_VERSION_PATCH )
600                 {
601 #ifdef NEW_LOGGING
602                         LDAP_LOG( BACK_BDB, ERR, 
603                                 "bdb_db_initialize: version mismatch: "
604                                 "\texpected: %s \tgot: %s\n", DB_VERSION_STRING, version, 0 );
605 #else
606                         Debug( LDAP_DEBUG_ANY,
607                                 "bdb_initialize: version mismatch\n"
608                                 "\texpected: " DB_VERSION_STRING "\n"
609                                 "\tgot: %s \n", version, 0, 0 );
610 #endif
611                 }
612
613 #ifdef NEW_LOGGING
614                 LDAP_LOG( BACK_BDB, DETAIL1, 
615                         "bdb_db_initialize: %s\n", version, 0, 0 );
616 #else
617                 Debug( LDAP_DEBUG_ANY, "bdb_initialize: %s\n",
618                         version, 0, 0 );
619 #endif
620         }
621
622         db_env_set_func_free( ber_memfree );
623         db_env_set_func_malloc( (db_malloc *)ber_memalloc );
624         db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
625 #ifndef NO_THREAD
626         /* This is a no-op on a NO_THREAD build. Leave the default
627          * alone so that BDB will sleep on interprocess conflicts.
628          */
629         db_env_set_func_yield( ldap_pvt_thread_yield );
630 #endif
631
632         {
633                 static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
634
635                 bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ));
636                 bdb_uuid.bv_val = uuidbuf;
637         }
638
639         bi->bi_open = 0;
640         bi->bi_close = 0;
641         bi->bi_config = 0;
642         bi->bi_destroy = 0;
643
644         bi->bi_db_init = bdb_db_init;
645         bi->bi_db_config = bdb_db_config;
646         bi->bi_db_open = bdb_db_open;
647         bi->bi_db_close = bdb_db_close;
648         bi->bi_db_destroy = bdb_db_destroy;
649
650         bi->bi_op_add = bdb_add;
651         bi->bi_op_bind = bdb_bind;
652         bi->bi_op_compare = bdb_compare;
653         bi->bi_op_delete = bdb_delete;
654         bi->bi_op_modify = bdb_modify;
655         bi->bi_op_modrdn = bdb_modrdn;
656         bi->bi_op_search = bdb_search;
657
658         bi->bi_op_unbind = 0;
659
660 #ifdef LDAP_CLIENT_UPDATE
661         bi->bi_op_abandon = bdb_abandon;
662         bi->bi_op_cancel = bdb_cancel;
663 #else
664         bi->bi_op_abandon = 0;
665         bi->bi_op_cancel = 0;
666 #endif
667
668         bi->bi_extended = bdb_extended;
669
670 #if 1
671         /*
672          * these routines (and their callers) are not yet designed
673          * to work with transaction.  Using them may cause deadlock.
674          */
675         bi->bi_acl_group = bdb_group;
676         bi->bi_acl_attribute = bdb_attribute;
677 #else
678         bi->bi_acl_group = 0;
679         bi->bi_acl_attribute = 0;
680 #endif
681
682         bi->bi_chk_referrals = bdb_referrals;
683         bi->bi_operational = bdb_operational;
684         bi->bi_has_subordinates = bdb_hasSubordinates;
685         bi->bi_entry_release_rw = bdb_entry_release;
686
687         /*
688          * hooks for slap tools
689          */
690         bi->bi_tool_entry_open = bdb_tool_entry_open;
691         bi->bi_tool_entry_close = bdb_tool_entry_close;
692         bi->bi_tool_entry_first = bdb_tool_entry_next;
693         bi->bi_tool_entry_next = bdb_tool_entry_next;
694         bi->bi_tool_entry_get = bdb_tool_entry_get;
695         bi->bi_tool_entry_put = bdb_tool_entry_put;
696         bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
697         bi->bi_tool_sync = 0;
698
699         bi->bi_connection_init = 0;
700         bi->bi_connection_destroy = 0;
701
702         return 0;
703 }