]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/init.c
matched values is "global"
[openldap] / servers / slapd / back-ldbm / init.c
1 /* init.c - initialize ldbm backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/string.h>
22 #include <ac/socket.h>
23
24 #include "slap.h"
25 #include "back-ldbm.h"
26
27 int
28 ldbm_back_initialize(
29     BackendInfo *bi
30 )
31 {
32         static char *controls[] = {
33                 LDAP_CONTROL_MANAGEDSAIT,
34 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
35                 LDAP_CONTROL_X_PERMISSIVE_MODIFY,
36 #endif
37                 NULL
38         };
39
40         bi->bi_controls = controls;
41
42         bi->bi_flags |= 
43                 SLAP_BFLAG_INCREMENT |
44 #ifdef LDBM_SUBENTRIES
45                 SLAP_BFLAG_SUBENTRIES |
46 #endif
47                 SLAP_BFLAG_ALIASES |
48                 SLAP_BFLAG_REFERRALS;
49
50         bi->bi_open = ldbm_back_open;
51         bi->bi_config = NULL;
52         bi->bi_close = ldbm_back_close;
53         bi->bi_destroy = ldbm_back_destroy;
54
55         bi->bi_db_init = ldbm_back_db_init;
56         bi->bi_db_config = ldbm_back_db_config;
57         bi->bi_db_open = ldbm_back_db_open;
58         bi->bi_db_close = ldbm_back_db_close;
59         bi->bi_db_destroy = ldbm_back_db_destroy;
60
61         bi->bi_op_bind = ldbm_back_bind;
62         bi->bi_op_unbind = 0;
63         bi->bi_op_search = ldbm_back_search;
64         bi->bi_op_compare = ldbm_back_compare;
65         bi->bi_op_modify = ldbm_back_modify;
66         bi->bi_op_modrdn = ldbm_back_modrdn;
67         bi->bi_op_add = ldbm_back_add;
68         bi->bi_op_delete = ldbm_back_delete;
69         bi->bi_op_abandon = 0;
70
71         bi->bi_extended = ldbm_back_extended;
72
73         bi->bi_entry_release_rw = ldbm_back_entry_release_rw;
74         bi->bi_entry_get_rw = ldbm_back_entry_get;
75         bi->bi_chk_referrals = ldbm_back_referrals;
76         bi->bi_operational = ldbm_back_operational;
77         bi->bi_has_subordinates = ldbm_back_hasSubordinates;
78
79         /*
80          * hooks for slap tools
81          */
82         bi->bi_tool_entry_open = ldbm_tool_entry_open;
83         bi->bi_tool_entry_close = ldbm_tool_entry_close;
84         bi->bi_tool_entry_first = ldbm_tool_entry_first;
85         bi->bi_tool_entry_next = ldbm_tool_entry_next;
86         bi->bi_tool_entry_get = ldbm_tool_entry_get;
87         bi->bi_tool_entry_put = ldbm_tool_entry_put;
88         bi->bi_tool_entry_reindex = ldbm_tool_entry_reindex;
89         bi->bi_tool_sync = ldbm_tool_sync;
90
91         bi->bi_tool_dn2id_get = 0;
92         bi->bi_tool_id2entry_get = 0;
93         bi->bi_tool_entry_modify = 0;
94
95         bi->bi_connection_init = 0;
96         bi->bi_connection_destroy = 0;
97
98         return 0;
99 }
100
101 int
102 ldbm_back_destroy(
103     BackendInfo *bi
104 )
105 {
106         return 0;
107 }
108
109 int
110 ldbm_back_open(
111     BackendInfo *bi
112 )
113 {
114         int rc;
115
116         /* initialize the underlying database system */
117         rc = ldbm_initialize( NULL );
118         return rc;
119 }
120
121 int
122 ldbm_back_close(
123     BackendInfo *bi
124 )
125 {
126         /* terminate the underlying database system */
127         ldbm_shutdown();
128         return 0;
129 }
130
131 int
132 ldbm_back_db_init(
133     Backend     *be
134 )
135 {
136         struct ldbminfo *li;
137
138         /* allocate backend-database-specific stuff */
139         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
140
141         /* arrange to read nextid later (on first request for it) */
142         li->li_nextid = NOID;
143
144         /* default cache size */
145         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
146
147         /* default database cache size */
148         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
149
150         /* default db mode is with locking */ 
151         li->li_dblocking = 1;
152
153         /* default db mode is with write synchronization */ 
154         li->li_dbwritesync = 1;
155
156         /* default file creation mode */
157         li->li_mode = SLAPD_DEFAULT_DB_MODE;
158
159         /* default database directory */
160         li->li_directory = ch_strdup( SLAPD_DEFAULT_DB_DIR );
161
162         /* DB_ENV environment pointer for DB3 */
163         li->li_dbenv = 0;
164
165         /* envdirok is turned on by ldbm_initialize_env if DB3 */
166         li->li_envdirok = 0;
167
168         /* syncfreq is 0 if disabled, or # seconds */
169         li->li_dbsyncfreq = 0;
170
171         /* wait up to dbsyncwaitn times if server is busy */
172         li->li_dbsyncwaitn = 12;
173
174         /* delay interval */
175         li->li_dbsyncwaitinterval = 5;
176
177         /* flag to notify ldbm_cache_sync_daemon to shut down */
178         li->li_dbshutdown = 0;
179
180         /* initialize various mutex locks & condition variables */
181         ldap_pvt_thread_rdwr_init( &li->li_giant_rwlock );
182         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
183         ldap_pvt_thread_mutex_init( &li->li_dbcache_mutex );
184         ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
185
186         be->be_private = li;
187
188         return 0;
189 }
190
191 int
192 ldbm_back_db_open(
193     BackendDB   *be
194 )
195 {
196         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
197         li->li_dbenv = ldbm_initialize_env( li->li_directory,
198                 li->li_dbcachesize, &li->li_envdirok );
199
200         /* sync thread */
201         if ( li->li_dbsyncfreq > 0 )
202         {
203                 int rc;
204                 rc = ldap_pvt_thread_create( &li->li_dbsynctid,
205                         0, ldbm_cache_sync_daemon, (void*)be );
206
207                 if ( rc != 0 )
208                 {
209                         Debug(  LDAP_DEBUG_ANY,
210                                 "sync ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
211                         return 1;
212                 }
213         }
214
215         return 0;
216 }
217
218 int
219 ldbm_back_db_destroy(
220     BackendDB   *be
221 )
222 {
223         /* should free/destroy every in be_private */
224         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
225
226         if (li->li_dbenv)
227             ldbm_shutdown_env(li->li_dbenv);
228
229         free( li->li_directory );
230         attr_index_destroy( li->li_attrs );
231
232         ldap_pvt_thread_rdwr_destroy( &li->li_giant_rwlock );
233         ldap_pvt_thread_mutex_destroy( &li->li_cache.c_mutex );
234         ldap_pvt_thread_mutex_destroy( &li->li_dbcache_mutex );
235         ldap_pvt_thread_cond_destroy( &li->li_dbcache_cv );
236
237         free( be->be_private );
238         be->be_private = NULL;
239
240         return 0;
241 }
242
243 #if SLAPD_LDBM == SLAPD_MOD_DYNAMIC
244
245 /* conditionally define the init_module() function */
246 SLAP_BACKEND_INIT_MODULE( ldbm )
247
248 #endif /* SLAPD_LDBM == SLAPD_MOD_DYNAMIC */
249
250