2 * Copyright 1999, Dmitry Kovalev (zmit@mail.ru), 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.
13 #include <sys/types.h>
17 #include "schema-map.h"
20 #ifdef SLAPD_SQL_DYNAMIC
22 int backsql_LTX_init_module(int argc, char *argv[]) {
25 memset( &bi, 0, sizeof(bi) );
27 bi.bi_init = backbacksql_initialize;
33 #endif /* SLAPD_SHELL_DYNAMIC */
35 int sql_back_initialize(
39 Debug(LDAP_DEBUG_TRACE,"==>backsql_initialize()\n",0,0,0);
45 bi->bi_db_init = backsql_db_init;
46 bi->bi_db_config = backsql_db_config;
47 bi->bi_db_open = backsql_db_open;
48 bi->bi_db_close = backsql_db_close;
49 bi->bi_db_destroy = backsql_db_destroy;
51 #ifdef BACKSQL_ALL_DONE
52 bi->bi_op_abandon = backsql_abandon;
53 bi->bi_op_compare = backsql_compare;
55 bi->bi_op_abandon = 0;
56 bi->bi_op_compare = 0;
58 bi->bi_op_bind = backsql_bind;
59 bi->bi_op_unbind = backsql_unbind;
60 bi->bi_op_search = backsql_search;
61 bi->bi_op_modify = backsql_modify;
62 bi->bi_op_modrdn = backsql_modrdn;
63 bi->bi_op_add = backsql_add;
64 bi->bi_op_delete = backsql_delete;
68 bi->bi_connection_init = 0;
69 bi->bi_connection_destroy = 0;
71 Debug(LDAP_DEBUG_TRACE,"<==backsql_initialize()\n",0,0,0);
76 int backsql_destroy ( BackendInfo *bi )
78 Debug(LDAP_DEBUG_TRACE,"==>backsql_destroy()\n",0,0,0);
79 Debug(LDAP_DEBUG_TRACE,"<==backsql_destroy()\n",0,0,0);
83 int backsql_db_init(BackendDB *bd)
87 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_init()\n",0,0,0);
88 si = (backsql_info *) ch_calloc( 1, sizeof(backsql_info) );
89 ldap_pvt_thread_mutex_init(&si->dbconn_mutex);
90 ldap_pvt_thread_mutex_init(&si->schema_mutex);
91 backsql_init_db_env(si);
94 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_init()\n",0,0,0);
98 int backsql_db_destroy(BackendDB *bd)
100 backsql_info *si=(backsql_info*)bd->be_private;
102 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_destroy()\n",0,0,0);
103 ldap_pvt_thread_mutex_lock(&si->dbconn_mutex);
104 backsql_free_db_env(si);
105 ldap_pvt_thread_mutex_unlock(&si->dbconn_mutex);
106 ldap_pvt_thread_mutex_lock(&si->schema_mutex);
107 backsql_destroy_schema_map(si);
108 ldap_pvt_thread_mutex_unlock(&si->schema_mutex);
109 ldap_pvt_thread_mutex_destroy(&si->schema_mutex);
110 ldap_pvt_thread_mutex_destroy(&si->dbconn_mutex);
117 free(si->subtree_cond);
120 free(si->insentry_query);
121 free(si->delentry_query);
123 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_destroy()\n",0,0,0);
127 int backsql_db_open (BackendDB *bd)
129 backsql_info *si=(backsql_info*)bd->be_private;
133 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_open(): testing RDBMS connection\n",0,0,0);
134 if (si->dbname==NULL)
136 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): datasource name not specified (use dbname directive in slapd.conf)\n",0,0,0);
139 if (si->dbuser==NULL)
141 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): user name not specified (use dbuser directive in slapd.conf)\n",0,0,0);
144 if (si->subtree_cond==NULL)
146 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): subtree search SQL condition not specified (use subtree_cond directive in slapd.conf)\n",0,0,0);
147 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' as default\n",backsql_def_subtree_cond,0,0);
148 si->subtree_cond=strdup(backsql_def_subtree_cond);
150 if (si->oc_query==NULL)
152 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): objectclass mapping SQL statement not specified (use oc_query directive in slapd.conf)\n",0,0,0);
153 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_oc_query,0,0);
154 si->oc_query=strdup(backsql_def_oc_query);
156 if (si->at_query==NULL)
158 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): attribute mapping SQL statement not specified (use at_query directive in slapd.conf)\n",0,0,0);
159 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_at_query,0,0);
160 si->at_query=strdup(backsql_def_at_query);
162 if (si->insentry_query==NULL)
164 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): entry insertion SQL statement not specified (use insentry_query directive in slapd.conf)\n",0,0,0);
165 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_insentry_query,0,0);
166 si->insentry_query=strdup(backsql_def_insentry_query);
168 if (si->delentry_query==NULL)
170 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): entry deletion SQL statement not specified (use delentry_query directive in slapd.conf)\n",0,0,0);
171 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): setting '%s' by default\n",backsql_def_delentry_query,0,0);
172 si->delentry_query=strdup(backsql_def_delentry_query);
175 dbh=backsql_get_db_conn(bd,&tmp);
178 Debug(LDAP_DEBUG_TRACE,"backsql_db_open(): connection failed, exiting\n",0,0,0);
181 backsql_free_db_conn(bd,&tmp);
182 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_open(): test succeeded, schema map loaded\n",0,0,0);
186 int backsql_db_close(BackendDB *bd)
188 Debug(LDAP_DEBUG_TRACE,"==>backsql_db_close()\n",0,0,0);
189 Debug(LDAP_DEBUG_TRACE,"<==backsql_db_close()\n",0,0,0);