]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/init.c
Use #ifdef, not #if
[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         static char *controls[] = {
59                 LDAP_CONTROL_MANAGEDSAIT,
60         /*      LDAP_CONTROL_X_CHANGE_PASSWD, */
61                 NULL
62         };
63
64         bi->bi_controls = controls;
65
66         bi->bi_open = bdb2_back_open;
67         bi->bi_config = bdb2_back_config;
68         bi->bi_close = bdb2_back_close;
69         bi->bi_destroy = bdb2_back_destroy;
70
71         bi->bi_db_init = bdb2_back_db_init;
72         bi->bi_db_config = bdb2_back_db_config;
73         bi->bi_db_open = bdb2_back_db_open;
74         bi->bi_db_close = bdb2_back_db_close;
75         bi->bi_db_destroy = bdb2_back_db_destroy;
76
77         bi->bi_op_bind = bdb2_back_bind;
78         bi->bi_op_unbind = bdb2_back_unbind;
79         bi->bi_op_search = bdb2_back_search;
80         bi->bi_op_compare = bdb2_back_compare;
81         bi->bi_op_modify = bdb2_back_modify;
82         bi->bi_op_modrdn = bdb2_back_modrdn;
83         bi->bi_op_add = bdb2_back_add;
84         bi->bi_op_delete = bdb2_back_delete;
85         bi->bi_op_abandon = bdb2_back_abandon;
86
87         bi->bi_extended = 0;
88
89         bi->bi_entry_release_rw = bdb2_back_entry_release_rw;
90         bi->bi_acl_group = bdb2_back_group;
91
92         /*
93          * hooks for slap tools
94          */
95         bi->bi_tool_entry_open = bdb2_tool_entry_open;
96         bi->bi_tool_entry_close = bdb2_tool_entry_close;
97         bi->bi_tool_entry_first = bdb2_tool_entry_first;
98         bi->bi_tool_entry_next = bdb2_tool_entry_next;
99         bi->bi_tool_entry_get = bdb2_tool_entry_get;
100         bi->bi_tool_entry_put = bdb2_tool_entry_put;
101         bi->bi_tool_index_attr = bdb2_tool_index_attr;
102         bi->bi_tool_index_change = bdb2_tool_index_change;
103         bi->bi_tool_sync = bdb2_tool_sync;
104
105 #ifdef HAVE_CYRUS_SASL
106         bi->bi_sasl_authorize = 0; 
107         bi->bi_sasl_getsecret = 0;
108         bi->bi_sasl_putsecret = 0;
109 #endif /* HAVE_CYRUS_SASL */
110
111         bi->bi_connection_init = 0;
112         bi->bi_connection_destroy = 0;
113
114         ret = bdb2i_back_init_private( bi );
115
116         Debug( LDAP_DEBUG_TRACE, "bdb2_back_initialize: done (%d).\n", ret, 0, 0 );
117
118         return( ret );
119 }
120
121 int
122 bdb2_back_destroy(
123     BackendInfo *bi
124 )
125 {
126         return 0;
127 }
128
129 int
130 bdb2_back_open(
131     BackendInfo *bi
132 )
133 {
134         static int initialized = 0;
135         int rc;
136
137         if ( initialized++ ) {
138
139                 Debug( LDAP_DEBUG_TRACE,
140                                 "bdb2_back_open: backend already initialized.\n", 0, 0, 0 );
141                 return 0;
142
143         }
144
145         /* initialize the underlying database system */
146         rc = bdb2i_back_startup( bi );
147
148         return rc;
149 }
150
151 int
152 bdb2_back_close(
153     BackendInfo *bi
154 )
155 {
156         int  rc;
157
158         /* close the underlying database system */
159         rc = bdb2i_back_shutdown( bi );
160
161         return rc;
162 }
163
164 /*  BDB2 changed  */
165 static int
166 bdb2i_back_db_init_internal(
167     BackendDB   *be
168 )
169 {
170         struct ldbminfo *li;
171         char            *argv[ 4 ];
172
173         /* allocate backend-database-specific stuff */
174         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
175
176         /* arrange to read nextid later (on first request for it) */
177         li->li_nextid = NOID;
178 #if     SLAPD_NEXTID_CHUNK > 1
179         li->li_nextid_wrote = NOID;
180 #endif
181
182         /* default cache size */
183         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
184
185         /* default database cache size */
186         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
187
188         /* default file creation mode */
189         li->li_mode = DEFAULT_MODE;
190
191         /* default database directory */
192         li->li_directory = DEFAULT_DB_DIRECTORY;
193
194         argv[ 0 ] = "objectclass";
195         argv[ 1 ] = "eq";
196         argv[ 2 ] = NULL;
197         bdb2i_attr_index_config( li, "ldbm objectclass initialization",
198                 0, 2, argv, 1 );
199
200         /*  initialize the cache mutex */
201         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
202
203         /*  initialize the TP file head  */
204         if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )
205                 return 1;
206
207         be->be_private = li;
208
209         return 0;
210 }
211
212
213 int
214 bdb2_back_db_init(
215     BackendDB   *be
216 )
217 {
218         struct timeval  time1;
219         int             ret;
220
221         bdb2i_start_timing( be->bd_info, &time1 );
222
223         ret = bdb2i_back_db_init_internal( be );
224         bdb2i_stop_timing( be->bd_info, time1, "DB-INIT", NULL, NULL );
225
226         return( ret );
227 }
228
229
230 int
231 bdb2_back_db_open(
232     BackendDB   *be
233 )
234 {
235         int  rc;
236
237         rc = bdb2_back_db_startup( be );
238
239         return( rc );
240 }
241
242 int
243 bdb2_back_db_destroy(
244     BackendDB   *be
245 )
246 {
247         /* should free/destroy every in be_private */
248         free( be->be_private );
249         be->be_private = NULL;
250         return 0;
251 }
252
253