]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/config.c
backport write operation timeouts from back-meta to back-ldap; minor cleanup & silenc...
[openldap] / servers / slapd / back-ldap / config.c
1 /* config.c - ldap backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-2005 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/ctype.h>
30 #include <ac/socket.h>
31
32 #include "slap.h"
33 #include "config.h"
34 #include "back-ldap.h"
35 #include "lutil.h"
36 #include "ldif.h"
37 #undef ldap_debug
38 /* for advanced URL parsing */
39 #include "../../../libraries/libldap/ldap-int.h"
40
41 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
42
43 static ConfigDriver ldap_back_cf_gen;
44
45 enum {
46         LDAP_BACK_CFG_URI = 1,
47         LDAP_BACK_CFG_TLS,
48         LDAP_BACK_CFG_ACL_AUTHCDN,
49         LDAP_BACK_CFG_ACL_PASSWD,
50         LDAP_BACK_CFG_ACL_METHOD,
51         LDAP_BACK_CFG_ACL_BIND,
52         LDAP_BACK_CFG_IDASSERT_MODE,
53         LDAP_BACK_CFG_IDASSERT_AUTHCDN,
54         LDAP_BACK_CFG_IDASSERT_PASSWD,
55         LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
56         LDAP_BACK_CFG_IDASSERT_METHOD,
57         LDAP_BACK_CFG_IDASSERT_BIND,
58         LDAP_BACK_CFG_REBIND,
59         LDAP_BACK_CFG_CHASE,
60         LDAP_BACK_CFG_T_F,
61         LDAP_BACK_CFG_WHOAMI,
62         LDAP_BACK_CFG_TIMEOUT,
63         LDAP_BACK_CFG_REWRITE
64 };
65
66 static ConfigTable ldapcfg[] = {
67         { "uri", "uri", 2, 2, 0,
68                 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_URI,
69                 ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
70                         "NAME 'olcDbURI' "
71                         "DESC 'URI (list) for remote DSA' "
72                         "SYNTAX OMsDirectoryString "
73                         "SINGLE-VALUE )",
74                 NULL, NULL },
75         { "tls", "what", 2, 2, 0,
76                 ARG_MAGIC|LDAP_BACK_CFG_TLS,
77                 ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
78                         "NAME 'olcDbStartTLS' "
79                         "DESC 'StartTLS' "
80                         "SYNTAX OMsDirectoryString "
81                         "SINGLE-VALUE )",
82                 NULL, NULL },
83         { "acl-authcDN", "DN", 2, 2, 0,
84                 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
85                 ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
86                         "NAME 'olcDbACLAuthcDn' "
87                         "DESC 'Remote ACL administrative identity' "
88                         "OBSOLETE "
89                         "SYNTAX OMsDN "
90                         "SINGLE-VALUE )",
91                 NULL, NULL },
92         /* deprecated, will be removed; aliases "acl-authcDN" */
93         { "binddn", "DN", 2, 2, 0,
94                 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
95                 ldap_back_cf_gen, NULL, NULL, NULL },
96         { "acl-passwd", "cred", 2, 2, 0,
97                 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
98                 ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
99                         "NAME 'olcDbACLPasswd' "
100                         "DESC 'Remote ACL administrative identity credentials' "
101                         "OBSOLETE "
102                         "SYNTAX OMsDirectoryString "
103                         "SINGLE-VALUE )",
104                 NULL, NULL },
105         /* deprecated, will be removed; aliases "acl-passwd" */
106         { "bindpw", "cred", 2, 2, 0,
107                 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
108                 ldap_back_cf_gen, NULL, NULL, NULL },
109         /* deprecated, will be removed; aliases "acl-bind" */
110         { "acl-method", "args", 2, 0, 0,
111                 ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
112                 ldap_back_cf_gen, NULL, NULL, NULL },
113         { "acl-bind", "args", 2, 0, 0,
114                 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
115                 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
116                         "NAME 'olcDbACLBind' "
117                         "DESC 'Remote ACL administrative identity auth bind configuration' "
118                         "SYNTAX OMsDirectoryString "
119                         "SINGLE-VALUE )",
120                 NULL, NULL },
121         { "idassert-authcDN", "DN", 2, 2, 0,
122                 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
123                 ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
124                         "NAME 'olcDbIDAssertAuthcDn' "
125                         "DESC 'Remote Identity Assertion administrative identity' "
126                         "OBSOLETE "
127                         "SYNTAX OMsDN "
128                         "SINGLE-VALUE )",
129                 NULL, NULL },
130         /* deprecated, will be removed; partially aliases "idassert-authcDN" */
131         { "proxyauthzdn", "DN", 2, 2, 0,
132                 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
133                 ldap_back_cf_gen, NULL, NULL, NULL },
134         { "idassert-passwd", "cred", 2, 2, 0,
135                 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
136                 ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
137                         "NAME 'olcDbIDAssertPasswd' "
138                         "DESC 'Remote Identity Assertion administrative identity credentials' "
139                         "OBSOLETE "
140                         "SYNTAX OMsDirectoryString "
141                         "SINGLE-VALUE )",
142                 NULL, NULL },
143         /* deprecated, will be removed; partially aliases "idassert-passwd" */
144         { "proxyauthzpw", "cred", 2, 2, 0,
145                 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
146                 ldap_back_cf_gen, NULL, NULL, NULL },
147         { "idassert-bind", "args", 2, 0, 0,
148                 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
149                 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
150                         "NAME 'olcDbIDAssertBind' "
151                         "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
152                         "SYNTAX OMsDirectoryString "
153                         "SINGLE-VALUE )",
154                 NULL, NULL },
155         { "idassert-method", "args", 2, 0, 0,
156                 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
157                 ldap_back_cf_gen, NULL, NULL, NULL },
158         { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
159                 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
160                 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
161                         "NAME 'olcDbIDAssertMode' "
162                         "DESC 'Remote Identity Assertion mode' "
163                         "OBSOLETE "
164                         "SYNTAX OMsDirectoryString "
165                         "SINGLE-VALUE)",
166                 NULL, NULL },
167         { "idassert-authzFrom", "authzRule", 2, 2, 0,
168                 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
169                 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
170                         "NAME 'olcDbIDAssertAuthzFrom' "
171                         "DESC 'Remote Identity Assertion authz rules' "
172                         "SYNTAX OMsDirectoryString "
173                         "X-ORDERED 'VALUES' )",
174                 NULL, NULL },
175         { "rebind-as-user", "NO|yes", 1, 2, 0,
176                 ARG_MAGIC|LDAP_BACK_CFG_REBIND,
177                 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
178                         "NAME 'olcDbRebindAsUser' "
179                         "DESC 'Rebind as user' "
180                         "SYNTAX OMsDirectoryString "
181                         "SINGLE-VALUE )",
182                 NULL, NULL },
183         { "chase-referrals", "YES|no", 2, 2, 0,
184                 ARG_MAGIC|LDAP_BACK_CFG_CHASE,
185                 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
186                         "NAME 'olcDbChaseReferrals' "
187                         "DESC 'Chase referrals' "
188                         "SYNTAX OMsDirectoryString "
189                         "SINGLE-VALUE )",
190                 NULL, NULL },
191         { "t-f-support", "NO|yes|discover", 2, 2, 0,
192                 ARG_MAGIC|LDAP_BACK_CFG_T_F,
193                 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
194                         "NAME 'olcDbTFSupport' "
195                         "DESC 'Absolute filters support' "
196                         "SYNTAX OMsDirectoryString "
197                         "SINGLE-VALUE )",
198                 NULL, NULL },
199         { "proxy-whoami", "NO|yes", 1, 2, 0,
200                 ARG_MAGIC|LDAP_BACK_CFG_WHOAMI,
201                 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
202                         "NAME 'olcDbProxyWhoAmI' "
203                         "DESC 'Proxy whoAmI exop' "
204                         "SYNTAX OMsDirectoryString "
205                         "SINGLE-VALUE )",
206                 NULL, NULL },
207         { "timeout", "timeout", 0, 2, 0,
208                 ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
209                 ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
210                         "NAME 'olcDbTimeout' "
211                         "DESC 'Per-operation timeouts' "
212                         "SYNTAX OMsDirectoryString "
213                         "SINGLE-VALUE )",
214                 NULL, NULL },
215         { "suffixmassage", "[virtual]> <real", 2, 3, 0,
216                 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
217                 ldap_back_cf_gen, NULL, NULL, NULL },
218         { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
219                 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
220                 ldap_back_cf_gen, NULL, NULL, NULL },
221         { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
222                 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
223                 ldap_back_cf_gen, NULL, NULL, NULL },
224         { NULL, NULL, 0, 0, 0, ARG_IGNORED,
225                 NULL, NULL, NULL, NULL }
226 };
227
228 static ConfigOCs ldapocs[] = {
229         { "( OLcfgDbOc:3.1 "
230                 "NAME 'olcLDAPConfig' "
231                 "DESC 'LDAP backend configuration' "
232                 "SUP olcDatabaseConfig "
233                 "MUST olcDbURI "
234                 "MAY ( olcDbStartTLS "
235                         "$ olcDbACLAuthcDn "
236                         "$ olcDbACLPasswd "
237                         "$ olcDbACLBind "
238                         "$ olcDbIDAssertAuthcDn "
239                         "$ olcDbIDAssertPasswd "
240                         "$ olcDbIDAssertBind "
241                         "$ olcDbIDAssertMode "
242                         "$ olcDbIDAssertAuthzFrom "
243                         "$ olcDbRebindAsUser "
244                         "$ olcDbChaseReferrals "
245                         "$ olcDbTFSupport "
246                         "$ olcDbProxyWhoAmI "
247                         "$ olcDbTimeout "
248                 ") )",
249                         Cft_Database, ldapcfg},
250         { NULL, 0, NULL }
251 };
252
253 #define LDAP_BACK_C_NO                  (0x0U)
254 #define LDAP_BACK_C_YES                 (0x1U)
255 static slap_verbmasks yn_mode[] = {
256         { BER_BVC( "yes" ),             LDAP_BACK_C_YES},
257         { BER_BVC( "no" ),              LDAP_BACK_C_NO },
258         { BER_BVNULL,                   0 }
259 };
260
261 static slap_verbmasks idassert_mode[] = {
262         { BER_BVC("self"),              LDAP_BACK_IDASSERT_SELF },
263         { BER_BVC("anonymous"),         LDAP_BACK_IDASSERT_ANONYMOUS },
264         { BER_BVC("none"),              LDAP_BACK_IDASSERT_NOASSERT },
265         { BER_BVC("legacy"),            LDAP_BACK_IDASSERT_LEGACY },
266         { BER_BVNULL,                   0 }
267 };
268
269 static slap_verbmasks tls_mode[] = {
270         { BER_BVC( "propagate" ),       LDAP_BACK_F_TLS_PROPAGATE_MASK },
271         { BER_BVC( "try-propagate" ),   LDAP_BACK_F_PROPAGATE_TLS },
272         { BER_BVC( "start" ),           LDAP_BACK_F_TLS_USE_MASK },
273         { BER_BVC( "try-start" ),       LDAP_BACK_F_USE_TLS },
274         { BER_BVC( "none" ),            LDAP_BACK_C_NO },
275         { BER_BVNULL,                   0 }
276 };
277
278 static slap_verbmasks t_f_mode[] = {
279         { BER_BVC( "yes" ),             LDAP_BACK_F_SUPPORT_T_F },
280         { BER_BVC( "discover" ),        LDAP_BACK_F_SUPPORT_T_F_DISCOVER },
281         { BER_BVC( "no" ),              LDAP_BACK_C_NO },
282         { BER_BVNULL,                   0 }
283 };
284
285 static slap_cf_aux_table timeout_table[] = {
286         { BER_BVC("add="), 0 * sizeof( time_t ), 'u', 0, NULL },
287         { BER_BVC("delete="), 1 * sizeof( time_t ), 'u', 0, NULL },
288         { BER_BVC("modify="), 2 * sizeof( time_t ), 'u', 0, NULL },
289         { BER_BVC("modrdn="), 3 * sizeof( time_t ), 'u', 0, NULL },
290         { BER_BVNULL, 0, 0, 0, NULL }
291 };
292
293 static int
294 ldap_back_cf_gen( ConfigArgs *c )
295 {
296         struct ldapinfo *li = ( struct ldapinfo * )c->be->be_private;
297         int             rc;
298         int             i;
299
300         if ( c->op == SLAP_CONFIG_EMIT ) {
301                 struct berval   bv = BER_BVNULL;
302                 rc = 0;
303
304                 switch( c->type ) {
305                 case LDAP_BACK_CFG_URI:
306                         if ( li->url != NULL ) {
307                                 c->value_string = ch_strdup( li->url );
308
309                         } else {
310                                 rc = 1;
311                         }
312                         break;
313
314                 case LDAP_BACK_CFG_TLS:
315                         enum_to_verb( tls_mode, ( li->flags & LDAP_BACK_F_TLS_MASK ), &bv );
316                         if ( BER_BVISNULL( &bv ) ) {
317                                 /* there's something wrong... */
318                                 assert( 0 );
319                                 rc = 1;
320
321                         } else {
322                                 value_add_one( &c->rvalue_vals, &bv );
323                         }
324                         break;
325
326                 case LDAP_BACK_CFG_ACL_AUTHCDN:
327                 case LDAP_BACK_CFG_ACL_PASSWD:
328                 case LDAP_BACK_CFG_ACL_METHOD:
329                         /* handled by LDAP_BACK_CFG_ACL_BIND */
330                         rc = 1;
331                         break;
332
333                 case LDAP_BACK_CFG_ACL_BIND: {
334                         int     i;
335
336                         bindconf_unparse( &li->acl_sb, &bv );
337
338                         for ( i = 0; isspace( bv.bv_val[ i ] ); i++ )
339                                 /* count spaces */ ;
340
341                         if ( i ) {
342                                 bv.bv_len -= i;
343                                 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
344                                         bv.bv_len + 1 );
345                         }
346
347                         ber_bvarray_add( &c->rvalue_vals, &bv );
348                         break;
349                 }
350
351                 case LDAP_BACK_CFG_IDASSERT_MODE:
352                 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
353                 case LDAP_BACK_CFG_IDASSERT_PASSWD:
354                 case LDAP_BACK_CFG_IDASSERT_METHOD:
355                         /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
356                         rc = 1;
357                         break;
358
359                 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
360                         int             i;
361
362                         if ( li->idassert_authz == NULL ) {
363                                 rc = 1;
364                                 break;
365                         }
366
367                         for ( i = 0; !BER_BVISNULL( &li->idassert_authz[ i ] ); i++ )
368                         {
369                                 value_add_one( &c->rvalue_vals, &li->idassert_authz[ i ] );
370                         }
371                         break;
372                 }
373
374                 case LDAP_BACK_CFG_IDASSERT_BIND: {
375                         int             i;
376                         struct berval   bc = BER_BVNULL;
377                         char            *ptr;
378
379                         if ( li->idassert_authmethod != LDAP_AUTH_NONE ) {
380                                 ber_len_t       len;
381
382                                 switch ( li->idassert_mode ) {
383                                 case LDAP_BACK_IDASSERT_OTHERID:
384                                 case LDAP_BACK_IDASSERT_OTHERDN:
385                                         break;
386
387                                 default: {
388                                         struct berval   mode = BER_BVNULL;
389
390                                         enum_to_verb( idassert_mode, li->idassert_mode, &mode );
391                                         if ( BER_BVISNULL( &mode ) ) {
392                                                 /* there's something wrong... */
393                                                 assert( 0 );
394                                                 rc = 1;
395         
396                                         } else {
397                                                 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
398                                                 bv.bv_val = ch_malloc( bv.bv_len + 1 );
399
400                                                 ptr = lutil_strcopy( bv.bv_val, "mode=" );
401                                                 ptr = lutil_strcopy( ptr, mode.bv_val );
402                                         }
403                                         break;
404                                 }
405                                 }
406
407                                 if ( li->idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
408                                         len = bv.bv_len + STRLENOF( "authz=native" );
409
410                                         if ( !BER_BVISEMPTY( &bv ) ) {
411                                                 len += STRLENOF( " " );
412                                         }
413
414                                         bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
415
416                                         ptr = &bv.bv_val[ bv.bv_len ];
417
418                                         if ( !BER_BVISEMPTY( &bv ) ) {
419                                                 ptr = lutil_strcopy( ptr, " " );
420                                         }
421
422                                         (void)lutil_strcopy( ptr, "authz=native" );
423                                 }
424
425                                 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override" );
426                                 /* flags */
427                                 if ( !BER_BVISEMPTY( &bv ) ) {
428                                         len += STRLENOF( " " );
429                                 }
430
431                                 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
432
433                                 ptr = &bv.bv_val[ bv.bv_len ];
434
435                                 if ( !BER_BVISEMPTY( &bv ) ) {
436                                         ptr = lutil_strcopy( ptr, " " );
437                                 }
438
439                                 ptr = lutil_strcopy( ptr, "flags=" );
440
441                                 if ( li->idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
442                                         ptr = lutil_strcopy( ptr, "prescriptive" );
443                                 } else {
444                                         ptr = lutil_strcopy( ptr, "non-prescriptive" );
445                                 }
446
447                                 if ( li->idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
448                                         ptr = lutil_strcopy( ptr, ",override" );
449                                 }
450
451                                 bv.bv_len = ( ptr - bv.bv_val );
452                                 /* end-of-flags */
453                         }
454
455                         bindconf_unparse( &li->idassert_sb, &bc );
456
457                         if ( !BER_BVISNULL( &bv ) ) {
458                                 ber_len_t       len = bv.bv_len + bc.bv_len;
459
460                                 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
461
462                                 assert( bc.bv_val[ 0 ] == ' ' );
463
464                                 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
465                                 free( bc.bv_val );
466                                 bv.bv_len = ptr - bv.bv_val;
467
468                         } else {
469                                 for ( i = 0; isspace( bc.bv_val[ i ] ); i++ )
470                                         /* count spaces */ ;
471
472                                 if ( i ) {
473                                         bc.bv_len -= i;
474                                         AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
475                                 }
476
477                                 bv = bc;
478                         }
479                         
480                         ber_bvarray_add( &c->rvalue_vals, &bv );
481
482                         break;
483                 }
484
485                 case LDAP_BACK_CFG_REBIND:
486                         enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_SAVECRED ) == LDAP_BACK_F_SAVECRED ), &bv );
487                         if ( BER_BVISNULL( &bv ) ) {
488                                 /* there's something wrong... */
489                                 assert( 0 );
490                                 rc = 1;
491
492                         } else {
493                                 value_add_one( &c->rvalue_vals, &bv );
494                         }
495                         break;
496
497                 case LDAP_BACK_CFG_CHASE:
498                         enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_CHASE_REFERRALS ) == LDAP_BACK_F_CHASE_REFERRALS ), &bv );
499                         if ( BER_BVISNULL( &bv ) ) {
500                                 /* there's something wrong... */
501                                 assert( 0 );
502                                 rc = 1;
503
504                         } else {
505                                 value_add_one( &c->rvalue_vals, &bv );
506                         }
507                         break;
508
509                 case LDAP_BACK_CFG_T_F:
510                         enum_to_verb( t_f_mode, ( ( li->flags & LDAP_BACK_F_SUPPORT_T_F_MASK ) == LDAP_BACK_F_SUPPORT_T_F_MASK ), &bv );
511                         if ( BER_BVISNULL( &bv ) ) {
512                                 /* there's something wrong... */
513                                 assert( 0 );
514                                 rc = 1;
515
516                         } else {
517                                 value_add_one( &c->rvalue_vals, &bv );
518                         }
519                         break;
520
521                 case LDAP_BACK_CFG_WHOAMI:
522                         enum_to_verb( yn_mode, ( ( li->flags & LDAP_BACK_F_PROXY_WHOAMI ) == LDAP_BACK_F_PROXY_WHOAMI ), &bv );
523                         if ( BER_BVISNULL( &bv ) ) {
524                                 /* there's something wrong... */
525                                 assert( 0 );
526                                 rc = 1;
527
528                         } else {
529                                 value_add_one( &c->rvalue_vals, &bv );
530                         }
531                         break;
532
533                 case LDAP_BACK_CFG_TIMEOUT:
534                         BER_BVZERO( &bv );
535
536                         slap_cf_aux_table_unparse( li->timeout, &bv, timeout_table );
537
538                         if ( !BER_BVISNULL( &bv ) ) {   
539                                 for ( i = 0; isspace( bv.bv_val[ i ] ); i++ )
540                                         /* count spaces */ ;
541
542                                 if ( i ) {
543                                         bv.bv_len -= i;
544                                         AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
545                                                 bv.bv_len + 1 );
546                                 }
547
548                                 ber_bvarray_add( &c->rvalue_vals, &bv );
549                         }
550                         break;
551
552                 default:
553                         /* FIXME: we need to handle all... */
554                         assert( 0 );
555                         break;
556                 }
557                 return rc;
558
559         } else if ( c->op == LDAP_MOD_DELETE ) {
560                 rc = 0;
561                 switch( c->type ) {
562                 case LDAP_BACK_CFG_URI:
563                         if ( li->url != NULL ) {
564                                 ch_free( li->url );
565                                 li->url = NULL;
566                         }
567
568                         if ( li->lud != NULL ) {
569                                 ldap_free_urllist( li->lud );
570                                 li->lud = NULL;
571                         }
572                         
573                         /* better cleanup the cached connections... */
574                         /* NOTE: don't worry about locking: if we got here,
575                          * other threads are suspended. */
576                         avl_free( li->conntree, ldap_back_conn_free );
577                         li->conntree = NULL;
578                         
579                         break;
580
581                 case LDAP_BACK_CFG_TLS:
582                         rc = 1;
583                         break;
584
585                 case LDAP_BACK_CFG_ACL_AUTHCDN:
586                 case LDAP_BACK_CFG_ACL_PASSWD:
587                 case LDAP_BACK_CFG_ACL_METHOD:
588                         /* handled by LDAP_BACK_CFG_ACL_BIND */
589                         rc = 1;
590                         break;
591
592                 case LDAP_BACK_CFG_ACL_BIND:
593                         bindconf_free( &li->acl_sb );
594                         break;
595
596                 case LDAP_BACK_CFG_IDASSERT_MODE:
597                 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
598                 case LDAP_BACK_CFG_IDASSERT_PASSWD:
599                 case LDAP_BACK_CFG_IDASSERT_METHOD:
600                         /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
601                         rc = 1;
602                         break;
603
604                 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
605                         if ( li->idassert_authz != NULL ) {
606                                 ber_bvarray_free( li->idassert_authz );
607                                 li->idassert_authz = NULL;
608                         }
609                         break;
610
611                 case LDAP_BACK_CFG_IDASSERT_BIND:
612                         bindconf_free( &li->idassert_sb );
613                         break;
614
615                 case LDAP_BACK_CFG_REBIND:
616                 case LDAP_BACK_CFG_CHASE:
617                 case LDAP_BACK_CFG_T_F:
618                 case LDAP_BACK_CFG_WHOAMI:
619                         rc = 1;
620                         break;
621
622                 case LDAP_BACK_CFG_TIMEOUT:
623                         for ( i = 0; i < LDAP_BACK_OP_LAST; i++ ) {
624                                 li->timeout[ i ] = 0;
625                         }
626                         break;
627
628                 default:
629                         /* FIXME: we need to handle all... */
630                         assert( 0 );
631                         break;
632                 }
633                 return rc;
634
635         }
636
637         switch( c->type ) {
638         case LDAP_BACK_CFG_URI: {
639                 LDAPURLDesc     *tmpludp;
640 #if 0
641                 char            **urllist;
642 #endif
643                 int             urlrc, i;
644
645                 if ( c->argc != 2 ) {
646                         fprintf( stderr, "%s: line %d: "
647                                         "missing uri "
648                                         "in \"uri <uri>\" line\n",
649                                         c->fname, c->lineno );
650                         return 1;
651                 }
652
653                 if ( li->url != NULL ) {
654                         ch_free( li->url );
655                 }
656
657                 if ( li->lud != NULL ) {
658                         ldap_free_urllist( li->lud );
659                 }
660
661 #if 0
662                 /* PARANOID: DN and more are not required nor allowed */
663                 urlrc = ldap_url_parselist_ext( &li->lud, c->value_string, "\t" );
664 #else
665                 urlrc = ldap_url_parselist( &li->lud, c->value_string );
666 #endif
667                 if ( urlrc != LDAP_URL_SUCCESS ) {
668                         char    *why;
669
670                         switch ( urlrc ) {
671                         case LDAP_URL_ERR_MEM:
672                                 why = "no memory";
673                                 break;
674                         case LDAP_URL_ERR_PARAM:
675                                 why = "parameter is bad";
676                                 break;
677                         case LDAP_URL_ERR_BADSCHEME:
678                                 why = "URL doesn't begin with \"[c]ldap[si]://\"";
679                                 break;
680                         case LDAP_URL_ERR_BADENCLOSURE:
681                                 why = "URL is missing trailing \">\"";
682                                 break;
683                         case LDAP_URL_ERR_BADURL:
684                                 why = "URL is bad";
685                         case LDAP_URL_ERR_BADHOST:
686                                 why = "host/port is bad";
687                                 break;
688                         case LDAP_URL_ERR_BADATTRS:
689                                 why = "bad (or missing) attributes";
690                                 break;
691                         case LDAP_URL_ERR_BADSCOPE:
692                                 why = "scope string is invalid (or missing)";
693                                 break;
694                         case LDAP_URL_ERR_BADFILTER:
695                                 why = "bad or missing filter";
696                                 break;
697                         case LDAP_URL_ERR_BADEXTS:
698                                 why = "bad or missing extensions";
699                                 break;
700                         default:
701                                 why = "unknown reason";
702                                 break;
703                         }
704                         fprintf( stderr, "%s: line %d: "
705                                         "unable to parse uri \"%s\" "
706                                         "in \"uri <uri>\" line: %s\n",
707                                         c->fname, c->lineno, c->value_string, why );
708                         return 1;
709                 }
710
711                 for ( i = 0, tmpludp = li->lud;
712                                 tmpludp;
713                                 i++, tmpludp = tmpludp->lud_next )
714                 {
715                         if ( ( tmpludp->lud_dn != NULL
716                                                 && tmpludp->lud_dn[0] != '\0' )
717                                         || tmpludp->lud_attrs != NULL
718                                         /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
719                                         || tmpludp->lud_filter != NULL
720                                         || tmpludp->lud_exts != NULL )
721                         {
722                                 fprintf( stderr, "%s: line %d: "
723                                                 "warning, only protocol, "
724                                                 "host and port allowed "
725                                                 "in \"uri <uri>\" statement "
726                                                 "for uri #%d of \"%s\"\n",
727                                                 c->fname, c->lineno, i, c->value_string );
728                         }
729                 }
730
731 #if 0
732                 for ( i = 0, tmpludp = li->lud;
733                                 tmpludp;
734                                 i++, tmpludp = tmpludp->lud_next )
735                         /* just count */
736                         ;
737                 urllist = ch_calloc( sizeof( char * ), i + 1 );
738
739                 for ( i = 0, tmpludp = li->lud;
740                                 tmpludp;
741                                 i++, tmpludp = tmpludp->lud_next )
742                 {
743                         LDAPURLDesc     tmplud;
744                         ber_len_t       oldlen = 0, len;
745
746                         tmplud = *tmpludp;
747                         tmplud.lud_dn = "";
748                         tmplud.lud_attrs = NULL;
749                         tmplud.lud_filter = NULL;
750                         if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
751                                 tmplud.lud_exts = NULL;
752                                 tmplud.lud_crit_exts = 0;
753                         }
754
755                         urllist[ i ]  = ldap_url_desc2str( &tmplud );
756
757                         if ( urllist[ i ] == NULL ) {
758                                 fprintf( stderr, "%s: line %d: "
759                                         "unable to rebuild uri "
760                                         "in \"uri <uri>\" statement "
761                                         "for \"%s\"\n",
762                                         c->fname, c->lineno, argv[ 1 ] );
763                                 return 1;
764                         }
765                 }
766
767                 li->url = ldap_charray2str( urllist, " " );
768                 ldap_charray_free( urllist );
769 #else
770                 li->url = c->value_string;
771                 c->value_string = NULL;
772 #endif
773                 break;
774         }
775
776         case LDAP_BACK_CFG_TLS:
777                 i = verb_to_mask( c->argv[1], tls_mode );
778                 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
779                         return 1;
780                 }
781                 li->flags &= ~LDAP_BACK_F_TLS_MASK;
782                 li->flags |= tls_mode[i].mask;
783                 break;
784
785         case LDAP_BACK_CFG_ACL_AUTHCDN:
786                 switch ( li->acl_authmethod ) {
787                 case LDAP_AUTH_NONE:
788                         li->acl_authmethod = LDAP_AUTH_SIMPLE;
789                         break;
790
791                 case LDAP_AUTH_SIMPLE:
792                         break;
793
794                 default:
795                         fprintf( stderr, "%s: line %d: "
796                                 "\"acl-authcDN <DN>\" incompatible "
797                                 "with auth method %d.",
798                                 c->fname, c->lineno, li->acl_authmethod );
799                         return 1;
800                 }
801                 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
802                         free( li->acl_authcDN.bv_val );
803                 }
804                 ber_memfree_x( c->value_dn.bv_val, NULL );
805                 li->acl_authcDN = c->value_ndn;
806                 BER_BVZERO( &c->value_dn );
807                 BER_BVZERO( &c->value_ndn );
808                 break;
809
810         case LDAP_BACK_CFG_ACL_PASSWD:
811                 switch ( li->acl_authmethod ) {
812                 case LDAP_AUTH_NONE:
813                         li->acl_authmethod = LDAP_AUTH_SIMPLE;
814                         break;
815
816                 case LDAP_AUTH_SIMPLE:
817                         break;
818
819                 default:
820                         fprintf( stderr, "%s: line %d: "
821                                 "\"acl-passwd <cred>\" incompatible "
822                                 "with auth method %d.",
823                                 c->fname, c->lineno, li->acl_authmethod );
824                         return 1;
825                 }
826                 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
827                         free( li->acl_passwd.bv_val );
828                 }
829                 ber_str2bv( c->argv[ 1 ], 0, 1, &li->acl_passwd );
830                 break;
831
832         case LDAP_BACK_CFG_ACL_METHOD:
833         case LDAP_BACK_CFG_ACL_BIND:
834                 for ( i = 1; i < c->argc; i++ ) {
835                         if ( bindconf_parse( c->argv[ i ], &li->acl_sb ) ) {
836                                 return 1;
837                         }
838                 }
839                 break;
840
841         case LDAP_BACK_CFG_IDASSERT_MODE:
842                 i = verb_to_mask( c->argv[1], idassert_mode );
843                 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
844                         if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
845                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
846                                 ber_str2bv( c->argv[1], 0, 1, &li->idassert_authzID );
847                                 li->idassert_authzID.bv_val[ 0 ] = 'u';
848                                 
849                         } else {
850                                 struct berval   id, ndn;
851
852                                 ber_str2bv( c->argv[1], 0, 0, &id );
853
854                                 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
855                                         id.bv_val += STRLENOF( "dn:" );
856                                         id.bv_len -= STRLENOF( "dn:" );
857                                 }
858
859                                 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
860                                 if ( rc != LDAP_SUCCESS ) {
861                                         Debug( LDAP_DEBUG_ANY,
862                                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
863                                                 c->fname, c->lineno, c->argv[1] );
864                                         return 1;
865                                 }
866
867                                 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
868                                 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
869                                 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
870                                 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
871                                 ch_free( ndn.bv_val );
872
873                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
874                         }
875
876                 } else {
877                         li->idassert_mode = idassert_mode[i].mask;
878                 }
879
880                 if ( c->argc > 2 ) {
881                         int     i;
882
883                         for ( i = 2; i < c->argc; i++ ) {
884                                 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
885                                         li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
886
887                                 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
888                                         li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
889
890                                 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
891                                         li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
892
893                                 } else {
894                                         Debug( LDAP_DEBUG_ANY,
895                                                 "%s: line %d: unknown flag #%d "
896                                                 "in \"idassert-mode <args> "
897                                                 "[<flags>]\" line.\n",
898                                                 c->fname, c->lineno, i - 2 );
899                                         return 1;
900                                 }
901                         }
902                 }
903                 break;
904
905         case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
906                 switch ( li->idassert_authmethod ) {
907                 case LDAP_AUTH_NONE:
908                         li->idassert_authmethod = LDAP_AUTH_SIMPLE;
909                         break;
910
911                 case LDAP_AUTH_SIMPLE:
912                         break;
913
914                 default:
915                         fprintf( stderr, "%s: line %d: "
916                                 "\"idassert-authcDN <DN>\" incompatible "
917                                 "with auth method %d.",
918                                 c->fname, c->lineno, li->idassert_authmethod );
919                         return 1;
920                 }
921                 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
922                         free( li->idassert_authcDN.bv_val );
923                 }
924                 ber_memfree_x( c->value_dn.bv_val, NULL );
925                 li->idassert_authcDN = c->value_ndn;
926                 BER_BVZERO( &c->value_dn );
927                 BER_BVZERO( &c->value_ndn );
928                 break;
929
930         case LDAP_BACK_CFG_IDASSERT_PASSWD:
931                 switch ( li->idassert_authmethod ) {
932                 case LDAP_AUTH_NONE:
933                         li->idassert_authmethod = LDAP_AUTH_SIMPLE;
934                         break;
935
936                 case LDAP_AUTH_SIMPLE:
937                         break;
938
939                 default:
940                         fprintf( stderr, "%s: line %d: "
941                                 "\"idassert-passwd <cred>\" incompatible "
942                                 "with auth method %d.",
943                                 c->fname, c->lineno, li->idassert_authmethod );
944                         return 1;
945                 }
946                 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
947                         free( li->idassert_passwd.bv_val );
948                 }
949                 ber_str2bv( c->argv[ 1 ], 0, 1, &li->idassert_passwd );
950                 break;
951
952         case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
953                 struct berval   bv;
954 #ifdef SLAP_AUTHZ_SYNTAX
955                 struct berval   in;
956                 int             rc;
957
958                 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
959                 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
960                 if ( rc != LDAP_SUCCESS ) {
961                         fprintf( stderr, "%s: %d: "
962                                 "\"idassert-authzFrom <authz>\": "
963                                 "invalid syntax.\n",
964                                 c->fname, c->lineno );
965                         return 1;
966                 }
967 #else /* !SLAP_AUTHZ_SYNTAX */
968                 ber_str2bv( c->argv[ 1 ], 0, 1, &bv );
969 #endif /* !SLAP_AUTHZ_SYNTAX */
970                 ber_bvarray_add( &li->idassert_authz, &bv );
971                 } break;
972
973         case LDAP_BACK_CFG_IDASSERT_METHOD:
974                 /* no longer supported */
975                 fprintf( stderr, "%s: %d: "
976                         "\"idassert-method <args>\": "
977                         "no longer supported; use \"idassert-bind\".\n",
978                         c->fname, c->lineno );
979                 return 1;
980
981         case LDAP_BACK_CFG_IDASSERT_BIND:
982                 for ( i = 1; i < c->argc; i++ ) {
983                         if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
984                                 char    *argvi = c->argv[ i ] + STRLENOF( "mode=" );
985                                 int     j;
986
987                                 j = verb_to_mask( argvi, idassert_mode );
988                                 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
989                                         fprintf( stderr, "%s: %d: "
990                                                 "\"idassert-bind <args>\": "
991                                                 "unknown mode \"%s\".\n",
992                                                 c->fname, c->lineno, argvi );
993                                         return 1;
994                                 }
995
996                                 li->idassert_mode = idassert_mode[ j ].mask;
997
998                         } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
999                                 char    *argvi = c->argv[ i ] + STRLENOF( "authz=" );
1000
1001                                 if ( strcasecmp( argvi, "native" ) == 0 ) {
1002                                         if ( li->idassert_authmethod != LDAP_AUTH_SASL ) {
1003                                                 fprintf( stderr, "%s: %d: "
1004                                                         "\"idassert-bind <args>\": "
1005                                                         "authz=\"native\" incompatible "
1006                                                         "with auth method.\n",
1007                                                         c->fname, c->lineno );
1008                                                 return 1;
1009                                         }
1010                                         li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1011
1012                                 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
1013                                         li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1014
1015                                 } else {
1016                                         fprintf( stderr, "%s: %d: "
1017                                                 "\"idassert-bind <args>\": "
1018                                                 "unknown authz \"%s\".\n",
1019                                                 c->fname, c->lineno, argvi );
1020                                         return 1;
1021                                 }
1022
1023                         } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
1024                                 char    *argvi = c->argv[ i ] + STRLENOF( "flags=" );
1025                                 char    **flags = ldap_str2charray( argvi, "," );
1026                                 int     j;
1027
1028                                 if ( flags == NULL ) {
1029                                         fprintf( stderr, "%s: %d: "
1030                                                 "\"idassert-bind <args>\": "
1031                                                 "unable to parse flags \"%s\".\n",
1032                                                 c->fname, c->lineno, argvi );
1033                                         return 1;
1034                                 }
1035
1036                                 for ( j = 0; flags[ j ] != NULL; j++ ) {
1037                                         if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
1038                                                 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1039
1040                                         } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
1041                                                 li->idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1042
1043                                         } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
1044                                                 li->idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1045
1046                                         } else {
1047                                                 fprintf( stderr, "%s: %d: "
1048                                                         "\"idassert-bind <args>\": "
1049                                                         "unknown flag \"%s\".\n",
1050                                                         c->fname, c->lineno, flags[ j ] );
1051                                                 return 1;
1052                                         }
1053                                 }
1054
1055                                 ldap_charray_free( flags );
1056
1057                         } else if ( bindconf_parse( c->argv[ i ], &li->idassert_sb ) ) {
1058                                 return 1;
1059                         }
1060                 }
1061                 break;
1062
1063         case LDAP_BACK_CFG_REBIND: {
1064                 int     dorebind = 0;
1065
1066                 if ( c->argc == 1 ) {
1067                         /* legacy */
1068                         dorebind = 1;
1069
1070                 } else {
1071                         i = verb_to_mask( c->argv[1], yn_mode );
1072                         if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1073                                 return 1;
1074                         }
1075                         if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1076                                 dorebind = 1;
1077                         }
1078                 }
1079
1080                 if ( dorebind ) {
1081                         li->flags |= LDAP_BACK_F_SAVECRED;
1082
1083                 } else {
1084                         li->flags &= ~LDAP_BACK_F_SAVECRED;
1085                 }
1086                 } break;
1087
1088         case LDAP_BACK_CFG_CHASE: {
1089                 int     dochase = 0;
1090
1091                 if ( c->argc == 1 ) {
1092                         /* legacy */
1093                         dochase = 1;
1094
1095                 } else {
1096                         i = verb_to_mask( c->argv[1], yn_mode );
1097                         if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1098                                 return 1;
1099                         }
1100                         if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1101                                 dochase = 1;
1102                         }
1103                 }
1104
1105                 if ( dochase ) {
1106                         li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1107
1108                 } else {
1109                         li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1110                 }
1111                 } break;
1112
1113         case LDAP_BACK_CFG_T_F:
1114                 i = verb_to_mask( c->argv[1], t_f_mode );
1115                 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1116                         return 1;
1117                 }
1118                 li->flags &= ~LDAP_BACK_F_SUPPORT_T_F_MASK;
1119                 li->flags |= t_f_mode[i].mask;
1120                 break;
1121
1122         case LDAP_BACK_CFG_WHOAMI: {
1123                 int     dowhoami = 0;
1124
1125                 if ( c->argc == 1 ) {
1126                         /* legacy */
1127                         dowhoami = 1;
1128
1129                 } else {
1130                         i = verb_to_mask( c->argv[1], yn_mode );
1131                         if ( BER_BVISNULL( &yn_mode[i].word ) ) {
1132                                 return 1;
1133                         }
1134                         if ( yn_mode[i].mask & LDAP_BACK_C_YES ) {
1135                                 dowhoami = 1;
1136                         }
1137                 }
1138
1139                 if ( dowhoami ) {
1140                         li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1141
1142                         load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1143                                         0, ldap_back_exop_whoami );
1144
1145                 } else {
1146                         li->flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1147                 }
1148                 } break;
1149
1150         case LDAP_BACK_CFG_TIMEOUT:
1151                 if ( c->argc < 2 ) {
1152                         return 1;
1153                 }
1154
1155                 for ( i = 1; i < c->argc; i++ ) {
1156                         if ( isdigit( c->argv[ i ][ 0 ] ) ) {
1157                                 char            *next;
1158                                 int             j;
1159                                 unsigned        u;
1160
1161                                 u = strtoul( c->argv[ i ], &next, 0 );
1162                                 if ( next == c->argv[ i ] || next[ 0 ] != '\0' ) {
1163                                         return 1;
1164                                 }
1165
1166                                 for ( j = 0; j < LDAP_BACK_OP_LAST; j++ ) {
1167                                         li->timeout[ j ] = u;
1168                                 }
1169
1170                                 continue;
1171                         }
1172
1173                         if ( slap_cf_aux_table_parse( c->argv[ i ], li->timeout, timeout_table, "slapd-ldap timeout" ) ) {
1174                                 return 1;
1175                         }
1176                 }
1177                 break;
1178
1179         case LDAP_BACK_CFG_REWRITE:
1180                 fprintf( stderr, "%s: line %d: "
1181                         "rewrite/remap capabilities have been moved "
1182                         "to the \"rwm\" overlay; see slapo-rwm(5) "
1183                         "for details (hint: add \"overlay rwm\" "
1184                         "and prefix all directives with \"rwm-\").\n",
1185                         c->fname, c->lineno );
1186                 return 1;
1187                 
1188         default:
1189                 /* FIXME: try to catch inconsistencies */
1190                 assert( 0 );
1191                 break;
1192         }
1193
1194         return 0;
1195 }
1196
1197 int
1198 ldap_back_init_cf( BackendInfo *bi )
1199 {
1200         int                     rc;
1201         AttributeDescription    *ad = NULL;
1202         const char              *text;
1203
1204         bi->bi_cf_ocs = ldapocs;
1205
1206         rc = config_register_schema( ldapcfg, ldapocs );
1207         if ( rc ) {
1208                 return rc;
1209         }
1210
1211         /* setup olcDbAclPasswd and olcDbIDAssertPasswd 
1212          * to be base64-encoded when written in LDIF form;
1213          * basically, we don't care if it fails */
1214         rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1215         if ( rc ) {
1216                 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1217                         "warning, unable to get \"olcDbACLPasswd\" "
1218                         "attribute description: %d: %s\n",
1219                         rc, text, 0 );
1220         } else {
1221                 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1222                         ad->ad_type->sat_oid );
1223         }
1224
1225         ad = NULL;
1226         rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1227         if ( rc ) {
1228                 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1229                         "warning, unable to get \"olcDbIDAssertPasswd\" "
1230                         "attribute description: %d: %s\n",
1231                         rc, text, 0 );
1232         } else {
1233                 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1234                         ad->ad_type->sat_oid );
1235         }
1236
1237         return 0;
1238 }
1239
1240
1241 static int
1242 parse_idassert( BackendDB *be, const char *fname, int lineno,
1243                 int argc, char **argv );
1244
1245 static int
1246 parse_acl_auth( BackendDB *be, const char *fname, int lineno,
1247                 int argc, char **argv );
1248
1249 int
1250 ldap_back_db_config(
1251                 BackendDB       *be,
1252                 const char      *fname,
1253                 int             lineno,
1254                 int             argc,
1255                 char            **argv )
1256 {
1257         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1258
1259         if ( li == NULL ) {
1260                 fprintf( stderr, "%s: line %d: ldap backend info is null!\n",
1261                                 fname, lineno );
1262                 return 1;
1263         }
1264
1265         /* server address to query (no longer supported, use "uri" directive) */
1266         if ( strcasecmp( argv[0], "server" ) == 0 ) {
1267                 fprintf( stderr,
1268         "%s: line %d: \"server <address>\" directive is no longer supported.\n",
1269                                         fname, lineno );
1270                 return 1;
1271
1272         /* URI of server to query (obsoletes "server" directive) */
1273         } else if ( strcasecmp( argv[0], "uri" ) == 0 ) {
1274                 LDAPURLDesc     *tmpludp;
1275 #if 0
1276                 char            **urllist;
1277 #endif
1278                 int             urlrc, i;
1279
1280                 if ( argc != 2 ) {
1281                         fprintf( stderr, "%s: line %d: "
1282                                         "missing uri "
1283                                         "in \"uri <uri>\" line\n",
1284                                         fname, lineno );
1285                         return 1;
1286                 }
1287                 if ( li->url != NULL ) {
1288                         ch_free( li->url );
1289                 }
1290                 if ( li->lud != NULL ) {
1291                         ldap_free_urllist( li->lud );
1292                 }
1293
1294 #if 0
1295                 /* PARANOID: DN and more are not required nor allowed */
1296                 urlrc = ldap_url_parselist_ext( &li->lud, argv[ 1 ], "\t" );
1297 #else
1298                 urlrc = ldap_url_parselist( &li->lud, argv[ 1 ] );
1299 #endif
1300                 if ( urlrc != LDAP_URL_SUCCESS ) {
1301                         char    *why;
1302
1303                         switch ( urlrc ) {
1304                         case LDAP_URL_ERR_MEM:
1305                                 why = "no memory";
1306                                 break;
1307                         case LDAP_URL_ERR_PARAM:
1308                                 why = "parameter is bad";
1309                                 break;
1310                         case LDAP_URL_ERR_BADSCHEME:
1311                                 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1312                                 break;
1313                         case LDAP_URL_ERR_BADENCLOSURE:
1314                                 why = "URL is missing trailing \">\"";
1315                                 break;
1316                         case LDAP_URL_ERR_BADURL:
1317                                 why = "URL is bad";
1318                         case LDAP_URL_ERR_BADHOST:
1319                                 why = "host/port is bad";
1320                                 break;
1321                         case LDAP_URL_ERR_BADATTRS:
1322                                 why = "bad (or missing) attributes";
1323                                 break;
1324                         case LDAP_URL_ERR_BADSCOPE:
1325                                 why = "scope string is invalid (or missing)";
1326                                 break;
1327                         case LDAP_URL_ERR_BADFILTER:
1328                                 why = "bad or missing filter";
1329                                 break;
1330                         case LDAP_URL_ERR_BADEXTS:
1331                                 why = "bad or missing extensions";
1332                                 break;
1333                         default:
1334                                 why = "unknown reason";
1335                                 break;
1336                         }
1337                         fprintf( stderr, "%s: line %d: "
1338                                         "unable to parse uri \"%s\" "
1339                                         "in \"uri <uri>\" line: %s\n",
1340                                         fname, lineno, argv[ 1 ], why );
1341                         return 1;
1342                 }
1343
1344                 for ( i = 0, tmpludp = li->lud;
1345                                 tmpludp;
1346                                 i++, tmpludp = tmpludp->lud_next )
1347                 {
1348                         if ( ( tmpludp->lud_dn != NULL
1349                                                 && tmpludp->lud_dn[0] != '\0' )
1350                                         || tmpludp->lud_attrs != NULL
1351                                         /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1352                                         || tmpludp->lud_filter != NULL
1353                                         || tmpludp->lud_exts != NULL )
1354                         {
1355                                 fprintf( stderr, "%s: line %d: "
1356                                                 "warning, only protocol, "
1357                                                 "host and port allowed "
1358                                                 "in \"uri <uri>\" statement "
1359                                                 "for uri #%d of \"%s\"\n",
1360                                                 fname, lineno, i, argv[1] );
1361                         }
1362                 }
1363
1364 #if 0
1365                 for ( i = 0, tmpludp = li->lud;
1366                                 tmpludp;
1367                                 i++, tmpludp = tmpludp->lud_next )
1368                         /* just count */
1369                         ;
1370                 urllist = ch_calloc( sizeof( char * ), i + 1 );
1371
1372                 for ( i = 0, tmpludp = li->lud;
1373                                 tmpludp;
1374                                 i++, tmpludp = tmpludp->lud_next )
1375                 {
1376                         LDAPURLDesc     tmplud;
1377                         ber_len_t       oldlen = 0, len;
1378
1379                         tmplud = *tmpludp;
1380                         tmplud.lud_dn = "";
1381                         tmplud.lud_attrs = NULL;
1382                         tmplud.lud_filter = NULL;
1383                         if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1384                                 tmplud.lud_exts = NULL;
1385                                 tmplud.lud_crit_exts = 0;
1386                         }
1387
1388                         urllist[ i ]  = ldap_url_desc2str( &tmplud );
1389
1390                         if ( urllist[ i ] == NULL ) {
1391                                 fprintf( stderr, "%s: line %d: "
1392                                         "unable to rebuild uri "
1393                                         "in \"uri <uri>\" statement "
1394                                         "for \"%s\"\n",
1395                                         fname, lineno, argv[ 1 ] );
1396                                 return 1;
1397                         }
1398                 }
1399
1400                 li->url = ldap_charray2str( urllist, " " );
1401                 ldap_charray_free( urllist );
1402 #else
1403                 li->url = ch_strdup( argv[ 1 ] );
1404 #endif
1405
1406         } else if ( strcasecmp( argv[0], "tls" ) == 0 ) {
1407                 if ( argc != 2 ) {
1408                         fprintf( stderr,
1409                 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
1410                                         fname, lineno );
1411                         return( 1 );
1412                 }
1413
1414                 /* none */
1415                 if ( strcasecmp( argv[1], "none" ) == 0 ) {
1416                         li->flags &= ~LDAP_BACK_F_TLS_MASK;
1417         
1418                 /* try start tls */
1419                 } else if ( strcasecmp( argv[1], "start" ) == 0 ) {
1420                         li->flags |= LDAP_BACK_F_TLS_USE_MASK;
1421         
1422                 /* try start tls */
1423                 } else if ( strcasecmp( argv[1], "try-start" ) == 0 ) {
1424                         li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1425                         li->flags |= LDAP_BACK_F_USE_TLS;
1426         
1427                 /* propagate start tls */
1428                 } else if ( strcasecmp( argv[1], "propagate" ) == 0 ) {
1429                         li->flags |= LDAP_BACK_F_TLS_PROPAGATE_MASK;
1430                 
1431                 /* try start tls */
1432                 } else if ( strcasecmp( argv[1], "try-propagate" ) == 0 ) {
1433                         li->flags &= ~LDAP_BACK_F_TLS_CRITICAL;
1434                         li->flags |= LDAP_BACK_F_PROPAGATE_TLS;
1435
1436                 } else {
1437                         fprintf( stderr,
1438                 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
1439                                         fname, lineno, argv[1] );
1440                         return( 1 );
1441                 }
1442         
1443         /* remote ACL stuff... */
1444         } else if ( strncasecmp( argv[0], "acl-", STRLENOF( "acl-" ) ) == 0
1445                         || strncasecmp( argv[0], "bind", STRLENOF( "bind" ) ) == 0 )
1446         {
1447                 /* NOTE: "bind{DN,pw}" was initially used; it's now
1448                  * deprected and undocumented, it can be dropped at some
1449                  * point, since nobody should be really using it */
1450                 return parse_acl_auth( be, fname, lineno, argc, argv );
1451
1452         /* identity assertion stuff... */
1453         } else if ( strncasecmp( argv[0], "idassert-", STRLENOF( "idassert-" ) ) == 0
1454                         || strncasecmp( argv[0], "proxyauthz", STRLENOF( "proxyauthz" ) ) == 0 )
1455         {
1456                 /* NOTE: "proxyauthz{DN,pw}" was initially used; it's now
1457                  * deprected and undocumented, it can be dropped at some
1458                  * point, since nobody should be really using it */
1459                 return parse_idassert( be, fname, lineno, argc, argv );
1460
1461         /* save bind creds for referral rebinds? */
1462         } else if ( strcasecmp( argv[0], "rebind-as-user" ) == 0 ) {
1463                 switch ( argc ) {
1464                 case 1:
1465                         fprintf( stderr,
1466         "%s: line %d: \"rebind-as-user {NO|yes}\": use without args is deprecated.\n",
1467                                 fname, lineno );
1468         
1469                         li->flags |= LDAP_BACK_F_SAVECRED;
1470                         break;
1471
1472                 case 2:
1473                         if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1474                                 li->flags |= LDAP_BACK_F_SAVECRED;
1475
1476                         } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1477                                 li->flags &= ~LDAP_BACK_F_SAVECRED;
1478
1479                         } else {
1480                                 fprintf( stderr,
1481         "%s: line %d: \"rebind-as-user {NO|yes}\": unknown argument \"%s\".\n",
1482                                         fname, lineno, argv[ 1 ] );
1483                                 return( 1 );
1484                         }
1485                         break;
1486
1487                 default:
1488                         fprintf( stderr,
1489         "%s: line %d: \"rebind-as-user {NO|yes}\" needs 1 argument.\n",
1490                                         fname, lineno );
1491                         return( 1 );
1492                 }
1493
1494         } else if ( strcasecmp( argv[0], "chase-referrals" ) == 0 ) {
1495                 if ( argc != 2 ) {
1496                         fprintf( stderr,
1497         "%s: line %d: \"chase-referrals {YES|no}\" needs 1 argument.\n",
1498                                         fname, lineno );
1499                         return( 1 );
1500                 }
1501
1502                 /* this is the default; we add it because the default might change... */
1503                 if ( strcasecmp( argv[1], "yes" ) == 0 ) {
1504                         li->flags |= LDAP_BACK_F_CHASE_REFERRALS;
1505
1506                 } else if ( strcasecmp( argv[1], "no" ) == 0 ) {
1507                         li->flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1508
1509                 } else {
1510                         fprintf( stderr,
1511                 "%s: line %d: \"chase-referrals {YES|no}\": unknown argument \"%s\".\n",
1512                                         fname, lineno, argv[1] );
1513                         return( 1 );
1514                 }
1515         
1516         } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
1517                 if ( argc != 2 ) {
1518                         fprintf( stderr,
1519                 "%s: line %d: \"t-f-support {NO|yes|discover}\" needs 1 argument.\n",
1520                                         fname, lineno );
1521                         return( 1 );
1522                 }
1523
1524                 if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
1525                         li->flags &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
1526
1527                 } else if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1528                         li->flags |= LDAP_BACK_F_SUPPORT_T_F;
1529
1530                 } else if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
1531                         li->flags |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
1532
1533                 } else {
1534                         fprintf( stderr,
1535         "%s: line %d: \"t-f-support {NO|yes|discover}\": unknown argument \"%s\".\n",
1536                                 fname, lineno, argv[ 1 ] );
1537                         return 1;
1538                 }
1539
1540         /* intercept exop_who_am_i? */
1541         } else if ( strcasecmp( argv[0], "proxy-whoami" ) == 0 ) {
1542                 int     doload_extop = 0;
1543
1544                 switch ( argc ) {
1545                 case 1:
1546                         fprintf( stderr,
1547         "%s: line %d: \"proxy-whoami {NO|yes}\": use without args is deprecated.\n",
1548                                 fname, lineno );
1549         
1550                         doload_extop = 1;
1551                         break;
1552
1553                 case 2:
1554                         if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
1555                                 doload_extop = 1;
1556
1557                         } else if ( strcasecmp( argv[ 1 ], "no" ) != 0 ) {
1558                                 fprintf( stderr,
1559         "%s: line %d: \"proxy-whoami {NO|yes}\": unknown argument \"%s\".\n",
1560                                         fname, lineno, argv[ 1 ] );
1561                                 return( 1 );
1562                         }
1563                         break;
1564
1565                 default:
1566                         fprintf( stderr,
1567         "%s: line %d: \"proxy-whoami {NO|yes}\" needs 1 argument.\n",
1568                                         fname, lineno );
1569                         return( 1 );
1570                 }
1571
1572                 if ( doload_extop ) {
1573                         li->flags |= LDAP_BACK_F_PROXY_WHOAMI;
1574
1575                         load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1576                                         0, ldap_back_exop_whoami );
1577                 }
1578
1579         /* FIXME: legacy: intercept old rewrite/remap directives
1580          * and try to start the rwm overlay */
1581         } else if ( strcasecmp( argv[0], "suffixmassage" ) == 0
1582                         || strcasecmp( argv[0], "map" ) == 0
1583                         || strncasecmp( argv[0], "rewrite", STRLENOF( "rewrite" ) ) == 0 )
1584         {
1585 #if 0
1586                 fprintf( stderr, "%s: line %d: "
1587                         "rewrite/remap capabilities have been moved "
1588                         "to the \"rwm\" overlay; see slapo-rwm(5) "
1589                         "for details.  I'm trying to do my best "
1590                         "to preserve backwards compatibility...\n",
1591                         fname, lineno );
1592
1593                 if ( li->rwm_started == 0 ) {
1594                         if ( overlay_config( be, "rwm" ) ) {
1595                                 fprintf( stderr, "%s: line %d: "
1596                                         "unable to configure the \"rwm\" "
1597                                         "overlay, required by directive "
1598                                         "\"%s\".\n",
1599                                         fname, lineno, argv[0] );
1600 #if SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC
1601                                 fprintf( stderr, "\thint: try loading the \"rwm.la\" dynamic module.\n" );
1602 #endif /* SLAPD_OVER_RWM == SLAPD_MOD_DYNAMIC */
1603                                 return( 1 );
1604                         }
1605
1606                         fprintf( stderr, "%s: line %d: back-ldap: "
1607                                 "automatically starting \"rwm\" overlay, "
1608                                 "triggered by \"%s\" directive.\n",
1609                                 fname, lineno, argv[ 0 ] );
1610
1611                 /* this is the default; we add it because the default might change... */
1612                         li->rwm_started = 1;
1613
1614                         return ( *be->bd_info->bi_db_config )( be, fname, lineno, argc, argv );
1615                 }
1616 #else
1617                 fprintf( stderr, "%s: line %d: "
1618                         "rewrite/remap capabilities have been moved "
1619                         "to the \"rwm\" overlay; see slapo-rwm(5) "
1620                         "for details (hint: add \"overlay rwm\" "
1621                         "and prefix all directives with \"rwm-\").\n",
1622                         fname, lineno );
1623 #endif
1624
1625                 return 1;
1626         
1627         /* anything else */
1628         } else {
1629                 return SLAP_CONF_UNKNOWN;
1630         }
1631
1632         return 0;
1633 }
1634
1635 static int
1636 ldap_back_exop_whoami(
1637                 Operation       *op,
1638                 SlapReply       *rs )
1639 {
1640         struct berval *bv = NULL;
1641
1642         if ( op->oq_extended.rs_reqdata != NULL ) {
1643                 /* no request data should be provided */
1644                 rs->sr_text = "no request data expected";
1645                 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1646         }
1647
1648         Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
1649             op->o_log_prefix, 0, 0, 0, 0 );
1650
1651         rs->sr_err = backend_check_restrictions( op, rs, 
1652                         (struct berval *)&slap_EXOP_WHOAMI );
1653         if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1654
1655         /* if auth'd by back-ldap and request is proxied, forward it */
1656         if ( op->o_conn->c_authz_backend && !strcmp(op->o_conn->c_authz_backend->be_type, "ldap" ) && !dn_match(&op->o_ndn, &op->o_conn->c_ndn)) {
1657                 struct ldapconn *lc;
1658
1659                 LDAPControl c, *ctrls[2] = {NULL, NULL};
1660                 LDAPMessage *res;
1661                 Operation op2 = *op;
1662                 ber_int_t msgid;
1663                 int doretry = 1;
1664
1665                 ctrls[0] = &c;
1666                 op2.o_ndn = op->o_conn->c_ndn;
1667                 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1668                 if (!lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR )) {
1669                         return -1;
1670                 }
1671                 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1672                 c.ldctl_iscritical = 1;
1673                 c.ldctl_value.bv_val = ch_malloc(op->o_ndn.bv_len+4);
1674                 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1675                 strcpy(c.ldctl_value.bv_val, "dn:");
1676                 strcpy(c.ldctl_value.bv_val+3, op->o_ndn.bv_val);
1677
1678 retry:
1679                 rs->sr_err = ldap_whoami(lc->lc_ld, ctrls, NULL, &msgid);
1680                 if (rs->sr_err == LDAP_SUCCESS) {
1681                         if (ldap_result(lc->lc_ld, msgid, 1, NULL, &res) == -1) {
1682                                 ldap_get_option(lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1683                                         &rs->sr_err);
1684                                 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1685                                         doretry = 0;
1686                                         if ( ldap_back_retry( lc, op, rs, LDAP_BACK_SENDERR ) )
1687                                                 goto retry;
1688                                 }
1689                                 ldap_back_freeconn( op, lc );
1690                                 lc = NULL;
1691
1692                         } else {
1693                                 rs->sr_err = ldap_parse_whoami(lc->lc_ld, res, &bv);
1694                                 ldap_msgfree(res);
1695                         }
1696                 }
1697                 ch_free(c.ldctl_value.bv_val);
1698                 if (rs->sr_err != LDAP_SUCCESS) {
1699                         rs->sr_err = slap_map_api2result( rs );
1700                 }
1701
1702                 if ( lc != NULL ) {
1703                         ldap_back_release_conn( &op2, rs, lc );
1704                 }
1705
1706         } else {
1707         /* else just do the same as before */
1708                 bv = (struct berval *) ch_malloc( sizeof(struct berval) );
1709                 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1710                         bv->bv_len = op->o_dn.bv_len + STRLENOF("dn:");
1711                         bv->bv_val = ch_malloc( bv->bv_len + 1 );
1712                         AC_MEMCPY( bv->bv_val, "dn:", STRLENOF("dn:") );
1713                         AC_MEMCPY( &bv->bv_val[STRLENOF("dn:")], op->o_dn.bv_val,
1714                                 op->o_dn.bv_len );
1715                         bv->bv_val[bv->bv_len] = '\0';
1716                 } else {
1717                         bv->bv_len = 0;
1718                         bv->bv_val = NULL;
1719                 }
1720         }
1721
1722         rs->sr_rspdata = bv;
1723         return rs->sr_err;
1724 }
1725
1726
1727 static int
1728 parse_idassert(
1729     BackendDB   *be,
1730     const char  *fname,
1731     int         lineno,
1732     int         argc,
1733     char        **argv
1734 )
1735 {
1736         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
1737
1738         /* identity assertion mode */
1739         if ( strcasecmp( argv[0], "idassert-mode" ) == 0 ) {
1740                 if ( argc < 2 ) {
1741                         Debug( LDAP_DEBUG_ANY,
1742                                 "%s: line %d: illegal args number %d in \"idassert-mode <args> [<flag> [...]]\" line.\n",
1743                                 fname, lineno, argc );
1744                         return 1;
1745                 }
1746
1747                 if ( strcasecmp( argv[1], "legacy" ) == 0 ) {
1748                         /* will proxyAuthz as client's identity only if bound */
1749                         li->idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
1750
1751                 } else if ( strcasecmp( argv[1], "self" ) == 0 ) {
1752                         /* will proxyAuthz as client's identity */
1753                         li->idassert_mode = LDAP_BACK_IDASSERT_SELF;
1754
1755                 } else if ( strcasecmp( argv[1], "anonymous" ) == 0 ) {
1756                         /* will proxyAuthz as anonymous */
1757                         li->idassert_mode = LDAP_BACK_IDASSERT_ANONYMOUS;
1758
1759                 } else if ( strcasecmp( argv[1], "none" ) == 0 ) {
1760                         /* will not proxyAuthz */
1761                         li->idassert_mode = LDAP_BACK_IDASSERT_NOASSERT;
1762
1763                 } else {
1764                         struct berval   id;
1765                         int             rc;
1766
1767                         /* will proxyAuthz as argv[1] */
1768                         ber_str2bv( argv[1], 0, 0, &id );
1769
1770                         if ( strncasecmp( id.bv_val, "u:", STRLENOF( "u:" ) ) == 0 ) {
1771                                 /* force lowercase... */
1772                                 id.bv_val[0] = 'u';
1773                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1774                                 ber_dupbv( &li->idassert_authzID, &id );
1775
1776                         } else {
1777                                 struct berval   dn;
1778
1779                                 /* default is DN? */
1780                                 if ( strncasecmp( id.bv_val, "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1781                                         id.bv_val += STRLENOF( "dn:" );
1782                                         id.bv_len -= STRLENOF( "dn:" );
1783                                 }
1784
1785                                 rc = dnNormalize( 0, NULL, NULL, &id, &dn, NULL );
1786                                 if ( rc != LDAP_SUCCESS ) {
1787                                         Debug( LDAP_DEBUG_ANY,
1788                                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1789                                                 fname, lineno, argv[1] );
1790                                         return 1;
1791                                 }
1792
1793                                 li->idassert_authzID.bv_len = STRLENOF( "dn:" ) + dn.bv_len;
1794                                 li->idassert_authzID.bv_val = ch_malloc( li->idassert_authzID.bv_len + 1 );
1795                                 AC_MEMCPY( li->idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1796                                 AC_MEMCPY( &li->idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], dn.bv_val, dn.bv_len + 1 );
1797                                 ch_free( dn.bv_val );
1798
1799                                 li->idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1800                         }
1801                 }
1802
1803                 for ( argc -= 2, argv += 2; argc--; argv++ ) {
1804                         if ( strcasecmp( argv[0], "override" ) == 0 ) {
1805                                 li->idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1806
1807                         } else {
1808                                 Debug( LDAP_DEBUG_ANY,
1809                                         "%s: line %d: unknown flag \"%s\" "
1810                                         "in \"idassert-mode <args> "
1811                                         "[<flags>]\" line.\n",
1812                                         fname, lineno, argv[0] );
1813                                 return 1;
1814                         }
1815                 }
1816
1817         /* name to use for proxyAuthz propagation */
1818         } else if ( strcasecmp( argv[0], "idassert-authcdn" ) == 0
1819                         || strcasecmp( argv[0], "proxyauthzdn" ) == 0 )
1820         {
1821                 struct berval   dn;
1822                 int             rc;
1823
1824                 /* FIXME: "proxyauthzdn" is no longer documented, and
1825                  * temporarily supported for backwards compatibility */
1826
1827                 if ( argc != 2 ) {
1828                         fprintf( stderr,
1829         "%s: line %d: missing name in \"%s <name>\" line\n",
1830                             fname, lineno, argv[0] );
1831                         return( 1 );
1832                 }
1833
1834                 if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1835                         fprintf( stderr, "%s: line %d: "
1836                                         "authcDN already defined; replacing...\n",
1837                                         fname, lineno );
1838                         ch_free( li->idassert_authcDN.bv_val );
1839                 }
1840                 
1841                 ber_str2bv( argv[1], 0, 0, &dn );
1842                 rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1843                 if ( rc != LDAP_SUCCESS ) {
1844                         Debug( LDAP_DEBUG_ANY,
1845                                 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1846                                 fname, lineno, argv[1] );
1847                         return 1;
1848                 }
1849
1850         /* password to use for proxyAuthz propagation */
1851         } else if ( strcasecmp( argv[0], "idassert-passwd" ) == 0
1852                         || strcasecmp( argv[0], "proxyauthzpw" ) == 0 )
1853         {
1854                 /* FIXME: "proxyauthzpw" is no longer documented, and
1855                  * temporarily supported for backwards compatibility */
1856
1857                 if ( argc != 2 ) {
1858                         fprintf( stderr,
1859         "%s: line %d: missing password in \"%s <password>\" line\n",
1860                             fname, lineno, argv[0] );
1861                         return( 1 );
1862                 }
1863
1864                 if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1865                         fprintf( stderr, "%s: line %d: "
1866                                         "passwd already defined; replacing...\n",
1867                                         fname, lineno );
1868                         ch_free( li->idassert_passwd.bv_val );
1869                 }
1870                 
1871                 ber_str2bv( argv[1], 0, 1, &li->idassert_passwd );
1872
1873         /* rules to accept identity assertion... */
1874         } else if ( strcasecmp( argv[0], "idassert-authzFrom" ) == 0 ) {
1875                 struct berval   rule;
1876
1877                 ber_str2bv( argv[1], 0, 1, &rule );
1878
1879                 ber_bvarray_add( &li->idassert_authz, &rule );
1880
1881         } else if ( strcasecmp( argv[0], "idassert-method" ) == 0 ) {
1882                 char    *argv1;
1883
1884                 if ( argc < 2 ) {
1885                         fprintf( stderr,
1886         "%s: line %d: missing method in \"%s <method>\" line\n",
1887                             fname, lineno, argv[0] );
1888                         return( 1 );
1889                 }
1890
1891                 argv1 = argv[1];
1892                 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
1893                         argv1 += STRLENOF( "bindmethod=" );
1894                 }
1895
1896                 if ( strcasecmp( argv1, "none" ) == 0 ) {
1897                         /* FIXME: is this at all useful? */
1898                         li->idassert_authmethod = LDAP_AUTH_NONE;
1899
1900                         if ( argc != 2 ) {
1901                                 fprintf( stderr,
1902         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
1903                                         fname, lineno, argv[0], argv[1] );
1904                         }
1905
1906                 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
1907                         int     arg;
1908
1909                         for ( arg = 2; arg < argc; arg++ ) {
1910                                 if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1911                                         char            *val = argv[arg] + STRLENOF( "authcdn=" );
1912                                         struct berval   dn;
1913                                         int             rc;
1914
1915                                         if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1916                                                 fprintf( stderr, "%s: line %d: "
1917                                                                 "SASL authcDN already defined; replacing...\n",
1918                                                                 fname, lineno );
1919                                                 ch_free( li->idassert_authcDN.bv_val );
1920                                         }
1921                                         if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1922                                                 val += STRLENOF( "dn:" );
1923                                         }
1924
1925                                         ber_str2bv( val, 0, 0, &dn );
1926                                         rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1927                                         if ( rc != LDAP_SUCCESS ) {
1928                                                 Debug( LDAP_DEBUG_ANY,
1929                                                         "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
1930                                                         fname, lineno, val );
1931                                                 return 1;
1932                                         }
1933
1934                                 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
1935                                         char    *val = argv[arg] + STRLENOF( "cred=" );
1936
1937                                         if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
1938                                                 fprintf( stderr, "%s: line %d: "
1939                                                                 "SASL cred already defined; replacing...\n",
1940                                                                 fname, lineno );
1941                                                 ch_free( li->idassert_passwd.bv_val );
1942                                         }
1943                                         ber_str2bv( val, 0, 1, &li->idassert_passwd );
1944
1945                                 } else {
1946                                         fprintf( stderr, "%s: line %d: "
1947                                                         "unknown parameter %s\n",
1948                                                         fname, lineno, argv[arg] );
1949                                         return 1;
1950                                 }
1951                         }
1952
1953                         li->idassert_authmethod = LDAP_AUTH_SIMPLE;
1954
1955                 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
1956 #ifdef HAVE_CYRUS_SASL
1957                         int     arg;
1958
1959                         for ( arg = 2; arg < argc; arg++ ) {
1960                                 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
1961                                         char    *val = argv[arg] + STRLENOF( "mech=" );
1962
1963                                         if ( !BER_BVISNULL( &li->idassert_sasl_mech ) ) {
1964                                                 fprintf( stderr, "%s: line %d: "
1965                                                                 "SASL mech already defined; replacing...\n",
1966                                                                 fname, lineno );
1967                                                 ch_free( li->idassert_sasl_mech.bv_val );
1968                                         }
1969                                         ber_str2bv( val, 0, 1, &li->idassert_sasl_mech );
1970
1971                                 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
1972                                         char    *val = argv[arg] + STRLENOF( "realm=" );
1973
1974                                         if ( !BER_BVISNULL( &li->idassert_sasl_realm ) ) {
1975                                                 fprintf( stderr, "%s: line %d: "
1976                                                                 "SASL realm already defined; replacing...\n",
1977                                                                 fname, lineno );
1978                                                 ch_free( li->idassert_sasl_realm.bv_val );
1979                                         }
1980                                         ber_str2bv( val, 0, 1, &li->idassert_sasl_realm );
1981
1982                                 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
1983                                         char            *val = argv[arg] + STRLENOF( "authcdn=" );
1984                                         struct berval   dn;
1985                                         int             rc;
1986
1987                                         if ( !BER_BVISNULL( &li->idassert_authcDN ) ) {
1988                                                 fprintf( stderr, "%s: line %d: "
1989                                                                 "SASL authcDN already defined; replacing...\n",
1990                                                                 fname, lineno );
1991                                                 ch_free( li->idassert_authcDN.bv_val );
1992                                         }
1993                                         if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1994                                                 val += STRLENOF( "dn:" );
1995                                         }
1996
1997                                         ber_str2bv( val, 0, 0, &dn );
1998                                         rc = dnNormalize( 0, NULL, NULL, &dn, &li->idassert_authcDN, NULL );
1999                                         if ( rc != LDAP_SUCCESS ) {
2000                                                 Debug( LDAP_DEBUG_ANY,
2001                                                         "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2002                                                         fname, lineno, val );
2003                                                 return 1;
2004                                         }
2005
2006                                 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2007                                         char    *val = argv[arg] + STRLENOF( "authcid=" );
2008
2009                                         if ( !BER_BVISNULL( &li->idassert_authcID ) ) {
2010                                                 fprintf( stderr, "%s: line %d: "
2011                                                                 "SASL authcID already defined; replacing...\n",
2012                                                                 fname, lineno );
2013                                                 ch_free( li->idassert_authcID.bv_val );
2014                                         }
2015                                         if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2016                                                 val += STRLENOF( "u:" );
2017                                         }
2018                                         ber_str2bv( val, 0, 1, &li->idassert_authcID );
2019
2020                                 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2021                                         char    *val = argv[arg] + STRLENOF( "cred=" );
2022
2023                                         if ( !BER_BVISNULL( &li->idassert_passwd ) ) {
2024                                                 fprintf( stderr, "%s: line %d: "
2025                                                                 "SASL cred already defined; replacing...\n",
2026                                                                 fname, lineno );
2027                                                 ch_free( li->idassert_passwd.bv_val );
2028                                         }
2029                                         ber_str2bv( val, 0, 1, &li->idassert_passwd );
2030
2031                                 } else if ( strncasecmp( argv[arg], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
2032                                         char    *val = argv[arg] + STRLENOF( "authz=" );
2033
2034                                         if ( strcasecmp( val, "proxyauthz" ) == 0 ) {
2035                                                 li->idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
2036
2037                                         } else if ( strcasecmp( val, "native" ) == 0 ) {
2038                                                 li->idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
2039
2040                                         } else {
2041                                                 fprintf( stderr, "%s: line %d: "
2042                                                         "unknown authz mode \"%s\"\n",
2043                                                         fname, lineno, val );
2044                                                 return 1;
2045                                         }
2046
2047                                 } else {
2048                                         fprintf( stderr, "%s: line %d: "
2049                                                         "unknown SASL parameter %s\n",
2050                                                         fname, lineno, argv[arg] );
2051                                         return 1;
2052                                 }
2053                         }
2054
2055                         li->idassert_authmethod = LDAP_AUTH_SASL;
2056
2057 #else /* !HAVE_CYRUS_SASL */
2058                         fprintf( stderr, "%s: line %d: "
2059                                         "compile --with-cyrus-sasl to enable SASL auth\n",
2060                                         fname, lineno );
2061                         return 1;
2062 #endif /* !HAVE_CYRUS_SASL */
2063
2064                 } else {
2065                         fprintf( stderr, "%s: line %d: "
2066                                         "unhandled idassert-method method %s\n",
2067                                         fname, lineno, argv[1] );
2068                         return 1;
2069                 }
2070
2071         } else {
2072                 return SLAP_CONF_UNKNOWN;
2073         }
2074
2075         return 0;
2076 }
2077
2078 static int
2079 parse_acl_auth(
2080     BackendDB   *be,
2081     const char  *fname,
2082     int         lineno,
2083     int         argc,
2084     char        **argv
2085 )
2086 {
2087         struct ldapinfo *li = (struct ldapinfo *) be->be_private;
2088
2089         /* name to use for remote ACL access */
2090         if ( strcasecmp( argv[0], "acl-authcdn" ) == 0
2091                         || strcasecmp( argv[0], "binddn" ) == 0 )
2092         {
2093                 struct berval   dn;
2094                 int             rc;
2095
2096                 /* FIXME: "binddn" is no longer documented, and
2097                  * temporarily supported for backwards compatibility */
2098
2099                 if ( argc != 2 ) {
2100                         fprintf( stderr,
2101         "%s: line %d: missing name in \"%s <name>\" line\n",
2102                             fname, lineno, argv[0] );
2103                         return( 1 );
2104                 }
2105
2106                 if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2107                         fprintf( stderr, "%s: line %d: "
2108                                         "authcDN already defined; replacing...\n",
2109                                         fname, lineno );
2110                         ch_free( li->acl_authcDN.bv_val );
2111                 }
2112                 
2113                 ber_str2bv( argv[1], 0, 0, &dn );
2114                 rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2115                 if ( rc != LDAP_SUCCESS ) {
2116                         Debug( LDAP_DEBUG_ANY,
2117                                 "%s: line %d: acl ID \"%s\" is not a valid DN\n",
2118                                 fname, lineno, argv[1] );
2119                         return 1;
2120                 }
2121
2122         /* password to use for remote ACL access */
2123         } else if ( strcasecmp( argv[0], "acl-passwd" ) == 0
2124                         || strcasecmp( argv[0], "bindpw" ) == 0 )
2125         {
2126                 /* FIXME: "bindpw" is no longer documented, and
2127                  * temporarily supported for backwards compatibility */
2128
2129                 if ( argc != 2 ) {
2130                         fprintf( stderr,
2131         "%s: line %d: missing password in \"%s <password>\" line\n",
2132                             fname, lineno, argv[0] );
2133                         return( 1 );
2134                 }
2135
2136                 if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2137                         fprintf( stderr, "%s: line %d: "
2138                                         "passwd already defined; replacing...\n",
2139                                         fname, lineno );
2140                         ch_free( li->acl_passwd.bv_val );
2141                 }
2142                 
2143                 ber_str2bv( argv[1], 0, 1, &li->acl_passwd );
2144
2145         } else if ( strcasecmp( argv[0], "acl-method" ) == 0 ) {
2146                 char    *argv1;
2147
2148                 if ( argc < 2 ) {
2149                         fprintf( stderr,
2150         "%s: line %d: missing method in \"%s <method>\" line\n",
2151                             fname, lineno, argv[0] );
2152                         return( 1 );
2153                 }
2154
2155                 argv1 = argv[1];
2156                 if ( strncasecmp( argv1, "bindmethod=", STRLENOF( "bindmethod=" ) ) == 0 ) {
2157                         argv1 += STRLENOF( "bindmethod=" );
2158                 }
2159
2160                 if ( strcasecmp( argv1, "none" ) == 0 ) {
2161                         /* FIXME: is this at all useful? */
2162                         li->acl_authmethod = LDAP_AUTH_NONE;
2163
2164                         if ( argc != 2 ) {
2165                                 fprintf( stderr,
2166         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2167                                         fname, lineno, argv[0], argv[1] );
2168                         }
2169
2170                 } else if ( strcasecmp( argv1, "simple" ) == 0 ) {
2171                         li->acl_authmethod = LDAP_AUTH_SIMPLE;
2172
2173                         if ( argc != 2 ) {
2174                                 fprintf( stderr,
2175         "%s: line %d: trailing args in \"%s %s ...\" line ignored\"\n",
2176                                         fname, lineno, argv[0], argv[1] );
2177                         }
2178
2179                 } else if ( strcasecmp( argv1, "sasl" ) == 0 ) {
2180 #ifdef HAVE_CYRUS_SASL
2181                         int     arg;
2182
2183                         for ( arg = 2; arg < argc; arg++ ) {
2184                                 if ( strncasecmp( argv[arg], "mech=", STRLENOF( "mech=" ) ) == 0 ) {
2185                                         char    *val = argv[arg] + STRLENOF( "mech=" );
2186
2187                                         if ( !BER_BVISNULL( &li->acl_sasl_mech ) ) {
2188                                                 fprintf( stderr, "%s: line %d: "
2189                                                                 "SASL mech already defined; replacing...\n",
2190                                                                 fname, lineno );
2191                                                 ch_free( li->acl_sasl_mech.bv_val );
2192                                         }
2193                                         ber_str2bv( val, 0, 1, &li->acl_sasl_mech );
2194
2195                                 } else if ( strncasecmp( argv[arg], "realm=", STRLENOF( "realm=" ) ) == 0 ) {
2196                                         char    *val = argv[arg] + STRLENOF( "realm=" );
2197
2198                                         if ( !BER_BVISNULL( &li->acl_sasl_realm ) ) {
2199                                                 fprintf( stderr, "%s: line %d: "
2200                                                                 "SASL realm already defined; replacing...\n",
2201                                                                 fname, lineno );
2202                                                 ch_free( li->acl_sasl_realm.bv_val );
2203                                         }
2204                                         ber_str2bv( val, 0, 1, &li->acl_sasl_realm );
2205
2206                                 } else if ( strncasecmp( argv[arg], "authcdn=", STRLENOF( "authcdn=" ) ) == 0 ) {
2207                                         char            *val = argv[arg] + STRLENOF( "authcdn=" );
2208                                         struct berval   dn;
2209                                         int             rc;
2210
2211                                         if ( !BER_BVISNULL( &li->acl_authcDN ) ) {
2212                                                 fprintf( stderr, "%s: line %d: "
2213                                                                 "SASL authcDN already defined; replacing...\n",
2214                                                                 fname, lineno );
2215                                                 ch_free( li->acl_authcDN.bv_val );
2216                                         }
2217                                         if ( strncasecmp( argv[arg], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
2218                                                 val += STRLENOF( "dn:" );
2219                                         }
2220
2221                                         ber_str2bv( val, 0, 0, &dn );
2222                                         rc = dnNormalize( 0, NULL, NULL, &dn, &li->acl_authcDN, NULL );
2223                                         if ( rc != LDAP_SUCCESS ) {
2224                                                 Debug( LDAP_DEBUG_ANY,
2225                                                         "%s: line %d: SASL authcdn \"%s\" is not a valid DN\n",
2226                                                         fname, lineno, val );
2227                                                 return 1;
2228                                         }
2229
2230                                 } else if ( strncasecmp( argv[arg], "authcid=", STRLENOF( "authcid=" ) ) == 0 ) {
2231                                         char    *val = argv[arg] + STRLENOF( "authcid=" );
2232
2233                                         if ( !BER_BVISNULL( &li->acl_authcID ) ) {
2234                                                 fprintf( stderr, "%s: line %d: "
2235                                                                 "SASL authcID already defined; replacing...\n",
2236                                                                 fname, lineno );
2237                                                 ch_free( li->acl_authcID.bv_val );
2238                                         }
2239                                         if ( strncasecmp( argv[arg], "u:", STRLENOF( "u:" ) ) == 0 ) {
2240                                                 val += STRLENOF( "u:" );
2241                                         }
2242                                         ber_str2bv( val, 0, 1, &li->acl_authcID );
2243
2244                                 } else if ( strncasecmp( argv[arg], "cred=", STRLENOF( "cred=" ) ) == 0 ) {
2245                                         char    *val = argv[arg] + STRLENOF( "cred=" );
2246
2247                                         if ( !BER_BVISNULL( &li->acl_passwd ) ) {
2248                                                 fprintf( stderr, "%s: line %d: "
2249                                                                 "SASL cred already defined; replacing...\n",
2250                                                                 fname, lineno );
2251                                                 ch_free( li->acl_passwd.bv_val );
2252                                         }
2253                                         ber_str2bv( val, 0, 1, &li->acl_passwd );
2254
2255                                 } else {
2256                                         fprintf( stderr, "%s: line %d: "
2257                                                         "unknown SASL parameter %s\n",
2258                                                         fname, lineno, argv[arg] );
2259                                         return 1;
2260                                 }
2261                         }
2262
2263                         li->acl_authmethod = LDAP_AUTH_SASL;
2264
2265 #else /* !HAVE_CYRUS_SASL */
2266                         fprintf( stderr, "%s: line %d: "
2267                                         "compile --with-cyrus-sasl to enable SASL auth\n",
2268                                         fname, lineno );
2269                         return 1;
2270 #endif /* !HAVE_CYRUS_SASL */
2271
2272                 } else {
2273                         fprintf( stderr, "%s: line %d: "
2274                                         "unhandled acl-method method %s\n",
2275                                         fname, lineno, argv[1] );
2276                         return 1;
2277                 }
2278
2279         } else {
2280                 return SLAP_CONF_UNKNOWN;
2281         }
2282
2283         return 0;
2284 }
2285