Home | History | Annotate | Line # | Download | only in back-mdb
init.c revision 1.1.1.6
      1  1.1.1.6  christos /*	$NetBSD: init.c,v 1.1.1.6 2021/08/14 16:05:23 christos Exp $	*/
      2      1.1      tron 
      3      1.1      tron /* init.c - initialize mdb backend */
      4      1.1      tron /* $OpenLDAP$ */
      5      1.1      tron /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6      1.1      tron  *
      7  1.1.1.6  christos  * Copyright 2000-2021 The OpenLDAP Foundation.
      8      1.1      tron  * All rights reserved.
      9      1.1      tron  *
     10      1.1      tron  * Redistribution and use in source and binary forms, with or without
     11      1.1      tron  * modification, are permitted only as authorized by the OpenLDAP
     12      1.1      tron  * Public License.
     13      1.1      tron  *
     14      1.1      tron  * A copy of this license is available in the file LICENSE in the
     15      1.1      tron  * top-level directory of the distribution or, alternatively, at
     16      1.1      tron  * <http://www.OpenLDAP.org/license.html>.
     17      1.1      tron  */
     18      1.1      tron 
     19  1.1.1.2  christos #include <sys/cdefs.h>
     20  1.1.1.6  christos __RCSID("$NetBSD: init.c,v 1.1.1.6 2021/08/14 16:05:23 christos Exp $");
     21  1.1.1.2  christos 
     22      1.1      tron #include "portable.h"
     23      1.1      tron 
     24      1.1      tron #include <stdio.h>
     25      1.1      tron #include <ac/string.h>
     26      1.1      tron #include <ac/unistd.h>
     27      1.1      tron #include <ac/stdlib.h>
     28      1.1      tron #include <ac/errno.h>
     29      1.1      tron #include <sys/stat.h>
     30      1.1      tron #include "back-mdb.h"
     31      1.1      tron #include <lutil.h>
     32      1.1      tron #include <ldap_rq.h>
     33  1.1.1.6  christos #include "slap-config.h"
     34      1.1      tron 
     35      1.1      tron static const struct berval mdmi_databases[] = {
     36      1.1      tron 	BER_BVC("ad2i"),
     37      1.1      tron 	BER_BVC("dn2i"),
     38      1.1      tron 	BER_BVC("id2e"),
     39  1.1.1.6  christos 	BER_BVC("id2v"),
     40      1.1      tron 	BER_BVNULL
     41      1.1      tron };
     42      1.1      tron 
     43      1.1      tron static int
     44      1.1      tron mdb_id_compare( const MDB_val *a, const MDB_val *b )
     45      1.1      tron {
     46      1.1      tron 	return *(ID *)a->mv_data < *(ID *)b->mv_data ? -1 : *(ID *)a->mv_data > *(ID *)b->mv_data;
     47      1.1      tron }
     48      1.1      tron 
     49      1.1      tron static int
     50      1.1      tron mdb_db_init( BackendDB *be, ConfigReply *cr )
     51      1.1      tron {
     52      1.1      tron 	struct mdb_info	*mdb;
     53      1.1      tron 	int rc;
     54      1.1      tron 
     55      1.1      tron 	Debug( LDAP_DEBUG_TRACE,
     56  1.1.1.6  christos 		LDAP_XSTRING(mdb_db_init) ": Initializing mdb database\n" );
     57      1.1      tron 
     58      1.1      tron 	/* allocate backend-database-specific stuff */
     59      1.1      tron 	mdb = (struct mdb_info *) ch_calloc( 1, sizeof(struct mdb_info) );
     60      1.1      tron 
     61      1.1      tron 	/* DBEnv parameters */
     62      1.1      tron 	mdb->mi_dbenv_home = ch_strdup( SLAPD_DEFAULT_DB_DIR );
     63      1.1      tron 	mdb->mi_dbenv_flags = 0;
     64      1.1      tron 	mdb->mi_dbenv_mode = SLAPD_DEFAULT_DB_MODE;
     65      1.1      tron 
     66      1.1      tron 	mdb->mi_search_stack_depth = DEFAULT_SEARCH_STACK_DEPTH;
     67      1.1      tron 	mdb->mi_search_stack = NULL;
     68      1.1      tron 
     69      1.1      tron 	mdb->mi_mapsize = DEFAULT_MAPSIZE;
     70  1.1.1.2  christos 	mdb->mi_rtxn_size = DEFAULT_RTXN_SIZE;
     71  1.1.1.6  christos 	mdb->mi_multi_hi = UINT_MAX;
     72  1.1.1.6  christos 	mdb->mi_multi_lo = UINT_MAX;
     73      1.1      tron 
     74      1.1      tron 	be->be_private = mdb;
     75  1.1.1.6  christos 	be->be_cf_ocs = be->bd_info->bi_cf_ocs+1;
     76      1.1      tron 
     77      1.1      tron #ifndef MDB_MULTIPLE_SUFFIXES
     78      1.1      tron 	SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_ONE_SUFFIX;
     79      1.1      tron #endif
     80      1.1      tron 
     81      1.1      tron 	rc = mdb_monitor_db_init( be );
     82      1.1      tron 
     83      1.1      tron 	return rc;
     84      1.1      tron }
     85      1.1      tron 
     86      1.1      tron static int
     87      1.1      tron mdb_db_close( BackendDB *be, ConfigReply *cr );
     88      1.1      tron 
     89      1.1      tron static int
     90      1.1      tron mdb_db_open( BackendDB *be, ConfigReply *cr )
     91      1.1      tron {
     92      1.1      tron 	int rc, i;
     93      1.1      tron 	struct mdb_info *mdb = (struct mdb_info *) be->be_private;
     94      1.1      tron 	struct stat stat1;
     95  1.1.1.5  christos 	unsigned flags;
     96      1.1      tron 	char *dbhome;
     97      1.1      tron 	MDB_txn *txn;
     98      1.1      tron 
     99      1.1      tron 	if ( be->be_suffix == NULL ) {
    100      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    101  1.1.1.6  christos 			LDAP_XSTRING(mdb_db_open) ": need suffix.\n" );
    102      1.1      tron 		return -1;
    103      1.1      tron 	}
    104      1.1      tron 
    105      1.1      tron 	Debug( LDAP_DEBUG_ARGS,
    106      1.1      tron 		LDAP_XSTRING(mdb_db_open) ": \"%s\"\n",
    107  1.1.1.6  christos 		be->be_suffix[0].bv_val );
    108      1.1      tron 
    109      1.1      tron 	/* Check existence of dbenv_home. Any error means trouble */
    110      1.1      tron 	rc = stat( mdb->mi_dbenv_home, &stat1 );
    111      1.1      tron 	if( rc != 0 ) {
    112  1.1.1.6  christos 		int saved_errno = errno;
    113      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    114      1.1      tron 			LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
    115      1.1      tron 			"cannot access database directory \"%s\" (%d).\n",
    116  1.1.1.6  christos 			be->be_suffix[0].bv_val, mdb->mi_dbenv_home, saved_errno );
    117      1.1      tron 		return -1;
    118      1.1      tron 	}
    119      1.1      tron 
    120      1.1      tron 	/* mdb is always clean */
    121      1.1      tron 	be->be_flags |= SLAP_DBFLAG_CLEAN;
    122      1.1      tron 
    123      1.1      tron 	rc = mdb_env_create( &mdb->mi_dbenv );
    124      1.1      tron 	if( rc != 0 ) {
    125      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    126      1.1      tron 			LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
    127      1.1      tron 			"mdb_env_create failed: %s (%d).\n",
    128      1.1      tron 			be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    129      1.1      tron 		goto fail;
    130      1.1      tron 	}
    131      1.1      tron 
    132      1.1      tron 	if ( mdb->mi_readers ) {
    133      1.1      tron 		rc = mdb_env_set_maxreaders( mdb->mi_dbenv, mdb->mi_readers );
    134      1.1      tron 		if( rc != 0 ) {
    135      1.1      tron 			Debug( LDAP_DEBUG_ANY,
    136      1.1      tron 				LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
    137      1.1      tron 				"mdb_env_set_maxreaders failed: %s (%d).\n",
    138      1.1      tron 				be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    139      1.1      tron 			goto fail;
    140      1.1      tron 		}
    141      1.1      tron 	}
    142      1.1      tron 
    143      1.1      tron 	rc = mdb_env_set_mapsize( mdb->mi_dbenv, mdb->mi_mapsize );
    144      1.1      tron 	if( rc != 0 ) {
    145      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    146      1.1      tron 			LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
    147      1.1      tron 			"mdb_env_set_mapsize failed: %s (%d).\n",
    148      1.1      tron 			be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    149      1.1      tron 		goto fail;
    150      1.1      tron 	}
    151      1.1      tron 
    152      1.1      tron 	rc = mdb_env_set_maxdbs( mdb->mi_dbenv, MDB_INDICES );
    153      1.1      tron 	if( rc != 0 ) {
    154      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    155      1.1      tron 			LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
    156      1.1      tron 			"mdb_env_set_maxdbs failed: %s (%d).\n",
    157      1.1      tron 			be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    158      1.1      tron 		goto fail;
    159      1.1      tron 	}
    160      1.1      tron 
    161      1.1      tron #ifdef HAVE_EBCDIC
    162      1.1      tron 	strcpy( path, mdb->mi_dbenv_home );
    163      1.1      tron 	__atoe( path );
    164      1.1      tron 	dbhome = path;
    165      1.1      tron #else
    166      1.1      tron 	dbhome = mdb->mi_dbenv_home;
    167      1.1      tron #endif
    168      1.1      tron 
    169      1.1      tron 	Debug( LDAP_DEBUG_TRACE,
    170      1.1      tron 		LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
    171      1.1      tron 		"dbenv_open(%s).\n",
    172  1.1.1.6  christos 		be->be_suffix[0].bv_val, mdb->mi_dbenv_home );
    173      1.1      tron 
    174      1.1      tron 	flags = mdb->mi_dbenv_flags;
    175      1.1      tron 
    176      1.1      tron 	if ( slapMode & SLAP_TOOL_QUICK )
    177      1.1      tron 		flags |= MDB_NOSYNC|MDB_WRITEMAP;
    178      1.1      tron 
    179      1.1      tron 	if ( slapMode & SLAP_TOOL_READONLY)
    180      1.1      tron 		flags |= MDB_RDONLY;
    181      1.1      tron 
    182      1.1      tron 	rc = mdb_env_open( mdb->mi_dbenv, dbhome,
    183      1.1      tron 			flags, mdb->mi_dbenv_mode );
    184      1.1      tron 
    185      1.1      tron 	if ( rc ) {
    186      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    187  1.1.1.2  christos 			LDAP_XSTRING(mdb_db_open) ": database \"%s\" cannot be opened: %s (%d). "
    188      1.1      tron 			"Restore from backup!\n",
    189  1.1.1.2  christos 			be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    190      1.1      tron 		goto fail;
    191      1.1      tron 	}
    192      1.1      tron 
    193      1.1      tron 	rc = mdb_txn_begin( mdb->mi_dbenv, NULL, flags & MDB_RDONLY, &txn );
    194      1.1      tron 	if ( rc ) {
    195      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    196  1.1.1.2  christos 			LDAP_XSTRING(mdb_db_open) ": database \"%s\" cannot be opened: %s (%d). "
    197      1.1      tron 			"Restore from backup!\n",
    198  1.1.1.2  christos 			be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    199      1.1      tron 		goto fail;
    200      1.1      tron 	}
    201      1.1      tron 
    202      1.1      tron 	/* open (and create) main databases */
    203      1.1      tron 	for( i = 0; mdmi_databases[i].bv_val; i++ ) {
    204      1.1      tron 		flags = MDB_INTEGERKEY;
    205      1.1      tron 		if( i == MDB_ID2ENTRY ) {
    206      1.1      tron 			if ( !(slapMode & (SLAP_TOOL_READMAIN|SLAP_TOOL_READONLY) ))
    207      1.1      tron 				flags |= MDB_CREATE;
    208      1.1      tron 		} else {
    209      1.1      tron 			if ( i == MDB_DN2ID )
    210      1.1      tron 				flags |= MDB_DUPSORT;
    211  1.1.1.6  christos 			if ( i == MDB_ID2VAL )
    212  1.1.1.6  christos 				flags ^= MDB_INTEGERKEY|MDB_DUPSORT;
    213      1.1      tron 			if ( !(slapMode & SLAP_TOOL_READONLY) )
    214      1.1      tron 				flags |= MDB_CREATE;
    215      1.1      tron 		}
    216      1.1      tron 
    217      1.1      tron 		rc = mdb_dbi_open( txn,
    218      1.1      tron 			mdmi_databases[i].bv_val,
    219      1.1      tron 			flags,
    220      1.1      tron 			&mdb->mi_dbis[i] );
    221      1.1      tron 
    222      1.1      tron 		if ( rc != 0 ) {
    223      1.1      tron 			snprintf( cr->msg, sizeof(cr->msg), "database \"%s\": "
    224      1.1      tron 				"mdb_dbi_open(%s/%s) failed: %s (%d).",
    225      1.1      tron 				be->be_suffix[0].bv_val,
    226      1.1      tron 				mdb->mi_dbenv_home, mdmi_databases[i].bv_val,
    227      1.1      tron 				mdb_strerror(rc), rc );
    228      1.1      tron 			Debug( LDAP_DEBUG_ANY,
    229      1.1      tron 				LDAP_XSTRING(mdb_db_open) ": %s\n",
    230  1.1.1.6  christos 				cr->msg );
    231      1.1      tron 			goto fail;
    232      1.1      tron 		}
    233      1.1      tron 
    234      1.1      tron 		if ( i == MDB_ID2ENTRY )
    235      1.1      tron 			mdb_set_compare( txn, mdb->mi_dbis[i], mdb_id_compare );
    236  1.1.1.6  christos 		else if ( i == MDB_ID2VAL ) {
    237  1.1.1.6  christos 			mdb_set_compare( txn, mdb->mi_dbis[i], mdb_id2v_compare );
    238  1.1.1.6  christos 			mdb_set_dupsort( txn, mdb->mi_dbis[i], mdb_id2v_dupsort );
    239  1.1.1.6  christos 		} else if ( i == MDB_DN2ID ) {
    240      1.1      tron 			MDB_cursor *mc;
    241      1.1      tron 			MDB_val key, data;
    242      1.1      tron 			mdb_set_dupsort( txn, mdb->mi_dbis[i], mdb_dup_compare );
    243      1.1      tron 			/* check for old dn2id format */
    244      1.1      tron 			rc = mdb_cursor_open( txn, mdb->mi_dbis[i], &mc );
    245      1.1      tron 			/* first record is always ID 0 */
    246      1.1      tron 			rc = mdb_cursor_get( mc, &key, &data, MDB_FIRST );
    247      1.1      tron 			if ( rc == 0 ) {
    248      1.1      tron 				rc = mdb_cursor_get( mc, &key, &data, MDB_NEXT );
    249      1.1      tron 				if ( rc == 0 ) {
    250      1.1      tron 					int len;
    251      1.1      tron 					unsigned char *ptr;
    252      1.1      tron 					ptr = data.mv_data;
    253      1.1      tron 					len = (ptr[0] & 0x7f) << 8 | ptr[1];
    254      1.1      tron 					if (data.mv_size < 2*len + 4 + 2*sizeof(ID)) {
    255      1.1      tron 						snprintf( cr->msg, sizeof(cr->msg),
    256      1.1      tron 						"database \"%s\": DN index needs upgrade, "
    257      1.1      tron 						"run \"slapindex entryDN\".",
    258      1.1      tron 						be->be_suffix[0].bv_val );
    259      1.1      tron 						Debug( LDAP_DEBUG_ANY,
    260      1.1      tron 							LDAP_XSTRING(mdb_db_open) ": %s\n",
    261  1.1.1.6  christos 							cr->msg );
    262      1.1      tron 						if ( !(slapMode & SLAP_TOOL_READMAIN ))
    263      1.1      tron 							rc = LDAP_OTHER;
    264      1.1      tron 						mdb->mi_flags |= MDB_NEED_UPGRADE;
    265      1.1      tron 					}
    266      1.1      tron 				}
    267      1.1      tron 			}
    268      1.1      tron 			mdb_cursor_close( mc );
    269      1.1      tron 			if ( rc == LDAP_OTHER )
    270      1.1      tron 				goto fail;
    271      1.1      tron 		}
    272      1.1      tron 	}
    273      1.1      tron 
    274      1.1      tron 	rc = mdb_ad_read( mdb, txn );
    275      1.1      tron 	if ( rc ) {
    276      1.1      tron 		mdb_txn_abort( txn );
    277      1.1      tron 		goto fail;
    278      1.1      tron 	}
    279      1.1      tron 
    280  1.1.1.2  christos 	/* slapcat doesn't need indexes. avoid a failure if
    281  1.1.1.2  christos 	 * a configured index wasn't created yet.
    282  1.1.1.2  christos 	 */
    283  1.1.1.2  christos 	if ( !(slapMode & SLAP_TOOL_READONLY) ) {
    284  1.1.1.2  christos 		rc = mdb_attr_dbs_open( be, txn, cr );
    285  1.1.1.2  christos 		if ( rc ) {
    286  1.1.1.2  christos 			mdb_txn_abort( txn );
    287  1.1.1.2  christos 			goto fail;
    288  1.1.1.2  christos 		}
    289      1.1      tron 	}
    290      1.1      tron 
    291      1.1      tron 	rc = mdb_txn_commit(txn);
    292      1.1      tron 	if ( rc != 0 ) {
    293      1.1      tron 		Debug( LDAP_DEBUG_ANY,
    294      1.1      tron 			LDAP_XSTRING(mdb_db_open) ": database %s: "
    295      1.1      tron 			"txn_commit failed: %s (%d)\n",
    296      1.1      tron 			be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    297      1.1      tron 		goto fail;
    298      1.1      tron 	}
    299      1.1      tron 
    300      1.1      tron 	/* monitor setup */
    301      1.1      tron 	rc = mdb_monitor_db_open( be );
    302      1.1      tron 	if ( rc != 0 ) {
    303      1.1      tron 		goto fail;
    304      1.1      tron 	}
    305      1.1      tron 
    306      1.1      tron 	mdb->mi_flags |= MDB_IS_OPEN;
    307      1.1      tron 
    308      1.1      tron 	return 0;
    309      1.1      tron 
    310      1.1      tron fail:
    311      1.1      tron 	mdb_db_close( be, NULL );
    312      1.1      tron 	return rc;
    313      1.1      tron }
    314      1.1      tron 
    315      1.1      tron static int
    316      1.1      tron mdb_db_close( BackendDB *be, ConfigReply *cr )
    317      1.1      tron {
    318      1.1      tron 	int rc;
    319      1.1      tron 	struct mdb_info *mdb = (struct mdb_info *) be->be_private;
    320      1.1      tron 
    321      1.1      tron 	/* monitor handling */
    322      1.1      tron 	(void)mdb_monitor_db_close( be );
    323      1.1      tron 
    324      1.1      tron 	mdb->mi_flags &= ~MDB_IS_OPEN;
    325      1.1      tron 
    326      1.1      tron 	if( mdb->mi_dbenv ) {
    327      1.1      tron 		mdb_reader_flush( mdb->mi_dbenv );
    328      1.1      tron 	}
    329      1.1      tron 
    330      1.1      tron 	if ( mdb->mi_dbenv ) {
    331      1.1      tron 		if ( mdb->mi_dbis[0] ) {
    332      1.1      tron 			int i;
    333      1.1      tron 
    334      1.1      tron 			mdb_attr_dbs_close( mdb );
    335      1.1      tron 			for ( i=0; i<MDB_NDB; i++ )
    336      1.1      tron 				mdb_dbi_close( mdb->mi_dbenv, mdb->mi_dbis[i] );
    337      1.1      tron 
    338      1.1      tron 			/* force a sync, but not if we were ReadOnly,
    339      1.1      tron 			 * and not in Quick mode.
    340      1.1      tron 			 */
    341      1.1      tron 			if (!(slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY))) {
    342      1.1      tron 				rc = mdb_env_sync( mdb->mi_dbenv, 1 );
    343      1.1      tron 				if( rc != 0 ) {
    344      1.1      tron 					Debug( LDAP_DEBUG_ANY,
    345      1.1      tron 						"mdb_db_close: database \"%s\": "
    346      1.1      tron 						"mdb_env_sync failed: %s (%d).\n",
    347      1.1      tron 						be->be_suffix[0].bv_val, mdb_strerror(rc), rc );
    348      1.1      tron 				}
    349      1.1      tron 			}
    350      1.1      tron 		}
    351      1.1      tron 
    352      1.1      tron 		mdb_env_close( mdb->mi_dbenv );
    353      1.1      tron 		mdb->mi_dbenv = NULL;
    354      1.1      tron 	}
    355      1.1      tron 
    356      1.1      tron 	return 0;
    357      1.1      tron }
    358      1.1      tron 
    359      1.1      tron static int
    360      1.1      tron mdb_db_destroy( BackendDB *be, ConfigReply *cr )
    361      1.1      tron {
    362      1.1      tron 	struct mdb_info *mdb = (struct mdb_info *) be->be_private;
    363      1.1      tron 
    364      1.1      tron 	/* stop and remove checkpoint task */
    365      1.1      tron 	if ( mdb->mi_txn_cp_task ) {
    366      1.1      tron 		struct re_s *re = mdb->mi_txn_cp_task;
    367      1.1      tron 		mdb->mi_txn_cp_task = NULL;
    368      1.1      tron 		ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
    369      1.1      tron 		if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) )
    370      1.1      tron 			ldap_pvt_runqueue_stoptask( &slapd_rq, re );
    371      1.1      tron 		ldap_pvt_runqueue_remove( &slapd_rq, re );
    372      1.1      tron 		ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
    373      1.1      tron 	}
    374      1.1      tron 
    375      1.1      tron 	/* monitor handling */
    376      1.1      tron 	(void)mdb_monitor_db_destroy( be );
    377      1.1      tron 
    378      1.1      tron 	if( mdb->mi_dbenv_home ) ch_free( mdb->mi_dbenv_home );
    379      1.1      tron 
    380      1.1      tron 	mdb_attr_index_destroy( mdb );
    381      1.1      tron 
    382      1.1      tron 	ch_free( mdb );
    383      1.1      tron 	be->be_private = NULL;
    384      1.1      tron 
    385      1.1      tron 	return 0;
    386      1.1      tron }
    387      1.1      tron 
    388      1.1      tron int
    389      1.1      tron mdb_back_initialize(
    390      1.1      tron 	BackendInfo	*bi )
    391      1.1      tron {
    392      1.1      tron 	int rc;
    393      1.1      tron 
    394      1.1      tron 	static char *controls[] = {
    395      1.1      tron 		LDAP_CONTROL_ASSERT,
    396      1.1      tron 		LDAP_CONTROL_MANAGEDSAIT,
    397      1.1      tron 		LDAP_CONTROL_NOOP,
    398      1.1      tron 		LDAP_CONTROL_PAGEDRESULTS,
    399      1.1      tron 		LDAP_CONTROL_PRE_READ,
    400      1.1      tron 		LDAP_CONTROL_POST_READ,
    401      1.1      tron 		LDAP_CONTROL_SUBENTRIES,
    402      1.1      tron 		LDAP_CONTROL_X_PERMISSIVE_MODIFY,
    403  1.1.1.6  christos 		LDAP_CONTROL_TXN_SPEC,
    404      1.1      tron 		NULL
    405      1.1      tron 	};
    406      1.1      tron 
    407      1.1      tron 	/* initialize the underlying database system */
    408      1.1      tron 	Debug( LDAP_DEBUG_TRACE,
    409      1.1      tron 		LDAP_XSTRING(mdb_back_initialize) ": initialize "
    410  1.1.1.6  christos 		MDB_UCTYPE " backend\n" );
    411      1.1      tron 
    412      1.1      tron 	bi->bi_flags |=
    413      1.1      tron 		SLAP_BFLAG_INCREMENT |
    414      1.1      tron 		SLAP_BFLAG_SUBENTRIES |
    415      1.1      tron 		SLAP_BFLAG_ALIASES |
    416  1.1.1.6  christos 		SLAP_BFLAG_REFERRALS |
    417  1.1.1.6  christos 		SLAP_BFLAG_TXNS;
    418      1.1      tron 
    419      1.1      tron 	bi->bi_controls = controls;
    420      1.1      tron 
    421      1.1      tron 	{	/* version check */
    422      1.1      tron 		int major, minor, patch, ver;
    423      1.1      tron 		char *version = mdb_version( &major, &minor, &patch );
    424      1.1      tron #ifdef HAVE_EBCDIC
    425      1.1      tron 		char v2[1024];
    426      1.1      tron 
    427      1.1      tron 		/* All our stdio does an ASCII to EBCDIC conversion on
    428      1.1      tron 		 * the output. Strings from the MDB library are already
    429      1.1      tron 		 * in EBCDIC; we have to go back and forth...
    430      1.1      tron 		 */
    431      1.1      tron 		strcpy( v2, version );
    432      1.1      tron 		__etoa( v2 );
    433      1.1      tron 		version = v2;
    434      1.1      tron #endif
    435      1.1      tron 		ver = (major << 24) | (minor << 16) | patch;
    436      1.1      tron 		if( ver != MDB_VERSION_FULL ) {
    437      1.1      tron 			/* fail if a versions don't match */
    438      1.1      tron 			Debug( LDAP_DEBUG_ANY,
    439      1.1      tron 				LDAP_XSTRING(mdb_back_initialize) ": "
    440      1.1      tron 				"MDB library version mismatch:"
    441      1.1      tron 				" expected " MDB_VERSION_STRING ","
    442  1.1.1.6  christos 				" got %s\n", version );
    443      1.1      tron 			return -1;
    444      1.1      tron 		}
    445      1.1      tron 
    446      1.1      tron 		Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_back_initialize)
    447  1.1.1.6  christos 			": %s\n", version );
    448      1.1      tron 	}
    449      1.1      tron 
    450      1.1      tron 	bi->bi_open = 0;
    451      1.1      tron 	bi->bi_close = 0;
    452      1.1      tron 	bi->bi_config = 0;
    453      1.1      tron 	bi->bi_destroy = 0;
    454      1.1      tron 
    455      1.1      tron 	bi->bi_db_init = mdb_db_init;
    456      1.1      tron 	bi->bi_db_config = config_generic_wrapper;
    457      1.1      tron 	bi->bi_db_open = mdb_db_open;
    458      1.1      tron 	bi->bi_db_close = mdb_db_close;
    459      1.1      tron 	bi->bi_db_destroy = mdb_db_destroy;
    460      1.1      tron 
    461      1.1      tron 	bi->bi_op_add = mdb_add;
    462      1.1      tron 	bi->bi_op_bind = mdb_bind;
    463      1.1      tron 	bi->bi_op_compare = mdb_compare;
    464      1.1      tron 	bi->bi_op_delete = mdb_delete;
    465      1.1      tron 	bi->bi_op_modify = mdb_modify;
    466      1.1      tron 	bi->bi_op_modrdn = mdb_modrdn;
    467      1.1      tron 	bi->bi_op_search = mdb_search;
    468      1.1      tron 
    469      1.1      tron 	bi->bi_op_unbind = 0;
    470  1.1.1.6  christos 	bi->bi_op_txn = mdb_txn;
    471      1.1      tron 
    472      1.1      tron 	bi->bi_extended = mdb_extended;
    473      1.1      tron 
    474      1.1      tron 	bi->bi_chk_referrals = 0;
    475      1.1      tron 	bi->bi_operational = mdb_operational;
    476      1.1      tron 
    477      1.1      tron 	bi->bi_has_subordinates = mdb_hasSubordinates;
    478      1.1      tron 	bi->bi_entry_release_rw = mdb_entry_release;
    479      1.1      tron 	bi->bi_entry_get_rw = mdb_entry_get;
    480      1.1      tron 
    481      1.1      tron 	/*
    482      1.1      tron 	 * hooks for slap tools
    483      1.1      tron 	 */
    484      1.1      tron 	bi->bi_tool_entry_open = mdb_tool_entry_open;
    485      1.1      tron 	bi->bi_tool_entry_close = mdb_tool_entry_close;
    486      1.1      tron 	bi->bi_tool_entry_first = backend_tool_entry_first;
    487      1.1      tron 	bi->bi_tool_entry_first_x = mdb_tool_entry_first_x;
    488      1.1      tron 	bi->bi_tool_entry_next = mdb_tool_entry_next;
    489      1.1      tron 	bi->bi_tool_entry_get = mdb_tool_entry_get;
    490      1.1      tron 	bi->bi_tool_entry_put = mdb_tool_entry_put;
    491      1.1      tron 	bi->bi_tool_entry_reindex = mdb_tool_entry_reindex;
    492      1.1      tron 	bi->bi_tool_sync = 0;
    493      1.1      tron 	bi->bi_tool_dn2id_get = mdb_tool_dn2id_get;
    494      1.1      tron 	bi->bi_tool_entry_modify = mdb_tool_entry_modify;
    495  1.1.1.6  christos 	bi->bi_tool_entry_delete = mdb_tool_entry_delete;
    496      1.1      tron 
    497      1.1      tron 	bi->bi_connection_init = 0;
    498      1.1      tron 	bi->bi_connection_destroy = 0;
    499      1.1      tron 
    500      1.1      tron 	rc = mdb_back_init_cf( bi );
    501      1.1      tron 
    502      1.1      tron 	return rc;
    503      1.1      tron }
    504      1.1      tron 
    505      1.1      tron #if	(SLAPD_MDB == SLAPD_MOD_DYNAMIC)
    506      1.1      tron 
    507      1.1      tron SLAP_BACKEND_INIT_MODULE( mdb )
    508      1.1      tron 
    509      1.1      tron #endif /* SLAPD_MDB == SLAPD_MOD_DYNAMIC */
    510      1.1      tron 
    511