]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/init.c
3941f4f93964012c4c3d2c66b2880f45dbced798
[openldap] / servers / slapd / back-bdb / init.c
1 /* init.c - initialize bdb backend */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "back-bdb.h"
17
18 #ifdef SLAPD_BDB_DYNAMIC
19
20 int back_bdb_LTX_init_module(int argc, char *argv[]) {
21     BackendInfo bi;
22
23     memset( &bi, '\0', sizeof(bi) );
24     bi.bi_type = "bdb";
25     bi.bi_init = bdb_back_initialize;
26
27     backend_add(&bi);
28     return 0;
29 }
30
31 #endif /* SLAPD_BDB_DYNAMIC */
32
33 int
34 bdb_back_initialize(
35     BackendInfo *bi
36 )
37 {
38         static char *controls[] = {
39                 LDAP_CONTROL_MANAGEDSAIT,
40                 NULL
41         };
42
43         {       /* version check */
44                 int major, minor, patch;
45                 char *version = db_version( &major, &minor, &patch );
46
47                 if( major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR ||
48                         patch < DB_VERSION_PATCH )
49                 {
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 );
54                 }
55
56                 Debug( LDAP_DEBUG_ANY, "bdb_back_initialize: %s\n",
57                         version, 0, 0 );
58         }
59
60 #if 0
61         bi->bi_controls = controls;
62
63         bi->bi_open = bdb_back_open;
64         bi->bi_config = 0;
65         bi->bi_close = bdb_back_close;
66         bi->bi_destroy = bdb_back_destroy;
67
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;
73
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;
83
84         bi->bi_extended = bdb_back_extended;
85
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;
90
91         /*
92          * hooks for slap tools
93          */
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;
102
103         bi->bi_connection_init = 0;
104         bi->bi_connection_destroy = 0;
105 #endif
106
107         return 0;
108 }
109
110 int
111 bdb_back_destroy(
112     BackendInfo *bi
113 )
114 {
115         return 0;
116 }
117
118 int
119 bdb_back_open(
120     BackendInfo *bi
121 )
122 {
123         /* initialize the underlying database system */
124         return 0;
125 }
126
127 int
128 bdb_back_close(
129     BackendInfo *bi
130 )
131 {
132         /* terminate the underlying database system */
133         return 0;
134 }
135
136 int
137 bdb_back_db_init(
138     Backend     *be
139 )
140 {
141         struct bdb_dbinfo       *bdi;
142
143         /* allocate backend-database-specific stuff */
144         bdi = (struct bdb_dbinfo *) ch_calloc( 1, sizeof(struct bdb_dbinfo) );
145
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;
150
151         /* default database directories */
152         bdi->bdi_db_directory = ch_strdup( DEFAULT_DB_DIRECTORY );
153
154         be->be_private = bdi;
155         return 0;
156 }
157
158 int
159 bdb_back_db_open(
160     BackendDB   *be
161 )
162 {
163         int rc;
164         struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
165         u_int32_t flags;
166
167         /* we should check existance of dbenv_home and db_directory */
168
169         rc = db_env_create( &bdi->bdi_dbenv, 0 );
170         if( rc != 0 ) {
171                 Debug( LDAP_DEBUG_ANY,
172                         "bdb_back_db_open: db_env_create failed: %s (%d)\n",
173                         db_strerror(rc), rc, 0 );
174                 return rc;
175         }
176
177         flags = DB_INIT_LOCK | DB_INIT_TXN |
178                 DB_PRIVATE | DB_RECOVER | DB_THREAD;
179
180         rc = bdi->bdi_dbenv->open( bdi->bdi_dbenv,
181                 bdi->bdi_dbenv_home,
182                 flags | bdi->bdi_dbenv_xflags,
183                 bdi->bdi_dbenv_mode );
184
185         if( rc != 0 ) {
186                 Debug( LDAP_DEBUG_ANY,
187                         "bdb_back_db_open: db_open failed: %s (%d)\n",
188                         db_strerror(rc), rc, 0 );
189                 return rc;
190         }
191
192         return 0;
193 }
194
195 int
196 bdb_back_db_destroy(
197     BackendDB   *be
198 )
199 {
200         int rc;
201         struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
202
203         rc = bdi->bdi_dbenv->close( bdi->bdi_dbenv, 0 );
204         bdi->bdi_dbenv = NULL;
205
206         if( rc != 0 ) {
207                 Debug( LDAP_DEBUG_ANY,
208                         "bdb_back_db_open: db_open failed: %s (%d)\n",
209                         db_strerror(rc), rc, 0 );
210                 return rc;
211         }
212
213         return 0;
214 }