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