]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/config.c
Added provisions for a layer between the backend and the ODBC
[openldap] / servers / slapd / back-sql / config.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2004 The OpenLDAP Foundation.
5  * Portions Copyright 1999 Dmitry Kovalev.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Dmitry Kovalev for inclusion
18  * by OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #ifdef SLAPD_SQL
24
25 #include <stdio.h>
26 #include "ac/string.h"
27 #include <sys/types.h>
28
29 #include "slap.h"
30 #include "proto-sql.h"
31
32 int
33 backsql_db_config(
34         BackendDB       *be,
35         const char      *fname,
36         int             lineno,
37         int             argc,
38         char            **argv )
39 {
40         backsql_info    *si = (backsql_info *)be->be_private;
41
42         Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 );
43         assert( si );
44   
45         if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) {
46                 if ( argc < 2 ) {
47                         Debug( LDAP_DEBUG_TRACE, 
48                                 "<==backsql_db_config (%s line %d): "
49                                 "missing hostname in \"dbhost\" directive\n",
50                                 fname, lineno, 0 );
51                         return 1;
52                 }
53                 si->dbhost = ch_strdup( argv[ 1 ] );
54                 Debug( LDAP_DEBUG_TRACE,
55                         "<==backsql_db_config(): hostname=%s\n",
56                         si->dbhost, 0, 0 );
57
58         } else if ( !strcasecmp( argv[ 0 ], "dbuser" ) ) {
59                 if ( argc < 2 ) {
60                         Debug( LDAP_DEBUG_TRACE, 
61                                 "<==backsql_db_config (%s line %d): "
62                                 "missing username in \"dbuser\" directive\n",
63                                 fname, lineno, 0 );
64                         return 1;
65                 }
66                 si->dbuser = ch_strdup( argv[ 1 ] );
67                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbuser=%s\n",
68                         si->dbuser, 0, 0 );
69
70         } else if ( !strcasecmp( argv[ 0 ], "dbpasswd" ) ) {
71                 if ( argc < 2 ) {
72                         Debug( LDAP_DEBUG_TRACE, 
73                                 "<==backsql_db_config (%s line %d): "
74                                 "missing password in \"dbpasswd\" directive\n",
75                                 fname, lineno, 0 );
76                         return 1;
77                 }
78                 si->dbpasswd = ch_strdup( argv[ 1 ] );
79                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
80                         "dbpasswd=%s\n", /* si->dbpasswd */ "xxxx", 0, 0 );
81
82         } else if ( !strcasecmp( argv[ 0 ], "dbname" ) ) {
83                 if ( argc < 2 ) {
84                         Debug( LDAP_DEBUG_TRACE, 
85                                 "<==backsql_db_config (%s line %d): "
86                                 "missing database name in \"dbname\" "
87                                 "directive\n", fname, lineno, 0 );
88                         return 1;
89                 }
90                 si->dbname = ch_strdup( argv[ 1 ] );
91                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbname=%s\n",
92                         si->dbname, 0, 0 );
93
94         } else if ( !strcasecmp( argv[ 0 ], "concat_pattern" ) ) {
95                 if ( argc < 2 ) {
96                         Debug( LDAP_DEBUG_TRACE, 
97                                 "<==backsql_db_config (%s line %d): "
98                                 "missing pattern"
99                                 "in \"concat_pattern\" directive\n",
100                                 fname, lineno, 0 );
101                         return 1;
102                 }
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 ] );
109                         return 1;
110                 }
111                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
112                         "concat_pattern=\"%s\"\n", argv[ 1 ], 0, 0 );
113
114         } else if ( !strcasecmp( argv[ 0 ], "subtree_cond" ) ) {
115                 if ( argc < 2 ) {
116                         Debug( LDAP_DEBUG_TRACE, 
117                                 "<==backsql_db_config (%s line %d): "
118                                 "missing SQL condition "
119                                 "in \"subtree_cond\" directive\n",
120                                 fname, lineno, 0 );
121                         return 1;
122                 }
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 );
126
127         } else if ( !strcasecmp( argv[ 0 ], "children_cond" ) ) {
128                 if ( argc < 2 ) {
129                         Debug( LDAP_DEBUG_TRACE, 
130                                 "<==backsql_db_config (%s line %d): "
131                                 "missing SQL condition "
132                                 "in \"children_cond\" directive\n",
133                                 fname, lineno, 0 );
134                         return 1;
135                 }
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 );
139
140         } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) {
141                 if ( argc < 2 ) {
142                         Debug( LDAP_DEBUG_TRACE, 
143                                 "<==backsql_db_config (%s line %d): "
144                                 "missing SQL statement "
145                                 "in \"oc_query\" directive\n",
146                                 fname, lineno, 0 );
147                         return 1;
148                 }
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 );
152
153         } else if ( !strcasecmp( argv[ 0 ], "at_query" ) ) {
154                 if ( argc < 2 ) {
155                         Debug( LDAP_DEBUG_TRACE,
156                                 "<==backsql_db_config (%s line %d): "
157                                 "missing SQL statement "
158                                 "in \"at_query\" directive\n",
159                                 fname, lineno, 0 );
160                         return 1;
161                 }
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 );
165
166         } else if ( !strcasecmp( argv[ 0 ], "insentry_query" ) ) {
167                 if ( argc < 2 ) {
168                         Debug( LDAP_DEBUG_TRACE, 
169                                 "<==backsql_db_config (%s line %d): "
170                                 "missing SQL statement "
171                                 "in \"insentry_query\" directive\n",
172                                 fname, lineno, 0 );
173                         return 1;
174                 }
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 );
178
179         } else if ( !strcasecmp( argv[ 0 ], "create_needs_select" ) ) {
180                 if ( argc < 2 ) {
181                         Debug( LDAP_DEBUG_TRACE,
182                                 "<==backsql_db_config (%s line %d): "
183                                 "missing { yes | no }"
184                                 "in \"create_needs_select\" directive\n",
185                                 fname, lineno, 0 );
186                         return 1;
187                 }
188
189                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
190                         si->bsql_flags |= BSQLF_CREATE_NEEDS_SELECT;
191
192                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
193                         si->bsql_flags &= ~BSQLF_CREATE_NEEDS_SELECT;
194
195                 } else {
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",
200                                 fname, lineno, 0 );
201                         return 1;
202
203                 }
204                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
205                         "create_needs_select =%s\n", 
206                         BACKSQL_CREATE_NEEDS_SELECT( si ) ? "yes" : "no",
207                         0, 0 );
208
209         } else if ( !strcasecmp( argv[ 0 ], "upper_func" ) ) {
210                 if ( argc < 2 ) {
211                         Debug( LDAP_DEBUG_TRACE,
212                                 "<==backsql_db_config (%s line %d): "
213                                 "missing function name "
214                                 "in \"upper_func\" directive\n",
215                                 fname, lineno, 0 );
216                         return 1;
217                 }
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 );
221
222         } else if ( !strcasecmp( argv[ 0 ], "upper_needs_cast" ) ) {
223                 if ( argc < 2 ) {
224                         Debug( LDAP_DEBUG_TRACE,
225                                 "<==backsql_db_config (%s line %d): "
226                                 "missing { yes | no }"
227                                 "in \"upper_needs_cast\" directive\n",
228                                 fname, lineno, 0 );
229                         return 1;
230                 }
231
232                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
233                         si->bsql_flags |= BSQLF_UPPER_NEEDS_CAST;
234
235                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
236                         si->bsql_flags &= ~BSQLF_UPPER_NEEDS_CAST;
237
238                 } else {
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",
243                                 fname, lineno, 0 );
244                         return 1;
245
246                 }
247                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
248                         "upper_needs_cast =%s\n", 
249                         BACKSQL_UPPER_NEEDS_CAST( si ) ? "yes" : "no", 0, 0 );
250
251         } else if ( !strcasecmp( argv[ 0 ], "strcast_func" ) ) {
252                 if ( argc < 2 ) {
253                         Debug( LDAP_DEBUG_TRACE,
254                                 "<==backsql_db_config (%s line %d): "
255                                 "missing function name "
256                                 "in \"strcast_func\" directive\n",
257                                 fname, lineno, 0 );
258                         return 1;
259                 }
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 );
263
264         } else if ( !strcasecmp( argv[ 0 ], "delentry_query" ) ) {
265                 if ( argc < 2 ) {
266                         Debug( LDAP_DEBUG_TRACE,
267                                 "<==backsql_db_config (%s line %d): "
268                                 "missing SQL statement "
269                                 "in \"delentry_query\" directive\n",
270                                 fname, lineno, 0 );
271                         return 1;
272                 }
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 );
276
277         } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
278                 if ( argc < 2 ) {
279                         Debug( LDAP_DEBUG_TRACE,
280                                 "<==backsql_db_config (%s line %d): "
281                                 "missing { yes | no }"
282                                 "in \"has_ldapinfo_dn_ru\" directive\n",
283                                 fname, lineno, 0 );
284                         return 1;
285                 }
286
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;
290
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;
294
295                 } else {
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",
300                                 fname, lineno, 0 );
301                         return 1;
302
303                 }
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 );
307
308         } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
309                 if ( argc < 2 ) {
310                         Debug( LDAP_DEBUG_TRACE,
311                                 "<==backsql_db_config (%s line %d): "
312                                 "missing { yes | no }"
313                                 "in \"fail_if_no_mapping\" directive\n",
314                                 fname, lineno, 0 );
315                         return 1;
316                 }
317
318                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
319                         si->bsql_flags |= BSQLF_FAIL_IF_NO_MAPPING;
320
321                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
322                         si->bsql_flags &= ~BSQLF_FAIL_IF_NO_MAPPING;
323
324                 } else {
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",
329                                 fname, lineno, 0 );
330                         return 1;
331
332                 }
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 );
336
337         } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) {
338                 if ( backsql_api_config( si, argv[ 1 ] ) ) {
339                         Debug( LDAP_DEBUG_TRACE,
340                                 "<==backsql_db_config (%s line %d): "
341                                 "unable to load sqllayer \"%s\"\n",
342                                 fname, lineno, argv[ 1 ] );
343                         return 1;
344                 }
345
346         } else {
347                 return SLAP_CONF_UNKNOWN;
348         }
349
350         return 0;
351 }
352
353 #endif /* SLAPD_SQL */
354