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>
19 #include "schema-map.h"
22 #ifdef SLAPD_SQL_DYNAMIC
24 int backsql_LTX_init_module(int argc, char *argv[]) {
27 memset( &bi, '\0', sizeof(bi) );
29 bi.bi_init = backbacksql_initialize;
35 #endif /* SLAPD_SHELL_DYNAMIC */
37 int sql_back_initialize(
41 Debug(LDAP_DEBUG_TRACE,"==>backsql_initialize()\n",0,0,0);
47 bi->bi_db_init = backsql_db_init;
48 bi->bi_db_config = backsql_db_config;
49 bi->bi_db_open = backsql_db_open;
50 bi->bi_db_close = backsql_db_close;
51 bi->bi_db_destroy = backsql_db_destroy;
53 #ifdef BACKSQL_ALL_DONE
54 bi->bi_op_abandon = backsql_abandon;
55 bi->bi_op_compare = backsql_compare;
57 bi->bi_op_abandon = 0;
58 bi->bi_op_compare = 0;
60 bi->bi_op_bind = backsql_bind;
61 bi->bi_op_unbind = backsql_unbind;
62 bi->bi_op_search = backsql_search;
63 bi->bi_op_modify = backsql_modify;
64 bi->bi_op_modrdn = backsql_modrdn;
65 bi->bi_op_add = backsql_add;
66 bi->bi_op_delete = backsql_delete;
69 bi->bi_acl_attribute = 0;
70 bi->bi_chk_referrals = 0;
72 bi->bi_connection_init = 0;
73 bi->bi_connection_destroy = backsql_connection_destroy;
75 Debug(LDAP_DEBUG_TRACE,"<==backsql_initialize()\n",0,0,0);
80 int backsql_destroy ( BackendInfo *bi )
82 Debug(LDAP_DEBUG_TRACE,"==>backsql_destroy()\n",0,0,0);
83 Debug(LDAP_DEBUG_TRACE,"<==backsql_destroy()\n",0,0,0);
87 int backsql_db_init(BackendDB *bd)
91 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_init()\n",0,0,0);
92 si = (backsql_info *) ch_calloc( 1, sizeof(backsql_info) );
93 ldap_pvt_thread_mutex_init(&si->dbconn_mutex);
94 ldap_pvt_thread_mutex_init(&si->schema_mutex);
95 backsql_init_db_env(si);
98 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_init()\n",0,0,0);
102 int backsql_db_destroy(BackendDB *bd)
104 backsql_info *si=(backsql_info*)bd->be_private;
106 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_destroy()\n",0,0,0);
107 ldap_pvt_thread_mutex_lock(&si->dbconn_mutex);
108 backsql_free_db_env(si);
109 ldap_pvt_thread_mutex_unlock(&si->dbconn_mutex);
110 ldap_pvt_thread_mutex_lock(&si->schema_mutex);
111 backsql_destroy_schema_map(si);
112 ldap_pvt_thread_mutex_unlock(&si->schema_mutex);
113 ldap_pvt_thread_mutex_destroy(&si->schema_mutex);
114 ldap_pvt_thread_mutex_destroy(&si->dbconn_mutex);
122 free(si->upper_func);
123 free(si->subtree_cond);
126 free(si->insentry_query);
127 free(si->delentry_query);
129 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_destroy()\n",0,0,0);
133 int backsql_db_open (BackendDB *bd)
135 backsql_info *si=(backsql_info*)bd->be_private;
140 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_open(): testing RDBMS connection\n",0,0,0);
141 if (si->dbname==NULL)
143 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): datasource name not specified (use dbname directive in slapd.conf)\n",0,0,0);
146 if (si->dbuser==NULL)
148 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): user name not specified (use dbuser directive in slapd.conf)\n",0,0,0);
151 if (si->subtree_cond==NULL)
153 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): subtree search SQL condition not specified (use subtree_cond directive in slapd.conf)\n",0,0,0);
154 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' as default\n",backsql_def_subtree_cond,0,0);
155 si->subtree_cond=ch_strdup(backsql_def_subtree_cond);
157 if (si->oc_query==NULL)
159 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): objectclass mapping SQL statement not specified (use oc_query directive in slapd.conf)\n",0,0,0);
160 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_oc_query,0,0);
161 si->oc_query=ch_strdup(backsql_def_oc_query);
163 if (si->at_query==NULL)
165 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): attribute mapping SQL statement not specified (use at_query directive in slapd.conf)\n",0,0,0);
166 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_at_query,0,0);
167 si->at_query=ch_strdup(backsql_def_at_query);
169 if (si->insentry_query==NULL)
171 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): entry insertion SQL statement not specified (use insentry_query directive in slapd.conf)\n",0,0,0);
172 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_insentry_query,0,0);
173 si->insentry_query=ch_strdup(backsql_def_insentry_query);
175 if (si->delentry_query==NULL)
177 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): entry deletion SQL statement not specified (use delentry_query directive in slapd.conf)\n",0,0,0);
178 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_delentry_query,0,0);
179 si->delentry_query=ch_strdup(backsql_def_delentry_query);
182 dbh=backsql_get_db_conn(bd,&tmp);
185 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): connection failed, exiting\n",0,0,0
192 if (si->upper_func==NULL)
194 si->id_query=backsql_strcat(si->id_query,&idq_len,backsql_id_query,"dn=?",NULL);
198 if (si->has_ldapinfo_dn_ru) {
199 si->id_query=backsql_strcat(si->id_query,&idq_len,backsql_id_query,"dn_ru=?",NULL);
202 if (si->isTimesTen) {
203 si->id_query=backsql_strcat(si->id_query,&idq_len,backsql_id_query,si->upper_func,"(dn)=?",NULL);
206 si->id_query=backsql_strcat(si->id_query,&idq_len,backsql_id_query,si->upper_func,"(dn)=",si->upper_func,"(?)",NULL);
211 backsql_free_db_conn(bd,&tmp);
212 if (!si->schema_loaded)
214 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): test failed, schema map not loaded - exiting\n",0,0,0);
217 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_open(): test succeeded, schema map loaded\n",0,0,0);
221 int backsql_db_close(BackendDB *bd)
223 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_close()\n",0,0,0);
224 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_close()\n",0,0,0);
228 int backsql_connection_destroy(BackendDB *be,Connection *conn)
230 Debug(LDAP_DEBUG_TRACE,"==>backsql_connection_destroy()\n",0,0,0);
231 backsql_free_db_conn(be,conn);
232 Debug(LDAP_DEBUG_TRACE,"<==backsql_connection_destroy()\n",0,0,0);
236 #endif /* SLAPD_SQL */