1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2006 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
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>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/string.h>
30 #include <ac/socket.h>
34 #include "back-ldap.h"
38 /* for advanced URL parsing */
39 #include "../../../libraries/libldap/ldap-int.h"
41 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
43 static ConfigDriver ldap_back_cf_gen;
46 LDAP_BACK_CFG_URI = 1,
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,
62 LDAP_BACK_CFG_TIMEOUT,
63 LDAP_BACK_CFG_IDLE_TIMEOUT,
64 LDAP_BACK_CFG_CONN_TTL,
65 LDAP_BACK_CFG_NETWORK_TIMEOUT,
66 LDAP_BACK_CFG_VERSION,
67 LDAP_BACK_CFG_SINGLECONN,
69 LDAP_BACK_CFG_QUARANTINE,
70 LDAP_BACK_CFG_REWRITE,
75 static ConfigTable ldapcfg[] = {
76 { "uri", "uri", 2, 2, 0,
77 ARG_MAGIC|LDAP_BACK_CFG_URI,
78 ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
80 "DESC 'URI (list) for remote DSA' "
81 "SYNTAX OMsDirectoryString "
84 { "tls", "what", 2, 2, 0,
85 ARG_MAGIC|LDAP_BACK_CFG_TLS,
86 ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
87 "NAME 'olcDbStartTLS' "
89 "SYNTAX OMsDirectoryString "
92 { "acl-authcDN", "DN", 2, 2, 0,
93 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
94 ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
95 "NAME 'olcDbACLAuthcDn' "
96 "DESC 'Remote ACL administrative identity' "
101 /* deprecated, will be removed; aliases "acl-authcDN" */
102 { "binddn", "DN", 2, 2, 0,
103 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
104 ldap_back_cf_gen, NULL, NULL, NULL },
105 { "acl-passwd", "cred", 2, 2, 0,
106 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
107 ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
108 "NAME 'olcDbACLPasswd' "
109 "DESC 'Remote ACL administrative identity credentials' "
111 "SYNTAX OMsDirectoryString "
114 /* deprecated, will be removed; aliases "acl-passwd" */
115 { "bindpw", "cred", 2, 2, 0,
116 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
117 ldap_back_cf_gen, NULL, NULL, NULL },
118 /* deprecated, will be removed; aliases "acl-bind" */
119 { "acl-method", "args", 2, 0, 0,
120 ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
121 ldap_back_cf_gen, NULL, NULL, NULL },
122 { "acl-bind", "args", 2, 0, 0,
123 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
124 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
125 "NAME 'olcDbACLBind' "
126 "DESC 'Remote ACL administrative identity auth bind configuration' "
127 "SYNTAX OMsDirectoryString "
130 { "idassert-authcDN", "DN", 2, 2, 0,
131 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
132 ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
133 "NAME 'olcDbIDAssertAuthcDn' "
134 "DESC 'Remote Identity Assertion administrative identity' "
139 /* deprecated, will be removed; partially aliases "idassert-authcDN" */
140 { "proxyauthzdn", "DN", 2, 2, 0,
141 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
142 ldap_back_cf_gen, NULL, NULL, NULL },
143 { "idassert-passwd", "cred", 2, 2, 0,
144 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
145 ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
146 "NAME 'olcDbIDAssertPasswd' "
147 "DESC 'Remote Identity Assertion administrative identity credentials' "
149 "SYNTAX OMsDirectoryString "
152 /* deprecated, will be removed; partially aliases "idassert-passwd" */
153 { "proxyauthzpw", "cred", 2, 2, 0,
154 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
155 ldap_back_cf_gen, NULL, NULL, NULL },
156 { "idassert-bind", "args", 2, 0, 0,
157 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
158 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
159 "NAME 'olcDbIDAssertBind' "
160 "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
161 "SYNTAX OMsDirectoryString "
164 { "idassert-method", "args", 2, 0, 0,
165 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
166 ldap_back_cf_gen, NULL, NULL, NULL },
167 { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
168 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
169 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
170 "NAME 'olcDbIDAssertMode' "
171 "DESC 'Remote Identity Assertion mode' "
173 "SYNTAX OMsDirectoryString "
176 { "idassert-authzFrom", "authzRule", 2, 2, 0,
177 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
178 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
179 "NAME 'olcDbIDAssertAuthzFrom' "
180 "DESC 'Remote Identity Assertion authz rules' "
181 "SYNTAX OMsDirectoryString "
182 "X-ORDERED 'VALUES' )",
184 { "rebind-as-user", "NO|yes", 1, 2, 0,
185 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_REBIND,
186 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
187 "NAME 'olcDbRebindAsUser' "
188 "DESC 'Rebind as user' "
192 { "chase-referrals", "YES|no", 2, 2, 0,
193 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_CHASE,
194 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
195 "NAME 'olcDbChaseReferrals' "
196 "DESC 'Chase referrals' "
200 { "t-f-support", "NO|yes|discover", 2, 2, 0,
201 ARG_MAGIC|LDAP_BACK_CFG_T_F,
202 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
203 "NAME 'olcDbTFSupport' "
204 "DESC 'Absolute filters support' "
205 "SYNTAX OMsDirectoryString "
208 { "proxy-whoami", "NO|yes", 1, 2, 0,
209 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_WHOAMI,
210 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
211 "NAME 'olcDbProxyWhoAmI' "
212 "DESC 'Proxy whoAmI exop' "
216 { "timeout", "timeout(list)", 2, 0, 0,
217 ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
218 ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
219 "NAME 'olcDbTimeout' "
220 "DESC 'Per-operation timeouts' "
221 "SYNTAX OMsDirectoryString "
224 { "idle-timeout", "timeout", 2, 0, 0,
225 ARG_MAGIC|LDAP_BACK_CFG_IDLE_TIMEOUT,
226 ldap_back_cf_gen, "( OLcfgDbAt:3.15 "
227 "NAME 'olcDbIdleTimeout' "
228 "DESC 'connection idle timeout' "
229 "SYNTAX OMsDirectoryString "
232 { "conn-ttl", "ttl", 2, 0, 0,
233 ARG_MAGIC|LDAP_BACK_CFG_CONN_TTL,
234 ldap_back_cf_gen, "( OLcfgDbAt:3.16 "
235 "NAME 'olcDbConnTtl' "
236 "DESC 'connection ttl' "
237 "SYNTAX OMsDirectoryString "
240 { "network-timeout", "timeout", 2, 0, 0,
241 ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
242 ldap_back_cf_gen, "( OLcfgDbAt:3.17 "
243 "NAME 'olcDbNetworkTimeout' "
244 "DESC 'connection network timeout' "
245 "SYNTAX OMsDirectoryString "
248 { "protocol-version", "version", 2, 0, 0,
249 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_VERSION,
250 ldap_back_cf_gen, "( OLcfgDbAt:3.18 "
251 "NAME 'olcDbProtocolVersion' "
252 "DESC 'protocol version' "
256 { "single-conn", "TRUE/FALSE", 2, 0, 0,
257 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_SINGLECONN,
258 ldap_back_cf_gen, "( OLcfgDbAt:3.19 "
259 "NAME 'olcDbSingleConn' "
260 "DESC 'cache a single connection per identity' "
264 { "cancel", "ABANDON|ignore|exop", 2, 0, 0,
265 ARG_MAGIC|LDAP_BACK_CFG_CANCEL,
266 ldap_back_cf_gen, "( OLcfgDbAt:3.20 "
267 "NAME 'olcDbCancel' "
268 "DESC 'abandon/ignore/exop operations when appropriate' "
269 "SYNTAX OMsDirectoryString "
272 { "quarantine", "retrylist", 2, 0, 0,
273 ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
274 ldap_back_cf_gen, "( OLcfgDbAt:3.21 "
275 "NAME 'olcDbQuarantine' "
276 "DESC 'Quarantine database if connection fails and retry according to rule' "
277 "SYNTAX OMsDirectoryString "
280 { "suffixmassage", "[virtual]> <real", 2, 3, 0,
281 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
282 ldap_back_cf_gen, NULL, NULL, NULL },
283 { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
284 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
285 ldap_back_cf_gen, NULL, NULL, NULL },
286 { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
287 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
288 ldap_back_cf_gen, NULL, NULL, NULL },
289 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
290 NULL, NULL, NULL, NULL }
293 static ConfigOCs ldapocs[] = {
295 "NAME 'olcLDAPConfig' "
296 "DESC 'LDAP backend configuration' "
297 "SUP olcDatabaseConfig "
299 "MAY ( olcDbStartTLS "
303 "$ olcDbIDAssertAuthcDn "
304 "$ olcDbIDAssertPasswd "
305 "$ olcDbIDAssertBind "
306 "$ olcDbIDAssertMode "
307 "$ olcDbIDAssertAuthzFrom "
308 "$ olcDbRebindAsUser "
309 "$ olcDbChaseReferrals "
311 "$ olcDbProxyWhoAmI "
313 "$ olcDbIdleTimeout "
318 Cft_Database, ldapcfg},
322 static slap_verbmasks idassert_mode[] = {
323 { BER_BVC("self"), LDAP_BACK_IDASSERT_SELF },
324 { BER_BVC("anonymous"), LDAP_BACK_IDASSERT_ANONYMOUS },
325 { BER_BVC("none"), LDAP_BACK_IDASSERT_NOASSERT },
326 { BER_BVC("legacy"), LDAP_BACK_IDASSERT_LEGACY },
330 static slap_verbmasks tls_mode[] = {
331 { BER_BVC( "propagate" ), LDAP_BACK_F_TLS_PROPAGATE_MASK },
332 { BER_BVC( "try-propagate" ), LDAP_BACK_F_PROPAGATE_TLS },
333 { BER_BVC( "start" ), LDAP_BACK_F_TLS_USE_MASK },
334 { BER_BVC( "try-start" ), LDAP_BACK_F_USE_TLS },
335 { BER_BVC( "none" ), LDAP_BACK_F_NONE },
339 static slap_verbmasks t_f_mode[] = {
340 { BER_BVC( "yes" ), LDAP_BACK_F_T_F },
341 { BER_BVC( "discover" ), LDAP_BACK_F_T_F_DISCOVER },
342 { BER_BVC( "no" ), LDAP_BACK_F_NONE },
346 static slap_verbmasks cancel_mode[] = {
347 { BER_BVC( "ignore" ), LDAP_BACK_F_CANCEL_IGNORE },
348 { BER_BVC( "exop" ), LDAP_BACK_F_CANCEL_EXOP },
349 { BER_BVC( "exop-discover" ), LDAP_BACK_F_CANCEL_EXOP_DISCOVER },
350 { BER_BVC( "abandon" ), LDAP_BACK_F_CANCEL_ABANDON },
354 static slap_cf_aux_table timeout_table[] = {
355 { BER_BVC("add="), 0 * sizeof( time_t ), 'u', 0, NULL },
356 { BER_BVC("delete="), 1 * sizeof( time_t ), 'u', 0, NULL },
357 { BER_BVC("modify="), 2 * sizeof( time_t ), 'u', 0, NULL },
358 { BER_BVC("modrdn="), 3 * sizeof( time_t ), 'u', 0, NULL },
359 { BER_BVNULL, 0, 0, 0, NULL }
363 slap_retry_info_parse(
365 slap_retry_info_t *ri,
369 char **retrylist = NULL;
373 slap_str2clist( &retrylist, in, " ;" );
374 if ( retrylist == NULL ) {
378 for ( i = 0; retrylist[ i ] != NULL; i++ )
381 ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 );
382 ri->ri_num = ch_calloc( sizeof( int ), i + 1 );
384 for ( i = 0; retrylist[ i ] != NULL; i++ ) {
386 char *sep = strchr( retrylist[ i ], ',' );
389 snprintf( buf, buflen,
390 "missing comma in retry pattern #%d \"%s\"",
398 if ( lutil_parse_time( retrylist[ i ], &t ) ) {
399 snprintf( buf, buflen,
400 "unable to parse interval #%d \"%s\"",
405 ri->ri_interval[ i ] = (time_t)t;
407 if ( strcmp( sep, "+" ) == 0 ) {
408 if ( retrylist[ i + 1 ] != NULL ) {
409 snprintf( buf, buflen,
410 "extra cruft after retry pattern "
411 "#%d \"%s,+\" with \"forever\" mark",
416 ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER;
418 } else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) {
419 snprintf( buf, buflen,
420 "unable to parse retry num #%d \"%s\"",
427 ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL;
431 ri->ri_last = (time_t)(-1);
434 ldap_charray_free( retrylist );
437 slap_retry_info_destroy( ri );
444 slap_retry_info_unparse(
445 slap_retry_info_t *ri,
446 struct berval *bvout )
449 char buf[ BUFSIZ * 2 ],
451 struct berval bv = BER_BVNULL;
453 assert( ri != NULL );
454 assert( bvout != NULL );
458 #define WHATSLEFT ( sizeof( buf ) - ( ptr - buf ) )
460 for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) {
462 if ( WHATSLEFT <= 1 ) {
468 if ( lutil_unparse_time( ptr, WHATSLEFT, (long)ri->ri_interval[i] ) ) {
471 ptr += strlen( ptr );
473 if ( WHATSLEFT <= 1 ) {
478 if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) {
479 if ( WHATSLEFT <= 1 ) {
485 ptr += snprintf( ptr, WHATSLEFT, "%d", ri->ri_num[i] );
486 if ( WHATSLEFT <= 0 ) {
493 bv.bv_len = ptr - buf;
495 ber_dupbv( bvout, &bv );
501 slap_retry_info_destroy(
502 slap_retry_info_t *ri )
504 assert( ri != NULL );
506 assert( ri->ri_interval != NULL );
507 ch_free( ri->ri_interval );
508 ri->ri_interval = NULL;
510 assert( ri->ri_num != NULL );
511 ch_free( ri->ri_num );
516 ldap_back_cf_gen( ConfigArgs *c )
518 ldapinfo_t *li = ( ldapinfo_t * )c->be->be_private;
522 if ( c->op == SLAP_CONFIG_EMIT ) {
523 struct berval bv = BER_BVNULL;
530 case LDAP_BACK_CFG_URI:
531 if ( li->li_uri != NULL ) {
534 ber_str2bv( li->li_uri, 0, 0, &bv );
535 value_add_one( &c->rvalue_vals, &bv );
542 case LDAP_BACK_CFG_TLS:
543 enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
544 assert( !BER_BVISNULL( &bv ) );
545 value_add_one( &c->rvalue_vals, &bv );
548 case LDAP_BACK_CFG_ACL_AUTHCDN:
549 case LDAP_BACK_CFG_ACL_PASSWD:
550 case LDAP_BACK_CFG_ACL_METHOD:
551 /* handled by LDAP_BACK_CFG_ACL_BIND */
555 case LDAP_BACK_CFG_ACL_BIND: {
558 if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
562 bindconf_unparse( &li->li_acl, &bv );
564 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
569 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
573 ber_bvarray_add( &c->rvalue_vals, &bv );
577 case LDAP_BACK_CFG_IDASSERT_MODE:
578 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
579 case LDAP_BACK_CFG_IDASSERT_PASSWD:
580 case LDAP_BACK_CFG_IDASSERT_METHOD:
581 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
585 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
588 if ( li->li_idassert_authz == NULL ) {
593 for ( i = 0; !BER_BVISNULL( &li->li_idassert_authz[ i ] ); i++ )
595 value_add_one( &c->rvalue_vals, &li->li_idassert_authz[ i ] );
600 case LDAP_BACK_CFG_IDASSERT_BIND: {
602 struct berval bc = BER_BVNULL;
605 if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
609 if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
612 switch ( li->li_idassert_mode ) {
613 case LDAP_BACK_IDASSERT_OTHERID:
614 case LDAP_BACK_IDASSERT_OTHERDN:
618 struct berval mode = BER_BVNULL;
620 enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
621 if ( BER_BVISNULL( &mode ) ) {
622 /* there's something wrong... */
627 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
628 bv.bv_val = ch_malloc( bv.bv_len + 1 );
630 ptr = lutil_strcopy( bv.bv_val, "mode=" );
631 ptr = lutil_strcopy( ptr, mode.bv_val );
637 if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
638 len = bv.bv_len + STRLENOF( "authz=native" );
640 if ( !BER_BVISEMPTY( &bv ) ) {
641 len += STRLENOF( " " );
644 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
646 ptr = &bv.bv_val[ bv.bv_len ];
648 if ( !BER_BVISEMPTY( &bv ) ) {
649 ptr = lutil_strcopy( ptr, " " );
652 (void)lutil_strcopy( ptr, "authz=native" );
655 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround" );
657 if ( !BER_BVISEMPTY( &bv ) ) {
658 len += STRLENOF( " " );
661 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
663 ptr = &bv.bv_val[ bv.bv_len ];
665 if ( !BER_BVISEMPTY( &bv ) ) {
666 ptr = lutil_strcopy( ptr, " " );
669 ptr = lutil_strcopy( ptr, "flags=" );
671 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
672 ptr = lutil_strcopy( ptr, "prescriptive" );
674 ptr = lutil_strcopy( ptr, "non-prescriptive" );
677 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
678 ptr = lutil_strcopy( ptr, ",override" );
681 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
682 ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" );
684 } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
685 ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" );
688 bv.bv_len = ( ptr - bv.bv_val );
692 bindconf_unparse( &li->li_idassert, &bc );
694 if ( !BER_BVISNULL( &bv ) ) {
695 ber_len_t len = bv.bv_len + bc.bv_len;
697 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
699 assert( bc.bv_val[ 0 ] == ' ' );
701 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
703 bv.bv_len = ptr - bv.bv_val;
706 for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ )
711 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
717 ber_bvarray_add( &c->rvalue_vals, &bv );
722 case LDAP_BACK_CFG_REBIND:
723 c->value_int = LDAP_BACK_SAVECRED( li );
726 case LDAP_BACK_CFG_CHASE:
727 c->value_int = LDAP_BACK_CHASE_REFERRALS( li );
730 case LDAP_BACK_CFG_T_F:
731 enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv );
732 if ( BER_BVISNULL( &bv ) ) {
733 /* there's something wrong... */
738 value_add_one( &c->rvalue_vals, &bv );
742 case LDAP_BACK_CFG_WHOAMI:
743 c->value_int = LDAP_BACK_PROXY_WHOAMI( li );
746 case LDAP_BACK_CFG_TIMEOUT:
749 for ( i = 0; i < LDAP_BACK_OP_LAST; i++ ) {
750 if ( li->li_timeout[ i ] != 0 ) {
755 if ( i == LDAP_BACK_OP_LAST ) {
759 slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table );
761 if ( BER_BVISNULL( &bv ) ) {
765 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
770 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
774 ber_bvarray_add( &c->rvalue_vals, &bv );
777 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
778 char buf[ SLAP_TEXT_BUFLEN ];
780 if ( li->li_idle_timeout == 0 ) {
784 lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout );
785 ber_str2bv( buf, 0, 0, &bv );
786 value_add_one( &c->rvalue_vals, &bv );
789 case LDAP_BACK_CFG_CONN_TTL: {
790 char buf[ SLAP_TEXT_BUFLEN ];
792 if ( li->li_conn_ttl == 0 ) {
796 lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl );
797 ber_str2bv( buf, 0, 0, &bv );
798 value_add_one( &c->rvalue_vals, &bv );
801 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
802 char buf[ SLAP_TEXT_BUFLEN ];
804 if ( li->li_network_timeout == 0 ) {
808 snprintf( buf, sizeof( buf ), "%ld",
809 (long)li->li_network_timeout );
810 ber_str2bv( buf, 0, 0, &bv );
811 value_add_one( &c->rvalue_vals, &bv );
814 case LDAP_BACK_CFG_VERSION:
815 if ( li->li_version == 0 ) {
819 c->value_int = li->li_version;
822 case LDAP_BACK_CFG_SINGLECONN:
823 c->value_int = LDAP_BACK_SINGLECONN( li );
826 case LDAP_BACK_CFG_CANCEL: {
827 slap_mask_t mask = LDAP_BACK_F_CANCEL_MASK2;
829 if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) {
830 mask &= ~LDAP_BACK_F_CANCEL_EXOP;
832 enum_to_verb( cancel_mode, (li->li_flags & mask), &bv );
833 if ( BER_BVISNULL( &bv ) ) {
834 /* there's something wrong... */
839 value_add_one( &c->rvalue_vals, &bv );
843 case LDAP_BACK_CFG_QUARANTINE:
844 if ( !LDAP_BACK_QUARANTINE( li ) ) {
849 rc = slap_retry_info_unparse( &li->li_quarantine, &bv );
851 ber_bvarray_add( &c->rvalue_vals, &bv );
856 /* FIXME: we need to handle all... */
862 } else if ( c->op == LDAP_MOD_DELETE ) {
864 case LDAP_BACK_CFG_URI:
865 if ( li->li_uri != NULL ) {
866 ch_free( li->li_uri );
869 assert( li->li_bvuri != NULL );
870 ber_bvarray_free( li->li_bvuri );
874 /* better cleanup the cached connections... */
875 /* NOTE: don't worry about locking: if we got here,
876 * other threads are suspended. */
877 if ( li->li_conninfo.lai_tree != NULL ) {
878 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
879 li->li_conninfo.lai_tree = NULL;
884 case LDAP_BACK_CFG_TLS:
888 case LDAP_BACK_CFG_ACL_AUTHCDN:
889 case LDAP_BACK_CFG_ACL_PASSWD:
890 case LDAP_BACK_CFG_ACL_METHOD:
891 /* handled by LDAP_BACK_CFG_ACL_BIND */
895 case LDAP_BACK_CFG_ACL_BIND:
896 bindconf_free( &li->li_acl );
899 case LDAP_BACK_CFG_IDASSERT_MODE:
900 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
901 case LDAP_BACK_CFG_IDASSERT_PASSWD:
902 case LDAP_BACK_CFG_IDASSERT_METHOD:
903 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
907 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
908 if ( li->li_idassert_authz != NULL ) {
909 ber_bvarray_free( li->li_idassert_authz );
910 li->li_idassert_authz = NULL;
914 case LDAP_BACK_CFG_IDASSERT_BIND:
915 bindconf_free( &li->li_idassert );
918 case LDAP_BACK_CFG_REBIND:
919 case LDAP_BACK_CFG_CHASE:
920 case LDAP_BACK_CFG_T_F:
921 case LDAP_BACK_CFG_WHOAMI:
922 case LDAP_BACK_CFG_CANCEL:
926 case LDAP_BACK_CFG_TIMEOUT:
927 for ( i = 0; i < LDAP_BACK_OP_LAST; i++ ) {
928 li->li_timeout[ i ] = 0;
932 case LDAP_BACK_CFG_IDLE_TIMEOUT:
933 li->li_idle_timeout = 0;
936 case LDAP_BACK_CFG_CONN_TTL:
940 case LDAP_BACK_CFG_NETWORK_TIMEOUT:
941 li->li_network_timeout = 0;
944 case LDAP_BACK_CFG_VERSION:
948 case LDAP_BACK_CFG_SINGLECONN:
949 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
952 case LDAP_BACK_CFG_QUARANTINE:
953 if ( !LDAP_BACK_QUARANTINE( li ) ) {
957 slap_retry_info_destroy( &li->li_quarantine );
958 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
959 li->li_isquarantined = 0;
963 /* FIXME: we need to handle all... */
972 case LDAP_BACK_CFG_URI: {
973 LDAPURLDesc *tmpludp, *lud;
974 char **urllist = NULL;
975 int urlrc = LDAP_URL_SUCCESS, i;
977 if ( li->li_uri != NULL ) {
978 ch_free( li->li_uri );
981 assert( li->li_bvuri != NULL );
982 ber_bvarray_free( li->li_bvuri );
986 /* PARANOID: DN and more are not required nor allowed */
987 urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
988 if ( urlrc != LDAP_URL_SUCCESS ) {
992 case LDAP_URL_ERR_MEM:
995 case LDAP_URL_ERR_PARAM:
996 why = "parameter is bad";
998 case LDAP_URL_ERR_BADSCHEME:
999 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1001 case LDAP_URL_ERR_BADENCLOSURE:
1002 why = "URL is missing trailing \">\"";
1004 case LDAP_URL_ERR_BADURL:
1007 case LDAP_URL_ERR_BADHOST:
1008 why = "host/port is bad";
1010 case LDAP_URL_ERR_BADATTRS:
1011 why = "bad (or missing) attributes";
1013 case LDAP_URL_ERR_BADSCOPE:
1014 why = "scope string is invalid (or missing)";
1016 case LDAP_URL_ERR_BADFILTER:
1017 why = "bad or missing filter";
1019 case LDAP_URL_ERR_BADEXTS:
1020 why = "bad or missing extensions";
1023 why = "unknown reason";
1026 snprintf( c->msg, sizeof( c->msg),
1027 "unable to parse uri \"%s\" "
1028 "in \"uri <uri>\" line: %s",
1029 c->value_string, why );
1030 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1035 for ( i = 0, tmpludp = lud;
1037 i++, tmpludp = tmpludp->lud_next )
1039 if ( ( tmpludp->lud_dn != NULL
1040 && tmpludp->lud_dn[0] != '\0' )
1041 || tmpludp->lud_attrs != NULL
1042 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1043 || tmpludp->lud_filter != NULL
1044 || tmpludp->lud_exts != NULL )
1046 snprintf( c->msg, sizeof( c->msg ),
1047 "warning, only protocol, "
1048 "host and port allowed "
1049 "in \"uri <uri>\" statement "
1050 "for uri #%d of \"%s\"",
1052 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1056 for ( i = 0, tmpludp = lud;
1058 i++, tmpludp = tmpludp->lud_next )
1061 urllist = ch_calloc( sizeof( char * ), i + 1 );
1063 for ( i = 0, tmpludp = lud;
1065 i++, tmpludp = tmpludp->lud_next )
1071 tmplud.lud_attrs = NULL;
1072 tmplud.lud_filter = NULL;
1073 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1074 tmplud.lud_exts = NULL;
1075 tmplud.lud_crit_exts = 0;
1078 urllist[ i ] = ldap_url_desc2str( &tmplud );
1080 if ( urllist[ i ] == NULL ) {
1081 snprintf( c->msg, sizeof( c->msg),
1082 "unable to rebuild uri "
1083 "in \"uri <uri>\" statement "
1086 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1092 li->li_uri = ldap_charray2str( urllist, " " );
1093 for ( i = 0; urllist[ i ] != NULL; i++ ) {
1096 ber_str2bv( urllist[ i ], 0, 0, &bv );
1097 ber_bvarray_add( &li->li_bvuri, &bv );
1098 urllist[ i ] = NULL;
1100 ldap_memfree( urllist );
1105 ldap_charray_free( urllist );
1108 ldap_free_urllist( lud );
1110 if ( urlrc != LDAP_URL_SUCCESS ) {
1116 case LDAP_BACK_CFG_TLS:
1117 i = verb_to_mask( c->argv[1], tls_mode );
1118 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
1121 li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
1122 li->li_flags |= tls_mode[i].mask;
1125 case LDAP_BACK_CFG_ACL_AUTHCDN:
1126 switch ( li->li_acl_authmethod ) {
1127 case LDAP_AUTH_NONE:
1128 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1131 case LDAP_AUTH_SIMPLE:
1135 snprintf( c->msg, sizeof( c->msg),
1136 "\"acl-authcDN <DN>\" incompatible "
1137 "with auth method %d",
1138 li->li_acl_authmethod );
1139 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1142 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
1143 free( li->li_acl_authcDN.bv_val );
1145 ber_memfree_x( c->value_dn.bv_val, NULL );
1146 li->li_acl_authcDN = c->value_ndn;
1147 BER_BVZERO( &c->value_dn );
1148 BER_BVZERO( &c->value_ndn );
1151 case LDAP_BACK_CFG_ACL_PASSWD:
1152 switch ( li->li_acl_authmethod ) {
1153 case LDAP_AUTH_NONE:
1154 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1157 case LDAP_AUTH_SIMPLE:
1161 snprintf( c->msg, sizeof( c->msg ),
1162 "\"acl-passwd <cred>\" incompatible "
1163 "with auth method %d",
1164 li->li_acl_authmethod );
1165 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1168 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
1169 free( li->li_acl_passwd.bv_val );
1171 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
1174 case LDAP_BACK_CFG_ACL_METHOD:
1175 case LDAP_BACK_CFG_ACL_BIND:
1176 for ( i = 1; i < c->argc; i++ ) {
1177 if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
1183 case LDAP_BACK_CFG_IDASSERT_MODE:
1184 i = verb_to_mask( c->argv[1], idassert_mode );
1185 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
1186 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
1187 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1188 ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
1189 li->li_idassert_authzID.bv_val[ 0 ] = 'u';
1192 struct berval id, ndn;
1194 ber_str2bv( c->argv[1], 0, 0, &id );
1196 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1197 id.bv_val += STRLENOF( "dn:" );
1198 id.bv_len -= STRLENOF( "dn:" );
1201 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
1202 if ( rc != LDAP_SUCCESS ) {
1203 Debug( LDAP_DEBUG_ANY,
1204 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1205 c->fname, c->lineno, c->argv[1] );
1209 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1210 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
1211 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1212 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
1213 ch_free( ndn.bv_val );
1215 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1219 li->li_idassert_mode = idassert_mode[i].mask;
1222 if ( c->argc > 2 ) {
1225 for ( i = 2; i < c->argc; i++ ) {
1226 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
1227 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1229 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
1230 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1232 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
1233 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1235 } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
1236 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1237 Debug( LDAP_DEBUG_ANY,
1238 "%s: line %d: \"obsolete-proxy-authz\" flag "
1239 "in \"idassert-mode <args>\" "
1240 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1241 c->fname, c->lineno, 0 );
1244 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1246 } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
1247 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1248 Debug( LDAP_DEBUG_ANY,
1249 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1250 "in \"idassert-mode <args>\" "
1251 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1252 c->fname, c->lineno, 0 );
1255 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1258 Debug( LDAP_DEBUG_ANY,
1259 "%s: line %d: unknown flag #%d "
1260 "in \"idassert-mode <args> "
1261 "[<flags>]\" line.\n",
1262 c->fname, c->lineno, i - 2 );
1269 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1270 switch ( li->li_idassert_authmethod ) {
1271 case LDAP_AUTH_NONE:
1272 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1275 case LDAP_AUTH_SIMPLE:
1279 snprintf( c->msg, sizeof( c->msg ),
1280 "\"idassert-authcDN <DN>\" incompatible "
1281 "with auth method %d",
1282 li->li_idassert_authmethod );
1283 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1286 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1287 free( li->li_idassert_authcDN.bv_val );
1289 ber_memfree_x( c->value_dn.bv_val, NULL );
1290 li->li_idassert_authcDN = c->value_ndn;
1291 BER_BVZERO( &c->value_dn );
1292 BER_BVZERO( &c->value_ndn );
1295 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1296 switch ( li->li_idassert_authmethod ) {
1297 case LDAP_AUTH_NONE:
1298 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1301 case LDAP_AUTH_SIMPLE:
1305 snprintf( c->msg, sizeof( c->msg ),
1306 "\"idassert-passwd <cred>\" incompatible "
1307 "with auth method %d",
1308 li->li_idassert_authmethod );
1309 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1312 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
1313 free( li->li_idassert_passwd.bv_val );
1315 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
1318 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
1323 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
1324 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
1325 if ( rc != LDAP_SUCCESS ) {
1326 snprintf( c->msg, sizeof( c->msg ),
1327 "\"idassert-authzFrom <authz>\": "
1329 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1332 ber_bvarray_add( &li->li_idassert_authz, &bv );
1335 case LDAP_BACK_CFG_IDASSERT_METHOD:
1336 /* no longer supported */
1337 snprintf( c->msg, sizeof( c->msg ),
1338 "\"idassert-method <args>\": "
1339 "no longer supported; use \"idassert-bind\"" );
1340 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1343 case LDAP_BACK_CFG_IDASSERT_BIND:
1344 for ( i = 1; i < c->argc; i++ ) {
1345 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
1346 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
1349 j = verb_to_mask( argvi, idassert_mode );
1350 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
1351 snprintf( c->msg, sizeof( c->msg ),
1352 "\"idassert-bind <args>\": "
1353 "unknown mode \"%s\"",
1355 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1359 li->li_idassert_mode = idassert_mode[ j ].mask;
1361 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1362 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
1364 if ( strcasecmp( argvi, "native" ) == 0 ) {
1365 if ( li->li_idassert_authmethod != LDAP_AUTH_SASL ) {
1366 snprintf( c->msg, sizeof( c->msg ),
1367 "\"idassert-bind <args>\": "
1368 "authz=\"native\" incompatible "
1369 "with auth method" );
1370 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1373 li->li_idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1375 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
1376 li->li_idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1379 snprintf( c->msg, sizeof( c->msg ),
1380 "\"idassert-bind <args>\": "
1381 "unknown authz \"%s\"",
1383 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1387 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
1388 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
1389 char **flags = ldap_str2charray( argvi, "," );
1392 if ( flags == NULL ) {
1393 snprintf( c->msg, sizeof( c->msg ),
1394 "\"idassert-bind <args>\": "
1395 "unable to parse flags \"%s\"",
1397 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1401 for ( j = 0; flags[ j ] != NULL; j++ ) {
1403 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
1404 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1406 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
1407 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1409 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
1410 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1412 } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
1413 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1414 Debug( LDAP_DEBUG_ANY,
1415 "%s: line %d: \"obsolete-proxy-authz\" flag "
1416 "in \"idassert-mode <args>\" "
1417 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1418 c->fname, c->lineno, 0 );
1423 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1426 } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
1427 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1428 Debug( LDAP_DEBUG_ANY,
1429 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1430 "in \"idassert-mode <args>\" "
1431 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1432 c->fname, c->lineno, 0 );
1437 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1441 snprintf( c->msg, sizeof( c->msg ),
1442 "\"idassert-bind <args>\": "
1443 "unknown flag \"%s\"",
1445 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1451 ldap_charray_free( flags );
1456 } else if ( bindconf_parse( c->argv[ i ], &li->li_idassert ) ) {
1462 case LDAP_BACK_CFG_REBIND:
1463 if ( c->argc == 1 || c->value_int ) {
1464 li->li_flags |= LDAP_BACK_F_SAVECRED;
1467 li->li_flags &= ~LDAP_BACK_F_SAVECRED;
1471 case LDAP_BACK_CFG_CHASE:
1472 if ( c->argc == 1 || c->value_int ) {
1473 li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
1476 li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1480 case LDAP_BACK_CFG_T_F: {
1483 i = verb_to_mask( c->argv[1], t_f_mode );
1484 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1488 mask = t_f_mode[i].mask;
1490 if ( LDAP_BACK_ISOPEN( li )
1491 && mask == LDAP_BACK_F_T_F_DISCOVER
1492 && !LDAP_BACK_T_F( li ) )
1496 if ( li->li_uri == NULL ) {
1497 snprintf( c->msg, sizeof( c->msg ),
1498 "need URI to discover \"cancel\" support "
1499 "in \"cancel exop-discover\"" );
1500 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1504 rc = slap_discover_feature( li->li_uri, li->li_version,
1505 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
1506 LDAP_FEATURE_ABSOLUTE_FILTERS );
1507 if ( rc == LDAP_COMPARE_TRUE ) {
1508 mask |= LDAP_BACK_F_T_F;
1512 li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
1513 li->li_flags |= mask;
1516 case LDAP_BACK_CFG_WHOAMI:
1517 if ( c->argc == 1 || c->value_int ) {
1518 li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
1519 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1520 0, ldap_back_exop_whoami );
1523 li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1527 case LDAP_BACK_CFG_TIMEOUT:
1528 for ( i = 1; i < c->argc; i++ ) {
1529 if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
1533 if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
1537 for ( j = 0; j < LDAP_BACK_OP_LAST; j++ ) {
1538 li->li_timeout[ j ] = u;
1544 if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
1550 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1553 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1554 snprintf( c->msg, sizeof( c->msg),
1555 "unable to parse idle timeout \"%s\"",
1557 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1560 li->li_idle_timeout = (time_t)t;
1563 case LDAP_BACK_CFG_CONN_TTL: {
1566 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1567 snprintf( c->msg, sizeof( c->msg),
1568 "unable to parse conn ttl\"%s\"",
1570 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1573 li->li_conn_ttl = (time_t)t;
1576 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1579 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1580 snprintf( c->msg, sizeof( c->msg),
1581 "unable to parse network timeout \"%s\"",
1583 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1586 li->li_network_timeout = (time_t)t;
1589 case LDAP_BACK_CFG_VERSION:
1590 if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
1591 snprintf( c->msg, sizeof( c->msg ),
1592 "unsupported version \"%s\" "
1593 "in \"protocol-version <version>\"",
1595 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1599 li->li_version = c->value_int;
1602 case LDAP_BACK_CFG_SINGLECONN:
1603 if ( c->value_int ) {
1604 li->li_flags |= LDAP_BACK_F_SINGLECONN;
1607 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1611 case LDAP_BACK_CFG_CANCEL: {
1614 i = verb_to_mask( c->argv[1], cancel_mode );
1615 if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
1619 mask = cancel_mode[i].mask;
1621 if ( LDAP_BACK_ISOPEN( li )
1622 && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
1623 && !LDAP_BACK_CANCEL( li ) )
1627 if ( li->li_uri == NULL ) {
1628 snprintf( c->msg, sizeof( c->msg ),
1629 "need URI to discover \"cancel\" support "
1630 "in \"cancel exop-discover\"" );
1631 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1635 rc = slap_discover_feature( li->li_uri, li->li_version,
1636 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
1638 if ( rc == LDAP_COMPARE_TRUE ) {
1639 mask |= LDAP_BACK_F_CANCEL_EXOP;
1643 li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
1644 li->li_flags |= mask;
1647 case LDAP_BACK_CFG_QUARANTINE:
1648 if ( LDAP_BACK_QUARANTINE( li ) ) {
1649 snprintf( c->msg, sizeof( c->msg ),
1650 "quarantine already defined" );
1651 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1654 rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
1655 c->msg, sizeof( c->msg ) );
1657 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1660 ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex );
1661 /* give it a chance to retry if the pattern gets reset
1662 * via back-config */
1663 li->li_isquarantined = 0;
1667 case LDAP_BACK_CFG_REWRITE:
1668 snprintf( c->msg, sizeof( c->msg ),
1669 "rewrite/remap capabilities have been moved "
1670 "to the \"rwm\" overlay; see slapo-rwm(5) "
1671 "for details (hint: add \"overlay rwm\" "
1672 "and prefix all directives with \"rwm-\")" );
1673 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1677 /* FIXME: try to catch inconsistencies */
1686 ldap_back_init_cf( BackendInfo *bi )
1689 AttributeDescription *ad = NULL;
1692 /* Make sure we don't exceed the bits reserved for userland */
1693 config_check_userland( LDAP_BACK_CFG_LAST );
1695 bi->bi_cf_ocs = ldapocs;
1697 rc = config_register_schema( ldapcfg, ldapocs );
1702 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1703 * to be base64-encoded when written in LDIF form;
1704 * basically, we don't care if it fails */
1705 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1707 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1708 "warning, unable to get \"olcDbACLPasswd\" "
1709 "attribute description: %d: %s\n",
1712 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1713 ad->ad_type->sat_oid );
1717 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1719 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1720 "warning, unable to get \"olcDbIDAssertPasswd\" "
1721 "attribute description: %d: %s\n",
1724 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1725 ad->ad_type->sat_oid );
1733 ldap_back_exop_whoami(
1737 struct berval *bv = NULL;
1739 if ( op->oq_extended.rs_reqdata != NULL ) {
1740 /* no request data should be provided */
1741 rs->sr_text = "no request data expected";
1742 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1745 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
1746 op->o_log_prefix, 0, 0, 0, 0 );
1748 rs->sr_err = backend_check_restrictions( op, rs,
1749 (struct berval *)&slap_EXOP_WHOAMI );
1750 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1752 /* if auth'd by back-ldap and request is proxied, forward it */
1753 if ( op->o_conn->c_authz_backend
1754 && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
1755 && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
1758 LDAPControl c, *ctrls[2] = {NULL, NULL};
1760 Operation op2 = *op;
1766 op2.o_ndn = op->o_conn->c_ndn;
1767 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1768 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
1771 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1772 c.ldctl_iscritical = 1;
1773 c.ldctl_value.bv_val = op->o_tmpalloc(
1774 op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
1776 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1777 ptr = c.ldctl_value.bv_val;
1778 ptr = lutil_strcopy( ptr, "dn:" );
1779 ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
1783 rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
1784 if ( rs->sr_err == LDAP_SUCCESS ) {
1785 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, NULL, &res ) == -1 ) {
1786 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1788 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1790 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
1796 /* NOTE: are we sure "bv" will be malloc'ed
1797 * with the appropriate memory? */
1798 rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
1802 op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
1803 if ( rs->sr_err != LDAP_SUCCESS ) {
1804 rs->sr_err = slap_map_api2result( rs );
1808 ldap_back_release_conn( &op2, rs, lc );
1812 /* else just do the same as before */
1813 bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
1814 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1815 bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
1816 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1817 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
1818 AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
1820 bv->bv_val[ bv->bv_len ] = '\0';
1828 rs->sr_rspdata = bv;