1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2013 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 static SLAP_EXTOP_MAIN_FN ldap_back_exop_whoami;
40 static ConfigDriver ldap_back_cf_gen;
41 static ConfigDriver ldap_pbind_cf_gen;
44 LDAP_BACK_CFG_URI = 1,
46 LDAP_BACK_CFG_ACL_AUTHCDN,
47 LDAP_BACK_CFG_ACL_PASSWD,
48 LDAP_BACK_CFG_ACL_METHOD,
49 LDAP_BACK_CFG_ACL_BIND,
50 LDAP_BACK_CFG_IDASSERT_MODE,
51 LDAP_BACK_CFG_IDASSERT_AUTHCDN,
52 LDAP_BACK_CFG_IDASSERT_PASSWD,
53 LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
54 LDAP_BACK_CFG_IDASSERT_PASSTHRU,
55 LDAP_BACK_CFG_IDASSERT_METHOD,
56 LDAP_BACK_CFG_IDASSERT_BIND,
61 LDAP_BACK_CFG_TIMEOUT,
62 LDAP_BACK_CFG_IDLE_TIMEOUT,
63 LDAP_BACK_CFG_CONN_TTL,
64 LDAP_BACK_CFG_NETWORK_TIMEOUT,
65 LDAP_BACK_CFG_VERSION,
66 LDAP_BACK_CFG_SINGLECONN,
67 LDAP_BACK_CFG_USETEMP,
68 LDAP_BACK_CFG_CONNPOOLMAX,
70 LDAP_BACK_CFG_QUARANTINE,
71 LDAP_BACK_CFG_ST_REQUEST,
73 LDAP_BACK_CFG_NOUNDEFFILTER,
76 LDAP_BACK_CFG_REWRITE,
77 LDAP_BACK_CFG_KEEPALIVE,
82 static ConfigTable ldapcfg[] = {
83 { "uri", "uri", 2, 2, 0,
84 ARG_MAGIC|LDAP_BACK_CFG_URI,
85 ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
87 "DESC 'URI (list) for remote DSA' "
88 "SYNTAX OMsDirectoryString "
91 { "tls", "what", 2, 0, 0,
92 ARG_MAGIC|LDAP_BACK_CFG_TLS,
93 ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
94 "NAME 'olcDbStartTLS' "
96 "SYNTAX OMsDirectoryString "
99 { "acl-authcDN", "DN", 2, 2, 0,
100 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
101 ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
102 "NAME 'olcDbACLAuthcDn' "
103 "DESC 'Remote ACL administrative identity' "
108 /* deprecated, will be removed; aliases "acl-authcDN" */
109 { "binddn", "DN", 2, 2, 0,
110 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
111 ldap_back_cf_gen, NULL, NULL, NULL },
112 { "acl-passwd", "cred", 2, 2, 0,
113 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
114 ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
115 "NAME 'olcDbACLPasswd' "
116 "DESC 'Remote ACL administrative identity credentials' "
118 "SYNTAX OMsDirectoryString "
121 /* deprecated, will be removed; aliases "acl-passwd" */
122 { "bindpw", "cred", 2, 2, 0,
123 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
124 ldap_back_cf_gen, NULL, NULL, NULL },
125 /* deprecated, will be removed; aliases "acl-bind" */
126 { "acl-method", "args", 2, 0, 0,
127 ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
128 ldap_back_cf_gen, NULL, NULL, NULL },
129 { "acl-bind", "args", 2, 0, 0,
130 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
131 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
132 "NAME 'olcDbACLBind' "
133 "DESC 'Remote ACL administrative identity auth bind configuration' "
134 "SYNTAX OMsDirectoryString "
137 { "idassert-authcDN", "DN", 2, 2, 0,
138 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
139 ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
140 "NAME 'olcDbIDAssertAuthcDn' "
141 "DESC 'Remote Identity Assertion administrative identity' "
146 /* deprecated, will be removed; partially aliases "idassert-authcDN" */
147 { "proxyauthzdn", "DN", 2, 2, 0,
148 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
149 ldap_back_cf_gen, NULL, NULL, NULL },
150 { "idassert-passwd", "cred", 2, 2, 0,
151 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
152 ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
153 "NAME 'olcDbIDAssertPasswd' "
154 "DESC 'Remote Identity Assertion administrative identity credentials' "
156 "SYNTAX OMsDirectoryString "
159 /* deprecated, will be removed; partially aliases "idassert-passwd" */
160 { "proxyauthzpw", "cred", 2, 2, 0,
161 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
162 ldap_back_cf_gen, NULL, NULL, NULL },
163 { "idassert-bind", "args", 2, 0, 0,
164 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
165 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
166 "NAME 'olcDbIDAssertBind' "
167 "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
168 "SYNTAX OMsDirectoryString "
171 { "idassert-method", "args", 2, 0, 0,
172 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
173 ldap_back_cf_gen, NULL, NULL, NULL },
174 { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
175 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
176 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
177 "NAME 'olcDbIDAssertMode' "
178 "DESC 'Remote Identity Assertion mode' "
180 "SYNTAX OMsDirectoryString "
183 { "idassert-authzFrom", "authzRule", 2, 2, 0,
184 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
185 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
186 "NAME 'olcDbIDAssertAuthzFrom' "
187 "DESC 'Remote Identity Assertion authz rules' "
188 "EQUALITY caseIgnoreMatch "
189 "SYNTAX OMsDirectoryString "
190 "X-ORDERED 'VALUES' )",
192 { "rebind-as-user", "true|FALSE", 1, 2, 0,
193 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_REBIND,
194 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
195 "NAME 'olcDbRebindAsUser' "
196 "DESC 'Rebind as user' "
200 { "chase-referrals", "true|FALSE", 2, 2, 0,
201 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_CHASE,
202 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
203 "NAME 'olcDbChaseReferrals' "
204 "DESC 'Chase referrals' "
208 { "t-f-support", "true|FALSE|discover", 2, 2, 0,
209 ARG_MAGIC|LDAP_BACK_CFG_T_F,
210 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
211 "NAME 'olcDbTFSupport' "
212 "DESC 'Absolute filters support' "
213 "SYNTAX OMsDirectoryString "
216 { "proxy-whoami", "true|FALSE", 1, 2, 0,
217 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_WHOAMI,
218 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
219 "NAME 'olcDbProxyWhoAmI' "
220 "DESC 'Proxy whoAmI exop' "
224 { "timeout", "timeout(list)", 2, 0, 0,
225 ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
226 ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
227 "NAME 'olcDbTimeout' "
228 "DESC 'Per-operation timeouts' "
229 "SYNTAX OMsDirectoryString "
232 { "idle-timeout", "timeout", 2, 2, 0,
233 ARG_MAGIC|LDAP_BACK_CFG_IDLE_TIMEOUT,
234 ldap_back_cf_gen, "( OLcfgDbAt:3.15 "
235 "NAME 'olcDbIdleTimeout' "
236 "DESC 'connection idle timeout' "
237 "SYNTAX OMsDirectoryString "
240 { "conn-ttl", "ttl", 2, 2, 0,
241 ARG_MAGIC|LDAP_BACK_CFG_CONN_TTL,
242 ldap_back_cf_gen, "( OLcfgDbAt:3.16 "
243 "NAME 'olcDbConnTtl' "
244 "DESC 'connection ttl' "
245 "SYNTAX OMsDirectoryString "
248 { "network-timeout", "timeout", 2, 2, 0,
249 ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
250 ldap_back_cf_gen, "( OLcfgDbAt:3.17 "
251 "NAME 'olcDbNetworkTimeout' "
252 "DESC 'connection network timeout' "
253 "SYNTAX OMsDirectoryString "
256 { "protocol-version", "version", 2, 2, 0,
257 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_VERSION,
258 ldap_back_cf_gen, "( OLcfgDbAt:3.18 "
259 "NAME 'olcDbProtocolVersion' "
260 "DESC 'protocol version' "
264 { "single-conn", "true|FALSE", 2, 2, 0,
265 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_SINGLECONN,
266 ldap_back_cf_gen, "( OLcfgDbAt:3.19 "
267 "NAME 'olcDbSingleConn' "
268 "DESC 'cache a single connection per identity' "
272 { "cancel", "ABANDON|ignore|exop", 2, 2, 0,
273 ARG_MAGIC|LDAP_BACK_CFG_CANCEL,
274 ldap_back_cf_gen, "( OLcfgDbAt:3.20 "
275 "NAME 'olcDbCancel' "
276 "DESC 'abandon/ignore/exop operations when appropriate' "
277 "SYNTAX OMsDirectoryString "
280 { "quarantine", "retrylist", 2, 2, 0,
281 ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
282 ldap_back_cf_gen, "( OLcfgDbAt:3.21 "
283 "NAME 'olcDbQuarantine' "
284 "DESC 'Quarantine database if connection fails and retry according to rule' "
285 "SYNTAX OMsDirectoryString "
288 { "use-temporary-conn", "true|FALSE", 2, 2, 0,
289 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_USETEMP,
290 ldap_back_cf_gen, "( OLcfgDbAt:3.22 "
291 "NAME 'olcDbUseTemporaryConn' "
292 "DESC 'Use temporary connections if the cached one is busy' "
296 { "conn-pool-max", "<n>", 2, 2, 0,
297 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_CONNPOOLMAX,
298 ldap_back_cf_gen, "( OLcfgDbAt:3.23 "
299 "NAME 'olcDbConnectionPoolMax' "
300 "DESC 'Max size of privileged connections pool' "
304 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
305 { "session-tracking-request", "true|FALSE", 2, 2, 0,
306 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_ST_REQUEST,
307 ldap_back_cf_gen, "( OLcfgDbAt:3.24 "
308 "NAME 'olcDbSessionTrackingRequest' "
309 "DESC 'Add session tracking control to proxied requests' "
313 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
314 { "norefs", "true|FALSE", 2, 2, 0,
315 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOREFS,
316 ldap_back_cf_gen, "( OLcfgDbAt:3.25 "
317 "NAME 'olcDbNoRefs' "
318 "DESC 'Do not return search reference responses' "
322 { "noundeffilter", "true|FALSE", 2, 2, 0,
323 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOUNDEFFILTER,
324 ldap_back_cf_gen, "( OLcfgDbAt:3.26 "
325 "NAME 'olcDbNoUndefFilter' "
326 "DESC 'Do not propagate undefined search filters' "
330 { "onerr", "CONTINUE|report|stop", 2, 2, 0,
331 ARG_MAGIC|LDAP_BACK_CFG_ONERR,
332 ldap_back_cf_gen, "( OLcfgDbAt:3.108 "
334 "DESC 'error handling' "
335 "SYNTAX OMsDirectoryString "
338 { "idassert-passThru", "authzRule", 2, 2, 0,
339 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSTHRU,
340 ldap_back_cf_gen, "( OLcfgDbAt:3.27 "
341 "NAME 'olcDbIDAssertPassThru' "
342 "DESC 'Remote Identity Assertion passthru rules' "
343 "EQUALITY caseIgnoreMatch "
344 "SYNTAX OMsDirectoryString "
345 "X-ORDERED 'VALUES' )",
348 { "suffixmassage", "[virtual]> <real", 2, 3, 0,
349 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
350 ldap_back_cf_gen, NULL, NULL, NULL },
351 { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
352 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
353 ldap_back_cf_gen, NULL, NULL, NULL },
354 { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
355 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
356 ldap_back_cf_gen, NULL, NULL, NULL },
357 { "keepalive", "keepalive", 2, 2, 0,
358 ARG_MAGIC|LDAP_BACK_CFG_KEEPALIVE,
359 ldap_back_cf_gen, "( OLcfgDbAt:3.29 "
360 "NAME 'olcDbKeepalive' "
361 "DESC 'TCP keepalive' "
362 "SYNTAX OMsDirectoryString "
365 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
366 NULL, NULL, NULL, NULL }
369 static ConfigOCs ldapocs[] = {
371 "NAME 'olcLDAPConfig' "
372 "DESC 'LDAP backend configuration' "
373 "SUP olcDatabaseConfig "
379 "$ olcDbIDAssertAuthcDn "
380 "$ olcDbIDAssertPasswd "
381 "$ olcDbIDAssertBind "
382 "$ olcDbIDAssertMode "
383 "$ olcDbIDAssertAuthzFrom "
384 "$ olcDbIDAssertPassThru "
385 "$ olcDbRebindAsUser "
386 "$ olcDbChaseReferrals "
388 "$ olcDbProxyWhoAmI "
390 "$ olcDbIdleTimeout "
392 "$ olcDbNetworkTimeout "
393 "$ olcDbProtocolVersion "
397 "$ olcDbUseTemporaryConn "
398 "$ olcDbConnectionPoolMax "
399 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
400 "$ olcDbSessionTrackingRequest "
401 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
403 "$ olcDbNoUndefFilter "
407 Cft_Database, ldapcfg},
411 static ConfigTable pbindcfg[] = {
412 { "uri", "uri", 2, 2, 0,
413 ARG_MAGIC|LDAP_BACK_CFG_URI,
414 ldap_pbind_cf_gen, "( OLcfgDbAt:0.14 "
416 "DESC 'URI (list) for remote DSA' "
417 "SYNTAX OMsDirectoryString "
420 { "tls", "what", 2, 0, 0,
421 ARG_MAGIC|LDAP_BACK_CFG_TLS,
422 ldap_pbind_cf_gen, "( OLcfgDbAt:3.1 "
423 "NAME 'olcDbStartTLS' "
425 "SYNTAX OMsDirectoryString "
428 { "network-timeout", "timeout", 2, 2, 0,
429 ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
430 ldap_pbind_cf_gen, "( OLcfgDbAt:3.17 "
431 "NAME 'olcDbNetworkTimeout' "
432 "DESC 'connection network timeout' "
433 "SYNTAX OMsDirectoryString "
436 { "quarantine", "retrylist", 2, 2, 0,
437 ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
438 ldap_pbind_cf_gen, "( OLcfgDbAt:3.21 "
439 "NAME 'olcDbQuarantine' "
440 "DESC 'Quarantine database if connection fails and retry according to rule' "
441 "SYNTAX OMsDirectoryString "
444 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
445 NULL, NULL, NULL, NULL }
448 static ConfigOCs pbindocs[] = {
450 "NAME 'olcPBindConfig' "
451 "DESC 'Proxy Bind configuration' "
452 "SUP olcOverlayConfig "
454 "MAY ( olcDbStartTLS "
455 "$ olcDbNetworkTimeout "
458 Cft_Overlay, pbindcfg},
462 static slap_verbmasks idassert_mode[] = {
463 { BER_BVC("self"), LDAP_BACK_IDASSERT_SELF },
464 { BER_BVC("anonymous"), LDAP_BACK_IDASSERT_ANONYMOUS },
465 { BER_BVC("none"), LDAP_BACK_IDASSERT_NOASSERT },
466 { BER_BVC("legacy"), LDAP_BACK_IDASSERT_LEGACY },
470 static slap_verbmasks tls_mode[] = {
471 { BER_BVC( "propagate" ), LDAP_BACK_F_TLS_PROPAGATE_MASK },
472 { BER_BVC( "try-propagate" ), LDAP_BACK_F_PROPAGATE_TLS },
473 { BER_BVC( "start" ), LDAP_BACK_F_TLS_USE_MASK },
474 { BER_BVC( "try-start" ), LDAP_BACK_F_USE_TLS },
475 { BER_BVC( "ldaps" ), LDAP_BACK_F_TLS_LDAPS },
476 { BER_BVC( "none" ), LDAP_BACK_F_NONE },
480 static slap_verbmasks t_f_mode[] = {
481 { BER_BVC( "yes" ), LDAP_BACK_F_T_F },
482 { BER_BVC( "discover" ), LDAP_BACK_F_T_F_DISCOVER },
483 { BER_BVC( "no" ), LDAP_BACK_F_NONE },
487 static slap_verbmasks cancel_mode[] = {
488 { BER_BVC( "ignore" ), LDAP_BACK_F_CANCEL_IGNORE },
489 { BER_BVC( "exop" ), LDAP_BACK_F_CANCEL_EXOP },
490 { BER_BVC( "exop-discover" ), LDAP_BACK_F_CANCEL_EXOP_DISCOVER },
491 { BER_BVC( "abandon" ), LDAP_BACK_F_CANCEL_ABANDON },
495 static slap_verbmasks onerr_mode[] = {
496 { BER_BVC( "stop" ), LDAP_BACK_F_ONERR_STOP },
497 { BER_BVC( "report" ), LDAP_BACK_F_ONERR_STOP }, /* same behavior */
498 { BER_BVC( "continue" ), LDAP_BACK_F_NONE },
502 /* see enum in slap.h */
503 static slap_cf_aux_table timeout_table[] = {
504 { BER_BVC("bind="), SLAP_OP_BIND * sizeof( time_t ), 'u', 0, NULL },
505 /* unbind makes no sense */
506 { BER_BVC("add="), SLAP_OP_ADD * sizeof( time_t ), 'u', 0, NULL },
507 { BER_BVC("delete="), SLAP_OP_DELETE * sizeof( time_t ), 'u', 0, NULL },
508 { BER_BVC("modrdn="), SLAP_OP_MODRDN * sizeof( time_t ), 'u', 0, NULL },
509 { BER_BVC("modify="), SLAP_OP_MODIFY * sizeof( time_t ), 'u', 0, NULL },
510 { BER_BVC("compare="), SLAP_OP_COMPARE * sizeof( time_t ), 'u', 0, NULL },
511 { BER_BVC("search="), SLAP_OP_SEARCH * sizeof( time_t ), 'u', 0, NULL },
512 /* abandon makes little sense */
513 #if 0 /* not implemented yet */
514 { BER_BVC("extended="), SLAP_OP_EXTENDED * sizeof( time_t ), 'u', 0, NULL },
516 { BER_BVNULL, 0, 0, 0, NULL }
520 slap_retry_info_parse(
522 slap_retry_info_t *ri,
526 char **retrylist = NULL;
530 slap_str2clist( &retrylist, in, " ;" );
531 if ( retrylist == NULL ) {
535 for ( i = 0; retrylist[ i ] != NULL; i++ )
538 ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 );
539 ri->ri_num = ch_calloc( sizeof( int ), i + 1 );
541 for ( i = 0; retrylist[ i ] != NULL; i++ ) {
543 char *sep = strchr( retrylist[ i ], ',' );
546 snprintf( buf, buflen,
547 "missing comma in retry pattern #%d \"%s\"",
555 if ( lutil_parse_time( retrylist[ i ], &t ) ) {
556 snprintf( buf, buflen,
557 "unable to parse interval #%d \"%s\"",
562 ri->ri_interval[ i ] = (time_t)t;
564 if ( strcmp( sep, "+" ) == 0 ) {
565 if ( retrylist[ i + 1 ] != NULL ) {
566 snprintf( buf, buflen,
567 "extra cruft after retry pattern "
568 "#%d \"%s,+\" with \"forever\" mark",
573 ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER;
575 } else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) {
576 snprintf( buf, buflen,
577 "unable to parse retry num #%d \"%s\"",
584 ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL;
588 ri->ri_last = (time_t)(-1);
591 ldap_charray_free( retrylist );
594 slap_retry_info_destroy( ri );
601 slap_retry_info_unparse(
602 slap_retry_info_t *ri,
603 struct berval *bvout )
605 char buf[ BUFSIZ * 2 ],
607 int i, len, restlen = (int) sizeof( buf );
610 assert( ri != NULL );
611 assert( bvout != NULL );
615 for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) {
617 if ( --restlen <= 0 ) {
623 if ( lutil_unparse_time( ptr, restlen, ri->ri_interval[i] ) < 0 ) {
626 len = (int) strlen( ptr );
627 if ( (restlen -= len + 1) <= 0 ) {
633 if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) {
634 if ( --restlen <= 0 ) {
640 len = snprintf( ptr, restlen, "%d", ri->ri_num[i] );
641 if ( (restlen -= len) <= 0 || len < 0 ) {
649 bv.bv_len = ptr - buf;
650 ber_dupbv( bvout, &bv );
656 slap_retry_info_destroy(
657 slap_retry_info_t *ri )
659 assert( ri != NULL );
661 assert( ri->ri_interval != NULL );
662 ch_free( ri->ri_interval );
663 ri->ri_interval = NULL;
665 assert( ri->ri_num != NULL );
666 ch_free( ri->ri_num );
671 slap_idassert_authzfrom_parse( ConfigArgs *c, slap_idassert_t *si )
677 if ( strcmp( c->argv[ 1 ], "*" ) == 0
678 || strcmp( c->argv[ 1 ], "dn:*" ) == 0
679 || strcasecmp( c->argv[ 1 ], "dn.regex:.*" ) == 0 )
681 if ( si->si_authz != NULL ) {
682 snprintf( c->cr_msg, sizeof( c->cr_msg ),
683 "\"idassert-authzFrom <authz>\": "
684 "\"%s\" conflicts with existing authz rules",
686 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
690 si->si_flags |= LDAP_BACK_AUTH_AUTHZ_ALL;
694 } else if ( ( si->si_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) {
695 snprintf( c->cr_msg, sizeof( c->cr_msg ),
696 "\"idassert-authzFrom <authz>\": "
697 "\"<authz>\" conflicts with \"*\"" );
698 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
702 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
703 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
704 if ( rc != LDAP_SUCCESS ) {
705 snprintf( c->cr_msg, sizeof( c->cr_msg ),
706 "\"idassert-authzFrom <authz>\": "
708 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
712 if ( c->valx == -1 ) {
713 ber_bvarray_add( &si->si_authz, &bv );
717 if ( si->si_authz != NULL ) {
718 for ( ; !BER_BVISNULL( &si->si_authz[ i ] ); i++ )
722 if ( i <= c->valx ) {
723 ber_bvarray_add( &si->si_authz, &bv );
726 BerVarray tmp = ber_memrealloc( si->si_authz,
727 sizeof( struct berval )*( i + 2 ) );
732 for ( ; i > c->valx; i-- ) {
733 si->si_authz[ i ] = si->si_authz[ i - 1 ];
735 si->si_authz[ c->valx ] = bv;
743 slap_idassert_passthru_parse( ConfigArgs *c, slap_idassert_t *si )
749 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
750 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
751 if ( rc != LDAP_SUCCESS ) {
752 snprintf( c->cr_msg, sizeof( c->cr_msg ),
753 "\"idassert-passThru <authz>\": "
755 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
759 if ( c->valx == -1 ) {
760 ber_bvarray_add( &si->si_passthru, &bv );
764 if ( si->si_passthru != NULL ) {
765 for ( ; !BER_BVISNULL( &si->si_passthru[ i ] ); i++ )
769 if ( i <= c->valx ) {
770 ber_bvarray_add( &si->si_passthru, &bv );
773 BerVarray tmp = ber_memrealloc( si->si_passthru,
774 sizeof( struct berval )*( i + 2 ) );
778 si->si_passthru = tmp;
779 for ( ; i > c->valx; i-- ) {
780 si->si_passthru[ i ] = si->si_passthru[ i - 1 ];
782 si->si_passthru[ c->valx ] = bv;
790 slap_idassert_parse( ConfigArgs *c, slap_idassert_t *si )
794 for ( i = 1; i < c->argc; i++ ) {
795 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
796 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
799 j = verb_to_mask( argvi, idassert_mode );
800 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
801 snprintf( c->cr_msg, sizeof( c->cr_msg ),
802 "\"idassert-bind <args>\": "
803 "unknown mode \"%s\"",
805 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
809 si->si_mode = idassert_mode[ j ].mask;
811 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
812 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
814 if ( strcasecmp( argvi, "native" ) == 0 ) {
815 if ( si->si_bc.sb_method != LDAP_AUTH_SASL ) {
816 snprintf( c->cr_msg, sizeof( c->cr_msg ),
817 "\"idassert-bind <args>\": "
818 "authz=\"native\" incompatible "
819 "with auth method" );
820 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
823 si->si_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
825 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
826 si->si_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
829 snprintf( c->cr_msg, sizeof( c->cr_msg ),
830 "\"idassert-bind <args>\": "
831 "unknown authz \"%s\"",
833 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
837 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
838 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
839 char **flags = ldap_str2charray( argvi, "," );
842 if ( flags == NULL ) {
843 snprintf( c->cr_msg, sizeof( c->cr_msg ),
844 "\"idassert-bind <args>\": "
845 "unable to parse flags \"%s\"",
847 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
851 for ( j = 0; flags[ j ] != NULL; j++ ) {
853 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
854 si->si_flags |= LDAP_BACK_AUTH_OVERRIDE;
856 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
857 si->si_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
859 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
860 si->si_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
862 } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
863 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
864 Debug( LDAP_DEBUG_ANY,
865 "%s: \"obsolete-proxy-authz\" flag "
866 "in \"idassert-mode <args>\" "
867 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
873 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
876 } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
877 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
878 Debug( LDAP_DEBUG_ANY,
879 "%s: \"obsolete-encoding-workaround\" flag "
880 "in \"idassert-mode <args>\" "
881 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
887 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
890 } else if ( strcasecmp( flags[ j ], "proxy-authz-critical" ) == 0 ) {
891 si->si_flags |= LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
893 } else if ( strcasecmp( flags[ j ], "proxy-authz-non-critical" ) == 0 ) {
894 si->si_flags &= ~LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
897 snprintf( c->cr_msg, sizeof( c->cr_msg ),
898 "\"idassert-bind <args>\": "
899 "unknown flag \"%s\"",
901 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
907 ldap_charray_free( flags );
912 } else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) {
913 snprintf( c->cr_msg, sizeof( c->cr_msg ),
914 "\"idassert-bind <args>\": "
915 "unable to parse field \"%s\"",
917 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
922 if ( si->si_bc.sb_method == LDAP_AUTH_SIMPLE ) {
923 if ( BER_BVISNULL( &si->si_bc.sb_binddn )
924 || BER_BVISNULL( &si->si_bc.sb_cred ) )
926 snprintf( c->cr_msg, sizeof( c->cr_msg ),
927 "\"idassert-bind <args>\": "
928 "SIMPLE needs \"binddn\" and \"credentials\"" );
929 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
934 bindconf_tls_defaults( &si->si_bc );
939 /* NOTE: temporary, until back-meta is ported to back-config */
941 slap_idassert_passthru_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
943 ConfigArgs c = { 0 };
946 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
949 argv[ 0 ] = "idassert-passThru";
950 argv[ 1 ] = (char *)arg;
953 return slap_idassert_passthru_parse( &c, si );
957 ldap_back_cf_gen( ConfigArgs *c )
959 ldapinfo_t *li = ( ldapinfo_t * )c->be->be_private;
963 if ( c->op == SLAP_CONFIG_EMIT ) {
964 struct berval bv = BER_BVNULL;
971 case LDAP_BACK_CFG_URI:
972 if ( li->li_uri != NULL ) {
973 struct berval bv, bv2;
975 ber_str2bv( li->li_uri, 0, 0, &bv );
976 bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" );
977 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
978 snprintf( bv2.bv_val, bv2.bv_len + 1,
979 "\"%s\"", bv.bv_val );
980 ber_bvarray_add( &c->rvalue_vals, &bv2 );
987 case LDAP_BACK_CFG_TLS: {
988 struct berval bc = BER_BVNULL, bv2;
989 enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
990 assert( !BER_BVISNULL( &bv ) );
991 bindconf_tls_unparse( &li->li_tls, &bc );
993 if ( !BER_BVISEMPTY( &bc )) {
994 bv2.bv_len = bv.bv_len + bc.bv_len + 1;
995 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
996 strcpy( bv2.bv_val, bv.bv_val );
997 bv2.bv_val[bv.bv_len] = ' ';
998 strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val );
999 ber_bvarray_add( &c->rvalue_vals, &bv2 );
1002 value_add_one( &c->rvalue_vals, &bv );
1004 ber_memfree( bc.bv_val );
1008 case LDAP_BACK_CFG_ACL_AUTHCDN:
1009 case LDAP_BACK_CFG_ACL_PASSWD:
1010 case LDAP_BACK_CFG_ACL_METHOD:
1011 /* handled by LDAP_BACK_CFG_ACL_BIND */
1015 case LDAP_BACK_CFG_ACL_BIND: {
1018 if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
1022 bindconf_unparse( &li->li_acl, &bv );
1024 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1025 /* count spaces */ ;
1029 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1033 ber_bvarray_add( &c->rvalue_vals, &bv );
1037 case LDAP_BACK_CFG_IDASSERT_MODE:
1038 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1039 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1040 case LDAP_BACK_CFG_IDASSERT_METHOD:
1041 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1045 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1046 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
1049 struct berval bv = BER_BVNULL;
1050 char buf[SLAP_TEXT_BUFLEN];
1052 switch ( c->type ) {
1053 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
1054 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
1055 default: assert( 0 ); break;
1058 if ( *bvp == NULL ) {
1059 if ( bvp == &li->li_idassert_authz
1060 && ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
1062 BER_BVSTR( &bv, "*" );
1063 value_add_one( &c->rvalue_vals, &bv );
1071 for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) {
1073 int len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
1074 bv.bv_len = ((*bvp)[ i ]).bv_len + len;
1075 bv.bv_val = ber_memrealloc( bv.bv_val, bv.bv_len + 1 );
1077 ptr = lutil_strcopy( ptr, buf );
1078 ptr = lutil_strncopy( ptr, ((*bvp)[ i ]).bv_val, ((*bvp)[ i ]).bv_len );
1079 value_add_one( &c->rvalue_vals, &bv );
1082 ber_memfree( bv.bv_val );
1087 case LDAP_BACK_CFG_IDASSERT_BIND: {
1089 struct berval bc = BER_BVNULL;
1092 if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
1096 if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
1099 switch ( li->li_idassert_mode ) {
1100 case LDAP_BACK_IDASSERT_OTHERID:
1101 case LDAP_BACK_IDASSERT_OTHERDN:
1105 struct berval mode = BER_BVNULL;
1107 enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
1108 if ( BER_BVISNULL( &mode ) ) {
1109 /* there's something wrong... */
1114 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
1115 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1117 ptr = lutil_strcopy( bv.bv_val, "mode=" );
1118 ptr = lutil_strcopy( ptr, mode.bv_val );
1124 if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
1125 len = bv.bv_len + STRLENOF( "authz=native" );
1127 if ( !BER_BVISEMPTY( &bv ) ) {
1128 len += STRLENOF( " " );
1131 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1133 ptr = &bv.bv_val[ bv.bv_len ];
1135 if ( !BER_BVISEMPTY( &bv ) ) {
1136 ptr = lutil_strcopy( ptr, " " );
1139 (void)lutil_strcopy( ptr, "authz=native" );
1142 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround,proxy-authz-non-critical" );
1144 if ( !BER_BVISEMPTY( &bv ) ) {
1145 len += STRLENOF( " " );
1148 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1150 ptr = &bv.bv_val[ bv.bv_len ];
1152 if ( !BER_BVISEMPTY( &bv ) ) {
1153 ptr = lutil_strcopy( ptr, " " );
1156 ptr = lutil_strcopy( ptr, "flags=" );
1158 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1159 ptr = lutil_strcopy( ptr, "prescriptive" );
1161 ptr = lutil_strcopy( ptr, "non-prescriptive" );
1164 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
1165 ptr = lutil_strcopy( ptr, ",override" );
1168 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1169 ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" );
1171 } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1172 ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" );
1175 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL ) {
1176 ptr = lutil_strcopy( ptr, ",proxy-authz-critical" );
1179 ptr = lutil_strcopy( ptr, ",proxy-authz-non-critical" );
1182 bv.bv_len = ( ptr - bv.bv_val );
1186 bindconf_unparse( &li->li_idassert.si_bc, &bc );
1188 if ( !BER_BVISNULL( &bv ) ) {
1189 ber_len_t len = bv.bv_len + bc.bv_len;
1191 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1193 assert( bc.bv_val[ 0 ] == ' ' );
1195 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
1197 bv.bv_len = ptr - bv.bv_val;
1200 for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ )
1201 /* count spaces */ ;
1205 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
1211 ber_bvarray_add( &c->rvalue_vals, &bv );
1216 case LDAP_BACK_CFG_REBIND:
1217 c->value_int = LDAP_BACK_SAVECRED( li );
1220 case LDAP_BACK_CFG_CHASE:
1221 c->value_int = LDAP_BACK_CHASE_REFERRALS( li );
1224 case LDAP_BACK_CFG_T_F:
1225 enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv );
1226 if ( BER_BVISNULL( &bv ) ) {
1227 /* there's something wrong... */
1232 value_add_one( &c->rvalue_vals, &bv );
1236 case LDAP_BACK_CFG_WHOAMI:
1237 c->value_int = LDAP_BACK_PROXY_WHOAMI( li );
1240 case LDAP_BACK_CFG_TIMEOUT:
1243 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1244 if ( li->li_timeout[ i ] != 0 ) {
1249 if ( i == SLAP_OP_LAST ) {
1253 slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table );
1255 if ( BER_BVISNULL( &bv ) ) {
1259 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1260 /* count spaces */ ;
1264 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1268 ber_bvarray_add( &c->rvalue_vals, &bv );
1271 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1272 char buf[ SLAP_TEXT_BUFLEN ];
1274 if ( li->li_idle_timeout == 0 ) {
1278 lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout );
1279 ber_str2bv( buf, 0, 0, &bv );
1280 value_add_one( &c->rvalue_vals, &bv );
1283 case LDAP_BACK_CFG_CONN_TTL: {
1284 char buf[ SLAP_TEXT_BUFLEN ];
1286 if ( li->li_conn_ttl == 0 ) {
1290 lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl );
1291 ber_str2bv( buf, 0, 0, &bv );
1292 value_add_one( &c->rvalue_vals, &bv );
1295 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1296 char buf[ SLAP_TEXT_BUFLEN ];
1298 if ( li->li_network_timeout == 0 ) {
1302 snprintf( buf, sizeof( buf ), "%ld",
1303 (long)li->li_network_timeout );
1304 ber_str2bv( buf, 0, 0, &bv );
1305 value_add_one( &c->rvalue_vals, &bv );
1308 case LDAP_BACK_CFG_VERSION:
1309 if ( li->li_version == 0 ) {
1313 c->value_int = li->li_version;
1316 case LDAP_BACK_CFG_SINGLECONN:
1317 c->value_int = LDAP_BACK_SINGLECONN( li );
1320 case LDAP_BACK_CFG_USETEMP:
1321 c->value_int = LDAP_BACK_USE_TEMPORARIES( li );
1324 case LDAP_BACK_CFG_CONNPOOLMAX:
1325 c->value_int = li->li_conn_priv_max;
1328 case LDAP_BACK_CFG_CANCEL: {
1329 slap_mask_t mask = LDAP_BACK_F_CANCEL_MASK2;
1331 if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) {
1332 mask &= ~LDAP_BACK_F_CANCEL_EXOP;
1334 enum_to_verb( cancel_mode, (li->li_flags & mask), &bv );
1335 if ( BER_BVISNULL( &bv ) ) {
1336 /* there's something wrong... */
1341 value_add_one( &c->rvalue_vals, &bv );
1345 case LDAP_BACK_CFG_QUARANTINE:
1346 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1351 rc = slap_retry_info_unparse( &li->li_quarantine, &bv );
1353 ber_bvarray_add( &c->rvalue_vals, &bv );
1357 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1358 case LDAP_BACK_CFG_ST_REQUEST:
1359 c->value_int = LDAP_BACK_ST_REQUEST( li );
1361 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1363 case LDAP_BACK_CFG_NOREFS:
1364 c->value_int = LDAP_BACK_NOREFS( li );
1367 case LDAP_BACK_CFG_NOUNDEFFILTER:
1368 c->value_int = LDAP_BACK_NOUNDEFFILTER( li );
1371 case LDAP_BACK_CFG_ONERR:
1372 enum_to_verb( onerr_mode, li->li_flags & LDAP_BACK_F_ONERR_STOP, &bv );
1373 if ( BER_BVISNULL( &bv )) {
1376 value_add_one( &c->rvalue_vals, &bv );
1380 case LDAP_BACK_CFG_KEEPALIVE: {
1382 char buf[AC_LINE_MAX];
1383 bv.bv_len = AC_LINE_MAX;
1384 bv.bv_val = &buf[0];
1385 slap_keepalive_parse(&bv, &li->li_tls.sb_keepalive, 0, 0, 1);
1386 value_add_one( &c->rvalue_vals, &bv );
1391 /* FIXME: we need to handle all... */
1397 } else if ( c->op == LDAP_MOD_DELETE ) {
1399 case LDAP_BACK_CFG_URI:
1400 if ( li->li_uri != NULL ) {
1401 ch_free( li->li_uri );
1404 assert( li->li_bvuri != NULL );
1405 ber_bvarray_free( li->li_bvuri );
1406 li->li_bvuri = NULL;
1409 /* better cleanup the cached connections... */
1410 /* NOTE: don't worry about locking: if we got here,
1411 * other threads are suspended. */
1412 if ( li->li_conninfo.lai_tree != NULL ) {
1413 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
1414 li->li_conninfo.lai_tree = NULL;
1419 case LDAP_BACK_CFG_TLS:
1423 case LDAP_BACK_CFG_ACL_AUTHCDN:
1424 case LDAP_BACK_CFG_ACL_PASSWD:
1425 case LDAP_BACK_CFG_ACL_METHOD:
1426 /* handled by LDAP_BACK_CFG_ACL_BIND */
1430 case LDAP_BACK_CFG_ACL_BIND:
1431 bindconf_free( &li->li_acl );
1434 case LDAP_BACK_CFG_IDASSERT_MODE:
1435 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1436 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1437 case LDAP_BACK_CFG_IDASSERT_METHOD:
1438 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1442 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1443 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
1446 switch ( c->type ) {
1447 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
1448 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
1449 default: assert( 0 ); break;
1452 if ( c->valx < 0 ) {
1453 if ( *bvp != NULL ) {
1454 ber_bvarray_free( *bvp );
1461 if ( *bvp == NULL ) {
1466 for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ )
1469 if ( i >= c->valx ) {
1473 ber_memfree( ((*bvp)[ c->valx ]).bv_val );
1474 for ( i = c->valx; !BER_BVISNULL( &((*bvp)[ i + 1 ]) ); i++ ) {
1475 (*bvp)[ i ] = (*bvp)[ i + 1 ];
1477 BER_BVZERO( &((*bvp)[ i ]) );
1481 case LDAP_BACK_CFG_IDASSERT_BIND:
1482 bindconf_free( &li->li_idassert.si_bc );
1483 memset( &li->li_idassert, 0, sizeof( slap_idassert_t ) );
1486 case LDAP_BACK_CFG_REBIND:
1487 case LDAP_BACK_CFG_CHASE:
1488 case LDAP_BACK_CFG_T_F:
1489 case LDAP_BACK_CFG_WHOAMI:
1490 case LDAP_BACK_CFG_CANCEL:
1494 case LDAP_BACK_CFG_TIMEOUT:
1495 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1496 li->li_timeout[ i ] = 0;
1500 case LDAP_BACK_CFG_IDLE_TIMEOUT:
1501 li->li_idle_timeout = 0;
1504 case LDAP_BACK_CFG_CONN_TTL:
1505 li->li_conn_ttl = 0;
1508 case LDAP_BACK_CFG_NETWORK_TIMEOUT:
1509 li->li_network_timeout = 0;
1512 case LDAP_BACK_CFG_VERSION:
1516 case LDAP_BACK_CFG_SINGLECONN:
1517 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1520 case LDAP_BACK_CFG_USETEMP:
1521 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
1524 case LDAP_BACK_CFG_CONNPOOLMAX:
1525 li->li_conn_priv_max = LDAP_BACK_CONN_PRIV_MIN;
1528 case LDAP_BACK_CFG_QUARANTINE:
1529 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1533 slap_retry_info_destroy( &li->li_quarantine );
1534 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
1535 li->li_isquarantined = 0;
1536 li->li_flags &= ~LDAP_BACK_F_QUARANTINE;
1539 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1540 case LDAP_BACK_CFG_ST_REQUEST:
1541 li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
1543 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1545 case LDAP_BACK_CFG_NOREFS:
1546 li->li_flags &= ~LDAP_BACK_F_NOREFS;
1549 case LDAP_BACK_CFG_NOUNDEFFILTER:
1550 li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
1553 case LDAP_BACK_CFG_ONERR:
1554 li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
1557 case LDAP_BACK_CFG_KEEPALIVE:
1558 li->li_tls.sb_keepalive.sk_idle = 0;
1559 li->li_tls.sb_keepalive.sk_probes = 0;
1560 li->li_tls.sb_keepalive.sk_interval = 0;
1564 /* FIXME: we need to handle all... */
1573 case LDAP_BACK_CFG_URI: {
1574 LDAPURLDesc *tmpludp, *lud;
1575 char **urllist = NULL;
1576 int urlrc = LDAP_URL_SUCCESS, i;
1578 if ( li->li_uri != NULL ) {
1579 ch_free( li->li_uri );
1582 assert( li->li_bvuri != NULL );
1583 ber_bvarray_free( li->li_bvuri );
1584 li->li_bvuri = NULL;
1587 /* PARANOID: DN and more are not required nor allowed */
1588 urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
1589 if ( urlrc != LDAP_URL_SUCCESS ) {
1593 case LDAP_URL_ERR_MEM:
1596 case LDAP_URL_ERR_PARAM:
1597 why = "parameter is bad";
1599 case LDAP_URL_ERR_BADSCHEME:
1600 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1602 case LDAP_URL_ERR_BADENCLOSURE:
1603 why = "URL is missing trailing \">\"";
1605 case LDAP_URL_ERR_BADURL:
1608 case LDAP_URL_ERR_BADHOST:
1609 why = "host/port is bad";
1611 case LDAP_URL_ERR_BADATTRS:
1612 why = "bad (or missing) attributes";
1614 case LDAP_URL_ERR_BADSCOPE:
1615 why = "scope string is invalid (or missing)";
1617 case LDAP_URL_ERR_BADFILTER:
1618 why = "bad or missing filter";
1620 case LDAP_URL_ERR_BADEXTS:
1621 why = "bad or missing extensions";
1624 why = "unknown reason";
1627 snprintf( c->cr_msg, sizeof( c->cr_msg),
1628 "unable to parse uri \"%s\" "
1629 "in \"uri <uri>\" line: %s",
1630 c->value_string, why );
1631 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1636 for ( i = 0, tmpludp = lud;
1638 i++, tmpludp = tmpludp->lud_next )
1640 if ( ( tmpludp->lud_dn != NULL
1641 && tmpludp->lud_dn[0] != '\0' )
1642 || tmpludp->lud_attrs != NULL
1643 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1644 || tmpludp->lud_filter != NULL
1645 || tmpludp->lud_exts != NULL )
1647 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1648 "warning, only protocol, "
1649 "host and port allowed "
1650 "in \"uri <uri>\" statement "
1651 "for uri #%d of \"%s\"",
1653 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1657 for ( i = 0, tmpludp = lud;
1659 i++, tmpludp = tmpludp->lud_next )
1662 urllist = ch_calloc( sizeof( char * ), i + 1 );
1664 for ( i = 0, tmpludp = lud;
1666 i++, tmpludp = tmpludp->lud_next )
1672 tmplud.lud_attrs = NULL;
1673 tmplud.lud_filter = NULL;
1674 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1675 tmplud.lud_exts = NULL;
1676 tmplud.lud_crit_exts = 0;
1679 urllist[ i ] = ldap_url_desc2str( &tmplud );
1681 if ( urllist[ i ] == NULL ) {
1682 snprintf( c->cr_msg, sizeof( c->cr_msg),
1683 "unable to rebuild uri "
1684 "in \"uri <uri>\" statement "
1687 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1693 li->li_uri = ldap_charray2str( urllist, " " );
1694 for ( i = 0; urllist[ i ] != NULL; i++ ) {
1697 ber_str2bv( urllist[ i ], 0, 0, &bv );
1698 ber_bvarray_add( &li->li_bvuri, &bv );
1699 urllist[ i ] = NULL;
1701 ldap_memfree( urllist );
1706 ldap_charray_free( urllist );
1709 ldap_free_urllist( lud );
1711 if ( urlrc != LDAP_URL_SUCCESS ) {
1717 case LDAP_BACK_CFG_TLS:
1718 i = verb_to_mask( c->argv[1], tls_mode );
1719 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
1722 li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
1723 li->li_flags |= tls_mode[i].mask;
1724 if ( c->argc > 2 ) {
1725 for ( i=2; i<c->argc; i++ ) {
1726 if ( bindconf_tls_parse( c->argv[i], &li->li_tls ))
1729 bindconf_tls_defaults( &li->li_tls );
1733 case LDAP_BACK_CFG_ACL_AUTHCDN:
1734 switch ( li->li_acl_authmethod ) {
1735 case LDAP_AUTH_NONE:
1736 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1739 case LDAP_AUTH_SIMPLE:
1743 snprintf( c->cr_msg, sizeof( c->cr_msg),
1744 "\"acl-authcDN <DN>\" incompatible "
1745 "with auth method %d",
1746 li->li_acl_authmethod );
1747 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1750 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
1751 free( li->li_acl_authcDN.bv_val );
1753 ber_memfree_x( c->value_dn.bv_val, NULL );
1754 li->li_acl_authcDN = c->value_ndn;
1755 BER_BVZERO( &c->value_dn );
1756 BER_BVZERO( &c->value_ndn );
1759 case LDAP_BACK_CFG_ACL_PASSWD:
1760 switch ( li->li_acl_authmethod ) {
1761 case LDAP_AUTH_NONE:
1762 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1765 case LDAP_AUTH_SIMPLE:
1769 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1770 "\"acl-passwd <cred>\" incompatible "
1771 "with auth method %d",
1772 li->li_acl_authmethod );
1773 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1776 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
1777 free( li->li_acl_passwd.bv_val );
1779 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
1782 case LDAP_BACK_CFG_ACL_METHOD:
1783 case LDAP_BACK_CFG_ACL_BIND:
1784 for ( i = 1; i < c->argc; i++ ) {
1785 if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
1789 bindconf_tls_defaults( &li->li_acl );
1792 case LDAP_BACK_CFG_IDASSERT_MODE:
1793 i = verb_to_mask( c->argv[1], idassert_mode );
1794 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
1795 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
1796 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1797 ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
1798 li->li_idassert_authzID.bv_val[ 0 ] = 'u';
1801 struct berval id, ndn;
1803 ber_str2bv( c->argv[1], 0, 0, &id );
1805 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1806 id.bv_val += STRLENOF( "dn:" );
1807 id.bv_len -= STRLENOF( "dn:" );
1810 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
1811 if ( rc != LDAP_SUCCESS ) {
1812 Debug( LDAP_DEBUG_ANY,
1813 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1814 c->fname, c->lineno, c->argv[1] );
1818 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1819 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
1820 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1821 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
1822 ch_free( ndn.bv_val );
1824 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1828 li->li_idassert_mode = idassert_mode[i].mask;
1831 if ( c->argc > 2 ) {
1834 for ( i = 2; i < c->argc; i++ ) {
1835 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
1836 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1838 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
1839 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1841 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
1842 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1844 } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
1845 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1846 Debug( LDAP_DEBUG_ANY,
1847 "%s: line %d: \"obsolete-proxy-authz\" flag "
1848 "in \"idassert-mode <args>\" "
1849 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1850 c->fname, c->lineno, 0 );
1853 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1855 } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
1856 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1857 Debug( LDAP_DEBUG_ANY,
1858 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1859 "in \"idassert-mode <args>\" "
1860 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1861 c->fname, c->lineno, 0 );
1864 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1867 Debug( LDAP_DEBUG_ANY,
1868 "%s: line %d: unknown flag #%d "
1869 "in \"idassert-mode <args> "
1870 "[<flags>]\" line.\n",
1871 c->fname, c->lineno, i - 2 );
1878 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1879 switch ( li->li_idassert_authmethod ) {
1880 case LDAP_AUTH_NONE:
1881 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1884 case LDAP_AUTH_SIMPLE:
1888 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1889 "\"idassert-authcDN <DN>\" incompatible "
1890 "with auth method %d",
1891 li->li_idassert_authmethod );
1892 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1895 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1896 free( li->li_idassert_authcDN.bv_val );
1898 ber_memfree_x( c->value_dn.bv_val, NULL );
1899 li->li_idassert_authcDN = c->value_ndn;
1900 BER_BVZERO( &c->value_dn );
1901 BER_BVZERO( &c->value_ndn );
1904 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1905 switch ( li->li_idassert_authmethod ) {
1906 case LDAP_AUTH_NONE:
1907 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1910 case LDAP_AUTH_SIMPLE:
1914 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1915 "\"idassert-passwd <cred>\" incompatible "
1916 "with auth method %d",
1917 li->li_idassert_authmethod );
1918 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1921 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
1922 free( li->li_idassert_passwd.bv_val );
1924 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
1927 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1928 rc = slap_idassert_authzfrom_parse( c, &li->li_idassert );
1931 case LDAP_BACK_CFG_IDASSERT_PASSTHRU:
1932 rc = slap_idassert_passthru_parse( c, &li->li_idassert );
1935 case LDAP_BACK_CFG_IDASSERT_METHOD:
1936 /* no longer supported */
1937 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1938 "\"idassert-method <args>\": "
1939 "no longer supported; use \"idassert-bind\"" );
1940 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1943 case LDAP_BACK_CFG_IDASSERT_BIND:
1944 rc = slap_idassert_parse( c, &li->li_idassert );
1947 case LDAP_BACK_CFG_REBIND:
1948 if ( c->argc == 1 || c->value_int ) {
1949 li->li_flags |= LDAP_BACK_F_SAVECRED;
1952 li->li_flags &= ~LDAP_BACK_F_SAVECRED;
1956 case LDAP_BACK_CFG_CHASE:
1957 if ( c->argc == 1 || c->value_int ) {
1958 li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
1961 li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1965 case LDAP_BACK_CFG_T_F: {
1968 i = verb_to_mask( c->argv[1], t_f_mode );
1969 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1973 mask = t_f_mode[i].mask;
1975 if ( LDAP_BACK_ISOPEN( li )
1976 && mask == LDAP_BACK_F_T_F_DISCOVER
1977 && !LDAP_BACK_T_F( li ) )
1979 slap_bindconf sb = { BER_BVNULL };
1982 if ( li->li_uri == NULL ) {
1983 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1984 "need URI to discover absolute filters support "
1985 "in \"t-f-support discover\"" );
1986 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1990 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
1991 sb.sb_version = li->li_version;
1992 sb.sb_method = LDAP_AUTH_SIMPLE;
1993 BER_BVSTR( &sb.sb_binddn, "" );
1995 rc = slap_discover_feature( &sb,
1996 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
1997 LDAP_FEATURE_ABSOLUTE_FILTERS );
1998 if ( rc == LDAP_COMPARE_TRUE ) {
1999 mask |= LDAP_BACK_F_T_F;
2003 li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
2004 li->li_flags |= mask;
2007 case LDAP_BACK_CFG_WHOAMI:
2008 if ( c->argc == 1 || c->value_int ) {
2009 li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
2010 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
2011 0, ldap_back_exop_whoami );
2014 li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
2018 case LDAP_BACK_CFG_TIMEOUT:
2019 for ( i = 1; i < c->argc; i++ ) {
2020 if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
2024 if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
2025 snprintf( c->cr_msg, sizeof( c->cr_msg),
2026 "unable to parse timeout \"%s\"",
2028 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2032 for ( j = 0; j < SLAP_OP_LAST; j++ ) {
2033 li->li_timeout[ j ] = u;
2039 if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
2040 snprintf( c->cr_msg, sizeof( c->cr_msg),
2041 "unable to parse timeout \"%s\"",
2043 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2049 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
2052 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2053 snprintf( c->cr_msg, sizeof( c->cr_msg),
2054 "unable to parse idle timeout \"%s\"",
2056 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2059 li->li_idle_timeout = (time_t)t;
2062 case LDAP_BACK_CFG_CONN_TTL: {
2065 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2066 snprintf( c->cr_msg, sizeof( c->cr_msg),
2067 "unable to parse conn ttl\"%s\"",
2069 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2072 li->li_conn_ttl = (time_t)t;
2075 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
2078 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2079 snprintf( c->cr_msg, sizeof( c->cr_msg),
2080 "unable to parse network timeout \"%s\"",
2082 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2085 li->li_network_timeout = (time_t)t;
2088 case LDAP_BACK_CFG_VERSION:
2089 if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
2090 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2091 "unsupported version \"%s\" "
2092 "in \"protocol-version <version>\"",
2094 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2098 li->li_version = c->value_int;
2101 case LDAP_BACK_CFG_SINGLECONN:
2102 if ( c->value_int ) {
2103 li->li_flags |= LDAP_BACK_F_SINGLECONN;
2106 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
2110 case LDAP_BACK_CFG_USETEMP:
2111 if ( c->value_int ) {
2112 li->li_flags |= LDAP_BACK_F_USE_TEMPORARIES;
2115 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
2119 case LDAP_BACK_CFG_CONNPOOLMAX:
2120 if ( c->value_int < LDAP_BACK_CONN_PRIV_MIN
2121 || c->value_int > LDAP_BACK_CONN_PRIV_MAX )
2123 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2124 "invalid max size " "of privileged "
2125 "connections pool \"%s\" "
2126 "in \"conn-pool-max <n> "
2127 "(must be between %d and %d)\"",
2129 LDAP_BACK_CONN_PRIV_MIN,
2130 LDAP_BACK_CONN_PRIV_MAX );
2131 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2134 li->li_conn_priv_max = c->value_int;
2137 case LDAP_BACK_CFG_CANCEL: {
2140 i = verb_to_mask( c->argv[1], cancel_mode );
2141 if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
2145 mask = cancel_mode[i].mask;
2147 if ( LDAP_BACK_ISOPEN( li )
2148 && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
2149 && !LDAP_BACK_CANCEL( li ) )
2151 slap_bindconf sb = { BER_BVNULL };
2154 if ( li->li_uri == NULL ) {
2155 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2156 "need URI to discover \"cancel\" support "
2157 "in \"cancel exop-discover\"" );
2158 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2162 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
2163 sb.sb_version = li->li_version;
2164 sb.sb_method = LDAP_AUTH_SIMPLE;
2165 BER_BVSTR( &sb.sb_binddn, "" );
2167 rc = slap_discover_feature( &sb,
2168 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
2170 if ( rc == LDAP_COMPARE_TRUE ) {
2171 mask |= LDAP_BACK_F_CANCEL_EXOP;
2175 li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
2176 li->li_flags |= mask;
2179 case LDAP_BACK_CFG_QUARANTINE:
2180 if ( LDAP_BACK_QUARANTINE( li ) ) {
2181 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2182 "quarantine already defined" );
2183 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2186 rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
2187 c->cr_msg, sizeof( c->cr_msg ) );
2189 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2192 ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex );
2193 /* give it a chance to retry if the pattern gets reset
2194 * via back-config */
2195 li->li_isquarantined = 0;
2196 li->li_flags |= LDAP_BACK_F_QUARANTINE;
2200 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
2201 case LDAP_BACK_CFG_ST_REQUEST:
2202 if ( c->value_int ) {
2203 li->li_flags |= LDAP_BACK_F_ST_REQUEST;
2206 li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
2209 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
2211 case LDAP_BACK_CFG_NOREFS:
2212 if ( c->value_int ) {
2213 li->li_flags |= LDAP_BACK_F_NOREFS;
2216 li->li_flags &= ~LDAP_BACK_F_NOREFS;
2220 case LDAP_BACK_CFG_NOUNDEFFILTER:
2221 if ( c->value_int ) {
2222 li->li_flags |= LDAP_BACK_F_NOUNDEFFILTER;
2225 li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
2229 case LDAP_BACK_CFG_ONERR:
2231 i = verb_to_mask( c->argv[1], onerr_mode );
2232 if ( BER_BVISNULL( &onerr_mode[i].word ) ) {
2233 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2234 "%s unknown argument \"%s\"",
2235 c->argv[0], c->argv[1] );
2236 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2239 li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
2240 li->li_flags |= onerr_mode[i].mask;
2243 case LDAP_BACK_CFG_REWRITE:
2244 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2245 "rewrite/remap capabilities have been moved "
2246 "to the \"rwm\" overlay; see slapo-rwm(5) "
2247 "for details (hint: add \"overlay rwm\" "
2248 "and prefix all directives with \"rwm-\")" );
2249 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2252 case LDAP_BACK_CFG_KEEPALIVE:
2253 slap_keepalive_parse( ber_bvstrdup(c->argv[1]),
2254 &li->li_tls.sb_keepalive, 0, 0, 0);
2258 /* FIXME: try to catch inconsistencies */
2267 ldap_back_init_cf( BackendInfo *bi )
2270 AttributeDescription *ad = NULL;
2273 /* Make sure we don't exceed the bits reserved for userland */
2274 config_check_userland( LDAP_BACK_CFG_LAST );
2276 bi->bi_cf_ocs = ldapocs;
2278 rc = config_register_schema( ldapcfg, ldapocs );
2283 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
2284 * to be base64-encoded when written in LDIF form;
2285 * basically, we don't care if it fails */
2286 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
2288 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
2289 "warning, unable to get \"olcDbACLPasswd\" "
2290 "attribute description: %d: %s\n",
2293 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
2294 ad->ad_type->sat_oid );
2298 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
2300 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
2301 "warning, unable to get \"olcDbIDAssertPasswd\" "
2302 "attribute description: %d: %s\n",
2305 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
2306 ad->ad_type->sat_oid );
2313 ldap_pbind_cf_gen( ConfigArgs *c )
2315 slap_overinst *on = (slap_overinst *)c->bi;
2316 void *private = c->be->be_private;
2319 c->be->be_private = on->on_bi.bi_private;
2320 rc = ldap_back_cf_gen( c );
2321 c->be->be_private = private;
2326 ldap_pbind_init_cf( BackendInfo *bi )
2328 bi->bi_cf_ocs = pbindocs;
2330 return config_register_schema( pbindcfg, pbindocs );
2334 ldap_back_exop_whoami(
2338 struct berval *bv = NULL;
2340 if ( op->oq_extended.rs_reqdata != NULL ) {
2341 /* no request data should be provided */
2342 rs->sr_text = "no request data expected";
2343 return rs->sr_err = LDAP_PROTOCOL_ERROR;
2346 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
2347 op->o_log_prefix, 0, 0, 0, 0 );
2349 rs->sr_err = backend_check_restrictions( op, rs,
2350 (struct berval *)&slap_EXOP_WHOAMI );
2351 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
2353 /* if auth'd by back-ldap and request is proxied, forward it */
2354 if ( op->o_conn->c_authz_backend
2355 && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
2356 && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
2358 ldapconn_t *lc = NULL;
2359 LDAPControl c, *ctrls[2] = {NULL, NULL};
2361 Operation op2 = *op;
2367 op2.o_ndn = op->o_conn->c_ndn;
2368 if ( !ldap_back_dobind( &lc, &op2, rs, LDAP_BACK_SENDERR ) ) {
2371 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
2372 c.ldctl_iscritical = 1;
2373 c.ldctl_value.bv_val = op->o_tmpalloc(
2374 op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
2376 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
2377 ptr = c.ldctl_value.bv_val;
2378 ptr = lutil_strcopy( ptr, "dn:" );
2379 ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
2383 rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
2384 if ( rs->sr_err == LDAP_SUCCESS ) {
2385 /* by now, make sure no timeout is used (ITS#6282) */
2386 struct timeval tv = { -1, 0 };
2387 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) == -1 ) {
2388 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
2390 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
2392 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
2398 /* NOTE: are we sure "bv" will be malloc'ed
2399 * with the appropriate memory? */
2400 rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
2404 op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
2405 if ( rs->sr_err != LDAP_SUCCESS ) {
2406 rs->sr_err = slap_map_api2result( rs );
2410 ldap_back_release_conn( (ldapinfo_t *)op2.o_bd->be_private, lc );
2414 /* else just do the same as before */
2415 bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
2416 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
2417 bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
2418 bv->bv_val = ch_malloc( bv->bv_len + 1 );
2419 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
2420 AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
2422 bv->bv_val[ bv->bv_len ] = '\0';
2430 rs->sr_rspdata = bv;