2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software.
26 #include "ac/string.h"
27 #include <sys/types.h>
30 #include "proto-sql.h"
40 backsql_info *si = (backsql_info *)be->be_private;
42 Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 );
45 if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) {
47 Debug( LDAP_DEBUG_TRACE,
48 "<==backsql_db_config (%s line %d): "
49 "missing hostname in \"dbhost\" directive\n",
53 si->dbhost = ch_strdup( argv[ 1 ] );
54 Debug( LDAP_DEBUG_TRACE,
55 "<==backsql_db_config(): hostname=%s\n",
58 } else if ( !strcasecmp( argv[ 0 ], "dbuser" ) ) {
60 Debug( LDAP_DEBUG_TRACE,
61 "<==backsql_db_config (%s line %d): "
62 "missing username in \"dbuser\" directive\n",
66 si->dbuser = ch_strdup( argv[ 1 ] );
67 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbuser=%s\n",
70 } else if ( !strcasecmp( argv[ 0 ], "dbpasswd" ) ) {
72 Debug( LDAP_DEBUG_TRACE,
73 "<==backsql_db_config (%s line %d): "
74 "missing password in \"dbpasswd\" directive\n",
78 si->dbpasswd = ch_strdup( argv[ 1 ] );
79 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
80 "dbpasswd=%s\n", /* si->dbpasswd */ "xxxx", 0, 0 );
82 } else if ( !strcasecmp( argv[ 0 ], "dbname" ) ) {
84 Debug( LDAP_DEBUG_TRACE,
85 "<==backsql_db_config (%s line %d): "
86 "missing database name in \"dbname\" "
87 "directive\n", fname, lineno, 0 );
90 si->dbname = ch_strdup( argv[ 1 ] );
91 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbname=%s\n",
94 } else if ( !strcasecmp( argv[ 0 ], "concat_pattern" ) ) {
96 Debug( LDAP_DEBUG_TRACE,
97 "<==backsql_db_config (%s line %d): "
99 "in \"concat_pattern\" directive\n",
103 if ( backsql_split_pattern( argv[ 1 ], &si->concat_func, 2 ) ) {
104 Debug( LDAP_DEBUG_TRACE,
105 "<==backsql_db_config (%s line %d): "
106 "unable to parse pattern \"%s\"\n"
107 "in \"concat_pattern\" directive\n",
108 fname, lineno, argv[ 1 ] );
111 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
112 "concat_pattern=\"%s\"\n", argv[ 1 ], 0, 0 );
114 } else if ( !strcasecmp( argv[ 0 ], "subtree_cond" ) ) {
116 Debug( LDAP_DEBUG_TRACE,
117 "<==backsql_db_config (%s line %d): "
118 "missing SQL condition "
119 "in \"subtree_cond\" directive\n",
123 ber_str2bv( argv[ 1 ], 0, 1, &si->subtree_cond );
124 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
125 "subtree_cond=%s\n", si->subtree_cond.bv_val, 0, 0 );
127 } else if ( !strcasecmp( argv[ 0 ], "children_cond" ) ) {
129 Debug( LDAP_DEBUG_TRACE,
130 "<==backsql_db_config (%s line %d): "
131 "missing SQL condition "
132 "in \"children_cond\" directive\n",
136 ber_str2bv( argv[ 1 ], 0, 1, &si->children_cond );
137 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
138 "subtree_cond=%s\n", si->children_cond.bv_val, 0, 0 );
140 } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) {
142 Debug( LDAP_DEBUG_TRACE,
143 "<==backsql_db_config (%s line %d): "
144 "missing SQL statement "
145 "in \"oc_query\" directive\n",
149 si->oc_query = ch_strdup( argv[ 1 ] );
150 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
151 "oc_query=%s\n", si->oc_query, 0, 0 );
153 } else if ( !strcasecmp( argv[ 0 ], "at_query" ) ) {
155 Debug( LDAP_DEBUG_TRACE,
156 "<==backsql_db_config (%s line %d): "
157 "missing SQL statement "
158 "in \"at_query\" directive\n",
162 si->at_query = ch_strdup( argv[ 1 ] );
163 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
164 "at_query=%s\n", si->at_query, 0, 0 );
166 } else if ( !strcasecmp( argv[ 0 ], "insentry_query" ) ) {
168 Debug( LDAP_DEBUG_TRACE,
169 "<==backsql_db_config (%s line %d): "
170 "missing SQL statement "
171 "in \"insentry_query\" directive\n",
175 si->insentry_query = ch_strdup( argv[ 1 ] );
176 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
177 "insentry_query=%s\n", si->insentry_query, 0, 0 );
179 } else if ( !strcasecmp( argv[ 0 ], "create_needs_select" ) ) {
181 Debug( LDAP_DEBUG_TRACE,
182 "<==backsql_db_config (%s line %d): "
183 "missing { yes | no }"
184 "in \"create_needs_select\" directive\n",
189 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
190 si->bsql_flags |= BSQLF_CREATE_NEEDS_SELECT;
192 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
193 si->bsql_flags &= ~BSQLF_CREATE_NEEDS_SELECT;
196 Debug( LDAP_DEBUG_TRACE,
197 "<==backsql_db_config (%s line %d): "
198 "\"create_needs_select\" directive arg "
199 "must be \"yes\" or \"no\"\n",
204 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
205 "create_needs_select =%s\n",
206 BACKSQL_CREATE_NEEDS_SELECT( si ) ? "yes" : "no",
209 } else if ( !strcasecmp( argv[ 0 ], "upper_func" ) ) {
211 Debug( LDAP_DEBUG_TRACE,
212 "<==backsql_db_config (%s line %d): "
213 "missing function name "
214 "in \"upper_func\" directive\n",
218 ber_str2bv( argv[ 1 ], 0, 1, &si->upper_func );
219 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
220 "upper_func=%s\n", si->upper_func.bv_val, 0, 0 );
222 } else if ( !strcasecmp( argv[ 0 ], "upper_needs_cast" ) ) {
224 Debug( LDAP_DEBUG_TRACE,
225 "<==backsql_db_config (%s line %d): "
226 "missing { yes | no }"
227 "in \"upper_needs_cast\" directive\n",
232 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
233 si->bsql_flags |= BSQLF_UPPER_NEEDS_CAST;
235 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
236 si->bsql_flags &= ~BSQLF_UPPER_NEEDS_CAST;
239 Debug( LDAP_DEBUG_TRACE,
240 "<==backsql_db_config (%s line %d): "
241 "\"upper_needs_cast\" directive arg "
242 "must be \"yes\" or \"no\"\n",
247 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
248 "upper_needs_cast =%s\n",
249 BACKSQL_UPPER_NEEDS_CAST( si ) ? "yes" : "no", 0, 0 );
251 } else if ( !strcasecmp( argv[ 0 ], "strcast_func" ) ) {
253 Debug( LDAP_DEBUG_TRACE,
254 "<==backsql_db_config (%s line %d): "
255 "missing function name "
256 "in \"strcast_func\" directive\n",
260 ber_str2bv( argv[ 1 ], 0, 1, &si->strcast_func );
261 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
262 "strcast_func=%s\n", si->strcast_func.bv_val, 0, 0 );
264 } else if ( !strcasecmp( argv[ 0 ], "delentry_query" ) ) {
266 Debug( LDAP_DEBUG_TRACE,
267 "<==backsql_db_config (%s line %d): "
268 "missing SQL statement "
269 "in \"delentry_query\" directive\n",
273 si->delentry_query = ch_strdup( argv[ 1 ] );
274 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
275 "delentry_query=%s\n", si->delentry_query, 0, 0 );
277 } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
279 Debug( LDAP_DEBUG_TRACE,
280 "<==backsql_db_config (%s line %d): "
281 "missing { yes | no }"
282 "in \"has_ldapinfo_dn_ru\" directive\n",
287 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
288 si->bsql_flags |= BSQLF_HAS_LDAPINFO_DN_RU;
289 si->bsql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
291 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
292 si->bsql_flags &= ~BSQLF_HAS_LDAPINFO_DN_RU;
293 si->bsql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
296 Debug( LDAP_DEBUG_TRACE,
297 "<==backsql_db_config (%s line %d): "
298 "\"has_ldapinfo_dn_ru\" directive arg "
299 "must be \"yes\" or \"no\"\n",
304 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
305 "has_ldapinfo_dn_ru=%s\n",
306 BACKSQL_HAS_LDAPINFO_DN_RU( si ) ? "yes" : "no", 0, 0 );
308 } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
310 Debug( LDAP_DEBUG_TRACE,
311 "<==backsql_db_config (%s line %d): "
312 "missing { yes | no }"
313 "in \"fail_if_no_mapping\" directive\n",
318 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
319 si->bsql_flags |= BSQLF_FAIL_IF_NO_MAPPING;
321 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
322 si->bsql_flags &= ~BSQLF_FAIL_IF_NO_MAPPING;
325 Debug( LDAP_DEBUG_TRACE,
326 "<==backsql_db_config (%s line %d): "
327 "\"fail_if_no_mapping\" directive arg "
328 "must be \"yes\" or \"no\"\n",
333 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
334 "fail_if_no_mapping=%s\n",
335 BACKSQL_FAIL_IF_NO_MAPPING( si ) ? "yes" : "no", 0, 0 );
338 return SLAP_CONF_UNKNOWN;
344 #endif /* SLAPD_SQL */