]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/config.c
Experimental cruft to propagate valid Operation to SASL callbacks.
[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 <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 ], "oc_query" ) ) {
118                 if ( argc < 2 ) {
119                         Debug( LDAP_DEBUG_TRACE, 
120                                 "<==backsql_db_config (%s line %d): "
121                                 "missing SQL statement "
122                                 "in \"oc_query\" directive\n",
123                                 fname, lineno, 0 );
124                         return 1;
125                 }
126                 si->oc_query = ch_strdup( argv[ 1 ] );
127                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
128                         "oc_query=%s\n", si->oc_query, 0, 0 );
129
130         } else if ( !strcasecmp( argv[ 0 ], "at_query" ) ) {
131                 if ( argc < 2 ) {
132                         Debug( LDAP_DEBUG_TRACE,
133                                 "<==backsql_db_config (%s line %d): "
134                                 "missing SQL statement "
135                                 "in \"at_query\" directive\n",
136                                 fname, lineno, 0 );
137                         return 1;
138                 }
139                 si->at_query = ch_strdup( argv[ 1 ] );
140                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
141                         "at_query=%s\n", si->at_query, 0, 0 );
142
143         } else if ( !strcasecmp( argv[ 0 ], "insentry_query" ) ) {
144                 if ( argc < 2 ) {
145                         Debug( LDAP_DEBUG_TRACE, 
146                                 "<==backsql_db_config (%s line %d): "
147                                 "missing SQL statement "
148                                 "in \"insentry_query\" directive\n",
149                                 fname, lineno, 0 );
150                         return 1;
151                 }
152                 si->insentry_query = ch_strdup( argv[ 1 ] );
153                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
154                         "insentry_query=%s\n", si->insentry_query, 0, 0 );
155
156         } else if ( !strcasecmp( argv[ 0 ], "create_needs_select" ) ) {
157                 if ( argc < 2 ) {
158                         Debug( LDAP_DEBUG_TRACE,
159                                 "<==backsql_db_config (%s line %d): "
160                                 "missing { yes | no }"
161                                 "in \"create_needs_select\" directive\n",
162                                 fname, lineno, 0 );
163                         return 1;
164                 }
165
166                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
167                         si->bsql_flags |= BSQLF_CREATE_NEEDS_SELECT;
168
169                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
170                         si->bsql_flags &= ~BSQLF_CREATE_NEEDS_SELECT;
171
172                 } else {
173                         Debug( LDAP_DEBUG_TRACE,
174                                 "<==backsql_db_config (%s line %d): "
175                                 "\"create_needs_select\" directive arg "
176                                 "must be \"yes\" or \"no\"\n",
177                                 fname, lineno, 0 );
178                         return 1;
179
180                 }
181                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
182                         "create_needs_select =%s\n", 
183                         BACKSQL_CREATE_NEEDS_SELECT( si ) ? "yes" : "no",
184                         0, 0 );
185
186         } else if ( !strcasecmp( argv[ 0 ], "upper_func" ) ) {
187                 if ( argc < 2 ) {
188                         Debug( LDAP_DEBUG_TRACE,
189                                 "<==backsql_db_config (%s line %d): "
190                                 "missing function name "
191                                 "in \"upper_func\" directive\n",
192                                 fname, lineno, 0 );
193                         return 1;
194                 }
195                 ber_str2bv( argv[ 1 ], 0, 1, &si->upper_func );
196                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
197                         "upper_func=%s\n", si->upper_func.bv_val, 0, 0 );
198
199         } else if ( !strcasecmp( argv[ 0 ], "upper_needs_cast" ) ) {
200                 if ( argc < 2 ) {
201                         Debug( LDAP_DEBUG_TRACE,
202                                 "<==backsql_db_config (%s line %d): "
203                                 "missing { yes | no }"
204                                 "in \"upper_needs_cast\" directive\n",
205                                 fname, lineno, 0 );
206                         return 1;
207                 }
208
209                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
210                         si->bsql_flags |= BSQLF_UPPER_NEEDS_CAST;
211
212                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
213                         si->bsql_flags &= ~BSQLF_UPPER_NEEDS_CAST;
214
215                 } else {
216                         Debug( LDAP_DEBUG_TRACE,
217                                 "<==backsql_db_config (%s line %d): "
218                                 "\"upper_needs_cast\" directive arg "
219                                 "must be \"yes\" or \"no\"\n",
220                                 fname, lineno, 0 );
221                         return 1;
222
223                 }
224                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
225                         "upper_needs_cast =%s\n", 
226                         BACKSQL_UPPER_NEEDS_CAST( si ) ? "yes" : "no", 0, 0 );
227
228         } else if ( !strcasecmp( argv[ 0 ], "strcast_func" ) ) {
229                 if ( argc < 2 ) {
230                         Debug( LDAP_DEBUG_TRACE,
231                                 "<==backsql_db_config (%s line %d): "
232                                 "missing function name "
233                                 "in \"strcast_func\" directive\n",
234                                 fname, lineno, 0 );
235                         return 1;
236                 }
237                 ber_str2bv( argv[ 1 ], 0, 1, &si->strcast_func );
238                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
239                         "strcast_func=%s\n", si->strcast_func.bv_val, 0, 0 );
240
241         } else if ( !strcasecmp( argv[ 0 ], "delentry_query" ) ) {
242                 if ( argc < 2 ) {
243                         Debug( LDAP_DEBUG_TRACE,
244                                 "<==backsql_db_config (%s line %d): "
245                                 "missing SQL statement "
246                                 "in \"delentry_query\" directive\n",
247                                 fname, lineno, 0 );
248                         return 1;
249                 }
250                 si->delentry_query = ch_strdup( argv[ 1 ] );
251                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
252                         "delentry_query=%s\n", si->delentry_query, 0, 0 );
253
254         } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
255                 if ( argc < 2 ) {
256                         Debug( LDAP_DEBUG_TRACE,
257                                 "<==backsql_db_config (%s line %d): "
258                                 "missing { yes | no }"
259                                 "in \"has_ldapinfo_dn_ru\" directive\n",
260                                 fname, lineno, 0 );
261                         return 1;
262                 }
263
264                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
265                         si->bsql_flags |= BSQLF_HAS_LDAPINFO_DN_RU;
266                         si->bsql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
267
268                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
269                         si->bsql_flags &= ~BSQLF_HAS_LDAPINFO_DN_RU;
270                         si->bsql_flags |= BSQLF_DONTCHECK_LDAPINFO_DN_RU;
271
272                 } else {
273                         Debug( LDAP_DEBUG_TRACE,
274                                 "<==backsql_db_config (%s line %d): "
275                                 "\"has_ldapinfo_dn_ru\" directive arg "
276                                 "must be \"yes\" or \"no\"\n",
277                                 fname, lineno, 0 );
278                         return 1;
279
280                 }
281                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
282                         "has_ldapinfo_dn_ru=%s\n", 
283                         BACKSQL_HAS_LDAPINFO_DN_RU( si ) ? "yes" : "no", 0, 0 );
284
285         } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
286                 if ( argc < 2 ) {
287                         Debug( LDAP_DEBUG_TRACE,
288                                 "<==backsql_db_config (%s line %d): "
289                                 "missing { yes | no }"
290                                 "in \"fail_if_no_mapping\" directive\n",
291                                 fname, lineno, 0 );
292                         return 1;
293                 }
294
295                 if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
296                         si->bsql_flags |= BSQLF_FAIL_IF_NO_MAPPING;
297
298                 } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
299                         si->bsql_flags &= ~BSQLF_FAIL_IF_NO_MAPPING;
300
301                 } else {
302                         Debug( LDAP_DEBUG_TRACE,
303                                 "<==backsql_db_config (%s line %d): "
304                                 "\"fail_if_no_mapping\" directive arg "
305                                 "must be \"yes\" or \"no\"\n",
306                                 fname, lineno, 0 );
307                         return 1;
308
309                 }
310                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
311                         "fail_if_no_mapping=%s\n", 
312                         BACKSQL_FAIL_IF_NO_MAPPING( si ) ? "yes" : "no", 0, 0 );
313
314         } else {
315                 Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config (%s line %d): "
316                         "unknown directive \"%s\" (ignored)\n",
317                         fname, lineno, argv[ 0 ] );
318         }
319
320         return 0;
321 }
322
323 #endif /* SLAPD_SQL */
324