2 * Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
4 * Redistribution and use in source and binary forms are permitted only
5 * as authorized by the OpenLDAP Public License. A copy of this
6 * license is available at http://www.OpenLDAP.org/license.html or
7 * in file LICENSE in the top-level directory of the distribution.
15 #include <sys/types.h>
20 #include "schema-map.h"
23 #ifdef SLAPD_SQL_DYNAMIC
26 backsql_LTX_init_module(
32 memset( &bi, '\0', sizeof( bi ) );
34 bi.bi_init = backbacksql_initialize;
40 #endif /* SLAPD_SHELL_DYNAMIC */
46 Debug( LDAP_DEBUG_TRACE,"==>backsql_initialize()\n", 0, 0, 0 );
53 bi->bi_db_init = backsql_db_init;
54 bi->bi_db_config = backsql_db_config;
55 bi->bi_db_open = backsql_db_open;
56 bi->bi_db_close = backsql_db_close;
57 bi->bi_db_destroy = backsql_db_destroy;
59 #ifdef BACKSQL_ALL_DONE
60 bi->bi_op_abandon = backsql_abandon;
61 bi->bi_op_compare = backsql_compare;
63 bi->bi_op_abandon = 0;
64 bi->bi_op_compare = 0;
66 bi->bi_op_bind = backsql_bind;
67 bi->bi_op_unbind = backsql_unbind;
68 bi->bi_op_search = backsql_search;
69 bi->bi_op_modify = backsql_modify;
70 bi->bi_op_modrdn = backsql_modrdn;
71 bi->bi_op_add = backsql_add;
72 bi->bi_op_delete = backsql_delete;
75 bi->bi_acl_attribute = 0;
76 bi->bi_chk_referrals = 0;
78 bi->bi_connection_init = 0;
79 bi->bi_connection_destroy = backsql_connection_destroy;
81 Debug( LDAP_DEBUG_TRACE,"<==backsql_initialize()\n", 0, 0, 0 );
90 Debug( LDAP_DEBUG_TRACE, "==>backsql_destroy()\n", 0, 0, 0 );
91 Debug( LDAP_DEBUG_TRACE, "<==backsql_destroy()\n", 0, 0, 0 );
101 Debug( LDAP_DEBUG_TRACE, "==>backsql_db_init()\n", 0, 0, 0 );
102 si = (backsql_info *)ch_calloc( 1, sizeof( backsql_info ) );
103 ldap_pvt_thread_mutex_init( &si->dbconn_mutex );
104 ldap_pvt_thread_mutex_init( &si->schema_mutex );
105 backsql_init_db_env( si );
106 si->has_ldapinfo_dn_ru = -1;
109 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_init()\n", 0, 0, 0 );
117 backsql_info *si = (backsql_info*)bd->be_private;
119 Debug( LDAP_DEBUG_TRACE, "==>backsql_db_destroy()\n", 0, 0, 0 );
120 ldap_pvt_thread_mutex_lock( &si->dbconn_mutex );
121 backsql_free_db_env( si );
122 ldap_pvt_thread_mutex_unlock( &si->dbconn_mutex );
123 ldap_pvt_thread_mutex_lock( &si->schema_mutex );
124 backsql_destroy_schema_map( si );
125 ldap_pvt_thread_mutex_unlock( &si->schema_mutex );
126 ldap_pvt_thread_mutex_destroy( &si->schema_mutex );
127 ldap_pvt_thread_mutex_destroy( &si->dbconn_mutex );
130 if ( si->dbpasswd ) {
131 free( si->dbpasswd );
136 if ( si->upper_func ) {
137 free( si->upper_func );
140 free( si->subtree_cond );
141 free( si->oc_query );
142 free( si->at_query );
143 free( si->insentry_query );
144 free( si->delentry_query );
147 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_destroy()\n", 0, 0, 0 );
155 backsql_info *si = (backsql_info*)bd->be_private;
161 Debug( LDAP_DEBUG_TRACE, "==>backsql_db_open(): "
162 "testing RDBMS connection\n", 0, 0, 0 );
163 if ( si->dbname == NULL ) {
164 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
165 "datasource name not specified "
166 "(use dbname directive in slapd.conf)\n", 0, 0, 0 );
170 if ( si->dbuser == NULL ) {
171 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
172 "user name not specified "
173 "(use dbuser directive in slapd.conf)\n", 0, 0, 0 );
177 if ( si->subtree_cond == NULL ) {
178 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
179 "subtree search SQL condition not specified "
180 "(use subtree_cond directive in slapd.conf)\n",
182 if ( si->upper_func ) {
183 struct berval bv = { 0, NULL };
186 backsql_strcat( &bv, &len, si->upper_func,
187 backsql_def_upper_subtree_cond, NULL );
188 si->subtree_cond = bv.bv_val;
190 si->subtree_cond = ch_strdup( backsql_def_subtree_cond );
193 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
194 "setting '%s' as default\n",
195 si->subtree_cond, 0, 0 );
198 if ( si->oc_query == NULL ) {
199 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
200 "objectclass mapping SQL statement not specified "
201 "(use oc_query directive in slapd.conf)\n", 0, 0, 0 );
202 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
203 "setting '%s' by default\n",
204 backsql_def_oc_query, 0, 0 );
205 si->oc_query = ch_strdup( backsql_def_oc_query );
208 if ( si->at_query == NULL ) {
209 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
210 "attribute mapping SQL statement not specified "
211 "(use at_query directive in slapd.conf)\n",
213 Debug(LDAP_DEBUG_TRACE, "backsql_db_open(): "
214 "setting '%s' by default\n",
215 backsql_def_at_query, 0, 0 );
216 si->at_query = ch_strdup( backsql_def_at_query );
219 if ( si->insentry_query == NULL ) {
220 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
221 "entry insertion SQL statement not specified "
222 "(use insentry_query directive in slapd.conf)\n",
224 Debug(LDAP_DEBUG_TRACE, "backsql_db_open(): "
225 "setting '%s' by default\n",
226 backsql_def_insentry_query, 0, 0 );
227 si->insentry_query = ch_strdup( backsql_def_insentry_query );
230 if ( si->delentry_query == NULL ) {
231 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
232 "entry deletion SQL statement not specified "
233 "(use delentry_query directive in slapd.conf)\n",
235 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
236 "setting '%s' by default\n",
237 backsql_def_delentry_query, 0, 0 );
238 si->delentry_query = ch_strdup( backsql_def_delentry_query );
242 if ( backsql_get_db_conn( bd, &tmp, &dbh ) != LDAP_SUCCESS ) {
243 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
244 "connection failed, exiting\n", 0, 0, 0 );
253 if ( si->upper_func == NULL ) {
254 backsql_strcat( &bv, &idq_len, backsql_id_query,
257 if ( si->has_ldapinfo_dn_ru ) {
258 backsql_strcat( &bv, &idq_len, backsql_id_query,
261 if ( si->isTimesTen ) {
262 backsql_strcat( &bv, &idq_len,
264 si->upper_func, "(dn)=?",
267 backsql_strcat( &bv, &idq_len,
269 si->upper_func, "(dn)=",
270 si->upper_func, "(?)", NULL );
274 si->id_query = bv.bv_val;
276 backsql_free_db_conn( bd, &tmp );
277 if ( !si->schema_loaded ) {
278 Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
279 "test failed, schema map not loaded - exiting\n",
284 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_open(): "
285 "test succeeded, schema map loaded\n", 0, 0, 0 );
293 Debug( LDAP_DEBUG_TRACE, "==>backsql_db_close()\n", 0, 0, 0 );
294 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_close()\n", 0, 0, 0 );
299 backsql_connection_destroy(
303 Debug( LDAP_DEBUG_TRACE, "==>backsql_connection_destroy()\n", 0, 0, 0 );
304 backsql_free_db_conn( be, conn );
305 Debug( LDAP_DEBUG_TRACE, "<==backsql_connection_destroy()\n", 0, 0, 0 );
309 #endif /* SLAPD_SQL */