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