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 #ifdef SLAPD_BDB_DYNAMIC
20 int back_bdb_LTX_init_module(int argc, char *argv[]) {
23 memset( &bi, '\0', sizeof(bi) );
25 bi.bi_init = bdb_back_initialize;
31 #endif /* SLAPD_BDB_DYNAMIC */
38 static char *controls[] = {
39 LDAP_CONTROL_MANAGEDSAIT,
44 int major, minor, patch;
45 char *version = db_version( &major, &minor, &patch );
47 if( major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR ||
48 patch < DB_VERSION_PATCH )
50 Debug( LDAP_DEBUG_ANY,
51 "bdb_back_initialize: version mismatch\n"
52 "\texpected: " DB_VERSION_STRING "\n"
53 "\tgot: %s \n", version, 0, 0 );
56 Debug( LDAP_DEBUG_ANY, "bdb_back_initialize: %s\n",
61 bi->bi_controls = controls;
63 bi->bi_open = bdb_back_open;
65 bi->bi_close = bdb_back_close;
66 bi->bi_destroy = bdb_back_destroy;
68 bi->bi_db_init = bdb_back_db_init;
69 bi->bi_db_config = bdb_back_db_config;
70 bi->bi_db_open = bdb_back_db_open;
71 bi->bi_db_close = bdb_back_db_close;
72 bi->bi_db_destroy = bdb_back_db_destroy;
74 bi->bi_op_bind = bdb_back_bind;
75 bi->bi_op_unbind = bdb_back_unbind;
76 bi->bi_op_search = bdb_back_search;
77 bi->bi_op_compare = bdb_back_compare;
78 bi->bi_op_modify = bdb_back_modify;
79 bi->bi_op_modrdn = bdb_back_modrdn;
80 bi->bi_op_add = bdb_back_add;
81 bi->bi_op_delete = bdb_back_delete;
82 bi->bi_op_abandon = bdb_back_abandon;
84 bi->bi_extended = bdb_back_extended;
86 bi->bi_entry_release_rw = bdb_back_entry_release_rw;
87 bi->bi_acl_group = bdb_back_group;
88 bi->bi_acl_attribute = bdb_back_attribute;
89 bi->bi_chk_referrals = bdb_back_referrals;
92 * hooks for slap tools
94 bi->bi_tool_entry_open = bdb_tool_entry_open;
95 bi->bi_tool_entry_close = bdb_tool_entry_close;
96 bi->bi_tool_entry_first = bdb_tool_entry_first;
97 bi->bi_tool_entry_next = bdb_tool_entry_next;
98 bi->bi_tool_entry_get = bdb_tool_entry_get;
99 bi->bi_tool_entry_put = bdb_tool_entry_put;
100 bi->bi_tool_entry_reindex = bdb_tool_entry_reindex;
101 bi->bi_tool_sync = bdb_tool_sync;
103 bi->bi_connection_init = 0;
104 bi->bi_connection_destroy = 0;
123 /* initialize the underlying database system */
132 /* terminate the underlying database system */
141 struct bdb_dbinfo *bdi;
143 /* allocate backend-database-specific stuff */
144 bdi = (struct bdb_dbinfo *) ch_calloc( 1, sizeof(struct bdb_dbinfo) );
146 /* DBEnv parameters */
147 bdi->bdi_dbenv_home = ch_strdup( DEFAULT_DBENV_HOME );
148 bdi->bdi_dbenv_xflags = 0;
149 bdi->bdi_dbenv_mode = DEFAULT_MODE;
151 /* default database directories */
152 bdi->bdi_db_tmp_dir = ch_strdup( DEFAULT_DB_TMP_DIR );
153 bdi->bdi_db_lg_dir = ch_strdup( DEFAULT_DB_LG_DIR );
154 bdi->bdi_db_data_dir = ch_strdup( DEFAULT_DB_DATA_DIR );
156 be->be_private = bdi;
166 struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
169 /* we should check existance of dbenv_home and db_directory */
171 rc = db_env_create( &bdi->bdi_dbenv, 0 );
173 Debug( LDAP_DEBUG_ANY,
174 "bdb_back_db_open: db_env_create failed: %s (%d)\n",
175 db_strerror(rc), rc, 0 );
179 flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN |
180 DB_CREATE | DB_RECOVER | DB_THREAD;
182 #ifdef SLAPD_BDB_PRIVATE
185 flags |= DB_INIT_MPOOL;
188 rc = bdi->bdi_dbenv->set_tmp_dir( bdi->bdi_dbenv,
189 bdi->bdi_db_tmp_dir );
192 Debug( LDAP_DEBUG_ANY,
193 "bdb_back_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
194 bdi->bdi_db_tmp_dir, db_strerror(rc), rc );
198 rc = bdi->bdi_dbenv->set_lg_dir( bdi->bdi_dbenv,
199 bdi->bdi_db_lg_dir );
202 Debug( LDAP_DEBUG_ANY,
203 "bdb_back_db_open: set_lg_dir(%s) failed: %s (%d)\n",
204 bdi->bdi_db_lg_dir, db_strerror(rc), rc );
208 rc = bdi->bdi_dbenv->set_data_dir( bdi->bdi_dbenv,
209 bdi->bdi_db_data_dir );
212 Debug( LDAP_DEBUG_ANY,
213 "bdb_back_db_open: set_data_dir(%s) failed: %s (%d)\n",
214 bdi->bdi_db_data_dir, db_strerror(rc), rc );
218 rc = bdi->bdi_dbenv->open( bdi->bdi_dbenv,
220 flags | bdi->bdi_dbenv_xflags,
221 bdi->bdi_dbenv_mode );
224 Debug( LDAP_DEBUG_ANY,
225 "bdb_back_db_open: db_open(%s) failed: %s (%d)\n",
226 bdi->bdi_dbenv_home, db_strerror(rc), rc );
239 struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
241 rc = bdi->bdi_dbenv->close( bdi->bdi_dbenv, 0 );
242 bdi->bdi_dbenv = NULL;
245 Debug( LDAP_DEBUG_ANY,
246 "bdb_back_db_open: db_open failed: %s (%d)\n",
247 db_strerror(rc), rc, 0 );