1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2018 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,
79 LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA,
84 static ConfigTable ldapcfg[] = {
85 { "uri", "uri", 2, 2, 0,
86 ARG_MAGIC|LDAP_BACK_CFG_URI,
87 ldap_back_cf_gen, "( OLcfgDbAt:0.14 "
89 "DESC 'URI (list) for remote DSA' "
90 "SYNTAX OMsDirectoryString "
93 { "tls", "what", 2, 0, 0,
94 ARG_MAGIC|LDAP_BACK_CFG_TLS,
95 ldap_back_cf_gen, "( OLcfgDbAt:3.1 "
96 "NAME 'olcDbStartTLS' "
98 "SYNTAX OMsDirectoryString "
101 { "acl-authcDN", "DN", 2, 2, 0,
102 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
103 ldap_back_cf_gen, "( OLcfgDbAt:3.2 "
104 "NAME 'olcDbACLAuthcDn' "
105 "DESC 'Remote ACL administrative identity' "
110 /* deprecated, will be removed; aliases "acl-authcDN" */
111 { "binddn", "DN", 2, 2, 0,
112 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_ACL_AUTHCDN,
113 ldap_back_cf_gen, NULL, NULL, NULL },
114 { "acl-passwd", "cred", 2, 2, 0,
115 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
116 ldap_back_cf_gen, "( OLcfgDbAt:3.3 "
117 "NAME 'olcDbACLPasswd' "
118 "DESC 'Remote ACL administrative identity credentials' "
120 "SYNTAX OMsDirectoryString "
123 /* deprecated, will be removed; aliases "acl-passwd" */
124 { "bindpw", "cred", 2, 2, 0,
125 ARG_MAGIC|LDAP_BACK_CFG_ACL_PASSWD,
126 ldap_back_cf_gen, NULL, NULL, NULL },
127 /* deprecated, will be removed; aliases "acl-bind" */
128 { "acl-method", "args", 2, 0, 0,
129 ARG_MAGIC|LDAP_BACK_CFG_ACL_METHOD,
130 ldap_back_cf_gen, NULL, NULL, NULL },
131 { "acl-bind", "args", 2, 0, 0,
132 ARG_MAGIC|LDAP_BACK_CFG_ACL_BIND,
133 ldap_back_cf_gen, "( OLcfgDbAt:3.4 "
134 "NAME 'olcDbACLBind' "
135 "DESC 'Remote ACL administrative identity auth bind configuration' "
136 "SYNTAX OMsDirectoryString "
139 { "idassert-authcDN", "DN", 2, 2, 0,
140 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
141 ldap_back_cf_gen, "( OLcfgDbAt:3.5 "
142 "NAME 'olcDbIDAssertAuthcDn' "
143 "DESC 'Remote Identity Assertion administrative identity' "
148 /* deprecated, will be removed; partially aliases "idassert-authcDN" */
149 { "proxyauthzdn", "DN", 2, 2, 0,
150 ARG_DN|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHCDN,
151 ldap_back_cf_gen, NULL, NULL, NULL },
152 { "idassert-passwd", "cred", 2, 2, 0,
153 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
154 ldap_back_cf_gen, "( OLcfgDbAt:3.6 "
155 "NAME 'olcDbIDAssertPasswd' "
156 "DESC 'Remote Identity Assertion administrative identity credentials' "
158 "SYNTAX OMsDirectoryString "
161 /* deprecated, will be removed; partially aliases "idassert-passwd" */
162 { "proxyauthzpw", "cred", 2, 2, 0,
163 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSWD,
164 ldap_back_cf_gen, NULL, NULL, NULL },
165 { "idassert-bind", "args", 2, 0, 0,
166 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_BIND,
167 ldap_back_cf_gen, "( OLcfgDbAt:3.7 "
168 "NAME 'olcDbIDAssertBind' "
169 "DESC 'Remote Identity Assertion administrative identity auth bind configuration' "
170 "SYNTAX OMsDirectoryString "
173 { "idassert-method", "args", 2, 0, 0,
174 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_METHOD,
175 ldap_back_cf_gen, NULL, NULL, NULL },
176 { "idassert-mode", "mode>|u:<user>|[dn:]<DN", 2, 0, 0,
177 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_MODE,
178 ldap_back_cf_gen, "( OLcfgDbAt:3.8 "
179 "NAME 'olcDbIDAssertMode' "
180 "DESC 'Remote Identity Assertion mode' "
182 "SYNTAX OMsDirectoryString "
185 { "idassert-authzFrom", "authzRule", 2, 2, 0,
186 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_AUTHZFROM,
187 ldap_back_cf_gen, "( OLcfgDbAt:3.9 "
188 "NAME 'olcDbIDAssertAuthzFrom' "
189 "DESC 'Remote Identity Assertion authz rules' "
190 "EQUALITY caseIgnoreMatch "
191 "SYNTAX OMsDirectoryString "
192 "X-ORDERED 'VALUES' )",
194 { "rebind-as-user", "true|FALSE", 1, 2, 0,
195 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_REBIND,
196 ldap_back_cf_gen, "( OLcfgDbAt:3.10 "
197 "NAME 'olcDbRebindAsUser' "
198 "DESC 'Rebind as user' "
202 { "chase-referrals", "true|FALSE", 2, 2, 0,
203 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_CHASE,
204 ldap_back_cf_gen, "( OLcfgDbAt:3.11 "
205 "NAME 'olcDbChaseReferrals' "
206 "DESC 'Chase referrals' "
210 { "t-f-support", "true|FALSE|discover", 2, 2, 0,
211 ARG_MAGIC|LDAP_BACK_CFG_T_F,
212 ldap_back_cf_gen, "( OLcfgDbAt:3.12 "
213 "NAME 'olcDbTFSupport' "
214 "DESC 'Absolute filters support' "
215 "SYNTAX OMsDirectoryString "
218 { "proxy-whoami", "true|FALSE", 1, 2, 0,
219 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_WHOAMI,
220 ldap_back_cf_gen, "( OLcfgDbAt:3.13 "
221 "NAME 'olcDbProxyWhoAmI' "
222 "DESC 'Proxy whoAmI exop' "
226 { "timeout", "timeout(list)", 2, 0, 0,
227 ARG_MAGIC|LDAP_BACK_CFG_TIMEOUT,
228 ldap_back_cf_gen, "( OLcfgDbAt:3.14 "
229 "NAME 'olcDbTimeout' "
230 "DESC 'Per-operation timeouts' "
231 "SYNTAX OMsDirectoryString "
234 { "idle-timeout", "timeout", 2, 2, 0,
235 ARG_MAGIC|LDAP_BACK_CFG_IDLE_TIMEOUT,
236 ldap_back_cf_gen, "( OLcfgDbAt:3.15 "
237 "NAME 'olcDbIdleTimeout' "
238 "DESC 'connection idle timeout' "
239 "SYNTAX OMsDirectoryString "
242 { "conn-ttl", "ttl", 2, 2, 0,
243 ARG_MAGIC|LDAP_BACK_CFG_CONN_TTL,
244 ldap_back_cf_gen, "( OLcfgDbAt:3.16 "
245 "NAME 'olcDbConnTtl' "
246 "DESC 'connection ttl' "
247 "SYNTAX OMsDirectoryString "
250 { "network-timeout", "timeout", 2, 2, 0,
251 ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
252 ldap_back_cf_gen, "( OLcfgDbAt:3.17 "
253 "NAME 'olcDbNetworkTimeout' "
254 "DESC 'connection network timeout' "
255 "SYNTAX OMsDirectoryString "
258 { "protocol-version", "version", 2, 2, 0,
259 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_VERSION,
260 ldap_back_cf_gen, "( OLcfgDbAt:3.18 "
261 "NAME 'olcDbProtocolVersion' "
262 "DESC 'protocol version' "
266 { "single-conn", "true|FALSE", 2, 2, 0,
267 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_SINGLECONN,
268 ldap_back_cf_gen, "( OLcfgDbAt:3.19 "
269 "NAME 'olcDbSingleConn' "
270 "DESC 'cache a single connection per identity' "
274 { "cancel", "ABANDON|ignore|exop", 2, 2, 0,
275 ARG_MAGIC|LDAP_BACK_CFG_CANCEL,
276 ldap_back_cf_gen, "( OLcfgDbAt:3.20 "
277 "NAME 'olcDbCancel' "
278 "DESC 'abandon/ignore/exop operations when appropriate' "
279 "SYNTAX OMsDirectoryString "
282 { "quarantine", "retrylist", 2, 2, 0,
283 ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
284 ldap_back_cf_gen, "( OLcfgDbAt:3.21 "
285 "NAME 'olcDbQuarantine' "
286 "DESC 'Quarantine database if connection fails and retry according to rule' "
287 "SYNTAX OMsDirectoryString "
290 { "use-temporary-conn", "true|FALSE", 2, 2, 0,
291 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_USETEMP,
292 ldap_back_cf_gen, "( OLcfgDbAt:3.22 "
293 "NAME 'olcDbUseTemporaryConn' "
294 "DESC 'Use temporary connections if the cached one is busy' "
298 { "conn-pool-max", "<n>", 2, 2, 0,
299 ARG_MAGIC|ARG_INT|LDAP_BACK_CFG_CONNPOOLMAX,
300 ldap_back_cf_gen, "( OLcfgDbAt:3.23 "
301 "NAME 'olcDbConnectionPoolMax' "
302 "DESC 'Max size of privileged connections pool' "
306 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
307 { "session-tracking-request", "true|FALSE", 2, 2, 0,
308 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_ST_REQUEST,
309 ldap_back_cf_gen, "( OLcfgDbAt:3.24 "
310 "NAME 'olcDbSessionTrackingRequest' "
311 "DESC 'Add session tracking control to proxied requests' "
315 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
316 { "norefs", "true|FALSE", 2, 2, 0,
317 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOREFS,
318 ldap_back_cf_gen, "( OLcfgDbAt:3.25 "
319 "NAME 'olcDbNoRefs' "
320 "DESC 'Do not return search reference responses' "
324 { "noundeffilter", "true|FALSE", 2, 2, 0,
325 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_NOUNDEFFILTER,
326 ldap_back_cf_gen, "( OLcfgDbAt:3.26 "
327 "NAME 'olcDbNoUndefFilter' "
328 "DESC 'Do not propagate undefined search filters' "
332 { "onerr", "CONTINUE|report|stop", 2, 2, 0,
333 ARG_MAGIC|LDAP_BACK_CFG_ONERR,
334 ldap_back_cf_gen, "( OLcfgDbAt:3.108 "
336 "DESC 'error handling' "
337 "SYNTAX OMsDirectoryString "
340 { "idassert-passThru", "authzRule", 2, 2, 0,
341 ARG_MAGIC|LDAP_BACK_CFG_IDASSERT_PASSTHRU,
342 ldap_back_cf_gen, "( OLcfgDbAt:3.27 "
343 "NAME 'olcDbIDAssertPassThru' "
344 "DESC 'Remote Identity Assertion passthru rules' "
345 "EQUALITY caseIgnoreMatch "
346 "SYNTAX OMsDirectoryString "
347 "X-ORDERED 'VALUES' )",
350 { "suffixmassage", "[virtual]> <real", 2, 3, 0,
351 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
352 ldap_back_cf_gen, NULL, NULL, NULL },
353 { "map", "attribute|objectClass> [*|<local>] *|<remote", 3, 4, 0,
354 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
355 ldap_back_cf_gen, NULL, NULL, NULL },
356 { "rewrite", "<arglist>", 2, 4, STRLENOF( "rewrite" ),
357 ARG_STRING|ARG_MAGIC|LDAP_BACK_CFG_REWRITE,
358 ldap_back_cf_gen, NULL, NULL, NULL },
359 { "omit-unknown-schema", "true|FALSE", 2, 2, 0,
360 ARG_MAGIC|ARG_ON_OFF|LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA,
361 ldap_back_cf_gen, "( OLcfgDbAt:3.28 "
362 "NAME 'olcDbRemoveUnknownSchema' "
363 "DESC 'Omit unknown schema when returning search results' "
367 { "keepalive", "keepalive", 2, 2, 0,
368 ARG_MAGIC|LDAP_BACK_CFG_KEEPALIVE,
369 ldap_back_cf_gen, "( OLcfgDbAt:3.29 "
370 "NAME 'olcDbKeepalive' "
371 "DESC 'TCP keepalive' "
372 "SYNTAX OMsDirectoryString "
375 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
376 NULL, NULL, NULL, NULL }
379 static ConfigOCs ldapocs[] = {
381 "NAME 'olcLDAPConfig' "
382 "DESC 'LDAP backend configuration' "
383 "SUP olcDatabaseConfig "
389 "$ olcDbIDAssertAuthcDn "
390 "$ olcDbIDAssertPasswd "
391 "$ olcDbIDAssertBind "
392 "$ olcDbIDAssertMode "
393 "$ olcDbIDAssertAuthzFrom "
394 "$ olcDbIDAssertPassThru "
395 "$ olcDbRebindAsUser "
396 "$ olcDbChaseReferrals "
398 "$ olcDbProxyWhoAmI "
400 "$ olcDbIdleTimeout "
402 "$ olcDbNetworkTimeout "
403 "$ olcDbProtocolVersion "
407 "$ olcDbUseTemporaryConn "
408 "$ olcDbConnectionPoolMax "
409 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
410 "$ olcDbSessionTrackingRequest "
411 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
413 "$ olcDbNoUndefFilter "
417 Cft_Database, ldapcfg},
421 static ConfigTable pbindcfg[] = {
422 { "uri", "uri", 2, 2, 0,
423 ARG_MAGIC|LDAP_BACK_CFG_URI,
424 ldap_pbind_cf_gen, "( OLcfgDbAt:0.14 "
426 "DESC 'URI (list) for remote DSA' "
427 "SYNTAX OMsDirectoryString "
430 { "tls", "what", 2, 0, 0,
431 ARG_MAGIC|LDAP_BACK_CFG_TLS,
432 ldap_pbind_cf_gen, "( OLcfgDbAt:3.1 "
433 "NAME 'olcDbStartTLS' "
435 "SYNTAX OMsDirectoryString "
438 { "network-timeout", "timeout", 2, 2, 0,
439 ARG_MAGIC|LDAP_BACK_CFG_NETWORK_TIMEOUT,
440 ldap_pbind_cf_gen, "( OLcfgDbAt:3.17 "
441 "NAME 'olcDbNetworkTimeout' "
442 "DESC 'connection network timeout' "
443 "SYNTAX OMsDirectoryString "
446 { "quarantine", "retrylist", 2, 2, 0,
447 ARG_MAGIC|LDAP_BACK_CFG_QUARANTINE,
448 ldap_pbind_cf_gen, "( OLcfgDbAt:3.21 "
449 "NAME 'olcDbQuarantine' "
450 "DESC 'Quarantine database if connection fails and retry according to rule' "
451 "SYNTAX OMsDirectoryString "
454 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
455 NULL, NULL, NULL, NULL }
458 static ConfigOCs pbindocs[] = {
460 "NAME 'olcPBindConfig' "
461 "DESC 'Proxy Bind configuration' "
462 "SUP olcOverlayConfig "
464 "MAY ( olcDbStartTLS "
465 "$ olcDbNetworkTimeout "
468 Cft_Overlay, pbindcfg},
472 static slap_verbmasks idassert_mode[] = {
473 { BER_BVC("self"), LDAP_BACK_IDASSERT_SELF },
474 { BER_BVC("anonymous"), LDAP_BACK_IDASSERT_ANONYMOUS },
475 { BER_BVC("none"), LDAP_BACK_IDASSERT_NOASSERT },
476 { BER_BVC("legacy"), LDAP_BACK_IDASSERT_LEGACY },
480 static slap_verbmasks tls_mode[] = {
481 { BER_BVC( "propagate" ), LDAP_BACK_F_TLS_PROPAGATE_MASK },
482 { BER_BVC( "try-propagate" ), LDAP_BACK_F_PROPAGATE_TLS },
483 { BER_BVC( "start" ), LDAP_BACK_F_TLS_USE_MASK },
484 { BER_BVC( "try-start" ), LDAP_BACK_F_USE_TLS },
485 { BER_BVC( "ldaps" ), LDAP_BACK_F_TLS_LDAPS },
486 { BER_BVC( "none" ), LDAP_BACK_F_NONE },
490 static slap_verbmasks t_f_mode[] = {
491 { BER_BVC( "yes" ), LDAP_BACK_F_T_F },
492 { BER_BVC( "discover" ), LDAP_BACK_F_T_F_DISCOVER },
493 { BER_BVC( "no" ), LDAP_BACK_F_NONE },
497 static slap_verbmasks cancel_mode[] = {
498 { BER_BVC( "ignore" ), LDAP_BACK_F_CANCEL_IGNORE },
499 { BER_BVC( "exop" ), LDAP_BACK_F_CANCEL_EXOP },
500 { BER_BVC( "exop-discover" ), LDAP_BACK_F_CANCEL_EXOP_DISCOVER },
501 { BER_BVC( "abandon" ), LDAP_BACK_F_CANCEL_ABANDON },
505 static slap_verbmasks onerr_mode[] = {
506 { BER_BVC( "stop" ), LDAP_BACK_F_ONERR_STOP },
507 { BER_BVC( "report" ), LDAP_BACK_F_ONERR_STOP }, /* same behavior */
508 { BER_BVC( "continue" ), LDAP_BACK_F_NONE },
512 /* see enum in slap.h */
513 static slap_cf_aux_table timeout_table[] = {
514 { BER_BVC("bind="), SLAP_OP_BIND * sizeof( time_t ), 'u', 0, NULL },
515 /* unbind makes no sense */
516 { BER_BVC("add="), SLAP_OP_ADD * sizeof( time_t ), 'u', 0, NULL },
517 { BER_BVC("delete="), SLAP_OP_DELETE * sizeof( time_t ), 'u', 0, NULL },
518 { BER_BVC("modrdn="), SLAP_OP_MODRDN * sizeof( time_t ), 'u', 0, NULL },
519 { BER_BVC("modify="), SLAP_OP_MODIFY * sizeof( time_t ), 'u', 0, NULL },
520 { BER_BVC("compare="), SLAP_OP_COMPARE * sizeof( time_t ), 'u', 0, NULL },
521 { BER_BVC("search="), SLAP_OP_SEARCH * sizeof( time_t ), 'u', 0, NULL },
522 /* abandon makes little sense */
523 #if 0 /* not implemented yet */
524 { BER_BVC("extended="), SLAP_OP_EXTENDED * sizeof( time_t ), 'u', 0, NULL },
526 { BER_BVNULL, 0, 0, 0, NULL }
530 slap_retry_info_parse(
532 slap_retry_info_t *ri,
536 char **retrylist = NULL;
540 slap_str2clist( &retrylist, in, " ;" );
541 if ( retrylist == NULL ) {
545 for ( i = 0; retrylist[ i ] != NULL; i++ )
548 ri->ri_interval = ch_calloc( sizeof( time_t ), i + 1 );
549 ri->ri_num = ch_calloc( sizeof( int ), i + 1 );
551 for ( i = 0; retrylist[ i ] != NULL; i++ ) {
553 char *sep = strchr( retrylist[ i ], ',' );
556 snprintf( buf, buflen,
557 "missing comma in retry pattern #%d \"%s\"",
565 if ( lutil_parse_time( retrylist[ i ], &t ) ) {
566 snprintf( buf, buflen,
567 "unable to parse interval #%d \"%s\"",
572 ri->ri_interval[ i ] = (time_t)t;
574 if ( strcmp( sep, "+" ) == 0 ) {
575 if ( retrylist[ i + 1 ] != NULL ) {
576 snprintf( buf, buflen,
577 "extra cruft after retry pattern "
578 "#%d \"%s,+\" with \"forever\" mark",
583 ri->ri_num[ i ] = SLAP_RETRYNUM_FOREVER;
585 } else if ( lutil_atoi( &ri->ri_num[ i ], sep ) ) {
586 snprintf( buf, buflen,
587 "unable to parse retry num #%d \"%s\"",
594 ri->ri_num[ i ] = SLAP_RETRYNUM_TAIL;
598 ri->ri_last = (time_t)(-1);
601 ldap_charray_free( retrylist );
604 slap_retry_info_destroy( ri );
611 slap_retry_info_unparse(
612 slap_retry_info_t *ri,
613 struct berval *bvout )
615 char buf[ BUFSIZ * 2 ],
617 int i, len, restlen = (int) sizeof( buf );
620 assert( ri != NULL );
621 assert( bvout != NULL );
625 for ( i = 0; ri->ri_num[ i ] != SLAP_RETRYNUM_TAIL; i++ ) {
627 if ( --restlen <= 0 ) {
633 if ( lutil_unparse_time( ptr, restlen, ri->ri_interval[i] ) < 0 ) {
636 len = (int) strlen( ptr );
637 if ( (restlen -= len + 1) <= 0 ) {
643 if ( ri->ri_num[i] == SLAP_RETRYNUM_FOREVER ) {
644 if ( --restlen <= 0 ) {
650 len = snprintf( ptr, restlen, "%d", ri->ri_num[i] );
651 if ( (restlen -= len) <= 0 || len < 0 ) {
659 bv.bv_len = ptr - buf;
660 ber_dupbv( bvout, &bv );
666 slap_retry_info_destroy(
667 slap_retry_info_t *ri )
669 assert( ri != NULL );
671 assert( ri->ri_interval != NULL );
672 ch_free( ri->ri_interval );
673 ri->ri_interval = NULL;
675 assert( ri->ri_num != NULL );
676 ch_free( ri->ri_num );
681 slap_idassert_authzfrom_parse( ConfigArgs *c, slap_idassert_t *si )
687 if ( strcmp( c->argv[ 1 ], "*" ) == 0
688 || strcmp( c->argv[ 1 ], "dn:*" ) == 0
689 || strcasecmp( c->argv[ 1 ], "dn.regex:.*" ) == 0 )
691 if ( si->si_authz != NULL ) {
692 snprintf( c->cr_msg, sizeof( c->cr_msg ),
693 "\"idassert-authzFrom <authz>\": "
694 "\"%s\" conflicts with existing authz rules",
696 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
700 si->si_flags |= LDAP_BACK_AUTH_AUTHZ_ALL;
704 } else if ( ( si->si_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) ) {
705 snprintf( c->cr_msg, sizeof( c->cr_msg ),
706 "\"idassert-authzFrom <authz>\": "
707 "\"<authz>\" conflicts with \"*\"" );
708 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
712 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
713 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
714 if ( rc != LDAP_SUCCESS ) {
715 snprintf( c->cr_msg, sizeof( c->cr_msg ),
716 "\"idassert-authzFrom <authz>\": "
718 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
722 if ( c->valx == -1 ) {
723 ber_bvarray_add( &si->si_authz, &bv );
727 if ( si->si_authz != NULL ) {
728 for ( ; !BER_BVISNULL( &si->si_authz[ i ] ); i++ )
732 if ( i <= c->valx ) {
733 ber_bvarray_add( &si->si_authz, &bv );
736 BerVarray tmp = ber_memrealloc( si->si_authz,
737 sizeof( struct berval )*( i + 2 ) );
742 for ( ; i > c->valx; i-- ) {
743 si->si_authz[ i ] = si->si_authz[ i - 1 ];
745 si->si_authz[ c->valx ] = bv;
753 slap_idassert_passthru_parse( ConfigArgs *c, slap_idassert_t *si )
759 ber_str2bv( c->argv[ 1 ], 0, 0, &in );
760 rc = authzNormalize( 0, NULL, NULL, &in, &bv, NULL );
761 if ( rc != LDAP_SUCCESS ) {
762 snprintf( c->cr_msg, sizeof( c->cr_msg ),
763 "\"idassert-passThru <authz>\": "
765 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
769 if ( c->valx == -1 ) {
770 ber_bvarray_add( &si->si_passthru, &bv );
774 if ( si->si_passthru != NULL ) {
775 for ( ; !BER_BVISNULL( &si->si_passthru[ i ] ); i++ )
779 if ( i <= c->valx ) {
780 ber_bvarray_add( &si->si_passthru, &bv );
783 BerVarray tmp = ber_memrealloc( si->si_passthru,
784 sizeof( struct berval )*( i + 2 ) );
788 si->si_passthru = tmp;
789 for ( ; i > c->valx; i-- ) {
790 si->si_passthru[ i ] = si->si_passthru[ i - 1 ];
792 si->si_passthru[ c->valx ] = bv;
800 slap_idassert_parse( ConfigArgs *c, slap_idassert_t *si )
804 for ( i = 1; i < c->argc; i++ ) {
805 if ( strncasecmp( c->argv[ i ], "mode=", STRLENOF( "mode=" ) ) == 0 ) {
806 char *argvi = c->argv[ i ] + STRLENOF( "mode=" );
809 j = verb_to_mask( argvi, idassert_mode );
810 if ( BER_BVISNULL( &idassert_mode[ j ].word ) ) {
811 snprintf( c->cr_msg, sizeof( c->cr_msg ),
812 "\"idassert-bind <args>\": "
813 "unknown mode \"%s\"",
815 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
819 si->si_mode = idassert_mode[ j ].mask;
821 } else if ( strncasecmp( c->argv[ i ], "authz=", STRLENOF( "authz=" ) ) == 0 ) {
822 char *argvi = c->argv[ i ] + STRLENOF( "authz=" );
824 if ( strcasecmp( argvi, "native" ) == 0 ) {
825 if ( si->si_bc.sb_method != LDAP_AUTH_SASL ) {
826 snprintf( c->cr_msg, sizeof( c->cr_msg ),
827 "\"idassert-bind <args>\": "
828 "authz=\"native\" incompatible "
829 "with auth method" );
830 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
833 si->si_flags |= LDAP_BACK_AUTH_NATIVE_AUTHZ;
835 } else if ( strcasecmp( argvi, "proxyAuthz" ) == 0 ) {
836 si->si_flags &= ~LDAP_BACK_AUTH_NATIVE_AUTHZ;
839 snprintf( c->cr_msg, sizeof( c->cr_msg ),
840 "\"idassert-bind <args>\": "
841 "unknown authz \"%s\"",
843 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
847 } else if ( strncasecmp( c->argv[ i ], "flags=", STRLENOF( "flags=" ) ) == 0 ) {
848 char *argvi = c->argv[ i ] + STRLENOF( "flags=" );
849 char **flags = ldap_str2charray( argvi, "," );
852 if ( flags == NULL ) {
853 snprintf( c->cr_msg, sizeof( c->cr_msg ),
854 "\"idassert-bind <args>\": "
855 "unable to parse flags \"%s\"",
857 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
861 for ( j = 0; flags[ j ] != NULL; j++ ) {
863 if ( strcasecmp( flags[ j ], "override" ) == 0 ) {
864 si->si_flags |= LDAP_BACK_AUTH_OVERRIDE;
866 } else if ( strcasecmp( flags[ j ], "prescriptive" ) == 0 ) {
867 si->si_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
869 } else if ( strcasecmp( flags[ j ], "non-prescriptive" ) == 0 ) {
870 si->si_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
872 } else if ( strcasecmp( flags[ j ], "obsolete-proxy-authz" ) == 0 ) {
873 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
874 Debug( LDAP_DEBUG_ANY,
875 "%s: \"obsolete-proxy-authz\" flag "
876 "in \"idassert-mode <args>\" "
877 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
883 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
886 } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
887 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
888 Debug( LDAP_DEBUG_ANY,
889 "%s: \"obsolete-encoding-workaround\" flag "
890 "in \"idassert-mode <args>\" "
891 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
897 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
900 } else if ( strcasecmp( flags[ j ], "proxy-authz-critical" ) == 0 ) {
901 si->si_flags |= LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
903 } else if ( strcasecmp( flags[ j ], "proxy-authz-non-critical" ) == 0 ) {
904 si->si_flags &= ~LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
907 snprintf( c->cr_msg, sizeof( c->cr_msg ),
908 "\"idassert-bind <args>\": "
909 "unknown flag \"%s\"",
911 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
917 ldap_charray_free( flags );
922 } else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) {
923 snprintf( c->cr_msg, sizeof( c->cr_msg ),
924 "\"idassert-bind <args>\": "
925 "unable to parse field \"%s\"",
927 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
932 if ( si->si_bc.sb_method == LDAP_AUTH_SIMPLE ) {
933 if ( BER_BVISNULL( &si->si_bc.sb_binddn )
934 || BER_BVISNULL( &si->si_bc.sb_cred ) )
936 snprintf( c->cr_msg, sizeof( c->cr_msg ),
937 "\"idassert-bind <args>\": "
938 "SIMPLE needs \"binddn\" and \"credentials\"" );
939 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
944 bindconf_tls_defaults( &si->si_bc );
949 /* NOTE: temporary, until back-meta is ported to back-config */
951 slap_idassert_passthru_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
953 ConfigArgs c = { 0 };
956 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
959 argv[ 0 ] = "idassert-passThru";
960 argv[ 1 ] = (char *)arg;
963 return slap_idassert_passthru_parse( &c, si );
967 ldap_back_cf_gen( ConfigArgs *c )
969 ldapinfo_t *li = ( ldapinfo_t * )c->be->be_private;
973 if ( c->op == SLAP_CONFIG_EMIT ) {
974 struct berval bv = BER_BVNULL;
981 case LDAP_BACK_CFG_URI:
982 if ( li->li_uri != NULL ) {
983 struct berval bv, bv2;
985 ber_str2bv( li->li_uri, 0, 0, &bv );
986 bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" );
987 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
988 snprintf( bv2.bv_val, bv2.bv_len + 1,
989 "\"%s\"", bv.bv_val );
990 ber_bvarray_add( &c->rvalue_vals, &bv2 );
997 case LDAP_BACK_CFG_TLS: {
998 struct berval bc = BER_BVNULL, bv2;
999 enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
1000 assert( !BER_BVISNULL( &bv ) );
1001 bindconf_tls_unparse( &li->li_tls, &bc );
1003 if ( !BER_BVISEMPTY( &bc )) {
1004 bv2.bv_len = bv.bv_len + bc.bv_len + 1;
1005 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
1006 strcpy( bv2.bv_val, bv.bv_val );
1007 bv2.bv_val[bv.bv_len] = ' ';
1008 strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val );
1009 ber_bvarray_add( &c->rvalue_vals, &bv2 );
1012 value_add_one( &c->rvalue_vals, &bv );
1014 ber_memfree( bc.bv_val );
1018 case LDAP_BACK_CFG_ACL_AUTHCDN:
1019 case LDAP_BACK_CFG_ACL_PASSWD:
1020 case LDAP_BACK_CFG_ACL_METHOD:
1021 /* handled by LDAP_BACK_CFG_ACL_BIND */
1025 case LDAP_BACK_CFG_ACL_BIND: {
1028 if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
1032 bindconf_unparse( &li->li_acl, &bv );
1034 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1035 /* count spaces */ ;
1039 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1043 ber_bvarray_add( &c->rvalue_vals, &bv );
1047 case LDAP_BACK_CFG_IDASSERT_MODE:
1048 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1049 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1050 case LDAP_BACK_CFG_IDASSERT_METHOD:
1051 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1055 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1056 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
1059 struct berval bv = BER_BVNULL;
1060 char buf[SLAP_TEXT_BUFLEN];
1062 switch ( c->type ) {
1063 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
1064 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
1065 default: assert( 0 ); break;
1068 if ( *bvp == NULL ) {
1069 if ( bvp == &li->li_idassert_authz
1070 && ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
1072 BER_BVSTR( &bv, "*" );
1073 value_add_one( &c->rvalue_vals, &bv );
1081 for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) {
1083 int len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
1084 bv.bv_len = ((*bvp)[ i ]).bv_len + len;
1085 bv.bv_val = ber_memrealloc( bv.bv_val, bv.bv_len + 1 );
1087 ptr = lutil_strcopy( ptr, buf );
1088 ptr = lutil_strncopy( ptr, ((*bvp)[ i ]).bv_val, ((*bvp)[ i ]).bv_len );
1089 value_add_one( &c->rvalue_vals, &bv );
1092 ber_memfree( bv.bv_val );
1097 case LDAP_BACK_CFG_IDASSERT_BIND: {
1099 struct berval bc = BER_BVNULL;
1102 if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
1106 if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
1109 switch ( li->li_idassert_mode ) {
1110 case LDAP_BACK_IDASSERT_OTHERID:
1111 case LDAP_BACK_IDASSERT_OTHERDN:
1115 struct berval mode = BER_BVNULL;
1117 enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
1118 if ( BER_BVISNULL( &mode ) ) {
1119 /* there's something wrong... */
1124 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
1125 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1127 ptr = lutil_strcopy( bv.bv_val, "mode=" );
1128 ptr = lutil_strcopy( ptr, mode.bv_val );
1134 if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
1135 len = bv.bv_len + STRLENOF( "authz=native" );
1137 if ( !BER_BVISEMPTY( &bv ) ) {
1138 len += STRLENOF( " " );
1141 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1143 ptr = &bv.bv_val[ bv.bv_len ];
1145 if ( !BER_BVISEMPTY( &bv ) ) {
1146 ptr = lutil_strcopy( ptr, " " );
1149 (void)lutil_strcopy( ptr, "authz=native" );
1152 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround,proxy-authz-non-critical" );
1154 if ( !BER_BVISEMPTY( &bv ) ) {
1155 len += STRLENOF( " " );
1158 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1160 ptr = &bv.bv_val[ bv.bv_len ];
1162 if ( !BER_BVISEMPTY( &bv ) ) {
1163 ptr = lutil_strcopy( ptr, " " );
1166 ptr = lutil_strcopy( ptr, "flags=" );
1168 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1169 ptr = lutil_strcopy( ptr, "prescriptive" );
1171 ptr = lutil_strcopy( ptr, "non-prescriptive" );
1174 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
1175 ptr = lutil_strcopy( ptr, ",override" );
1178 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1179 ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" );
1181 } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1182 ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" );
1185 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL ) {
1186 ptr = lutil_strcopy( ptr, ",proxy-authz-critical" );
1189 ptr = lutil_strcopy( ptr, ",proxy-authz-non-critical" );
1192 bv.bv_len = ( ptr - bv.bv_val );
1196 bindconf_unparse( &li->li_idassert.si_bc, &bc );
1198 if ( !BER_BVISNULL( &bv ) ) {
1199 ber_len_t len = bv.bv_len + bc.bv_len;
1201 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1203 assert( bc.bv_val[ 0 ] == ' ' );
1205 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
1207 bv.bv_len = ptr - bv.bv_val;
1210 for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ )
1211 /* count spaces */ ;
1215 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
1221 ber_bvarray_add( &c->rvalue_vals, &bv );
1226 case LDAP_BACK_CFG_REBIND:
1227 c->value_int = LDAP_BACK_SAVECRED( li );
1230 case LDAP_BACK_CFG_CHASE:
1231 c->value_int = LDAP_BACK_CHASE_REFERRALS( li );
1234 case LDAP_BACK_CFG_T_F:
1235 enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv );
1236 if ( BER_BVISNULL( &bv ) ) {
1237 /* there's something wrong... */
1242 value_add_one( &c->rvalue_vals, &bv );
1246 case LDAP_BACK_CFG_WHOAMI:
1247 c->value_int = LDAP_BACK_PROXY_WHOAMI( li );
1250 case LDAP_BACK_CFG_TIMEOUT:
1253 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1254 if ( li->li_timeout[ i ] != 0 ) {
1259 if ( i == SLAP_OP_LAST ) {
1263 slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table );
1265 if ( BER_BVISNULL( &bv ) ) {
1269 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1270 /* count spaces */ ;
1274 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1278 ber_bvarray_add( &c->rvalue_vals, &bv );
1281 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1282 char buf[ SLAP_TEXT_BUFLEN ];
1284 if ( li->li_idle_timeout == 0 ) {
1288 lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout );
1289 ber_str2bv( buf, 0, 0, &bv );
1290 value_add_one( &c->rvalue_vals, &bv );
1293 case LDAP_BACK_CFG_CONN_TTL: {
1294 char buf[ SLAP_TEXT_BUFLEN ];
1296 if ( li->li_conn_ttl == 0 ) {
1300 lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl );
1301 ber_str2bv( buf, 0, 0, &bv );
1302 value_add_one( &c->rvalue_vals, &bv );
1305 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1306 char buf[ SLAP_TEXT_BUFLEN ];
1308 if ( li->li_network_timeout == 0 ) {
1312 snprintf( buf, sizeof( buf ), "%ld",
1313 (long)li->li_network_timeout );
1314 ber_str2bv( buf, 0, 0, &bv );
1315 value_add_one( &c->rvalue_vals, &bv );
1318 case LDAP_BACK_CFG_VERSION:
1319 if ( li->li_version == 0 ) {
1323 c->value_int = li->li_version;
1326 case LDAP_BACK_CFG_SINGLECONN:
1327 c->value_int = LDAP_BACK_SINGLECONN( li );
1330 case LDAP_BACK_CFG_USETEMP:
1331 c->value_int = LDAP_BACK_USE_TEMPORARIES( li );
1334 case LDAP_BACK_CFG_CONNPOOLMAX:
1335 c->value_int = li->li_conn_priv_max;
1338 case LDAP_BACK_CFG_CANCEL: {
1339 slap_mask_t mask = LDAP_BACK_F_CANCEL_MASK2;
1341 if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) {
1342 mask &= ~LDAP_BACK_F_CANCEL_EXOP;
1344 enum_to_verb( cancel_mode, (li->li_flags & mask), &bv );
1345 if ( BER_BVISNULL( &bv ) ) {
1346 /* there's something wrong... */
1351 value_add_one( &c->rvalue_vals, &bv );
1355 case LDAP_BACK_CFG_QUARANTINE:
1356 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1361 rc = slap_retry_info_unparse( &li->li_quarantine, &bv );
1363 ber_bvarray_add( &c->rvalue_vals, &bv );
1367 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1368 case LDAP_BACK_CFG_ST_REQUEST:
1369 c->value_int = LDAP_BACK_ST_REQUEST( li );
1371 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1373 case LDAP_BACK_CFG_NOREFS:
1374 c->value_int = LDAP_BACK_NOREFS( li );
1377 case LDAP_BACK_CFG_NOUNDEFFILTER:
1378 c->value_int = LDAP_BACK_NOUNDEFFILTER( li );
1381 case LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA:
1382 c->value_int = LDAP_BACK_OMIT_UNKNOWN_SCHEMA( li );
1385 case LDAP_BACK_CFG_ONERR:
1386 enum_to_verb( onerr_mode, li->li_flags & LDAP_BACK_F_ONERR_STOP, &bv );
1387 if ( BER_BVISNULL( &bv )) {
1390 value_add_one( &c->rvalue_vals, &bv );
1394 case LDAP_BACK_CFG_KEEPALIVE: {
1396 char buf[AC_LINE_MAX];
1397 bv.bv_len = AC_LINE_MAX;
1398 bv.bv_val = &buf[0];
1399 slap_keepalive_parse(&bv, &li->li_tls.sb_keepalive, 0, 0, 1);
1400 value_add_one( &c->rvalue_vals, &bv );
1405 /* FIXME: we need to handle all... */
1411 } else if ( c->op == LDAP_MOD_DELETE ) {
1413 case LDAP_BACK_CFG_URI:
1414 if ( li->li_uri != NULL ) {
1415 ch_free( li->li_uri );
1418 assert( li->li_bvuri != NULL );
1419 ber_bvarray_free( li->li_bvuri );
1420 li->li_bvuri = NULL;
1423 /* better cleanup the cached connections... */
1424 /* NOTE: don't worry about locking: if we got here,
1425 * other threads are suspended. */
1426 if ( li->li_conninfo.lai_tree != NULL ) {
1427 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
1428 li->li_conninfo.lai_tree = NULL;
1433 case LDAP_BACK_CFG_TLS:
1437 case LDAP_BACK_CFG_ACL_AUTHCDN:
1438 case LDAP_BACK_CFG_ACL_PASSWD:
1439 case LDAP_BACK_CFG_ACL_METHOD:
1440 /* handled by LDAP_BACK_CFG_ACL_BIND */
1444 case LDAP_BACK_CFG_ACL_BIND:
1445 bindconf_free( &li->li_acl );
1448 case LDAP_BACK_CFG_IDASSERT_MODE:
1449 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1450 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1451 case LDAP_BACK_CFG_IDASSERT_METHOD:
1452 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1456 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1457 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
1460 switch ( c->type ) {
1461 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
1462 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
1463 default: assert( 0 ); break;
1466 if ( c->valx < 0 ) {
1467 if ( *bvp != NULL ) {
1468 ber_bvarray_free( *bvp );
1475 if ( *bvp == NULL ) {
1480 for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ )
1483 if ( i >= c->valx ) {
1487 ber_memfree( ((*bvp)[ c->valx ]).bv_val );
1488 for ( i = c->valx; !BER_BVISNULL( &((*bvp)[ i + 1 ]) ); i++ ) {
1489 (*bvp)[ i ] = (*bvp)[ i + 1 ];
1491 BER_BVZERO( &((*bvp)[ i ]) );
1495 case LDAP_BACK_CFG_IDASSERT_BIND:
1496 bindconf_free( &li->li_idassert.si_bc );
1497 memset( &li->li_idassert, 0, sizeof( slap_idassert_t ) );
1500 case LDAP_BACK_CFG_REBIND:
1501 case LDAP_BACK_CFG_CHASE:
1502 case LDAP_BACK_CFG_T_F:
1503 case LDAP_BACK_CFG_WHOAMI:
1504 case LDAP_BACK_CFG_CANCEL:
1508 case LDAP_BACK_CFG_TIMEOUT:
1509 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1510 li->li_timeout[ i ] = 0;
1514 case LDAP_BACK_CFG_IDLE_TIMEOUT:
1515 li->li_idle_timeout = 0;
1518 case LDAP_BACK_CFG_CONN_TTL:
1519 li->li_conn_ttl = 0;
1522 case LDAP_BACK_CFG_NETWORK_TIMEOUT:
1523 li->li_network_timeout = 0;
1526 case LDAP_BACK_CFG_VERSION:
1530 case LDAP_BACK_CFG_SINGLECONN:
1531 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1534 case LDAP_BACK_CFG_USETEMP:
1535 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
1538 case LDAP_BACK_CFG_CONNPOOLMAX:
1539 li->li_conn_priv_max = LDAP_BACK_CONN_PRIV_MIN;
1542 case LDAP_BACK_CFG_QUARANTINE:
1543 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1547 slap_retry_info_destroy( &li->li_quarantine );
1548 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
1549 li->li_isquarantined = 0;
1550 li->li_flags &= ~LDAP_BACK_F_QUARANTINE;
1553 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1554 case LDAP_BACK_CFG_ST_REQUEST:
1555 li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
1557 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1559 case LDAP_BACK_CFG_NOREFS:
1560 li->li_flags &= ~LDAP_BACK_F_NOREFS;
1563 case LDAP_BACK_CFG_NOUNDEFFILTER:
1564 li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
1567 case LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA:
1568 li->li_flags &= ~LDAP_BACK_F_OMIT_UNKNOWN_SCHEMA;
1571 case LDAP_BACK_CFG_ONERR:
1572 li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
1575 case LDAP_BACK_CFG_KEEPALIVE:
1576 li->li_tls.sb_keepalive.sk_idle = 0;
1577 li->li_tls.sb_keepalive.sk_probes = 0;
1578 li->li_tls.sb_keepalive.sk_interval = 0;
1582 /* FIXME: we need to handle all... */
1591 case LDAP_BACK_CFG_URI: {
1592 LDAPURLDesc *tmpludp, *lud;
1593 char **urllist = NULL;
1594 int urlrc = LDAP_URL_SUCCESS, i;
1596 if ( li->li_uri != NULL ) {
1597 ch_free( li->li_uri );
1600 assert( li->li_bvuri != NULL );
1601 ber_bvarray_free( li->li_bvuri );
1602 li->li_bvuri = NULL;
1605 /* PARANOID: DN and more are not required nor allowed */
1606 urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
1607 if ( urlrc != LDAP_URL_SUCCESS ) {
1611 case LDAP_URL_ERR_MEM:
1614 case LDAP_URL_ERR_PARAM:
1615 why = "parameter is bad";
1617 case LDAP_URL_ERR_BADSCHEME:
1618 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1620 case LDAP_URL_ERR_BADENCLOSURE:
1621 why = "URL is missing trailing \">\"";
1623 case LDAP_URL_ERR_BADURL:
1626 case LDAP_URL_ERR_BADHOST:
1627 why = "host/port is bad";
1629 case LDAP_URL_ERR_BADATTRS:
1630 why = "bad (or missing) attributes";
1632 case LDAP_URL_ERR_BADSCOPE:
1633 why = "scope string is invalid (or missing)";
1635 case LDAP_URL_ERR_BADFILTER:
1636 why = "bad or missing filter";
1638 case LDAP_URL_ERR_BADEXTS:
1639 why = "bad or missing extensions";
1642 why = "unknown reason";
1645 snprintf( c->cr_msg, sizeof( c->cr_msg),
1646 "unable to parse uri \"%s\" "
1647 "in \"uri <uri>\" line: %s",
1648 c->value_string, why );
1649 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1654 for ( i = 0, tmpludp = lud;
1656 i++, tmpludp = tmpludp->lud_next )
1658 if ( ( tmpludp->lud_dn != NULL
1659 && tmpludp->lud_dn[0] != '\0' )
1660 || tmpludp->lud_attrs != NULL
1661 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1662 || tmpludp->lud_filter != NULL
1663 || tmpludp->lud_exts != NULL )
1665 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1666 "warning, only protocol, "
1667 "host and port allowed "
1668 "in \"uri <uri>\" statement "
1669 "for uri #%d of \"%s\"",
1671 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1675 for ( i = 0, tmpludp = lud;
1677 i++, tmpludp = tmpludp->lud_next )
1680 urllist = ch_calloc( sizeof( char * ), i + 1 );
1682 for ( i = 0, tmpludp = lud;
1684 i++, tmpludp = tmpludp->lud_next )
1690 tmplud.lud_attrs = NULL;
1691 tmplud.lud_filter = NULL;
1692 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1693 tmplud.lud_exts = NULL;
1694 tmplud.lud_crit_exts = 0;
1697 urllist[ i ] = ldap_url_desc2str( &tmplud );
1699 if ( urllist[ i ] == NULL ) {
1700 snprintf( c->cr_msg, sizeof( c->cr_msg),
1701 "unable to rebuild uri "
1702 "in \"uri <uri>\" statement "
1705 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1711 li->li_uri = ldap_charray2str( urllist, " " );
1712 for ( i = 0; urllist[ i ] != NULL; i++ ) {
1715 ber_str2bv( urllist[ i ], 0, 0, &bv );
1716 ber_bvarray_add( &li->li_bvuri, &bv );
1717 urllist[ i ] = NULL;
1719 ldap_memfree( urllist );
1724 ldap_charray_free( urllist );
1727 ldap_free_urllist( lud );
1729 if ( urlrc != LDAP_URL_SUCCESS ) {
1735 case LDAP_BACK_CFG_TLS:
1736 i = verb_to_mask( c->argv[1], tls_mode );
1737 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
1740 li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
1741 li->li_flags |= tls_mode[i].mask;
1742 if ( c->argc > 2 ) {
1743 for ( i=2; i<c->argc; i++ ) {
1744 if ( bindconf_tls_parse( c->argv[i], &li->li_tls ))
1747 bindconf_tls_defaults( &li->li_tls );
1751 case LDAP_BACK_CFG_ACL_AUTHCDN:
1752 switch ( li->li_acl_authmethod ) {
1753 case LDAP_AUTH_NONE:
1754 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1757 case LDAP_AUTH_SIMPLE:
1761 snprintf( c->cr_msg, sizeof( c->cr_msg),
1762 "\"acl-authcDN <DN>\" incompatible "
1763 "with auth method %d",
1764 li->li_acl_authmethod );
1765 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1768 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
1769 free( li->li_acl_authcDN.bv_val );
1771 ber_memfree_x( c->value_dn.bv_val, NULL );
1772 li->li_acl_authcDN = c->value_ndn;
1773 BER_BVZERO( &c->value_dn );
1774 BER_BVZERO( &c->value_ndn );
1777 case LDAP_BACK_CFG_ACL_PASSWD:
1778 switch ( li->li_acl_authmethod ) {
1779 case LDAP_AUTH_NONE:
1780 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1783 case LDAP_AUTH_SIMPLE:
1787 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1788 "\"acl-passwd <cred>\" incompatible "
1789 "with auth method %d",
1790 li->li_acl_authmethod );
1791 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1794 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
1795 free( li->li_acl_passwd.bv_val );
1797 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
1800 case LDAP_BACK_CFG_ACL_METHOD:
1801 case LDAP_BACK_CFG_ACL_BIND:
1802 for ( i = 1; i < c->argc; i++ ) {
1803 if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
1807 bindconf_tls_defaults( &li->li_acl );
1810 case LDAP_BACK_CFG_IDASSERT_MODE:
1811 i = verb_to_mask( c->argv[1], idassert_mode );
1812 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
1813 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
1814 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1815 ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
1816 li->li_idassert_authzID.bv_val[ 0 ] = 'u';
1819 struct berval id, ndn;
1821 ber_str2bv( c->argv[1], 0, 0, &id );
1823 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1824 id.bv_val += STRLENOF( "dn:" );
1825 id.bv_len -= STRLENOF( "dn:" );
1828 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
1829 if ( rc != LDAP_SUCCESS ) {
1830 Debug( LDAP_DEBUG_ANY,
1831 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1832 c->fname, c->lineno, c->argv[1] );
1836 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1837 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
1838 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1839 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
1840 ch_free( ndn.bv_val );
1842 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1846 li->li_idassert_mode = idassert_mode[i].mask;
1849 if ( c->argc > 2 ) {
1852 for ( i = 2; i < c->argc; i++ ) {
1853 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
1854 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1856 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
1857 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1859 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
1860 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1862 } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
1863 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1864 Debug( LDAP_DEBUG_ANY,
1865 "%s: line %d: \"obsolete-proxy-authz\" flag "
1866 "in \"idassert-mode <args>\" "
1867 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1868 c->fname, c->lineno, 0 );
1871 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1873 } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
1874 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1875 Debug( LDAP_DEBUG_ANY,
1876 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1877 "in \"idassert-mode <args>\" "
1878 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1879 c->fname, c->lineno, 0 );
1882 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1885 Debug( LDAP_DEBUG_ANY,
1886 "%s: line %d: unknown flag #%d "
1887 "in \"idassert-mode <args> "
1888 "[<flags>]\" line.\n",
1889 c->fname, c->lineno, i - 2 );
1896 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1897 switch ( li->li_idassert_authmethod ) {
1898 case LDAP_AUTH_NONE:
1899 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1902 case LDAP_AUTH_SIMPLE:
1906 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1907 "\"idassert-authcDN <DN>\" incompatible "
1908 "with auth method %d",
1909 li->li_idassert_authmethod );
1910 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1913 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1914 free( li->li_idassert_authcDN.bv_val );
1916 ber_memfree_x( c->value_dn.bv_val, NULL );
1917 li->li_idassert_authcDN = c->value_ndn;
1918 BER_BVZERO( &c->value_dn );
1919 BER_BVZERO( &c->value_ndn );
1922 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1923 switch ( li->li_idassert_authmethod ) {
1924 case LDAP_AUTH_NONE:
1925 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1928 case LDAP_AUTH_SIMPLE:
1932 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1933 "\"idassert-passwd <cred>\" incompatible "
1934 "with auth method %d",
1935 li->li_idassert_authmethod );
1936 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1939 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
1940 free( li->li_idassert_passwd.bv_val );
1942 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
1945 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1946 rc = slap_idassert_authzfrom_parse( c, &li->li_idassert );
1949 case LDAP_BACK_CFG_IDASSERT_PASSTHRU:
1950 rc = slap_idassert_passthru_parse( c, &li->li_idassert );
1953 case LDAP_BACK_CFG_IDASSERT_METHOD:
1954 /* no longer supported */
1955 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1956 "\"idassert-method <args>\": "
1957 "no longer supported; use \"idassert-bind\"" );
1958 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1961 case LDAP_BACK_CFG_IDASSERT_BIND:
1962 rc = slap_idassert_parse( c, &li->li_idassert );
1965 case LDAP_BACK_CFG_REBIND:
1966 if ( c->argc == 1 || c->value_int ) {
1967 li->li_flags |= LDAP_BACK_F_SAVECRED;
1970 li->li_flags &= ~LDAP_BACK_F_SAVECRED;
1974 case LDAP_BACK_CFG_CHASE:
1975 if ( c->argc == 1 || c->value_int ) {
1976 li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
1979 li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
1983 case LDAP_BACK_CFG_T_F: {
1986 i = verb_to_mask( c->argv[1], t_f_mode );
1987 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
1991 mask = t_f_mode[i].mask;
1993 if ( LDAP_BACK_ISOPEN( li )
1994 && mask == LDAP_BACK_F_T_F_DISCOVER
1995 && !LDAP_BACK_T_F( li ) )
1997 slap_bindconf sb = { BER_BVNULL };
2000 if ( li->li_uri == NULL ) {
2001 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2002 "need URI to discover absolute filters support "
2003 "in \"t-f-support discover\"" );
2004 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2008 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
2009 sb.sb_version = li->li_version;
2010 sb.sb_method = LDAP_AUTH_SIMPLE;
2011 BER_BVSTR( &sb.sb_binddn, "" );
2013 rc = slap_discover_feature( &sb,
2014 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
2015 LDAP_FEATURE_ABSOLUTE_FILTERS );
2016 if ( rc == LDAP_COMPARE_TRUE ) {
2017 mask |= LDAP_BACK_F_T_F;
2021 li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
2022 li->li_flags |= mask;
2025 case LDAP_BACK_CFG_WHOAMI:
2026 if ( c->argc == 1 || c->value_int ) {
2027 li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
2028 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
2029 0, ldap_back_exop_whoami );
2032 li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
2036 case LDAP_BACK_CFG_TIMEOUT:
2037 for ( i = 1; i < c->argc; i++ ) {
2038 if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
2042 if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
2043 snprintf( c->cr_msg, sizeof( c->cr_msg),
2044 "unable to parse timeout \"%s\"",
2046 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2050 for ( j = 0; j < SLAP_OP_LAST; j++ ) {
2051 li->li_timeout[ j ] = u;
2057 if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
2058 snprintf( c->cr_msg, sizeof( c->cr_msg),
2059 "unable to parse timeout \"%s\"",
2061 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2067 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
2070 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2071 snprintf( c->cr_msg, sizeof( c->cr_msg),
2072 "unable to parse idle timeout \"%s\"",
2074 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2077 li->li_idle_timeout = (time_t)t;
2080 case LDAP_BACK_CFG_CONN_TTL: {
2083 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2084 snprintf( c->cr_msg, sizeof( c->cr_msg),
2085 "unable to parse conn ttl\"%s\"",
2087 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2090 li->li_conn_ttl = (time_t)t;
2093 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
2096 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2097 snprintf( c->cr_msg, sizeof( c->cr_msg),
2098 "unable to parse network timeout \"%s\"",
2100 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2103 li->li_network_timeout = (time_t)t;
2106 case LDAP_BACK_CFG_VERSION:
2107 if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
2108 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2109 "unsupported version \"%s\" "
2110 "in \"protocol-version <version>\"",
2112 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2116 li->li_version = c->value_int;
2119 case LDAP_BACK_CFG_SINGLECONN:
2120 if ( c->value_int ) {
2121 li->li_flags |= LDAP_BACK_F_SINGLECONN;
2124 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
2128 case LDAP_BACK_CFG_USETEMP:
2129 if ( c->value_int ) {
2130 li->li_flags |= LDAP_BACK_F_USE_TEMPORARIES;
2133 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
2137 case LDAP_BACK_CFG_CONNPOOLMAX:
2138 if ( c->value_int < LDAP_BACK_CONN_PRIV_MIN
2139 || c->value_int > LDAP_BACK_CONN_PRIV_MAX )
2141 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2142 "invalid max size " "of privileged "
2143 "connections pool \"%s\" "
2144 "in \"conn-pool-max <n> "
2145 "(must be between %d and %d)\"",
2147 LDAP_BACK_CONN_PRIV_MIN,
2148 LDAP_BACK_CONN_PRIV_MAX );
2149 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2152 li->li_conn_priv_max = c->value_int;
2155 case LDAP_BACK_CFG_CANCEL: {
2158 i = verb_to_mask( c->argv[1], cancel_mode );
2159 if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
2163 mask = cancel_mode[i].mask;
2165 if ( LDAP_BACK_ISOPEN( li )
2166 && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
2167 && !LDAP_BACK_CANCEL( li ) )
2169 slap_bindconf sb = { BER_BVNULL };
2172 if ( li->li_uri == NULL ) {
2173 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2174 "need URI to discover \"cancel\" support "
2175 "in \"cancel exop-discover\"" );
2176 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2180 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
2181 sb.sb_version = li->li_version;
2182 sb.sb_method = LDAP_AUTH_SIMPLE;
2183 BER_BVSTR( &sb.sb_binddn, "" );
2185 rc = slap_discover_feature( &sb,
2186 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
2188 if ( rc == LDAP_COMPARE_TRUE ) {
2189 mask |= LDAP_BACK_F_CANCEL_EXOP;
2193 li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
2194 li->li_flags |= mask;
2197 case LDAP_BACK_CFG_QUARANTINE:
2198 if ( LDAP_BACK_QUARANTINE( li ) ) {
2199 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2200 "quarantine already defined" );
2201 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2204 rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
2205 c->cr_msg, sizeof( c->cr_msg ) );
2207 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2210 ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex );
2211 /* give it a chance to retry if the pattern gets reset
2212 * via back-config */
2213 li->li_isquarantined = 0;
2214 li->li_flags |= LDAP_BACK_F_QUARANTINE;
2218 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
2219 case LDAP_BACK_CFG_ST_REQUEST:
2220 if ( c->value_int ) {
2221 li->li_flags |= LDAP_BACK_F_ST_REQUEST;
2224 li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
2227 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
2229 case LDAP_BACK_CFG_NOREFS:
2230 if ( c->value_int ) {
2231 li->li_flags |= LDAP_BACK_F_NOREFS;
2234 li->li_flags &= ~LDAP_BACK_F_NOREFS;
2238 case LDAP_BACK_CFG_NOUNDEFFILTER:
2239 if ( c->value_int ) {
2240 li->li_flags |= LDAP_BACK_F_NOUNDEFFILTER;
2243 li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
2247 case LDAP_BACK_CFG_ONERR:
2249 i = verb_to_mask( c->argv[1], onerr_mode );
2250 if ( BER_BVISNULL( &onerr_mode[i].word ) ) {
2251 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2252 "%s unknown argument \"%s\"",
2253 c->argv[0], c->argv[1] );
2254 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2257 li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
2258 li->li_flags |= onerr_mode[i].mask;
2261 case LDAP_BACK_CFG_REWRITE:
2262 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2263 "rewrite/remap capabilities have been moved "
2264 "to the \"rwm\" overlay; see slapo-rwm(5) "
2265 "for details (hint: add \"overlay rwm\" "
2266 "and prefix all directives with \"rwm-\")" );
2267 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2270 case LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA:
2271 if ( c->value_int ) {
2272 li->li_flags |= LDAP_BACK_F_OMIT_UNKNOWN_SCHEMA;
2275 li->li_flags &= ~LDAP_BACK_F_OMIT_UNKNOWN_SCHEMA;
2279 case LDAP_BACK_CFG_KEEPALIVE:
2280 slap_keepalive_parse( ber_bvstrdup(c->argv[1]),
2281 &li->li_tls.sb_keepalive, 0, 0, 0);
2285 /* FIXME: try to catch inconsistencies */
2294 ldap_back_init_cf( BackendInfo *bi )
2297 AttributeDescription *ad = NULL;
2300 /* Make sure we don't exceed the bits reserved for userland */
2301 config_check_userland( LDAP_BACK_CFG_LAST );
2303 bi->bi_cf_ocs = ldapocs;
2305 rc = config_register_schema( ldapcfg, ldapocs );
2310 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
2311 * to be base64-encoded when written in LDIF form;
2312 * basically, we don't care if it fails */
2313 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
2315 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
2316 "warning, unable to get \"olcDbACLPasswd\" "
2317 "attribute description: %d: %s\n",
2320 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
2321 ad->ad_type->sat_oid );
2325 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
2327 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
2328 "warning, unable to get \"olcDbIDAssertPasswd\" "
2329 "attribute description: %d: %s\n",
2332 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
2333 ad->ad_type->sat_oid );
2340 ldap_pbind_cf_gen( ConfigArgs *c )
2342 slap_overinst *on = (slap_overinst *)c->bi;
2343 void *private = c->be->be_private;
2346 c->be->be_private = on->on_bi.bi_private;
2347 rc = ldap_back_cf_gen( c );
2348 c->be->be_private = private;
2353 ldap_pbind_init_cf( BackendInfo *bi )
2355 bi->bi_cf_ocs = pbindocs;
2357 return config_register_schema( pbindcfg, pbindocs );
2361 ldap_back_exop_whoami(
2365 struct berval *bv = NULL;
2367 if ( op->oq_extended.rs_reqdata != NULL ) {
2368 /* no request data should be provided */
2369 rs->sr_text = "no request data expected";
2370 return rs->sr_err = LDAP_PROTOCOL_ERROR;
2373 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
2374 op->o_log_prefix, 0, 0, 0, 0 );
2376 rs->sr_err = backend_check_restrictions( op, rs,
2377 (struct berval *)&slap_EXOP_WHOAMI );
2378 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
2380 /* if auth'd by back-ldap and request is proxied, forward it */
2381 if ( op->o_conn->c_authz_backend
2382 && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
2383 && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
2385 ldapconn_t *lc = NULL;
2386 LDAPControl c, *ctrls[2] = {NULL, NULL};
2388 Operation op2 = *op;
2394 op2.o_ndn = op->o_conn->c_ndn;
2395 if ( !ldap_back_dobind( &lc, &op2, rs, LDAP_BACK_SENDERR ) ) {
2398 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
2399 c.ldctl_iscritical = 1;
2400 c.ldctl_value.bv_val = op->o_tmpalloc(
2401 op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
2403 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
2404 ptr = c.ldctl_value.bv_val;
2405 ptr = lutil_strcopy( ptr, "dn:" );
2406 ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
2410 rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
2411 if ( rs->sr_err == LDAP_SUCCESS ) {
2412 /* by now, make sure no timeout is used (ITS#6282) */
2413 struct timeval tv = { -1, 0 };
2414 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) == -1 ) {
2415 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
2417 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
2419 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
2425 /* NOTE: are we sure "bv" will be malloc'ed
2426 * with the appropriate memory? */
2427 rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
2431 op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
2432 if ( rs->sr_err != LDAP_SUCCESS ) {
2433 rs->sr_err = slap_map_api2result( rs );
2437 ldap_back_release_conn( (ldapinfo_t *)op2.o_bd->be_private, lc );
2441 /* else just do the same as before */
2442 bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
2443 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
2444 bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
2445 bv->bv_val = ch_malloc( bv->bv_len + 1 );
2446 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
2447 AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
2449 bv->bv_val[ bv->bv_len ] = '\0';
2457 rs->sr_rspdata = bv;