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 li->li_isquarantined = 0;
962 /* FIXME: we need to handle all... */
971 case LDAP_BACK_CFG_URI: {
972 LDAPURLDesc *tmpludp, *lud;
973 char **urllist = NULL;
974 int urlrc = LDAP_URL_SUCCESS, i;
976 if ( li->li_uri != NULL ) {
977 ch_free( li->li_uri );
980 assert( li->li_bvuri != NULL );
981 ber_bvarray_free( li->li_bvuri );
985 /* PARANOID: DN and more are not required nor allowed */
986 urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
987 if ( urlrc != LDAP_URL_SUCCESS ) {
991 case LDAP_URL_ERR_MEM:
994 case LDAP_URL_ERR_PARAM:
995 why = "parameter is bad";
997 case LDAP_URL_ERR_BADSCHEME:
998 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1000 case LDAP_URL_ERR_BADENCLOSURE:
1001 why = "URL is missing trailing \">\"";
1003 case LDAP_URL_ERR_BADURL:
1006 case LDAP_URL_ERR_BADHOST:
1007 why = "host/port is bad";
1009 case LDAP_URL_ERR_BADATTRS:
1010 why = "bad (or missing) attributes";
1012 case LDAP_URL_ERR_BADSCOPE:
1013 why = "scope string is invalid (or missing)";
1015 case LDAP_URL_ERR_BADFILTER:
1016 why = "bad or missing filter";
1018 case LDAP_URL_ERR_BADEXTS:
1019 why = "bad or missing extensions";
1022 why = "unknown reason";
1025 snprintf( c->msg, sizeof( c->msg),
1026 "unable to parse uri \"%s\" "
1027 "in \"uri <uri>\" line: %s",
1028 c->value_string, why );
1029 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1034 for ( i = 0, tmpludp = lud;
1036 i++, tmpludp = tmpludp->lud_next )
1038 if ( ( tmpludp->lud_dn != NULL
1039 && tmpludp->lud_dn[0] != '\0' )
1040 || tmpludp->lud_attrs != NULL
1041 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1042 || tmpludp->lud_filter != NULL
1043 || tmpludp->lud_exts != NULL )
1045 snprintf( c->msg, sizeof( c->msg ),
1046 "warning, only protocol, "
1047 "host and port allowed "
1048 "in \"uri <uri>\" statement "
1049 "for uri #%d of \"%s\"",
1051 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1055 for ( i = 0, tmpludp = lud;
1057 i++, tmpludp = tmpludp->lud_next )
1060 urllist = ch_calloc( sizeof( char * ), i + 1 );
1062 for ( i = 0, tmpludp = lud;
1064 i++, tmpludp = tmpludp->lud_next )
1070 tmplud.lud_attrs = NULL;
1071 tmplud.lud_filter = NULL;
1072 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1073 tmplud.lud_exts = NULL;
1074 tmplud.lud_crit_exts = 0;
1077 urllist[ i ] = ldap_url_desc2str( &tmplud );
1079 if ( urllist[ i ] == NULL ) {
1080 snprintf( c->msg, sizeof( c->msg),
1081 "unable to rebuild uri "
1082 "in \"uri <uri>\" statement "
1085 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1091 li->li_uri = ldap_charray2str( urllist, " " );
1092 for ( i = 0; urllist[ i ] != NULL; i++ ) {
1095 ber_str2bv( urllist[ i ], 0, 0, &bv );
1096 ber_bvarray_add( &li->li_bvuri, &bv );
1097 urllist[ i ] = NULL;
1099 ldap_memfree( urllist );
1104 ldap_charray_free( urllist );
1107 ldap_free_urllist( lud );
1109 if ( urlrc != LDAP_URL_SUCCESS ) {
1115 case LDAP_BACK_CFG_TLS:
1116 i = verb_to_mask( c->argv[1], tls_mode );
1117 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
1120 li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
1121 li->li_flags |= tls_mode[i].mask;
1124 case LDAP_BACK_CFG_ACL_AUTHCDN:
1125 switch ( li->li_acl_authmethod ) {
1126 case LDAP_AUTH_NONE:
1127 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1130 case LDAP_AUTH_SIMPLE:
1134 snprintf( c->msg, sizeof( c->msg),
1135 "\"acl-authcDN <DN>\" incompatible "
1136 "with auth method %d",
1137 li->li_acl_authmethod );
1138 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1141 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
1142 free( li->li_acl_authcDN.bv_val );
1144 ber_memfree_x( c->value_dn.bv_val, NULL );
1145 li->li_acl_authcDN = c->value_ndn;
1146 BER_BVZERO( &c->value_dn );
1147 BER_BVZERO( &c->value_ndn );
1150 case LDAP_BACK_CFG_ACL_PASSWD:
1151 switch ( li->li_acl_authmethod ) {
1152 case LDAP_AUTH_NONE:
1153 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1156 case LDAP_AUTH_SIMPLE:
1160 snprintf( c->msg, sizeof( c->msg ),
1161 "\"acl-passwd <cred>\" incompatible "
1162 "with auth method %d",
1163 li->li_acl_authmethod );
1164 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1167 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
1168 free( li->li_acl_passwd.bv_val );
1170 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
1173 case LDAP_BACK_CFG_ACL_METHOD:
1174 case LDAP_BACK_CFG_ACL_BIND:
1175 for ( i = 1; i < c->argc; i++ ) {
1176 if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
1182 case LDAP_BACK_CFG_IDASSERT_MODE:
1183 i = verb_to_mask( c->argv[1], idassert_mode );
1184 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
1185 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
1186 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1187 ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
1188 li->li_idassert_authzID.bv_val[ 0 ] = 'u';
1191 struct berval id, ndn;
1193 ber_str2bv( c->argv[1], 0, 0, &id );
1195 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1196 id.bv_val += STRLENOF( "dn:" );
1197 id.bv_len -= STRLENOF( "dn:" );
1200 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
1201 if ( rc != LDAP_SUCCESS ) {
1202 Debug( LDAP_DEBUG_ANY,
1203 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1204 c->fname, c->lineno, c->argv[1] );
1208 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1209 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
1210 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1211 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
1212 ch_free( ndn.bv_val );
1214 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1218 li->li_idassert_mode = idassert_mode[i].mask;
1221 if ( c->argc > 2 ) {
1224 for ( i = 2; i < c->argc; i++ ) {
1225 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
1226 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1228 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
1229 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1231 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
1232 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1234 } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
1235 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1236 Debug( LDAP_DEBUG_ANY,
1237 "%s: line %d: \"obsolete-proxy-authz\" flag "
1238 "in \"idassert-mode <args>\" "
1239 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1240 c->fname, c->lineno, 0 );
1243 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1245 } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
1246 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1247 Debug( LDAP_DEBUG_ANY,
1248 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1249 "in \"idassert-mode <args>\" "
1250 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1251 c->fname, c->lineno, 0 );
1254 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1257 Debug( LDAP_DEBUG_ANY,
1258 "%s: line %d: unknown flag #%d "
1259 "in \"idassert-mode <args> "
1260 "[<flags>]\" line.\n",
1261 c->fname, c->lineno, i - 2 );
1268 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1269 switch ( li->li_idassert_authmethod ) {
1270 case LDAP_AUTH_NONE:
1271 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1274 case LDAP_AUTH_SIMPLE:
1278 snprintf( c->msg, sizeof( c->msg ),
1279 "\"idassert-authcDN <DN>\" incompatible "
1280 "with auth method %d",
1281 li->li_idassert_authmethod );
1282 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1285 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1286 free( li->li_idassert_authcDN.bv_val );
1288 ber_memfree_x( c->value_dn.bv_val, NULL );
1289 li->li_idassert_authcDN = c->value_ndn;
1290 BER_BVZERO( &c->value_dn );
1291 BER_BVZERO( &c->value_ndn );
1294 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1295 switch ( li->li_idassert_authmethod ) {
1296 case LDAP_AUTH_NONE:
1297 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1300 case LDAP_AUTH_SIMPLE:
1304 snprintf( c->msg, sizeof( c->msg ),
1305 "\"idassert-passwd <cred>\" incompatible "
1306 "with auth method %d",
1307 li->li_idassert_authmethod );
1308 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1311 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
1312 free( li->li_idassert_passwd.bv_val );
1314 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
1317 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
1322 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
1323 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
1324 if ( rc != LDAP_SUCCESS ) {
1325 snprintf( c->msg, sizeof( c->msg ),
1326 "\"idassert-authzFrom <authz>\": "
1328 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1331 ber_bvarray_add( &li->li_idassert_authz, &bv );
1334 case LDAP_BACK_CFG_IDASSERT_METHOD:
1335 /* no longer supported */
1336 snprintf( c->msg, sizeof( c->msg ),
1337 "\"idassert-method <args>\": "
1338 "no longer supported; use \"idassert-bind\"" );
1339 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1342 case LDAP_BACK_CFG_IDASSERT_BIND:
1343 for ( i = 1; i < c->argc; i++ ) {
1344 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
1345 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
1348 j = verb_to_mask( argvi, idassert_mode );
1349 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
1350 snprintf( c->msg, sizeof( c->msg ),
1351 "\"idassert-bind <args>\": "
1352 "unknown mode \"%s\"",
1354 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1358 li->li_idassert_mode = idassert_mode[ j ].mask;
1360 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
1361 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
1363 if ( strcasecmp( argvi, "native" ) == 0 ) {
1364 if ( li->li_idassert_authmethod != LDAP_AUTH_SASL ) {
1365 snprintf( c->msg, sizeof( c->msg ),
1366 "\"idassert-bind <args>\": "
1367 "authz=\"native\" incompatible "
1368 "with auth method" );
1369 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1372 li->li_idassert_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
1374 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
1375 li->li_idassert_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
1378 snprintf( c->msg, sizeof( c->msg ),
1379 "\"idassert-bind <args>\": "
1380 "unknown authz \"%s\"",
1382 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1386 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
1387 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
1388 char **flags = ldap_str2charray( argvi, "," );
1391 if ( flags == NULL ) {
1392 snprintf( c->msg, sizeof( c->msg ),
1393 "\"idassert-bind <args>\": "
1394 "unable to parse flags \"%s\"",
1396 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1400 for ( j = 0; flags[ j ] != NULL; j++ ) {
1402 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
1403 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1405 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
1406 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1408 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
1409 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1411 } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
1412 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1413 Debug( LDAP_DEBUG_ANY,
1414 "%s: line %d: \"obsolete-proxy-authz\" flag "
1415 "in \"idassert-mode <args>\" "
1416 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1417 c->fname, c->lineno, 0 );
1422 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1425 } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
1426 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1427 Debug( LDAP_DEBUG_ANY,
1428 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1429 "in \"idassert-mode <args>\" "
1430 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1431 c->fname, c->lineno, 0 );
1436 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1440 snprintf( c->msg, sizeof( c->msg ),
1441 "\"idassert-bind <args>\": "
1442 "unknown flag \"%s\"",
1444 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1450 ldap_charray_free( flags );
1455 } else if ( bindconf_parse( c->argv[ i ], &li->li_idassert ) ) {
1461 case LDAP_BACK_CFG_REBIND:
1462 if ( c->argc == 1 || c->value_int ) {
1463 li->li_flags |= LDAP_BACK_F_SAVECRED;
1466 li->li_flags &= ~LDAP_BACK_F_SAVECRED;
1470 case LDAP_BACK_CFG_CHASE:
1471 if ( c->argc == 1 || c->value_int ) {
1472 li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
1475 li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1479 case LDAP_BACK_CFG_T_F: {
1482 i = verb_to_mask( c->argv[1], t_f_mode );
1483 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1487 mask = t_f_mode[i].mask;
1489 if ( LDAP_BACK_ISOPEN( li )
1490 && mask == LDAP_BACK_F_T_F_DISCOVER
1491 && !LDAP_BACK_T_F( li ) )
1495 if ( li->li_uri == NULL ) {
1496 snprintf( c->msg, sizeof( c->msg ),
1497 "need URI to discover \"cancel\" support "
1498 "in \"cancel exop-discover\"" );
1499 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1503 rc = slap_discover_feature( li->li_uri, li->li_version,
1504 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
1505 LDAP_FEATURE_ABSOLUTE_FILTERS );
1506 if ( rc == LDAP_COMPARE_TRUE ) {
1507 mask |= LDAP_BACK_F_T_F;
1511 li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
1512 li->li_flags |= mask;
1515 case LDAP_BACK_CFG_WHOAMI:
1516 if ( c->argc == 1 || c->value_int ) {
1517 li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
1518 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1519 0, ldap_back_exop_whoami );
1522 li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1526 case LDAP_BACK_CFG_TIMEOUT:
1527 for ( i = 1; i < c->argc; i++ ) {
1528 if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
1532 if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
1536 for ( j = 0; j < LDAP_BACK_OP_LAST; j++ ) {
1537 li->li_timeout[ j ] = u;
1543 if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
1549 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1552 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1553 snprintf( c->msg, sizeof( c->msg),
1554 "unable to parse idle timeout \"%s\"",
1556 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1559 li->li_idle_timeout = (time_t)t;
1562 case LDAP_BACK_CFG_CONN_TTL: {
1565 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1566 snprintf( c->msg, sizeof( c->msg),
1567 "unable to parse conn ttl\"%s\"",
1569 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1572 li->li_conn_ttl = (time_t)t;
1575 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1578 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1579 snprintf( c->msg, sizeof( c->msg),
1580 "unable to parse network timeout \"%s\"",
1582 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1585 li->li_network_timeout = (time_t)t;
1588 case LDAP_BACK_CFG_VERSION:
1589 if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
1590 snprintf( c->msg, sizeof( c->msg ),
1591 "unsupported version \"%s\" "
1592 "in \"protocol-version <version>\"",
1594 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1598 li->li_version = c->value_int;
1601 case LDAP_BACK_CFG_SINGLECONN:
1602 if ( c->value_int ) {
1603 li->li_flags |= LDAP_BACK_F_SINGLECONN;
1606 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1610 case LDAP_BACK_CFG_CANCEL: {
1613 i = verb_to_mask( c->argv[1], cancel_mode );
1614 if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
1618 mask = cancel_mode[i].mask;
1620 if ( LDAP_BACK_ISOPEN( li )
1621 && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
1622 && !LDAP_BACK_CANCEL( li ) )
1626 if ( li->li_uri == NULL ) {
1627 snprintf( c->msg, sizeof( c->msg ),
1628 "need URI to discover \"cancel\" support "
1629 "in \"cancel exop-discover\"" );
1630 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1634 rc = slap_discover_feature( li->li_uri, li->li_version,
1635 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
1637 if ( rc == LDAP_COMPARE_TRUE ) {
1638 mask |= LDAP_BACK_F_CANCEL_EXOP;
1642 li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
1643 li->li_flags |= mask;
1646 case LDAP_BACK_CFG_QUARANTINE:
1647 if ( LDAP_BACK_QUARANTINE( li ) ) {
1648 snprintf( c->msg, sizeof( c->msg ),
1649 "quarantine already defined" );
1650 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1653 rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
1654 c->msg, sizeof( c->msg ) );
1656 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1658 /* give it a chance to retry if the pattern gets reset
1659 * via back-config */
1660 li->li_isquarantined = 0;
1663 case LDAP_BACK_CFG_REWRITE:
1664 snprintf( c->msg, sizeof( c->msg ),
1665 "rewrite/remap capabilities have been moved "
1666 "to the \"rwm\" overlay; see slapo-rwm(5) "
1667 "for details (hint: add \"overlay rwm\" "
1668 "and prefix all directives with \"rwm-\")" );
1669 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1673 /* FIXME: try to catch inconsistencies */
1682 ldap_back_init_cf( BackendInfo *bi )
1685 AttributeDescription *ad = NULL;
1688 /* Make sure we don't exceed the bits reserved for userland */
1689 config_check_userland( LDAP_BACK_CFG_LAST );
1691 bi->bi_cf_ocs = ldapocs;
1693 rc = config_register_schema( ldapcfg, ldapocs );
1698 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1699 * to be base64-encoded when written in LDIF form;
1700 * basically, we don't care if it fails */
1701 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1703 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1704 "warning, unable to get \"olcDbACLPasswd\" "
1705 "attribute description: %d: %s\n",
1708 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1709 ad->ad_type->sat_oid );
1713 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1715 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1716 "warning, unable to get \"olcDbIDAssertPasswd\" "
1717 "attribute description: %d: %s\n",
1720 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1721 ad->ad_type->sat_oid );
1729 ldap_back_exop_whoami(
1733 struct berval *bv = NULL;
1735 if ( op->oq_extended.rs_reqdata != NULL ) {
1736 /* no request data should be provided */
1737 rs->sr_text = "no request data expected";
1738 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1741 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
1742 op->o_log_prefix, 0, 0, 0, 0 );
1744 rs->sr_err = backend_check_restrictions( op, rs,
1745 (struct berval *)&slap_EXOP_WHOAMI );
1746 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1748 /* if auth'd by back-ldap and request is proxied, forward it */
1749 if ( op->o_conn->c_authz_backend
1750 && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
1751 && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
1754 LDAPControl c, *ctrls[2] = {NULL, NULL};
1756 Operation op2 = *op;
1762 op2.o_ndn = op->o_conn->c_ndn;
1763 lc = ldap_back_getconn(&op2, rs, LDAP_BACK_SENDERR);
1764 if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) {
1767 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1768 c.ldctl_iscritical = 1;
1769 c.ldctl_value.bv_val = op->o_tmpalloc(
1770 op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
1772 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1773 ptr = c.ldctl_value.bv_val;
1774 ptr = lutil_strcopy( ptr, "dn:" );
1775 ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
1779 rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
1780 if ( rs->sr_err == LDAP_SUCCESS ) {
1781 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, NULL, &res ) == -1 ) {
1782 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1784 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1786 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
1792 /* NOTE: are we sure "bv" will be malloc'ed
1793 * with the appropriate memory? */
1794 rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
1798 op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
1799 if ( rs->sr_err != LDAP_SUCCESS ) {
1800 rs->sr_err = slap_map_api2result( rs );
1804 ldap_back_release_conn( &op2, rs, lc );
1808 /* else just do the same as before */
1809 bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
1810 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
1811 bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
1812 bv->bv_val = ch_malloc( bv->bv_len + 1 );
1813 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
1814 AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
1816 bv->bv_val[ bv->bv_len ] = '\0';
1824 rs->sr_rspdata = bv;