]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/init.c
Merged dynamic module support patch (see ITS #196). To enable, run ./configure w
[openldap] / servers / slapd / back-bdb2 / init.c
1 /* init.c - initialize bdb2 backend */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12
13 #ifdef SLAPD_BDB2_DYNAMIC
14 #include <gmodule.h>
15
16 G_MODULE_EXPORT void init_module(int argc, char *argv[]) {
17    BackendInfo bi;
18
19    bi.bi_type = "bdb2";
20    bi.bi_init = bdb2_back_initialize;
21
22    backend_add(&bi);
23 }
24
25 #endif /* SLAPD_BDB2_DYNAMIC */
26
27 static int
28 bdb2i_back_init_private(
29     BackendInfo *bi
30 )
31 {
32         struct ldbtype  *bt;
33
34         /*  allocate backend-type-specific stuff */
35         bt = (struct ldbtype *) ch_calloc( 1, sizeof(struct ldbtype) );
36
37         bt->lty_dbhome = DEFAULT_DB_HOME;
38         bt->lty_mpsize = DEFAULT_DBCACHE_SIZE;
39
40         if ( slapMode == SLAP_TIMEDSERVER_MODE )
41                 bt->lty_betiming = 1;
42
43         bi->bi_private = bt;
44
45         return 0;
46 }
47
48
49 int
50 bdb2_back_initialize(
51     BackendInfo *bi
52 )
53 {
54         int  ret;
55
56         bi->bi_open = bdb2_back_open;
57         bi->bi_config = bdb2_back_config;
58         bi->bi_close = bdb2_back_close;
59         bi->bi_destroy = bdb2_back_destroy;
60
61         bi->bi_db_init = bdb2_back_db_init;
62         bi->bi_db_config = bdb2_back_db_config;
63         bi->bi_db_open = bdb2_back_db_open;
64         bi->bi_db_close = bdb2_back_db_close;
65         bi->bi_db_destroy = bdb2_back_db_destroy;
66
67         bi->bi_op_bind = bdb2_back_bind;
68         bi->bi_op_unbind = bdb2_back_unbind;
69         bi->bi_op_search = bdb2_back_search;
70         bi->bi_op_compare = bdb2_back_compare;
71         bi->bi_op_modify = bdb2_back_modify;
72         bi->bi_op_modrdn = bdb2_back_modrdn;
73         bi->bi_op_add = bdb2_back_add;
74         bi->bi_op_delete = bdb2_back_delete;
75         bi->bi_op_abandon = bdb2_back_abandon;
76
77         bi->bi_entry_release_rw = bdb2_back_entry_release_rw;
78 #ifdef SLAPD_ACLGROUPS
79         bi->bi_acl_group = bdb2_back_group;
80 #endif
81
82         bi->bi_connection_init = 0;
83         bi->bi_connection_destroy = 0;
84
85         ret = bdb2i_back_init_private( bi );
86
87         Debug( LDAP_DEBUG_TRACE, "bdb2_back_initialize: done (%d).\n", ret, 0, 0 );
88
89         return( ret );
90 }
91
92 int
93 bdb2_back_destroy(
94     BackendInfo *bi
95 )
96 {
97         return 0;
98 }
99
100 int
101 bdb2_back_open(
102     BackendInfo *bi
103 )
104 {
105         static int initialized = 0;
106         int rc;
107
108         if ( initialized++ ) {
109
110                 Debug( LDAP_DEBUG_TRACE,
111                                 "bdb2_back_open: backend already initialized.\n", 0, 0, 0 );
112                 return 0;
113
114         }
115
116         /* initialize the underlying database system */
117         rc = bdb2i_back_startup( bi );
118
119         return rc;
120 }
121
122 int
123 bdb2_back_close(
124     BackendInfo *bi
125 )
126 {
127         int  rc;
128
129         /* close the underlying database system */
130         rc = bdb2i_back_shutdown( bi );
131
132         return rc;
133 }
134
135 /*  BDB2 changed  */
136 static int
137 bdb2i_back_db_init_internal(
138     BackendDB   *be
139 )
140 {
141         struct ldbminfo *li;
142         char            *argv[ 4 ];
143
144         /* allocate backend-database-specific stuff */
145         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
146
147         /* arrange to read nextid later (on first request for it) */
148         li->li_nextid = NOID;
149 #if     SLAPD_NEXTID_CHUNK > 1
150         li->li_nextid_wrote = NOID;
151 #endif
152
153         /* default cache size */
154         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
155
156         /* default database cache size */
157         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
158
159         /* default cache mode is sync on write */
160         li->li_dbcachewsync = 1;
161
162         /* default file creation mode */
163         li->li_mode = DEFAULT_MODE;
164
165         /* default database directory */
166         li->li_directory = DEFAULT_DB_DIRECTORY;
167
168         /* always index dn, id2children, objectclass (used in some searches) */
169         if ( !at_find( "dn" ) ) {
170                 argv[ 0 ] = "dn";
171                 argv[ 1 ] = "dn";
172                 argv[ 2 ] = NULL;
173                 attr_syntax_config( "ldbm dn initialization", 0, 2, argv );
174         }
175         argv[ 0 ] = "dn";
176         argv[ 1 ] = "sub";
177         argv[ 2 ] = "eq";
178         argv[ 3 ] = NULL;
179         bdb2i_attr_index_config( li, "ldbm dn initialization", 0, 3, argv, 1 );
180         argv[ 0 ] = "id2children";
181         argv[ 1 ] = "eq";
182         argv[ 2 ] = NULL;
183         bdb2i_attr_index_config( li, "ldbm id2children initialization", 0, 2, argv,
184             1 );
185         argv[ 0 ] = "objectclass";
186         argv[ 1 ] = ch_strdup( "pres,eq" );
187         argv[ 2 ] = NULL;
188         bdb2i_attr_index_config( li, "ldbm objectclass initialization", 0, 2, argv,
189             1 );
190         free( argv[ 1 ] );
191
192         /*  initialize the cache mutex */
193         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
194
195         /*  initialize the TP file head  */
196         if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )
197                 return 1;
198
199         be->be_private = li;
200
201         return 0;
202 }
203
204
205 int
206 bdb2_back_db_init(
207     BackendDB   *be
208 )
209 {
210         struct timeval  time1;
211         int             ret;
212
213         bdb2i_start_timing( be->bd_info, &time1 );
214
215         ret = bdb2i_back_db_init_internal( be );
216         bdb2i_stop_timing( be->bd_info, time1, "DB-INIT", NULL, NULL );
217
218         return( ret );
219 }
220
221
222 int
223 bdb2_back_db_open(
224     BackendDB   *be
225 )
226 {
227         int  rc;
228
229         rc = bdb2_back_db_startup( be );
230
231         return( rc );
232 }
233
234 int
235 bdb2_back_db_destroy(
236     BackendDB   *be
237 )
238 {
239         /* should free/destroy every in be_private */
240         free( be->be_private );
241         be->be_private = NULL;
242         return 0;
243 }
244
245