]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/config.c
d88a57396d590554e58e6f27d0061b6c0f004b7c
[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 #include "slap.h"
29 #include "back-sql.h"
30 #include "sql-wrap.h"
31 #include "util.h"
32
33 int
34 backsql_db_config(
35         BackendDB       *be,
36         const char      *fname,
37         int             lineno,
38         int             argc,
39         char            **argv )
40 {
41         backsql_info    *si = (backsql_info *)be->be_private;
42
43         Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 );
44         assert( si );
45   
46         if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) {
47                 if ( argc < 2 ) {
48                         Debug( LDAP_DEBUG_TRACE, 
49                                 "<==backsql_db_config (%s line %d): "
50                                 "missing hostname in \"dbhost\" directive\n",
51                                 fname, lineno, 0 );
52                         return 1;
53                 }
54                 si->dbhost = ch_strdup( argv[ 1 ] );
55                 Debug( LDAP_DEBUG_TRACE,
56                         "<==backsql_db_config(): hostname=%s\n",
57                         si->dbhost, 0, 0 );
58
59         } else if ( !strcasecmp( argv[ 0 ], "dbuser" ) ) {
60                 if ( argc < 2 ) {
61                         Debug( LDAP_DEBUG_TRACE, 
62                                 "<==backsql_db_config (%s line %d): "
63                                 "missing username in \"dbuser\" directive\n",
64                                 fname, lineno, 0 );
65                         return 1;
66                 }
67                 si->dbuser = ch_strdup( argv[ 1 ] );
68                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbuser=%s\n",
69                         si->dbuser, 0, 0 );
70
71         } else if ( !strcasecmp( argv[ 0 ], "dbpasswd" ) ) {
72                 if ( argc < 2 ) {
73                         Debug( LDAP_DEBUG_TRACE, 
74                                 "<==backsql_db_config (%s line %d): "
75                                 "missing password in \"dbpasswd\" directive\n",
76                                 fname, lineno, 0 );
77                         return 1;
78                 }
79                 si->dbpasswd = ch_strdup( argv[ 1 ] );
80                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
81                         "dbpasswd=%s\n", /* si->dbpasswd */ "xxxx", 0, 0 );
82
83         } else if ( !strcasecmp( argv[ 0 ], "dbname" ) ) {
84                 if ( argc < 2 ) {
85                         Debug( LDAP_DEBUG_TRACE, 
86                                 "<==backsql_db_config (%s line %d): "
87                                 "missing database name in \"dbname\" "
88                                 "directive\n", fname, lineno, 0 );
89                         return 1;
90                 }
91                 si->dbname = ch_strdup( argv[ 1 ] );
92                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): dbname=%s\n",
93                         si->dbname, 0, 0 );
94
95         } else if ( !strcasecmp( argv[ 0 ], "concat_pattern" ) ) {
96                 if ( argc < 2 ) {
97                         Debug( LDAP_DEBUG_TRACE, 
98                                 "<==backsql_db_config (%s line %d): "
99                                 "missing pattern"
100                                 "in \"concat_pattern\" directive\n",
101                                 fname, lineno, 0 );
102                         return 1;
103                 }
104                 if ( backsql_split_pattern( argv[ 1 ], &si->concat_func, 2 ) ) {
105                         Debug( LDAP_DEBUG_TRACE, 
106                                 "<==backsql_db_config (%s line %d): "
107                                 "unable to parse pattern \"%s\"\n"
108                                 "in \"concat_pattern\" directive\n",
109                                 fname, lineno, argv[ 1 ] );
110                         return 1;
111                 }
112                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
113                         "concat_pattern=\"%s\"\n", argv[ 1 ], 0, 0 );
114
115         } else if ( !strcasecmp( argv[ 0 ], "subtree_cond" ) ) {
116                 if ( argc < 2 ) {
117                         Debug( LDAP_DEBUG_TRACE, 
118                                 "<==backsql_db_config (%s line %d): "
119                                 "missing SQL condition "
120                                 "in \"subtree_cond\" directive\n",
121                                 fname, lineno, 0 );
122                         return 1;
123                 }
124                 ber_str2bv( argv[ 1 ], 0, 1, &si->subtree_cond );
125                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
126                         "subtree_cond=%s\n", si->subtree_cond.bv_val, 0, 0 );
127
128         } else if ( !strcasecmp( argv[ 0 ], "children_cond" ) ) {
129                 if ( argc < 2 ) {
130                         Debug( LDAP_DEBUG_TRACE, 
131                                 "<==backsql_db_config (%s line %d): "
132                                 "missing SQL condition "
133                                 "in \"children_cond\" directive\n",
134                                 fname, lineno, 0 );
135                         return 1;
136                 }
137                 ber_str2bv( argv[ 1 ], 0, 1, &si->children_cond );
138                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
139                         "subtree_cond=%s\n", si->children_cond.bv_val, 0, 0 );
140
141         } else if ( !strcasecmp( argv[ 0 ], "oc_query" ) ) {
142                 if ( argc < 2 ) {
143                         Debug( LDAP_DEBUG_TRACE, 
144                                 "<==backsql_db_config (%s line %d): "
145                                 "missing SQL statement "
146                                 "in \"oc_query\" directive\n",
147                                 fname, lineno, 0 );
148                         return 1;
149                 }
150                 si->oc_query = ch_strdup( argv[ 1 ] );
151                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
152                         "oc_query=%s\n", si->oc_query, 0, 0 );
153
154         } else if ( !strcasecmp( argv[ 0 ], "at_query" ) ) {
155                 if ( argc < 2 ) {
156                         Debug( LDAP_DEBUG_TRACE,
157                                 "<==backsql_db_config (%s line %d): "
158                                 "missing SQL statement "
159                                 "in \"at_query\" directive\n",
160                                 fname, lineno, 0 );
161                         return 1;
162                 }
163                 si->at_query = ch_strdup( argv[ 1 ] );
164                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
165                         "at_query=%s\n", si->at_query, 0, 0 );
166
167         } else if ( !strcasecmp( argv[ 0 ], "insentry_query" ) ) {
168                 if ( argc < 2 ) {
169                         Debug( LDAP_DEBUG_TRACE, 
170                                 "<==backsql_db_config (%s line %d): "
171                                 "missing SQL statement "
172                                 "in \"insentry_query\" directive\n",
173                                 fname, lineno, 0 );
174                         return 1;
175                 }
176                 si->insentry_query = ch_strdup( argv[ 1 ] );
177                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
178                         "insentry_query=%s\n", si->insentry_query, 0, 0 );
179
180         } else if ( !strcasecmp( argv[ 0 ], "create_needs_select" ) ) {
181                 if ( argc < 2 ) {
182                         Debug( LDAP_DEBUG_TRACE,
183                                 "<==backsql_db_config (%s line %d): "
184                                 "missing { yes | no }"
185                                 "in \"create_needs_select\" directive\n",
186                                 fname, lineno, 0 );
187                         return 1;
188                 }
189
190                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
191                         si->bsql_flags |= BSQLF_CREATE_NEEDS_SELECT;
192
193                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
194                         si->bsql_flags &= ~BSQLF_CREATE_NEEDS_SELECT;
195
196                 } else {
197                         Debug( LDAP_DEBUG_TRACE,
198                                 "<==backsql_db_config (%s line %d): "
199                                 "\"create_needs_select\" directive arg "
200                                 "must be \"yes\" or \"no\"\n",
201                                 fname, lineno, 0 );
202                         return 1;
203
204                 }
205                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
206                         "create_needs_select =%s\n", 
207                         BACKSQL_CREATE_NEEDS_SELECT( si ) ? "yes" : "no",
208                         0, 0 );
209
210         } else if ( !strcasecmp( argv[ 0 ], "upper_func" ) ) {
211                 if ( argc < 2 ) {
212                         Debug( LDAP_DEBUG_TRACE,
213                                 "<==backsql_db_config (%s line %d): "
214                                 "missing function name "
215                                 "in \"upper_func\" directive\n",
216                                 fname, lineno, 0 );
217                         return 1;
218                 }
219                 ber_str2bv( argv[ 1 ], 0, 1, &si->upper_func );
220                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
221                         "upper_func=%s\n", si->upper_func.bv_val, 0, 0 );
222
223         } else if ( !strcasecmp( argv[ 0 ], "upper_needs_cast" ) ) {
224                 if ( argc < 2 ) {
225                         Debug( LDAP_DEBUG_TRACE,
226                                 "<==backsql_db_config (%s line %d): "
227                                 "missing { yes | no }"
228                                 "in \"upper_needs_cast\" directive\n",
229                                 fname, lineno, 0 );
230                         return 1;
231                 }
232
233                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
234                         si->bsql_flags |= BSQLF_UPPER_NEEDS_CAST;
235
236                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
237                         si->bsql_flags &= ~BSQLF_UPPER_NEEDS_CAST;
238
239                 } else {
240                         Debug( LDAP_DEBUG_TRACE,
241                                 "<==backsql_db_config (%s line %d): "
242                                 "\"upper_needs_cast\" directive arg "
243                                 "must be \"yes\" or \"no\"\n",
244                                 fname, lineno, 0 );
245                         return 1;
246
247                 }
248                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
249                         "upper_needs_cast =%s\n", 
250                         BACKSQL_UPPER_NEEDS_CAST( si ) ? "yes" : "no", 0, 0 );
251
252         } else if ( !strcasecmp( argv[ 0 ], "strcast_func" ) ) {
253                 if ( argc < 2 ) {
254                         Debug( LDAP_DEBUG_TRACE,
255                                 "<==backsql_db_config (%s line %d): "
256                                 "missing function name "
257                                 "in \"strcast_func\" directive\n",
258                                 fname, lineno, 0 );
259                         return 1;
260                 }
261                 ber_str2bv( argv[ 1 ], 0, 1, &si->strcast_func );
262                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
263                         "strcast_func=%s\n", si->strcast_func.bv_val, 0, 0 );
264
265         } else if ( !strcasecmp( argv[ 0 ], "delentry_query" ) ) {
266                 if ( argc < 2 ) {
267                         Debug( LDAP_DEBUG_TRACE,
268                                 "<==backsql_db_config (%s line %d): "
269                                 "missing SQL statement "
270                                 "in \"delentry_query\" directive\n",
271                                 fname, lineno, 0 );
272                         return 1;
273                 }
274                 si->delentry_query = ch_strdup( argv[ 1 ] );
275                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
276                         "delentry_query=%s\n", si->delentry_query, 0, 0 );
277
278         } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
279                 if ( argc < 2 ) {
280                         Debug( LDAP_DEBUG_TRACE,
281                                 "<==backsql_db_config (%s line %d): "
282                                 "missing { yes | no }"
283                                 "in \"has_ldapinfo_dn_ru\" directive\n",
284                                 fname, lineno, 0 );
285                         return 1;
286                 }
287
288                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
289                         si->bsql_flags |= BSQLF_HAS_LDAPINFO_DN_RU;
290                         si->bsql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
291
292                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
293                         si->bsql_flags &= ~BSQLF_HAS_LDAPINFO_DN_RU;
294                         si->bsql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
295
296                 } else {
297                         Debug( LDAP_DEBUG_TRACE,
298                                 "<==backsql_db_config (%s line %d): "
299                                 "\"has_ldapinfo_dn_ru\" directive arg "
300                                 "must be \"yes\" or \"no\"\n",
301                                 fname, lineno, 0 );
302                         return 1;
303
304                 }
305                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
306                         "has_ldapinfo_dn_ru=%s\n", 
307                         BACKSQL_HAS_LDAPINFO_DN_RU( si ) ? "yes" : "no", 0, 0 );
308
309         } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
310                 if ( argc < 2 ) {
311                         Debug( LDAP_DEBUG_TRACE,
312                                 "<==backsql_db_config (%s line %d): "
313                                 "missing { yes | no }"
314                                 "in \"fail_if_no_mapping\" directive\n",
315                                 fname, lineno, 0 );
316                         return 1;
317                 }
318
319                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
320                         si->bsql_flags |= BSQLF_FAIL_IF_NO_MAPPING;
321
322                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
323                         si->bsql_flags &= ~BSQLF_FAIL_IF_NO_MAPPING;
324
325                 } else {
326                         Debug( LDAP_DEBUG_TRACE,
327                                 "<==backsql_db_config (%s line %d): "
328                                 "\"fail_if_no_mapping\" directive arg "
329                                 "must be \"yes\" or \"no\"\n",
330                                 fname, lineno, 0 );
331                         return 1;
332
333                 }
334                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
335                         "fail_if_no_mapping=%s\n", 
336                         BACKSQL_FAIL_IF_NO_MAPPING( si ) ? "yes" : "no", 0, 0 );
337
338         } else {
339                 return SLAP_CONF_UNKNOWN;
340         }
341
342         return 0;
343 }
344
345 #endif /* SLAPD_SQL */
346