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