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_DBENV_MODE;
151 /* default database directories */
152 bdi->bdi_db_directory = ch_strdup( DEFAULT_DB_DIRECTORY );
154 be->be_private = bdi;
164 struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
167 /* we should check existance of dbenv_home and db_directory */
169 rc = db_env_create( &bdi->bdi_dbenv, 0 );
171 Debug( LDAP_DEBUG_ANY,
172 "bdb_back_db_open: db_env_create failed: %s (%d)\n",
173 db_strerror(rc), rc, 0 );
177 #ifdef SLAPD_BDB_PRIVATE
178 flags = DB_INIT_LOCK | DB_INIT_TXN |
179 DB_PRIVATE | DB_RECOVER | DB_THREAD;
181 flags = DB_INIT_LOCK | DB_INIT_TXN | DB_INIT_MPOOL |
182 DB_RECOVER | DB_THREAD;
185 rc = bdi->bdi_dbenv->open( bdi->bdi_dbenv,
187 flags | bdi->bdi_dbenv_xflags,
188 bdi->bdi_dbenv_mode );
191 Debug( LDAP_DEBUG_ANY,
192 "bdb_back_db_open: db_open failed: %s (%d)\n",
193 db_strerror(rc), rc, 0 );
206 struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
208 rc = bdi->bdi_dbenv->close( bdi->bdi_dbenv, 0 );
209 bdi->bdi_dbenv = NULL;
212 Debug( LDAP_DEBUG_ANY,
213 "bdb_back_db_open: db_open failed: %s (%d)\n",
214 db_strerror(rc), rc, 0 );