]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/init.c
e399f676ab1bcab0f5a3166f8d58156d92e9266d
[openldap] / servers / slapd / back-ldbm / init.c
1 /* init.c - initialize ldbm backend */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17
18 #ifdef SLAPD_LDBM_DYNAMIC
19
20 int back_ldbm_LTX_init_module(int argc, char *argv[]) {
21     BackendInfo bi;
22
23     memset( &bi, 0, sizeof(bi) );
24     bi.bi_type = "ldbm";
25     bi.bi_init = ldbm_back_initialize;
26
27     backend_add(&bi);
28     return 0;
29 }
30
31 #endif /* SLAPD_LDBM_DYNAMIC */
32
33 int
34 ldbm_back_initialize(
35     BackendInfo *bi
36 )
37 {
38         bi->bi_open = ldbm_back_open;
39         bi->bi_config = 0;
40         bi->bi_close = ldbm_back_close;
41         bi->bi_destroy = ldbm_back_destroy;
42
43         bi->bi_db_init = ldbm_back_db_init;
44         bi->bi_db_config = ldbm_back_db_config;
45         bi->bi_db_open = ldbm_back_db_open;
46         bi->bi_db_close = ldbm_back_db_close;
47         bi->bi_db_destroy = ldbm_back_db_destroy;
48
49         bi->bi_op_bind = ldbm_back_bind;
50         bi->bi_op_unbind = ldbm_back_unbind;
51         bi->bi_op_search = ldbm_back_search;
52         bi->bi_op_compare = ldbm_back_compare;
53         bi->bi_op_modify = ldbm_back_modify;
54         bi->bi_op_modrdn = ldbm_back_modrdn;
55         bi->bi_op_add = ldbm_back_add;
56         bi->bi_op_delete = ldbm_back_delete;
57         bi->bi_op_abandon = ldbm_back_abandon;
58
59         bi->bi_entry_release_rw = ldbm_back_entry_release_rw;
60         bi->bi_acl_group = ldbm_back_group;
61
62         /*
63          * hooks for slap tools
64          */
65         bi->bi_tool_entry_open = ldbm_tool_entry_open;
66         bi->bi_tool_entry_close = ldbm_tool_entry_close;
67         bi->bi_tool_entry_first = ldbm_tool_entry_first;
68         bi->bi_tool_entry_next = ldbm_tool_entry_next;
69         bi->bi_tool_entry_get = ldbm_tool_entry_get;
70         bi->bi_tool_entry_put = ldbm_tool_entry_put;
71         bi->bi_tool_index_attr = ldbm_tool_index_attr;
72         bi->bi_tool_index_change = ldbm_tool_index_change;
73         bi->bi_tool_sync = ldbm_tool_sync;
74
75         bi->bi_connection_init = 0;
76         bi->bi_connection_destroy = 0;
77
78         return 0;
79 }
80
81 int
82 ldbm_back_destroy(
83     BackendInfo *bi
84 )
85 {
86         return 0;
87 }
88
89 int
90 ldbm_back_open(
91     BackendInfo *bi
92 )
93 {
94         int rc;
95
96         /* initialize the underlying database system */
97         rc = ldbm_initialize();
98
99         return rc;
100 }
101
102 int
103 ldbm_back_close(
104     BackendInfo *bi
105 )
106 {
107         /* terminate the underlying database system */
108         ldbm_shutdown();
109
110         return 0;
111 }
112
113 int
114 ldbm_back_db_init(
115     Backend     *be
116 )
117 {
118         struct ldbminfo *li;
119         char            *argv[ 4 ];
120
121         /* allocate backend-database-specific stuff */
122         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
123
124         /* arrange to read nextid later (on first request for it) */
125         li->li_nextid = NOID;
126
127         /* default cache size */
128         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
129
130         /* default database cache size */
131         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
132
133         /* default db mode is with locking */ 
134         li->li_dblocking = 1;
135
136         /* default db mode is with write synchronization */ 
137         li->li_dbwritesync = 1;
138
139         /* default file creation mode */
140         li->li_mode = DEFAULT_MODE;
141
142         /* default database directory */
143         li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY );
144
145         argv[ 0 ] = "objectclass";
146         argv[ 1 ] = "eq";
147         argv[ 2 ] = NULL;
148         attr_index_config( li, "ldbm objectclass initialization",
149                 0, 2, argv, 1 );
150
151         /* initialize various mutex locks & condition variables */
152         ldap_pvt_thread_mutex_init( &li->li_root_mutex );
153         ldap_pvt_thread_mutex_init( &li->li_add_mutex );
154         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
155         ldap_pvt_thread_mutex_init( &li->li_nextid_mutex );
156         ldap_pvt_thread_mutex_init( &li->li_dbcache_mutex );
157         ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
158
159         be->be_private = li;
160
161         return 0;
162 }
163
164 int
165 ldbm_back_db_open(
166     BackendDB   *be
167 )
168 {
169         return 0;
170 }
171
172 int
173 ldbm_back_db_destroy(
174     BackendDB   *be
175 )
176 {
177         /* should free/destroy every in be_private */
178         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
179         free( li->li_directory );
180         attr_index_destroy( li->li_attrs );
181
182         ldap_pvt_thread_mutex_destroy( &li->li_root_mutex );
183         ldap_pvt_thread_mutex_destroy( &li->li_add_mutex );
184         ldap_pvt_thread_mutex_destroy( &li->li_cache.c_mutex );
185         ldap_pvt_thread_mutex_destroy( &li->li_nextid_mutex );
186         ldap_pvt_thread_mutex_destroy( &li->li_dbcache_mutex );
187         ldap_pvt_thread_cond_destroy( &li->li_dbcache_cv );
188
189         free( be->be_private );
190         be->be_private = NULL;
191
192         return 0;
193 }