+ if( bdb->bi_dbenv_xflags != 0 ) {
+ rc = bdb->bi_dbenv->set_flags( bdb->bi_dbenv,
+ bdb->bi_dbenv_xflags, 1);
+ if( rc != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
+ db_strerror(rc), rc, 0 );
+ return rc;
+ }
+ }
+
+ flags = DB_THREAD | DB_CREATE | bdb->bi_db_opflags;
+
+ bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
+ BDB_INDICES * sizeof(struct bdb_db_info *) );
+
+ /* open (and create) main database */
+ for( i = 0; bdbi_databases[i].name; i++ ) {
+ struct bdb_db_info *db;
+
+ db = (struct bdb_db_info *) ch_calloc(1, sizeof(struct bdb_db_info));
+
+ rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
+ if( rc != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_open: db_create(%s) failed: %s (%d)\n",
+ bdb->bi_dbenv_home, db_strerror(rc), rc );
+ return rc;
+ }
+
+ if( i == BDB_ID2ENTRY ) {
+ rc = db->bdi_db->set_bt_compare( db->bdi_db,
+ bdb_bt_compare );
+ rc = db->bdi_db->set_pagesize( db->bdi_db,
+ BDB_ID2ENTRY_PAGESIZE );
+ } else {
+#ifdef BDB_HIER
+ rc = db->bdi_db->set_bt_compare( db->bdi_db,
+ bdb_bt_compare );
+#elif defined(BDB_IDL_MULTI)
+ rc = db->bdi_db->set_flags( db->bdi_db,
+ DB_DUP | DB_DUPSORT );
+ rc = db->bdi_db->set_dup_compare( db->bdi_db,
+ bdb_bt_compare );
+#endif
+ rc = db->bdi_db->set_pagesize( db->bdi_db,
+ BDB_PAGESIZE );
+ }
+
+ rc = db->bdi_db->open( db->bdi_db,
+ bdbi_databases[i].file,
+ /* bdbi_databases[i].name, */ NULL,
+ bdbi_databases[i].type,
+ bdbi_databases[i].flags | flags,
+ bdb->bi_dbenv_mode );
+
+ if( rc != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_open: db_open(%s) failed: %s (%d)\n",
+ bdb->bi_dbenv_home, db_strerror(rc), rc );
+ return rc;
+ }
+
+ db->bdi_name = bdbi_databases[i].name;
+ bdb->bi_databases[i] = db;
+ }
+
+ bdb->bi_databases[i] = NULL;
+ bdb->bi_ndatabases = i;
+
+ /* get nextid */
+ rc = bdb_last_id( be, NULL );
+ if( rc != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_open: last_id(%s) failed: %s (%d)\n",
+ bdb->bi_dbenv_home, db_strerror(rc), rc );
+ return rc;
+ }
+
+ /* <insert> open (and create) index databases */
+#ifdef BDB_HIER
+ rc = bdb_build_tree( be );
+#endif
+
+#if 0 /* ifndef NO_THREADS */
+ if( bdb->bi_lock_detect != DB_LOCK_NORUN ) {
+ /* listener as a separate THREAD */
+ rc = ldap_pvt_thread_create( &bdb->bi_lock_detect_tid,
+ 1, lock_detect_task, bdb );
+ }
+#endif