1 /* init.c - initialize bdb backend */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
18 bi_back_destroy( BackendInfo *bi )
24 bi_back_open( BackendInfo *bi )
26 /* initialize the underlying database system */
31 bi_back_close( BackendInfo *bi )
33 /* terminate the underlying database system */
38 bi_back_db_init( Backend *be )
42 /* allocate backend-database-specific stuff */
43 bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
45 /* DBEnv parameters */
46 bdb->bi_dbenv_home = ch_strdup( DEFAULT_DBENV_HOME );
47 bdb->bi_dbenv_xflags = 0;
48 bdb->bi_dbenv_mode = DEFAULT_MODE;
50 /* default database directories */
51 bdb->bi_db_tmp_dir = ch_strdup( DEFAULT_DB_TMP_DIR );
52 bdb->bi_db_lg_dir = ch_strdup( DEFAULT_DB_LG_DIR );
53 bdb->bi_db_data_dir = ch_strdup( DEFAULT_DB_DATA_DIR );
55 bdb->bi_lastid = NOID;
62 bi_back_db_open( BackendDB *be )
65 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
68 /* we should check existance of dbenv_home and db_directory */
70 rc = db_env_create( &bdb->bi_dbenv, 0 );
72 Debug( LDAP_DEBUG_ANY,
73 "bi_back_db_open: db_env_create failed: %s (%d)\n",
74 db_strerror(rc), rc, 0 );
78 flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN |
79 DB_CREATE | DB_RECOVER | DB_THREAD;
81 #ifdef SLAPD_BDB_PRIVATE
84 flags |= DB_INIT_MPOOL;
87 bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0] );
88 bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
90 if( bdb->bi_tx_max ) {
91 rc = bdb->bi_dbenv->set_tx_max( bdb->bi_dbenv,
94 Debug( LDAP_DEBUG_ANY,
95 "bi_back_db_open: set_tx_max(%d) failed: %s (%d)\n",
96 bdb->bi_tx_max, db_strerror(rc), rc );
101 rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv,
102 bdb->bi_db_tmp_dir );
104 Debug( LDAP_DEBUG_ANY,
105 "bi_back_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
106 bdb->bi_db_tmp_dir, db_strerror(rc), rc );
110 rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv,
113 Debug( LDAP_DEBUG_ANY,
114 "bi_back_db_open: set_lg_dir(%s) failed: %s (%d)\n",
115 bdb->bi_db_lg_dir, db_strerror(rc), rc );
119 rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv,
120 bdb->bi_db_data_dir );
122 Debug( LDAP_DEBUG_ANY,
123 "bi_back_db_open: set_data_dir(%s) failed: %s (%d)\n",
124 bdb->bi_db_data_dir, db_strerror(rc), rc );
128 rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
130 flags | bdb->bi_dbenv_xflags,
131 bdb->bi_dbenv_mode );
133 Debug( LDAP_DEBUG_ANY,
134 "bi_back_db_open: db_open(%s) failed: %s (%d)\n",
135 bdb->bi_dbenv_home, db_strerror(rc), rc );
143 bi_back_db_destroy( BackendDB *be )
146 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
148 /* force a checkpoint */
149 rc = txn_checkpoint( bdb->bi_dbenv, 0, 0, DB_FORCE );
151 Debug( LDAP_DEBUG_ANY,
152 "bi_back_db_destroy: txn_checkpoint failed: %s (%d)\n",
153 db_strerror(rc), rc, 0 );
157 /* close db environment */
158 rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
159 bdb->bi_dbenv = NULL;
161 Debug( LDAP_DEBUG_ANY,
162 "bi_back_db_destroy: close failed: %s (%d)\n",
163 db_strerror(rc), rc, 0 );
170 #ifdef SLAPD_BDB_DYNAMIC
171 int back_bdb_LTX_init_module( int argc, char *argv[] ) {
174 memset( &bi, '\0', sizeof(bi) );
176 bi.bi_init = bi_back_initialize;
181 #endif /* SLAPD_BDB_DYNAMIC */
188 static char *controls[] = {
189 LDAP_CONTROL_MANAGEDSAIT,
193 { /* version check */
194 int major, minor, patch;
195 char *version = db_version( &major, &minor, &patch );
197 if( major != DB_VERSION_MAJOR ||
198 minor != DB_VERSION_MINOR ||
199 patch < DB_VERSION_PATCH )
201 Debug( LDAP_DEBUG_ANY,
202 "bi_back_initialize: version mismatch\n"
203 "\texpected: " DB_VERSION_STRING "\n"
204 "\tgot: %s \n", version, 0, 0 );
207 Debug( LDAP_DEBUG_ANY, "bi_back_initialize: %s\n",
211 bi->bi_controls = controls;
213 bi->bi_open = bi_back_open;
214 bi->bi_close = bi_back_close;
216 bi->bi_destroy = bi_back_destroy;
219 bi->bi_db_init = bi_back_db_init;
220 bi->bi_db_config = bi_back_db_config;
221 bi->bi_db_open = bi_back_db_open;
222 bi->bi_db_close = bi_back_db_close;
223 bi->bi_db_destroy = bi_back_db_destroy;
225 bi->bi_op_bind = bi_back_bind;
226 bi->bi_op_unbind = bi_back_unbind;
227 bi->bi_op_search = bi_back_search;
228 bi->bi_op_compare = bi_back_compare;
229 bi->bi_op_modify = bi_back_modify;
230 bi->bi_op_modrdn = bi_back_modrdn;
231 bi->bi_op_add = bi_back_add;
232 bi->bi_op_delete = bi_back_delete;
233 bi->bi_op_abandon = bi_back_abandon;
235 bi->bi_extended = bi_back_extended;
237 bi->bi_entry_release_rw = bi_back_entry_release_rw;
238 bi->bi_acl_group = bi_back_group;
239 bi->bi_acl_attribute = bi_back_attribute;
240 bi->bi_chk_referrals = bi_back_referrals;
243 * hooks for slap tools
245 bi->bi_tool_entry_open = bi_tool_entry_open;
246 bi->bi_tool_entry_close = bi_tool_entry_close;
247 bi->bi_tool_entry_first = bi_tool_entry_first;
248 bi->bi_tool_entry_next = bi_tool_entry_next;
249 bi->bi_tool_entry_get = bi_tool_entry_get;
250 bi->bi_tool_entry_put = bi_tool_entry_put;
251 bi->bi_tool_entry_reindex = bi_tool_entry_reindex;
252 bi->bi_tool_sync = bi_tool_sync;
254 bi->bi_connection_init = 0;
255 bi->bi_connection_destroy = 0;