1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2007 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,
68 LDAP_BACK_CFG_USETEMP,
69 LDAP_BACK_CFG_CONNPOOLMAX,
71 LDAP_BACK_CFG_QUARANTINE,
72 LDAP_BACK_CFG_REWRITE,
77 static ConfigTable ldapcfg[] = {
78 { "uri", "uri", 2, 2, 0,
79 ARG_MAGIC|LDAP_BACK_CFG_URI,
80 ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
82 "DESC 'URI (list) for remote DSA' "
83 "SYNTAX OMsDirectoryString "
86 { "tls", "what", 2, 0, 0,
87 ARG_MAGIC|LDAP_BACK_CFG_TLS,
88 ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
89 "NAME 'olcDbStartTLS' "
91 "SYNTAX OMsDirectoryString "
94 { "acl-authcDN", "DN", 2, 2, 0,
95 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
96 ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
97 "NAME 'olcDbACLAuthcDn' "
98 "DESC 'Remote ACL administrative identity' "
103 /* deprecated, will be removed; aliases "acl-authcDN" */
104 { "binddn", "DN", 2, 2, 0,
105 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
106 ldap_back_cf_gen, NULL, NULL, NULL },
107 { "acl-passwd", "cred", 2, 2, 0,
108 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
109 ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
110 "NAME 'olcDbACLPasswd' "
111 "DESC 'Remote ACL administrative identity credentials' "
113 "SYNTAX OMsDirectoryString "
116 /* deprecated, will be removed; aliases "acl-passwd" */
117 { "bindpw", "cred", 2, 2, 0,
118 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
119 ldap_back_cf_gen, NULL, NULL, NULL },
120 /* deprecated, will be removed; aliases "acl-bind" */
121 { "acl-method", "args", 2, 0, 0,
122 ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
123 ldap_back_cf_gen, NULL, NULL, NULL },
124 { "acl-bind", "args", 2, 0, 0,
125 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
126 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
127 "NAME 'olcDbACLBind' "
128 "DESC 'Remote ACL administrative identity auth bind configuration' "
129 "SYNTAX OMsDirectoryString "
132 { "idassert-authcDN", "DN", 2, 2, 0,
133 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
134 ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
135 "NAME 'olcDbIDAssertAuthcDn' "
136 "DESC 'Remote Identity Assertion administrative identity' "
141 /* deprecated, will be removed; partially aliases "idassert-authcDN" */
142 { "proxyauthzdn", "DN", 2, 2, 0,
143 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
144 ldap_back_cf_gen, NULL, NULL, NULL },
145 { "idassert-passwd", "cred", 2, 2, 0,
146 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
147 ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
148 "NAME 'olcDbIDAssertPasswd' "
149 "DESC 'Remote Identity Assertion administrative identity credentials' "
151 "SYNTAX OMsDirectoryString "
154 /* deprecated, will be removed; partially aliases "idassert-passwd" */
155 { "proxyauthzpw", "cred", 2, 2, 0,
156 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
157 ldap_back_cf_gen, NULL, NULL, NULL },
158 { "idassert-bind", "args", 2, 0, 0,
159 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
160 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
161 "NAME 'olcDbIDAssertBind' "
162 "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
163 "SYNTAX OMsDirectoryString "
166 { "idassert-method", "args", 2, 0, 0,
167 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
168 ldap_back_cf_gen, NULL, NULL, NULL },
169 { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
170 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
171 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
172 "NAME 'olcDbIDAssertMode' "
173 "DESC 'Remote Identity Assertion mode' "
175 "SYNTAX OMsDirectoryString "
178 { "idassert-authzFrom", "authzRule", 2, 2, 0,
179 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
180 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
181 "NAME 'olcDbIDAssertAuthzFrom' "
182 "DESC 'Remote Identity Assertion authz rules' "
183 "SYNTAX OMsDirectoryString "
184 "X-ORDERED 'VALUES' )",
186 { "rebind-as-user", "NO|yes", 1, 2, 0,
187 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_REBIND,
188 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
189 "NAME 'olcDbRebindAsUser' "
190 "DESC 'Rebind as user' "
194 { "chase-referrals", "YES|no", 2, 2, 0,
195 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_CHASE,
196 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
197 "NAME 'olcDbChaseReferrals' "
198 "DESC 'Chase referrals' "
202 { "t-f-support", "NO|yes|discover", 2, 2, 0,
203 ARG_MAGIC|LDAP_BACK_CFG_T_F,
204 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
205 "NAME 'olcDbTFSupport' "
206 "DESC 'Absolute filters support' "
207 "SYNTAX OMsDirectoryString "
210 { "proxy-whoami", "NO|yes", 1, 2, 0,
211 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_WHOAMI,
212 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
213 "NAME 'olcDbProxyWhoAmI' "
214 "DESC 'Proxy whoAmI exop' "
218 { "timeout", "timeout(list)", 2, 0, 0,
219 ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
220 ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
221 "NAME 'olcDbTimeout' "
222 "DESC 'Per-operation timeouts' "
223 "SYNTAX OMsDirectoryString "
226 { "idle-timeout", "timeout", 2, 0, 0,
227 ARG_MAGIC|LDAP_BACK_CFG_IDLE_TIMEOUT,
228 ldap_back_cf_gen, "( OLcfgDbAt:3.15 "
229 "NAME 'olcDbIdleTimeout' "
230 "DESC 'connection idle timeout' "
231 "SYNTAX OMsDirectoryString "
234 { "conn-ttl", "ttl", 2, 0, 0,
235 ARG_MAGIC|LDAP_BACK_CFG_CONN_TTL,
236 ldap_back_cf_gen, "( OLcfgDbAt:3.16 "
237 "NAME 'olcDbConnTtl' "
238 "DESC 'connection ttl' "
239 "SYNTAX OMsDirectoryString "
242 { "network-timeout", "timeout", 2, 0, 0,
243 ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
244 ldap_back_cf_gen, "( OLcfgDbAt:3.17 "
245 "NAME 'olcDbNetworkTimeout' "
246 "DESC 'connection network timeout' "
247 "SYNTAX OMsDirectoryString "
250 { "protocol-version", "version", 2, 0, 0,
251 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_VERSION,
252 ldap_back_cf_gen, "( OLcfgDbAt:3.18 "
253 "NAME 'olcDbProtocolVersion' "
254 "DESC 'protocol version' "
258 { "single-conn", "TRUE/FALSE", 2, 0, 0,
259 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_SINGLECONN,
260 ldap_back_cf_gen, "( OLcfgDbAt:3.19 "
261 "NAME 'olcDbSingleConn' "
262 "DESC 'cache a single connection per identity' "
266 { "cancel", "ABANDON|ignore|exop", 2, 0, 0,
267 ARG_MAGIC|LDAP_BACK_CFG_CANCEL,
268 ldap_back_cf_gen, "( OLcfgDbAt:3.20 "
269 "NAME 'olcDbCancel' "
270 "DESC 'abandon/ignore/exop operations when appropriate' "
271 "SYNTAX OMsDirectoryString "
274 { "quarantine", "retrylist", 2, 0, 0,
275 ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
276 ldap_back_cf_gen, "( OLcfgDbAt:3.21 "
277 "NAME 'olcDbQuarantine' "
278 "DESC 'Quarantine database if connection fails and retry according to rule' "
279 "SYNTAX OMsDirectoryString "
282 { "use-temporary-conn", "TRUE/FALSE", 2, 0, 0,
283 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_USETEMP,
284 ldap_back_cf_gen, "( OLcfgDbAt:3.22 "
285 "NAME 'olcDbUseTemporaryConn' "
286 "DESC 'Use temporary connections if the cached one is busy' "
290 { "conn-pool-max", "<n>", 2, 0, 0,
291 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_CONNPOOLMAX,
292 ldap_back_cf_gen, "( OLcfgDbAt:3.23 "
293 "NAME 'olcDbConnectionPoolMax' "
294 "DESC 'Max size of privileged connections pool' "
298 { "suffixmassage", "[virtual]> <real", 2, 3, 0,
299 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
300 ldap_back_cf_gen, NULL, NULL, NULL },
301 { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
302 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
303 ldap_back_cf_gen, NULL, NULL, NULL },
304 { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
305 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
306 ldap_back_cf_gen, NULL, NULL, NULL },
307 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
308 NULL, NULL, NULL, NULL }
311 static ConfigOCs ldapocs[] = {
313 "NAME 'olcLDAPConfig' "
314 "DESC 'LDAP backend configuration' "
315 "SUP olcDatabaseConfig "
321 "$ olcDbIDAssertAuthcDn "
322 "$ olcDbIDAssertPasswd "
323 "$ olcDbIDAssertBind "
324 "$ olcDbIDAssertMode "
325 "$ olcDbIDAssertAuthzFrom "
326 "$ olcDbRebindAsUser "
327 "$ olcDbChaseReferrals "
329 "$ olcDbProxyWhoAmI "
331 "$ olcDbIdleTimeout "
335 "$ olcDbUseTemporaryConn "
336 "$ olcDbConnectionPoolMax "
338 Cft_Database, ldapcfg},
342 static slap_verbmasks idassert_mode[] = {
343 { BER_BVC("self"), LDAP_BACK_IDASSERT_SELF },
344 { BER_BVC("anonymous"), LDAP_BACK_IDASSERT_ANONYMOUS },
345 { BER_BVC("none"), LDAP_BACK_IDASSERT_NOASSERT },
346 { BER_BVC("legacy"), LDAP_BACK_IDASSERT_LEGACY },
350 static slap_verbmasks tls_mode[] = {
351 { BER_BVC( "propagate" ), LDAP_BACK_F_TLS_PROPAGATE_MASK },
352 { BER_BVC( "try-propagate" ), LDAP_BACK_F_PROPAGATE_TLS },
353 { BER_BVC( "start" ), LDAP_BACK_F_TLS_USE_MASK },
354 { BER_BVC( "try-start" ), LDAP_BACK_F_USE_TLS },
355 { BER_BVC( "ldaps" ), LDAP_BACK_F_TLS_LDAPS },
356 { BER_BVC( "none" ), LDAP_BACK_F_NONE },
360 static slap_verbmasks t_f_mode[] = {
361 { BER_BVC( "yes" ), LDAP_BACK_F_T_F },
362 { BER_BVC( "discover" ), LDAP_BACK_F_T_F_DISCOVER },
363 { BER_BVC( "no" ), LDAP_BACK_F_NONE },
367 static slap_verbmasks cancel_mode[] = {
368 { BER_BVC( "ignore" ), LDAP_BACK_F_CANCEL_IGNORE },
369 { BER_BVC( "exop" ), LDAP_BACK_F_CANCEL_EXOP },
370 { BER_BVC( "exop-discover" ), LDAP_BACK_F_CANCEL_EXOP_DISCOVER },
371 { BER_BVC( "abandon" ), LDAP_BACK_F_CANCEL_ABANDON },
375 /* see enum in slap.h */
376 static slap_cf_aux_table timeout_table[] = {
377 { BER_BVC("bind="), SLAP_OP_BIND * sizeof( time_t ), 'u', 0, NULL },
378 /* unbind makes no sense */
379 { BER_BVC("add="), SLAP_OP_ADD * sizeof( time_t ), 'u', 0, NULL },
380 { BER_BVC("delete="), SLAP_OP_DELETE * sizeof( time_t ), 'u', 0, NULL },
381 { BER_BVC("modrdn="), SLAP_OP_MODRDN * sizeof( time_t ), 'u', 0, NULL },
382 { BER_BVC("modify="), SLAP_OP_MODIFY * sizeof( time_t ), 'u', 0, NULL },
383 { BER_BVC("compare="), SLAP_OP_COMPARE * sizeof( time_t ), 'u', 0, NULL },
384 #if 0 /* uses timelimit instead */
385 { BER_BVC("search="), SLAP_OP_SEARCH * sizeof( time_t ), 'u', 0, NULL },
387 /* abandon makes little sense */
388 #if 0 /* not implemented yet */
389 { BER_BVC("extended="), SLAP_OP_EXTENDED * sizeof( time_t ), 'u', 0, NULL },
391 { BER_BVNULL, 0, 0, 0, NULL }
395 slap_retry_info_parse(
397 slap_retry_info_t *ri,
401 char **retrylist = NULL;
405 slap_str2clist( &retrylist, in, " ;" );
406 if ( retrylist == NULL ) {
410 for ( i = 0; retrylist[ i ] != NULL; i++ )
413 ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 );
414 ri->ri_num = ch_calloc( sizeof( int ), i + 1 );
416 for ( i = 0; retrylist[ i ] != NULL; i++ ) {
418 char *sep = strchr( retrylist[ i ], ',' );
421 snprintf( buf, buflen,
422 "missing comma in retry pattern #%d \"%s\"",
430 if ( lutil_parse_time( retrylist[ i ], &t ) ) {
431 snprintf( buf, buflen,
432 "unable to parse interval #%d \"%s\"",
437 ri->ri_interval[ i ] = (time_t)t;
439 if ( strcmp( sep, "+" ) == 0 ) {
440 if ( retrylist[ i + 1 ] != NULL ) {
441 snprintf( buf, buflen,
442 "extra cruft after retry pattern "
443 "#%d \"%s,+\" with \"forever\" mark",
448 ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER;
450 } else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) {
451 snprintf( buf, buflen,
452 "unable to parse retry num #%d \"%s\"",
459 ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL;
463 ri->ri_last = (time_t)(-1);
466 ldap_charray_free( retrylist );
469 slap_retry_info_destroy( ri );
476 slap_retry_info_unparse(
477 slap_retry_info_t *ri,
478 struct berval *bvout )
481 char buf[ BUFSIZ * 2 ],
483 struct berval bv = BER_BVNULL;
485 assert( ri != NULL );
486 assert( bvout != NULL );
490 #define WHATSLEFT ( sizeof( buf ) - ( ptr - buf ) )
492 for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) {
494 if ( WHATSLEFT <= 1 ) {
500 if ( lutil_unparse_time( ptr, WHATSLEFT, (long)ri->ri_interval[i] ) ) {
503 ptr += strlen( ptr );
505 if ( WHATSLEFT <= 1 ) {
510 if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) {
511 if ( WHATSLEFT <= 1 ) {
517 ptr += snprintf( ptr, WHATSLEFT, "%d", ri->ri_num[i] );
518 if ( WHATSLEFT <= 0 ) {
525 bv.bv_len = ptr - buf;
527 ber_dupbv( bvout, &bv );
533 slap_retry_info_destroy(
534 slap_retry_info_t *ri )
536 assert( ri != NULL );
538 assert( ri->ri_interval != NULL );
539 ch_free( ri->ri_interval );
540 ri->ri_interval = NULL;
542 assert( ri->ri_num != NULL );
543 ch_free( ri->ri_num );
548 slap_idassert_authzfrom_parse( ConfigArgs *c, slap_idassert_t *si )
554 if ( strcmp( c->argv[ 1 ], "*" ) == 0
555 || strcmp( c->argv[ 1 ], ".*" ) == 0
556 || strcmp( c->argv[ 1 ], "dn:*" ) == 0
557 || strcasecmp( c->argv[ 1 ], "dn.regex:.*" ) == 0 )
559 if ( si->si_authz != NULL ) {
560 snprintf( c->msg, sizeof( c->msg ),
561 "\"idassert-authzFrom <authz>\": "
562 "\"%s\" conflicts with existing authz rules",
564 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
568 si->si_flags |= LDAP_BACK_AUTH_AUTHZ_ALL;
572 } else if ( ( si->si_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) {
573 snprintf( c->msg, sizeof( c->msg ),
574 "\"idassert-authzFrom <authz>\": "
575 "\"<authz>\" conflicts with \"*\"" );
576 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
580 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
581 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
582 if ( rc != LDAP_SUCCESS ) {
583 snprintf( c->msg, sizeof( c->msg ),
584 "\"idassert-authzFrom <authz>\": "
586 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
590 ber_bvarray_add( &si->si_authz, &bv );
596 slap_idassert_parse( ConfigArgs *c, slap_idassert_t *si )
600 for ( i = 1; i < c->argc; i++ ) {
601 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
602 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
605 j = verb_to_mask( argvi, idassert_mode );
606 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
607 snprintf( c->msg, sizeof( c->msg ),
608 "\"idassert-bind <args>\": "
609 "unknown mode \"%s\"",
611 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
615 si->si_mode = idassert_mode[ j ].mask;
617 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
618 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
620 if ( strcasecmp( argvi, "native" ) == 0 ) {
621 if ( si->si_bc.sb_method != LDAP_AUTH_SASL ) {
622 snprintf( c->msg, sizeof( c->msg ),
623 "\"idassert-bind <args>\": "
624 "authz=\"native\" incompatible "
625 "with auth method" );
626 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
629 si->si_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
631 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
632 si->si_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
635 snprintf( c->msg, sizeof( c->msg ),
636 "\"idassert-bind <args>\": "
637 "unknown authz \"%s\"",
639 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
643 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
644 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
645 char **flags = ldap_str2charray( argvi, "," );
648 if ( flags == NULL ) {
649 snprintf( c->msg, sizeof( c->msg ),
650 "\"idassert-bind <args>\": "
651 "unable to parse flags \"%s\"",
653 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
657 for ( j = 0; flags[ j ] != NULL; j++ ) {
659 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
660 si->si_flags |= LDAP_BACK_AUTH_OVERRIDE;
662 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
663 si->si_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
665 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
666 si->si_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
668 } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
669 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
670 Debug( LDAP_DEBUG_ANY,
671 "%s: \"obsolete-proxy-authz\" flag "
672 "in \"idassert-mode <args>\" "
673 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
679 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
682 } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
683 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
684 Debug( LDAP_DEBUG_ANY,
685 "%s: \"obsolete-encoding-workaround\" flag "
686 "in \"idassert-mode <args>\" "
687 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
693 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
697 snprintf( c->msg, sizeof( c->msg ),
698 "\"idassert-bind <args>\": "
699 "unknown flag \"%s\"",
701 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
707 ldap_charray_free( flags );
712 } else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) {
716 bindconf_tls_defaults( &si->si_bc );
721 /* NOTE: temporary, until back-meta is ported to back-config */
723 slap_idassert_authzfrom_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
725 ConfigArgs c = { 0 };
728 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
731 argv[ 0 ] = "idassert-authzFrom";
732 argv[ 1 ] = (char *)arg;
735 return slap_idassert_authzfrom_parse( &c, si );
739 slap_idassert_parse_cf( const char *fname, int lineno, int argc, char *argv[], slap_idassert_t *si )
741 ConfigArgs c = { 0 };
743 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
747 return slap_idassert_parse( &c, si );
751 ldap_back_cf_gen( ConfigArgs *c )
753 ldapinfo_t *li = ( ldapinfo_t * )c->be->be_private;
757 if ( c->op == SLAP_CONFIG_EMIT ) {
758 struct berval bv = BER_BVNULL;
765 case LDAP_BACK_CFG_URI:
766 if ( li->li_uri != NULL ) {
767 struct berval bv, bv2;
769 ber_str2bv( li->li_uri, 0, 0, &bv );
770 bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" );
771 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
772 snprintf( bv2.bv_val, bv2.bv_len + 1,
773 "\"%s\"", bv.bv_val );
774 ber_bvarray_add( &c->rvalue_vals, &bv2 );
781 case LDAP_BACK_CFG_TLS: {
782 struct berval bc = BER_BVNULL, bv2;
783 enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
784 assert( !BER_BVISNULL( &bv ) );
785 bindconf_tls_unparse( &li->li_tls, &bc );
787 if ( !BER_BVISEMPTY( &bc )) {
788 bv2.bv_len = bv.bv_len + bc.bv_len + 1;
789 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
790 strcpy( bv2.bv_val, bv.bv_val );
791 bv2.bv_val[bv.bv_len] = ' ';
792 strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val );
793 ber_bvarray_add( &c->rvalue_vals, &bv2 );
796 value_add_one( &c->rvalue_vals, &bv );
798 ber_memfree( bc.bv_val );
802 case LDAP_BACK_CFG_ACL_AUTHCDN:
803 case LDAP_BACK_CFG_ACL_PASSWD:
804 case LDAP_BACK_CFG_ACL_METHOD:
805 /* handled by LDAP_BACK_CFG_ACL_BIND */
809 case LDAP_BACK_CFG_ACL_BIND: {
812 if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
816 bindconf_unparse( &li->li_acl, &bv );
818 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
823 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
827 ber_bvarray_add( &c->rvalue_vals, &bv );
831 case LDAP_BACK_CFG_IDASSERT_MODE:
832 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
833 case LDAP_BACK_CFG_IDASSERT_PASSWD:
834 case LDAP_BACK_CFG_IDASSERT_METHOD:
835 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
839 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: {
842 if ( li->li_idassert_authz == NULL ) {
843 if ( ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) {
844 BER_BVSTR( &bv, "*" );
845 value_add_one( &c->rvalue_vals, &bv );
853 for ( i = 0; !BER_BVISNULL( &li->li_idassert_authz[ i ] ); i++ )
855 value_add_one( &c->rvalue_vals, &li->li_idassert_authz[ i ] );
860 case LDAP_BACK_CFG_IDASSERT_BIND: {
862 struct berval bc = BER_BVNULL;
865 if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
869 if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
872 switch ( li->li_idassert_mode ) {
873 case LDAP_BACK_IDASSERT_OTHERID:
874 case LDAP_BACK_IDASSERT_OTHERDN:
878 struct berval mode = BER_BVNULL;
880 enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
881 if ( BER_BVISNULL( &mode ) ) {
882 /* there's something wrong... */
887 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
888 bv.bv_val = ch_malloc( bv.bv_len + 1 );
890 ptr = lutil_strcopy( bv.bv_val, "mode=" );
891 ptr = lutil_strcopy( ptr, mode.bv_val );
897 if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
898 len = bv.bv_len + STRLENOF( "authz=native" );
900 if ( !BER_BVISEMPTY( &bv ) ) {
901 len += STRLENOF( " " );
904 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
906 ptr = &bv.bv_val[ bv.bv_len ];
908 if ( !BER_BVISEMPTY( &bv ) ) {
909 ptr = lutil_strcopy( ptr, " " );
912 (void)lutil_strcopy( ptr, "authz=native" );
915 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround" );
917 if ( !BER_BVISEMPTY( &bv ) ) {
918 len += STRLENOF( " " );
921 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
923 ptr = &bv.bv_val[ bv.bv_len ];
925 if ( !BER_BVISEMPTY( &bv ) ) {
926 ptr = lutil_strcopy( ptr, " " );
929 ptr = lutil_strcopy( ptr, "flags=" );
931 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
932 ptr = lutil_strcopy( ptr, "prescriptive" );
934 ptr = lutil_strcopy( ptr, "non-prescriptive" );
937 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
938 ptr = lutil_strcopy( ptr, ",override" );
941 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
942 ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" );
944 } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
945 ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" );
948 bv.bv_len = ( ptr - bv.bv_val );
952 bindconf_unparse( &li->li_idassert.si_bc, &bc );
954 if ( !BER_BVISNULL( &bv ) ) {
955 ber_len_t len = bv.bv_len + bc.bv_len;
957 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
959 assert( bc.bv_val[ 0 ] == ' ' );
961 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
963 bv.bv_len = ptr - bv.bv_val;
966 for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ )
971 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
977 ber_bvarray_add( &c->rvalue_vals, &bv );
982 case LDAP_BACK_CFG_REBIND:
983 c->value_int = LDAP_BACK_SAVECRED( li );
986 case LDAP_BACK_CFG_CHASE:
987 c->value_int = LDAP_BACK_CHASE_REFERRALS( li );
990 case LDAP_BACK_CFG_T_F:
991 enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv );
992 if ( BER_BVISNULL( &bv ) ) {
993 /* there's something wrong... */
998 value_add_one( &c->rvalue_vals, &bv );
1002 case LDAP_BACK_CFG_WHOAMI:
1003 c->value_int = LDAP_BACK_PROXY_WHOAMI( li );
1006 case LDAP_BACK_CFG_TIMEOUT:
1009 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1010 if ( li->li_timeout[ i ] != 0 ) {
1015 if ( i == SLAP_OP_LAST ) {
1019 slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table );
1021 if ( BER_BVISNULL( &bv ) ) {
1025 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1026 /* count spaces */ ;
1030 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1034 ber_bvarray_add( &c->rvalue_vals, &bv );
1037 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1038 char buf[ SLAP_TEXT_BUFLEN ];
1040 if ( li->li_idle_timeout == 0 ) {
1044 lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout );
1045 ber_str2bv( buf, 0, 0, &bv );
1046 value_add_one( &c->rvalue_vals, &bv );
1049 case LDAP_BACK_CFG_CONN_TTL: {
1050 char buf[ SLAP_TEXT_BUFLEN ];
1052 if ( li->li_conn_ttl == 0 ) {
1056 lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl );
1057 ber_str2bv( buf, 0, 0, &bv );
1058 value_add_one( &c->rvalue_vals, &bv );
1061 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1062 char buf[ SLAP_TEXT_BUFLEN ];
1064 if ( li->li_network_timeout == 0 ) {
1068 snprintf( buf, sizeof( buf ), "%ld",
1069 (long)li->li_network_timeout );
1070 ber_str2bv( buf, 0, 0, &bv );
1071 value_add_one( &c->rvalue_vals, &bv );
1074 case LDAP_BACK_CFG_VERSION:
1075 if ( li->li_version == 0 ) {
1079 c->value_int = li->li_version;
1082 case LDAP_BACK_CFG_SINGLECONN:
1083 c->value_int = LDAP_BACK_SINGLECONN( li );
1086 case LDAP_BACK_CFG_USETEMP:
1087 c->value_int = LDAP_BACK_USE_TEMPORARIES( li );
1090 case LDAP_BACK_CFG_CONNPOOLMAX:
1091 c->value_int = li->li_conn_priv_max;
1094 case LDAP_BACK_CFG_CANCEL: {
1095 slap_mask_t mask = LDAP_BACK_F_CANCEL_MASK2;
1097 if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) {
1098 mask &= ~LDAP_BACK_F_CANCEL_EXOP;
1100 enum_to_verb( cancel_mode, (li->li_flags & mask), &bv );
1101 if ( BER_BVISNULL( &bv ) ) {
1102 /* there's something wrong... */
1107 value_add_one( &c->rvalue_vals, &bv );
1111 case LDAP_BACK_CFG_QUARANTINE:
1112 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1117 rc = slap_retry_info_unparse( &li->li_quarantine, &bv );
1119 ber_bvarray_add( &c->rvalue_vals, &bv );
1124 /* FIXME: we need to handle all... */
1130 } else if ( c->op == LDAP_MOD_DELETE ) {
1132 case LDAP_BACK_CFG_URI:
1133 if ( li->li_uri != NULL ) {
1134 ch_free( li->li_uri );
1137 assert( li->li_bvuri != NULL );
1138 ber_bvarray_free( li->li_bvuri );
1139 li->li_bvuri = NULL;
1142 /* better cleanup the cached connections... */
1143 /* NOTE: don't worry about locking: if we got here,
1144 * other threads are suspended. */
1145 if ( li->li_conninfo.lai_tree != NULL ) {
1146 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
1147 li->li_conninfo.lai_tree = NULL;
1152 case LDAP_BACK_CFG_TLS:
1156 case LDAP_BACK_CFG_ACL_AUTHCDN:
1157 case LDAP_BACK_CFG_ACL_PASSWD:
1158 case LDAP_BACK_CFG_ACL_METHOD:
1159 /* handled by LDAP_BACK_CFG_ACL_BIND */
1163 case LDAP_BACK_CFG_ACL_BIND:
1164 bindconf_free( &li->li_acl );
1167 case LDAP_BACK_CFG_IDASSERT_MODE:
1168 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1169 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1170 case LDAP_BACK_CFG_IDASSERT_METHOD:
1171 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1175 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1176 if ( li->li_idassert_authz != NULL ) {
1177 ber_bvarray_free( li->li_idassert_authz );
1178 li->li_idassert_authz = NULL;
1182 case LDAP_BACK_CFG_IDASSERT_BIND:
1183 bindconf_free( &li->li_idassert.si_bc );
1186 case LDAP_BACK_CFG_REBIND:
1187 case LDAP_BACK_CFG_CHASE:
1188 case LDAP_BACK_CFG_T_F:
1189 case LDAP_BACK_CFG_WHOAMI:
1190 case LDAP_BACK_CFG_CANCEL:
1194 case LDAP_BACK_CFG_TIMEOUT:
1195 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1196 li->li_timeout[ i ] = 0;
1200 case LDAP_BACK_CFG_IDLE_TIMEOUT:
1201 li->li_idle_timeout = 0;
1204 case LDAP_BACK_CFG_CONN_TTL:
1205 li->li_conn_ttl = 0;
1208 case LDAP_BACK_CFG_NETWORK_TIMEOUT:
1209 li->li_network_timeout = 0;
1212 case LDAP_BACK_CFG_VERSION:
1216 case LDAP_BACK_CFG_SINGLECONN:
1217 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1220 case LDAP_BACK_CFG_USETEMP:
1221 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
1224 case LDAP_BACK_CFG_CONNPOOLMAX:
1225 li->li_conn_priv_max = LDAP_BACK_CONN_PRIV_MIN;
1228 case LDAP_BACK_CFG_QUARANTINE:
1229 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1233 slap_retry_info_destroy( &li->li_quarantine );
1234 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
1235 li->li_isquarantined = 0;
1239 /* FIXME: we need to handle all... */
1248 case LDAP_BACK_CFG_URI: {
1249 LDAPURLDesc *tmpludp, *lud;
1250 char **urllist = NULL;
1251 int urlrc = LDAP_URL_SUCCESS, i;
1253 if ( li->li_uri != NULL ) {
1254 ch_free( li->li_uri );
1257 assert( li->li_bvuri != NULL );
1258 ber_bvarray_free( li->li_bvuri );
1259 li->li_bvuri = NULL;
1262 /* PARANOID: DN and more are not required nor allowed */
1263 urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
1264 if ( urlrc != LDAP_URL_SUCCESS ) {
1268 case LDAP_URL_ERR_MEM:
1271 case LDAP_URL_ERR_PARAM:
1272 why = "parameter is bad";
1274 case LDAP_URL_ERR_BADSCHEME:
1275 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1277 case LDAP_URL_ERR_BADENCLOSURE:
1278 why = "URL is missing trailing \">\"";
1280 case LDAP_URL_ERR_BADURL:
1283 case LDAP_URL_ERR_BADHOST:
1284 why = "host/port is bad";
1286 case LDAP_URL_ERR_BADATTRS:
1287 why = "bad (or missing) attributes";
1289 case LDAP_URL_ERR_BADSCOPE:
1290 why = "scope string is invalid (or missing)";
1292 case LDAP_URL_ERR_BADFILTER:
1293 why = "bad or missing filter";
1295 case LDAP_URL_ERR_BADEXTS:
1296 why = "bad or missing extensions";
1299 why = "unknown reason";
1302 snprintf( c->msg, sizeof( c->msg),
1303 "unable to parse uri \"%s\" "
1304 "in \"uri <uri>\" line: %s",
1305 c->value_string, why );
1306 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1311 for ( i = 0, tmpludp = lud;
1313 i++, tmpludp = tmpludp->lud_next )
1315 if ( ( tmpludp->lud_dn != NULL
1316 && tmpludp->lud_dn[0] != '\0' )
1317 || tmpludp->lud_attrs != NULL
1318 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1319 || tmpludp->lud_filter != NULL
1320 || tmpludp->lud_exts != NULL )
1322 snprintf( c->msg, sizeof( c->msg ),
1323 "warning, only protocol, "
1324 "host and port allowed "
1325 "in \"uri <uri>\" statement "
1326 "for uri #%d of \"%s\"",
1328 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1332 for ( i = 0, tmpludp = lud;
1334 i++, tmpludp = tmpludp->lud_next )
1337 urllist = ch_calloc( sizeof( char * ), i + 1 );
1339 for ( i = 0, tmpludp = lud;
1341 i++, tmpludp = tmpludp->lud_next )
1347 tmplud.lud_attrs = NULL;
1348 tmplud.lud_filter = NULL;
1349 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1350 tmplud.lud_exts = NULL;
1351 tmplud.lud_crit_exts = 0;
1354 urllist[ i ] = ldap_url_desc2str( &tmplud );
1356 if ( urllist[ i ] == NULL ) {
1357 snprintf( c->msg, sizeof( c->msg),
1358 "unable to rebuild uri "
1359 "in \"uri <uri>\" statement "
1362 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1368 li->li_uri = ldap_charray2str( urllist, " " );
1369 for ( i = 0; urllist[ i ] != NULL; i++ ) {
1372 ber_str2bv( urllist[ i ], 0, 0, &bv );
1373 ber_bvarray_add( &li->li_bvuri, &bv );
1374 urllist[ i ] = NULL;
1376 ldap_memfree( urllist );
1381 ldap_charray_free( urllist );
1384 ldap_free_urllist( lud );
1386 if ( urlrc != LDAP_URL_SUCCESS ) {
1392 case LDAP_BACK_CFG_TLS:
1393 i = verb_to_mask( c->argv[1], tls_mode );
1394 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
1397 li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
1398 li->li_flags |= tls_mode[i].mask;
1399 if ( c->argc > 3 ) {
1400 for ( i=2; i<c->argc; i++ ) {
1401 if ( bindconf_tls_parse( c->argv[i], &li->li_tls ))
1404 bindconf_tls_defaults( &li->li_tls );
1408 case LDAP_BACK_CFG_ACL_AUTHCDN:
1409 switch ( li->li_acl_authmethod ) {
1410 case LDAP_AUTH_NONE:
1411 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1414 case LDAP_AUTH_SIMPLE:
1418 snprintf( c->msg, sizeof( c->msg),
1419 "\"acl-authcDN <DN>\" incompatible "
1420 "with auth method %d",
1421 li->li_acl_authmethod );
1422 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1425 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
1426 free( li->li_acl_authcDN.bv_val );
1428 ber_memfree_x( c->value_dn.bv_val, NULL );
1429 li->li_acl_authcDN = c->value_ndn;
1430 BER_BVZERO( &c->value_dn );
1431 BER_BVZERO( &c->value_ndn );
1434 case LDAP_BACK_CFG_ACL_PASSWD:
1435 switch ( li->li_acl_authmethod ) {
1436 case LDAP_AUTH_NONE:
1437 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1440 case LDAP_AUTH_SIMPLE:
1444 snprintf( c->msg, sizeof( c->msg ),
1445 "\"acl-passwd <cred>\" incompatible "
1446 "with auth method %d",
1447 li->li_acl_authmethod );
1448 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1451 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
1452 free( li->li_acl_passwd.bv_val );
1454 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
1457 case LDAP_BACK_CFG_ACL_METHOD:
1458 case LDAP_BACK_CFG_ACL_BIND:
1459 for ( i = 1; i < c->argc; i++ ) {
1460 if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
1464 bindconf_tls_defaults( &li->li_acl );
1467 case LDAP_BACK_CFG_IDASSERT_MODE:
1468 i = verb_to_mask( c->argv[1], idassert_mode );
1469 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
1470 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
1471 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1472 ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
1473 li->li_idassert_authzID.bv_val[ 0 ] = 'u';
1476 struct berval id, ndn;
1478 ber_str2bv( c->argv[1], 0, 0, &id );
1480 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1481 id.bv_val += STRLENOF( "dn:" );
1482 id.bv_len -= STRLENOF( "dn:" );
1485 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
1486 if ( rc != LDAP_SUCCESS ) {
1487 Debug( LDAP_DEBUG_ANY,
1488 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1489 c->fname, c->lineno, c->argv[1] );
1493 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1494 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
1495 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1496 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
1497 ch_free( ndn.bv_val );
1499 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1503 li->li_idassert_mode = idassert_mode[i].mask;
1506 if ( c->argc > 2 ) {
1509 for ( i = 2; i < c->argc; i++ ) {
1510 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
1511 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1513 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
1514 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1516 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
1517 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1519 } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
1520 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1521 Debug( LDAP_DEBUG_ANY,
1522 "%s: line %d: \"obsolete-proxy-authz\" flag "
1523 "in \"idassert-mode <args>\" "
1524 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1525 c->fname, c->lineno, 0 );
1528 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1530 } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
1531 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1532 Debug( LDAP_DEBUG_ANY,
1533 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1534 "in \"idassert-mode <args>\" "
1535 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1536 c->fname, c->lineno, 0 );
1539 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1542 Debug( LDAP_DEBUG_ANY,
1543 "%s: line %d: unknown flag #%d "
1544 "in \"idassert-mode <args> "
1545 "[<flags>]\" line.\n",
1546 c->fname, c->lineno, i - 2 );
1553 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1554 switch ( li->li_idassert_authmethod ) {
1555 case LDAP_AUTH_NONE:
1556 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1559 case LDAP_AUTH_SIMPLE:
1563 snprintf( c->msg, sizeof( c->msg ),
1564 "\"idassert-authcDN <DN>\" incompatible "
1565 "with auth method %d",
1566 li->li_idassert_authmethod );
1567 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1570 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1571 free( li->li_idassert_authcDN.bv_val );
1573 ber_memfree_x( c->value_dn.bv_val, NULL );
1574 li->li_idassert_authcDN = c->value_ndn;
1575 BER_BVZERO( &c->value_dn );
1576 BER_BVZERO( &c->value_ndn );
1579 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1580 switch ( li->li_idassert_authmethod ) {
1581 case LDAP_AUTH_NONE:
1582 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1585 case LDAP_AUTH_SIMPLE:
1589 snprintf( c->msg, sizeof( c->msg ),
1590 "\"idassert-passwd <cred>\" incompatible "
1591 "with auth method %d",
1592 li->li_idassert_authmethod );
1593 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1596 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
1597 free( li->li_idassert_passwd.bv_val );
1599 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
1602 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1603 rc = slap_idassert_authzfrom_parse( c, &li->li_idassert );
1606 case LDAP_BACK_CFG_IDASSERT_METHOD:
1607 /* no longer supported */
1608 snprintf( c->msg, sizeof( c->msg ),
1609 "\"idassert-method <args>\": "
1610 "no longer supported; use \"idassert-bind\"" );
1611 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1614 case LDAP_BACK_CFG_IDASSERT_BIND:
1615 rc = slap_idassert_parse( c, &li->li_idassert );
1618 case LDAP_BACK_CFG_REBIND:
1619 if ( c->argc == 1 || c->value_int ) {
1620 li->li_flags |= LDAP_BACK_F_SAVECRED;
1623 li->li_flags &= ~LDAP_BACK_F_SAVECRED;
1627 case LDAP_BACK_CFG_CHASE:
1628 if ( c->argc == 1 || c->value_int ) {
1629 li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
1632 li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1636 case LDAP_BACK_CFG_T_F: {
1639 i = verb_to_mask( c->argv[1], t_f_mode );
1640 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1644 mask = t_f_mode[i].mask;
1646 if ( LDAP_BACK_ISOPEN( li )
1647 && mask == LDAP_BACK_F_T_F_DISCOVER
1648 && !LDAP_BACK_T_F( li ) )
1650 slap_bindconf sb = { BER_BVNULL };
1653 if ( li->li_uri == NULL ) {
1654 snprintf( c->msg, sizeof( c->msg ),
1655 "need URI to discover \"cancel\" support "
1656 "in \"cancel exop-discover\"" );
1657 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1661 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
1662 sb.sb_version = li->li_version;
1663 sb.sb_method = LDAP_AUTH_SIMPLE;
1664 BER_BVSTR( &sb.sb_binddn, "" );
1666 rc = slap_discover_feature( &sb,
1667 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
1668 LDAP_FEATURE_ABSOLUTE_FILTERS );
1669 if ( rc == LDAP_COMPARE_TRUE ) {
1670 mask |= LDAP_BACK_F_T_F;
1674 li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
1675 li->li_flags |= mask;
1678 case LDAP_BACK_CFG_WHOAMI:
1679 if ( c->argc == 1 || c->value_int ) {
1680 li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
1681 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
1682 0, ldap_back_exop_whoami );
1685 li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
1689 case LDAP_BACK_CFG_TIMEOUT:
1690 for ( i = 1; i < c->argc; i++ ) {
1691 if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
1695 if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
1696 snprintf( c->msg, sizeof( c->msg),
1697 "unable to parse timeout \"%s\"",
1699 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1703 for ( j = 0; j < SLAP_OP_LAST; j++ ) {
1704 li->li_timeout[ j ] = u;
1710 if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
1711 snprintf( c->msg, sizeof( c->msg),
1712 "unable to parse timeout \"%s\"",
1714 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1720 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1723 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1724 snprintf( c->msg, sizeof( c->msg),
1725 "unable to parse idle timeout \"%s\"",
1727 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1730 li->li_idle_timeout = (time_t)t;
1733 case LDAP_BACK_CFG_CONN_TTL: {
1736 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1737 snprintf( c->msg, sizeof( c->msg),
1738 "unable to parse conn ttl\"%s\"",
1740 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1743 li->li_conn_ttl = (time_t)t;
1746 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1749 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
1750 snprintf( c->msg, sizeof( c->msg),
1751 "unable to parse network timeout \"%s\"",
1753 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1756 li->li_network_timeout = (time_t)t;
1759 case LDAP_BACK_CFG_VERSION:
1760 if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
1761 snprintf( c->msg, sizeof( c->msg ),
1762 "unsupported version \"%s\" "
1763 "in \"protocol-version <version>\"",
1765 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1769 li->li_version = c->value_int;
1772 case LDAP_BACK_CFG_SINGLECONN:
1773 if ( c->value_int ) {
1774 li->li_flags |= LDAP_BACK_F_SINGLECONN;
1777 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1781 case LDAP_BACK_CFG_USETEMP:
1782 if ( c->value_int ) {
1783 li->li_flags |= LDAP_BACK_F_USE_TEMPORARIES;
1786 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
1790 case LDAP_BACK_CFG_CONNPOOLMAX:
1791 if ( c->value_int < LDAP_BACK_CONN_PRIV_MIN
1792 || c->value_int > LDAP_BACK_CONN_PRIV_MAX )
1794 snprintf( c->msg, sizeof( c->msg ),
1795 "invalid max size " "of privileged "
1796 "connections pool \"%s\" "
1797 "in \"conn-pool-max <n> "
1798 "(must be between %d and %d)\"",
1800 LDAP_BACK_CONN_PRIV_MIN,
1801 LDAP_BACK_CONN_PRIV_MAX );
1802 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1805 li->li_conn_priv_max = c->value_int;
1808 case LDAP_BACK_CFG_CANCEL: {
1811 i = verb_to_mask( c->argv[1], cancel_mode );
1812 if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
1816 mask = cancel_mode[i].mask;
1818 if ( LDAP_BACK_ISOPEN( li )
1819 && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
1820 && !LDAP_BACK_CANCEL( li ) )
1822 slap_bindconf sb = { BER_BVNULL };
1825 if ( li->li_uri == NULL ) {
1826 snprintf( c->msg, sizeof( c->msg ),
1827 "need URI to discover \"cancel\" support "
1828 "in \"cancel exop-discover\"" );
1829 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1833 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
1834 sb.sb_version = li->li_version;
1835 sb.sb_method = LDAP_AUTH_SIMPLE;
1836 BER_BVSTR( &sb.sb_binddn, "" );
1838 rc = slap_discover_feature( &sb,
1839 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
1841 if ( rc == LDAP_COMPARE_TRUE ) {
1842 mask |= LDAP_BACK_F_CANCEL_EXOP;
1846 li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
1847 li->li_flags |= mask;
1850 case LDAP_BACK_CFG_QUARANTINE:
1851 if ( LDAP_BACK_QUARANTINE( li ) ) {
1852 snprintf( c->msg, sizeof( c->msg ),
1853 "quarantine already defined" );
1854 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1857 rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
1858 c->msg, sizeof( c->msg ) );
1860 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1863 ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex );
1864 /* give it a chance to retry if the pattern gets reset
1865 * via back-config */
1866 li->li_isquarantined = 0;
1870 case LDAP_BACK_CFG_REWRITE:
1871 snprintf( c->msg, sizeof( c->msg ),
1872 "rewrite/remap capabilities have been moved "
1873 "to the \"rwm\" overlay; see slapo-rwm(5) "
1874 "for details (hint: add \"overlay rwm\" "
1875 "and prefix all directives with \"rwm-\")" );
1876 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->msg, 0 );
1880 /* FIXME: try to catch inconsistencies */
1889 ldap_back_init_cf( BackendInfo *bi )
1892 AttributeDescription *ad = NULL;
1895 /* Make sure we don't exceed the bits reserved for userland */
1896 config_check_userland( LDAP_BACK_CFG_LAST );
1898 bi->bi_cf_ocs = ldapocs;
1900 rc = config_register_schema( ldapcfg, ldapocs );
1905 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
1906 * to be base64-encoded when written in LDIF form;
1907 * basically, we don't care if it fails */
1908 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
1910 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1911 "warning, unable to get \"olcDbACLPasswd\" "
1912 "attribute description: %d: %s\n",
1915 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1916 ad->ad_type->sat_oid );
1920 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
1922 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
1923 "warning, unable to get \"olcDbIDAssertPasswd\" "
1924 "attribute description: %d: %s\n",
1927 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
1928 ad->ad_type->sat_oid );
1936 ldap_back_exop_whoami(
1940 struct berval *bv = NULL;
1942 if ( op->oq_extended.rs_reqdata != NULL ) {
1943 /* no request data should be provided */
1944 rs->sr_text = "no request data expected";
1945 return rs->sr_err = LDAP_PROTOCOL_ERROR;
1948 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
1949 op->o_log_prefix, 0, 0, 0, 0 );
1951 rs->sr_err = backend_check_restrictions( op, rs,
1952 (struct berval *)&slap_EXOP_WHOAMI );
1953 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
1955 /* if auth'd by back-ldap and request is proxied, forward it */
1956 if ( op->o_conn->c_authz_backend
1957 && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
1958 && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
1960 ldapconn_t *lc = NULL;
1961 LDAPControl c, *ctrls[2] = {NULL, NULL};
1963 Operation op2 = *op;
1969 op2.o_ndn = op->o_conn->c_ndn;
1970 if ( !ldap_back_dobind( &lc, &op2, rs, LDAP_BACK_SENDERR ) ) {
1973 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
1974 c.ldctl_iscritical = 1;
1975 c.ldctl_value.bv_val = op->o_tmpalloc(
1976 op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
1978 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
1979 ptr = c.ldctl_value.bv_val;
1980 ptr = lutil_strcopy( ptr, "dn:" );
1981 ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
1985 rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
1986 if ( rs->sr_err == LDAP_SUCCESS ) {
1987 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, NULL, &res ) == -1 ) {
1988 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
1990 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
1992 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
1998 /* NOTE: are we sure "bv" will be malloc'ed
1999 * with the appropriate memory? */
2000 rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
2004 op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
2005 if ( rs->sr_err != LDAP_SUCCESS ) {
2006 rs->sr_err = slap_map_api2result( rs );
2010 ldap_back_release_conn( &op2, rs, lc );
2014 /* else just do the same as before */
2015 bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
2016 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
2017 bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
2018 bv->bv_val = ch_malloc( bv->bv_len + 1 );
2019 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
2020 AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
2022 bv->bv_val[ bv->bv_len ] = '\0';
2030 rs->sr_rspdata = bv;