1 /* config.c - ldap backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2017 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 ),
694 "\"%s\" conflicts with existing authz rules",
695 c->argv[ 0 ], c->argv[ 1 ] );
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 ),
707 "\"<authz>\" conflicts with \"*\"", c->argv[0] );
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 ),
717 "invalid syntax", c->argv[0] );
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 ),
764 "invalid syntax", c->argv[0] );
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 ),
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 ),
828 "authz=\"native\" incompatible "
829 "with auth method", c->argv[0] );
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 ),
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 ),
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 snprintf( c->cr_msg, sizeof( c->cr_msg ),
876 "\"obsolete-proxy-authz\" flag "
877 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.",
879 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
884 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
887 } else if ( strcasecmp( flags[ j ], "obsolete-encoding-workaround" ) == 0 ) {
888 if ( si->si_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
889 snprintf( c->cr_msg, sizeof( c->cr_msg ),
891 "\"obsolete-encoding-workaround\" flag "
892 "incompatible with previously issued \"obsolete-proxy-authz\" flag.",
894 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
899 si->si_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
902 } else if ( strcasecmp( flags[ j ], "proxy-authz-critical" ) == 0 ) {
903 si->si_flags |= LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
905 } else if ( strcasecmp( flags[ j ], "proxy-authz-non-critical" ) == 0 ) {
906 si->si_flags &= ~LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL;
908 } else if ( strcasecmp( flags[ j ], "dn-none" ) == 0 ) {
909 si->si_flags &= ~LDAP_BACK_AUTH_DN_MASK;
911 } else if ( strcasecmp( flags[ j ], "dn-authzid" ) == 0 ) {
912 si->si_flags &= ~LDAP_BACK_AUTH_DN_MASK;
913 si->si_flags |= LDAP_BACK_AUTH_DN_AUTHZID;
915 } else if ( strcasecmp( flags[ j ], "dn-whoami" ) == 0 ) {
916 si->si_flags &= ~LDAP_BACK_AUTH_DN_MASK;
917 si->si_flags |= LDAP_BACK_AUTH_DN_WHOAMI;
920 snprintf( c->cr_msg, sizeof( c->cr_msg ),
922 "unknown flag \"%s\"",
923 c->argv[0], flags[ j ] );
924 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
930 ldap_charray_free( flags );
935 } else if ( bindconf_parse( c->argv[ i ], &si->si_bc ) ) {
936 snprintf( c->cr_msg, sizeof( c->cr_msg ),
938 "unable to parse field \"%s\"",
939 c->argv[0], c->argv[ i ] );
940 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
945 if ( si->si_bc.sb_method == LDAP_AUTH_SIMPLE ) {
946 if ( BER_BVISNULL( &si->si_bc.sb_binddn )
947 || BER_BVISNULL( &si->si_bc.sb_cred ) )
949 snprintf( c->cr_msg, sizeof( c->cr_msg ),
951 "SIMPLE needs \"binddn\" and \"credentials\"", c->argv[0] );
952 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
956 } else if ( si->si_bc.sb_method == LDAP_AUTH_SASL ) {
957 if ( BER_BVISNULL( &si->si_bc.sb_binddn ) &&
958 !(si->si_flags & LDAP_BACK_AUTH_DN_MASK) )
960 static struct berval authid = BER_BVC("cn=auth");
961 ber_dupbv( &si->si_bc.sb_binddn, &authid );
965 bindconf_tls_defaults( &si->si_bc );
970 /* NOTE: temporary, until back-meta is ported to back-config */
972 slap_idassert_passthru_parse_cf( const char *fname, int lineno, const char *arg, slap_idassert_t *si )
974 ConfigArgs c = { 0 };
977 snprintf( c.log, sizeof( c.log ), "%s: line %d", fname, lineno );
980 argv[ 0 ] = "idassert-passThru";
981 argv[ 1 ] = (char *)arg;
984 return slap_idassert_passthru_parse( &c, si );
988 ldap_back_cf_gen( ConfigArgs *c )
990 ldapinfo_t *li = ( ldapinfo_t * )c->be->be_private;
994 if ( c->op == SLAP_CONFIG_EMIT ) {
995 struct berval bv = BER_BVNULL;
1002 case LDAP_BACK_CFG_URI:
1003 if ( li->li_uri != NULL ) {
1004 struct berval bv, bv2;
1006 ber_str2bv( li->li_uri, 0, 0, &bv );
1007 bv2.bv_len = bv.bv_len + STRLENOF( "\"\"" );
1008 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
1009 snprintf( bv2.bv_val, bv2.bv_len + 1,
1010 "\"%s\"", bv.bv_val );
1011 ber_bvarray_add( &c->rvalue_vals, &bv2 );
1018 case LDAP_BACK_CFG_TLS: {
1019 struct berval bc = BER_BVNULL, bv2;
1020 enum_to_verb( tls_mode, ( li->li_flags & LDAP_BACK_F_TLS_MASK ), &bv );
1021 assert( !BER_BVISNULL( &bv ) );
1022 bindconf_tls_unparse( &li->li_tls, &bc );
1024 if ( !BER_BVISEMPTY( &bc )) {
1025 bv2.bv_len = bv.bv_len + bc.bv_len + 1;
1026 bv2.bv_val = ch_malloc( bv2.bv_len + 1 );
1027 strcpy( bv2.bv_val, bv.bv_val );
1028 bv2.bv_val[bv.bv_len] = ' ';
1029 strcpy( &bv2.bv_val[bv.bv_len + 1], bc.bv_val );
1030 ber_bvarray_add( &c->rvalue_vals, &bv2 );
1033 value_add_one( &c->rvalue_vals, &bv );
1035 ber_memfree( bc.bv_val );
1039 case LDAP_BACK_CFG_ACL_AUTHCDN:
1040 case LDAP_BACK_CFG_ACL_PASSWD:
1041 case LDAP_BACK_CFG_ACL_METHOD:
1042 /* handled by LDAP_BACK_CFG_ACL_BIND */
1046 case LDAP_BACK_CFG_ACL_BIND: {
1049 if ( li->li_acl_authmethod == LDAP_AUTH_NONE ) {
1053 bindconf_unparse( &li->li_acl, &bv );
1055 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1056 /* count spaces */ ;
1060 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1064 ber_bvarray_add( &c->rvalue_vals, &bv );
1068 case LDAP_BACK_CFG_IDASSERT_MODE:
1069 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1070 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1071 case LDAP_BACK_CFG_IDASSERT_METHOD:
1072 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1076 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1077 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
1080 struct berval bv = BER_BVNULL;
1081 char buf[SLAP_TEXT_BUFLEN];
1083 switch ( c->type ) {
1084 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
1085 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
1086 default: assert( 0 ); break;
1089 if ( *bvp == NULL ) {
1090 if ( bvp == &li->li_idassert_authz
1091 && ( li->li_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
1093 BER_BVSTR( &bv, "*" );
1094 value_add_one( &c->rvalue_vals, &bv );
1102 for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ ) {
1104 int len = snprintf( buf, sizeof( buf ), SLAP_X_ORDERED_FMT, i );
1105 bv.bv_len = ((*bvp)[ i ]).bv_len + len;
1106 bv.bv_val = ber_memrealloc( bv.bv_val, bv.bv_len + 1 );
1108 ptr = lutil_strcopy( ptr, buf );
1109 ptr = lutil_strncopy( ptr, ((*bvp)[ i ]).bv_val, ((*bvp)[ i ]).bv_len );
1110 value_add_one( &c->rvalue_vals, &bv );
1113 ber_memfree( bv.bv_val );
1118 case LDAP_BACK_CFG_IDASSERT_BIND: {
1120 struct berval bc = BER_BVNULL;
1123 if ( li->li_idassert_authmethod == LDAP_AUTH_NONE ) {
1127 if ( li->li_idassert_authmethod != LDAP_AUTH_NONE ) {
1130 switch ( li->li_idassert_mode ) {
1131 case LDAP_BACK_IDASSERT_OTHERID:
1132 case LDAP_BACK_IDASSERT_OTHERDN:
1136 struct berval mode = BER_BVNULL;
1138 enum_to_verb( idassert_mode, li->li_idassert_mode, &mode );
1139 if ( BER_BVISNULL( &mode ) ) {
1140 /* there's something wrong... */
1145 bv.bv_len = STRLENOF( "mode=" ) + mode.bv_len;
1146 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1148 ptr = lutil_strcopy( bv.bv_val, "mode=" );
1149 ptr = lutil_strcopy( ptr, mode.bv_val );
1155 if ( li->li_idassert_flags & LDAP_BACK_AUTH_NATIVE_AUTHZ ) {
1156 len = bv.bv_len + STRLENOF( "authz=native" );
1158 if ( !BER_BVISEMPTY( &bv ) ) {
1159 len += STRLENOF( " " );
1162 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1164 ptr = &bv.bv_val[ bv.bv_len ];
1166 if ( !BER_BVISEMPTY( &bv ) ) {
1167 ptr = lutil_strcopy( ptr, " " );
1170 (void)lutil_strcopy( ptr, "authz=native" );
1173 len = bv.bv_len + STRLENOF( "flags=non-prescriptive,override,obsolete-encoding-workaround,proxy-authz-non-critical,dn-authzid" );
1175 if ( !BER_BVISEMPTY( &bv ) ) {
1176 len += STRLENOF( " " );
1179 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1181 ptr = &bv.bv_val[ bv.bv_len ];
1183 if ( !BER_BVISEMPTY( &bv ) ) {
1184 ptr = lutil_strcopy( ptr, " " );
1187 ptr = lutil_strcopy( ptr, "flags=" );
1189 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) {
1190 ptr = lutil_strcopy( ptr, "prescriptive" );
1192 ptr = lutil_strcopy( ptr, "non-prescriptive" );
1195 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OVERRIDE ) {
1196 ptr = lutil_strcopy( ptr, ",override" );
1199 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1200 ptr = lutil_strcopy( ptr, ",obsolete-proxy-authz" );
1202 } else if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1203 ptr = lutil_strcopy( ptr, ",obsolete-encoding-workaround" );
1206 if ( li->li_idassert_flags & LDAP_BACK_AUTH_PROXYAUTHZ_CRITICAL ) {
1207 ptr = lutil_strcopy( ptr, ",proxy-authz-critical" );
1210 ptr = lutil_strcopy( ptr, ",proxy-authz-non-critical" );
1213 switch ( li->li_idassert_flags & LDAP_BACK_AUTH_DN_MASK ) {
1214 case LDAP_BACK_AUTH_DN_AUTHZID:
1215 ptr = lutil_strcopy( ptr, ",dn-authzid" );
1218 case LDAP_BACK_AUTH_DN_WHOAMI:
1219 ptr = lutil_strcopy( ptr, ",dn-whoami" );
1223 #if 0 /* implicit */
1224 ptr = lutil_strcopy( ptr, ",dn-none" );
1229 bv.bv_len = ( ptr - bv.bv_val );
1233 bindconf_unparse( &li->li_idassert.si_bc, &bc );
1235 if ( !BER_BVISNULL( &bv ) ) {
1236 ber_len_t len = bv.bv_len + bc.bv_len;
1238 bv.bv_val = ch_realloc( bv.bv_val, len + 1 );
1240 assert( bc.bv_val[ 0 ] == ' ' );
1242 ptr = lutil_strcopy( &bv.bv_val[ bv.bv_len ], bc.bv_val );
1244 bv.bv_len = ptr - bv.bv_val;
1247 for ( i = 0; isspace( (unsigned char) bc.bv_val[ i ] ); i++ )
1248 /* count spaces */ ;
1252 AC_MEMCPY( bc.bv_val, &bc.bv_val[ i ], bc.bv_len + 1 );
1258 ber_bvarray_add( &c->rvalue_vals, &bv );
1263 case LDAP_BACK_CFG_REBIND:
1264 c->value_int = LDAP_BACK_SAVECRED( li );
1267 case LDAP_BACK_CFG_CHASE:
1268 c->value_int = LDAP_BACK_CHASE_REFERRALS( li );
1271 case LDAP_BACK_CFG_T_F:
1272 enum_to_verb( t_f_mode, (li->li_flags & LDAP_BACK_F_T_F_MASK2), &bv );
1273 if ( BER_BVISNULL( &bv ) ) {
1274 /* there's something wrong... */
1279 value_add_one( &c->rvalue_vals, &bv );
1283 case LDAP_BACK_CFG_WHOAMI:
1284 c->value_int = LDAP_BACK_PROXY_WHOAMI( li );
1287 case LDAP_BACK_CFG_TIMEOUT:
1290 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1291 if ( li->li_timeout[ i ] != 0 ) {
1296 if ( i == SLAP_OP_LAST ) {
1300 slap_cf_aux_table_unparse( li->li_timeout, &bv, timeout_table );
1302 if ( BER_BVISNULL( &bv ) ) {
1306 for ( i = 0; isspace( (unsigned char) bv.bv_val[ i ] ); i++ )
1307 /* count spaces */ ;
1311 AC_MEMCPY( bv.bv_val, &bv.bv_val[ i ],
1315 ber_bvarray_add( &c->rvalue_vals, &bv );
1318 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
1319 char buf[ SLAP_TEXT_BUFLEN ];
1321 if ( li->li_idle_timeout == 0 ) {
1325 lutil_unparse_time( buf, sizeof( buf ), li->li_idle_timeout );
1326 ber_str2bv( buf, 0, 0, &bv );
1327 value_add_one( &c->rvalue_vals, &bv );
1330 case LDAP_BACK_CFG_CONN_TTL: {
1331 char buf[ SLAP_TEXT_BUFLEN ];
1333 if ( li->li_conn_ttl == 0 ) {
1337 lutil_unparse_time( buf, sizeof( buf ), li->li_conn_ttl );
1338 ber_str2bv( buf, 0, 0, &bv );
1339 value_add_one( &c->rvalue_vals, &bv );
1342 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
1343 char buf[ SLAP_TEXT_BUFLEN ];
1345 if ( li->li_network_timeout == 0 ) {
1349 snprintf( buf, sizeof( buf ), "%ld",
1350 (long)li->li_network_timeout );
1351 ber_str2bv( buf, 0, 0, &bv );
1352 value_add_one( &c->rvalue_vals, &bv );
1355 case LDAP_BACK_CFG_VERSION:
1356 if ( li->li_version == 0 ) {
1360 c->value_int = li->li_version;
1363 case LDAP_BACK_CFG_SINGLECONN:
1364 c->value_int = LDAP_BACK_SINGLECONN( li );
1367 case LDAP_BACK_CFG_USETEMP:
1368 c->value_int = LDAP_BACK_USE_TEMPORARIES( li );
1371 case LDAP_BACK_CFG_CONNPOOLMAX:
1372 c->value_int = li->li_conn_priv_max;
1375 case LDAP_BACK_CFG_CANCEL: {
1376 slap_mask_t mask = LDAP_BACK_F_CANCEL_MASK2;
1378 if ( LDAP_BACK_CANCEL_DISCOVER( li ) ) {
1379 mask &= ~LDAP_BACK_F_CANCEL_EXOP;
1381 enum_to_verb( cancel_mode, (li->li_flags & mask), &bv );
1382 if ( BER_BVISNULL( &bv ) ) {
1383 /* there's something wrong... */
1388 value_add_one( &c->rvalue_vals, &bv );
1392 case LDAP_BACK_CFG_QUARANTINE:
1393 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1398 rc = slap_retry_info_unparse( &li->li_quarantine, &bv );
1400 ber_bvarray_add( &c->rvalue_vals, &bv );
1404 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1405 case LDAP_BACK_CFG_ST_REQUEST:
1406 c->value_int = LDAP_BACK_ST_REQUEST( li );
1408 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1410 case LDAP_BACK_CFG_NOREFS:
1411 c->value_int = LDAP_BACK_NOREFS( li );
1414 case LDAP_BACK_CFG_NOUNDEFFILTER:
1415 c->value_int = LDAP_BACK_NOUNDEFFILTER( li );
1418 case LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA:
1419 c->value_int = LDAP_BACK_OMIT_UNKNOWN_SCHEMA( li );
1422 case LDAP_BACK_CFG_ONERR:
1423 enum_to_verb( onerr_mode, li->li_flags & LDAP_BACK_F_ONERR_STOP, &bv );
1424 if ( BER_BVISNULL( &bv )) {
1427 value_add_one( &c->rvalue_vals, &bv );
1431 case LDAP_BACK_CFG_KEEPALIVE: {
1433 char buf[AC_LINE_MAX];
1434 bv.bv_len = AC_LINE_MAX;
1435 bv.bv_val = &buf[0];
1436 slap_keepalive_parse(&bv, &li->li_tls.sb_keepalive, 0, 0, 1);
1437 value_add_one( &c->rvalue_vals, &bv );
1442 /* FIXME: we need to handle all... */
1448 } else if ( c->op == LDAP_MOD_DELETE ) {
1450 case LDAP_BACK_CFG_URI:
1451 if ( li->li_uri != NULL ) {
1452 ch_free( li->li_uri );
1455 assert( li->li_bvuri != NULL );
1456 ber_bvarray_free( li->li_bvuri );
1457 li->li_bvuri = NULL;
1460 /* better cleanup the cached connections... */
1461 /* NOTE: don't worry about locking: if we got here,
1462 * other threads are suspended. */
1463 if ( li->li_conninfo.lai_tree != NULL ) {
1464 avl_free( li->li_conninfo.lai_tree, ldap_back_conn_free );
1465 li->li_conninfo.lai_tree = NULL;
1470 case LDAP_BACK_CFG_TLS:
1474 case LDAP_BACK_CFG_ACL_AUTHCDN:
1475 case LDAP_BACK_CFG_ACL_PASSWD:
1476 case LDAP_BACK_CFG_ACL_METHOD:
1477 /* handled by LDAP_BACK_CFG_ACL_BIND */
1481 case LDAP_BACK_CFG_ACL_BIND:
1482 bindconf_free( &li->li_acl );
1485 case LDAP_BACK_CFG_IDASSERT_MODE:
1486 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1487 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1488 case LDAP_BACK_CFG_IDASSERT_METHOD:
1489 /* handled by LDAP_BACK_CFG_IDASSERT_BIND */
1493 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1494 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: {
1497 switch ( c->type ) {
1498 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM: bvp = &li->li_idassert_authz; break;
1499 case LDAP_BACK_CFG_IDASSERT_PASSTHRU: bvp = &li->li_idassert_passthru; break;
1500 default: assert( 0 ); break;
1503 if ( c->valx < 0 ) {
1504 if ( *bvp != NULL ) {
1505 ber_bvarray_free( *bvp );
1512 if ( *bvp == NULL ) {
1517 for ( i = 0; !BER_BVISNULL( &((*bvp)[ i ]) ); i++ )
1520 if ( i >= c->valx ) {
1524 ber_memfree( ((*bvp)[ c->valx ]).bv_val );
1525 for ( i = c->valx; !BER_BVISNULL( &((*bvp)[ i + 1 ]) ); i++ ) {
1526 (*bvp)[ i ] = (*bvp)[ i + 1 ];
1528 BER_BVZERO( &((*bvp)[ i ]) );
1532 case LDAP_BACK_CFG_IDASSERT_BIND:
1533 bindconf_free( &li->li_idassert.si_bc );
1534 memset( &li->li_idassert, 0, sizeof( slap_idassert_t ) );
1537 case LDAP_BACK_CFG_REBIND:
1538 case LDAP_BACK_CFG_CHASE:
1539 case LDAP_BACK_CFG_T_F:
1540 case LDAP_BACK_CFG_WHOAMI:
1541 case LDAP_BACK_CFG_CANCEL:
1545 case LDAP_BACK_CFG_TIMEOUT:
1546 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1547 li->li_timeout[ i ] = 0;
1551 case LDAP_BACK_CFG_IDLE_TIMEOUT:
1552 li->li_idle_timeout = 0;
1555 case LDAP_BACK_CFG_CONN_TTL:
1556 li->li_conn_ttl = 0;
1559 case LDAP_BACK_CFG_NETWORK_TIMEOUT:
1560 li->li_network_timeout = 0;
1563 case LDAP_BACK_CFG_VERSION:
1567 case LDAP_BACK_CFG_SINGLECONN:
1568 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
1571 case LDAP_BACK_CFG_USETEMP:
1572 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
1575 case LDAP_BACK_CFG_CONNPOOLMAX:
1576 li->li_conn_priv_max = LDAP_BACK_CONN_PRIV_MIN;
1579 case LDAP_BACK_CFG_QUARANTINE:
1580 if ( !LDAP_BACK_QUARANTINE( li ) ) {
1584 slap_retry_info_destroy( &li->li_quarantine );
1585 ldap_pvt_thread_mutex_destroy( &li->li_quarantine_mutex );
1586 li->li_isquarantined = 0;
1587 li->li_flags &= ~LDAP_BACK_F_QUARANTINE;
1590 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1591 case LDAP_BACK_CFG_ST_REQUEST:
1592 li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
1594 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1596 case LDAP_BACK_CFG_NOREFS:
1597 li->li_flags &= ~LDAP_BACK_F_NOREFS;
1600 case LDAP_BACK_CFG_NOUNDEFFILTER:
1601 li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
1604 case LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA:
1605 li->li_flags &= ~LDAP_BACK_F_OMIT_UNKNOWN_SCHEMA;
1608 case LDAP_BACK_CFG_ONERR:
1609 li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
1612 case LDAP_BACK_CFG_KEEPALIVE:
1613 li->li_tls.sb_keepalive.sk_idle = 0;
1614 li->li_tls.sb_keepalive.sk_probes = 0;
1615 li->li_tls.sb_keepalive.sk_interval = 0;
1619 /* FIXME: we need to handle all... */
1628 case LDAP_BACK_CFG_URI: {
1629 LDAPURLDesc *tmpludp, *lud;
1630 char **urllist = NULL;
1631 int urlrc = LDAP_URL_SUCCESS, i;
1633 if ( li->li_uri != NULL ) {
1634 ch_free( li->li_uri );
1637 assert( li->li_bvuri != NULL );
1638 ber_bvarray_free( li->li_bvuri );
1639 li->li_bvuri = NULL;
1642 /* PARANOID: DN and more are not required nor allowed */
1643 urlrc = ldap_url_parselist_ext( &lud, c->argv[ 1 ], ", \t", LDAP_PVT_URL_PARSE_NONE );
1644 if ( urlrc != LDAP_URL_SUCCESS ) {
1648 case LDAP_URL_ERR_MEM:
1651 case LDAP_URL_ERR_PARAM:
1652 why = "parameter is bad";
1654 case LDAP_URL_ERR_BADSCHEME:
1655 why = "URL doesn't begin with \"[c]ldap[si]://\"";
1657 case LDAP_URL_ERR_BADENCLOSURE:
1658 why = "URL is missing trailing \">\"";
1660 case LDAP_URL_ERR_BADURL:
1663 case LDAP_URL_ERR_BADHOST:
1664 why = "host/port is bad";
1666 case LDAP_URL_ERR_BADATTRS:
1667 why = "bad (or missing) attributes";
1669 case LDAP_URL_ERR_BADSCOPE:
1670 why = "scope string is invalid (or missing)";
1672 case LDAP_URL_ERR_BADFILTER:
1673 why = "bad or missing filter";
1675 case LDAP_URL_ERR_BADEXTS:
1676 why = "bad or missing extensions";
1679 why = "unknown reason";
1682 snprintf( c->cr_msg, sizeof( c->cr_msg),
1683 "unable to parse uri \"%s\" "
1684 "in \"uri <uri>\" line: %s",
1685 c->value_string, why );
1686 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1691 for ( i = 0, tmpludp = lud;
1693 i++, tmpludp = tmpludp->lud_next )
1695 if ( ( tmpludp->lud_dn != NULL
1696 && tmpludp->lud_dn[0] != '\0' )
1697 || tmpludp->lud_attrs != NULL
1698 /* || tmpludp->lud_scope != LDAP_SCOPE_DEFAULT */
1699 || tmpludp->lud_filter != NULL
1700 || tmpludp->lud_exts != NULL )
1702 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1703 "warning, only protocol, "
1704 "host and port allowed "
1705 "in \"uri <uri>\" statement "
1706 "for uri #%d of \"%s\"",
1708 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1712 for ( i = 0, tmpludp = lud;
1714 i++, tmpludp = tmpludp->lud_next )
1717 urllist = ch_calloc( sizeof( char * ), i + 1 );
1719 for ( i = 0, tmpludp = lud;
1721 i++, tmpludp = tmpludp->lud_next )
1727 tmplud.lud_attrs = NULL;
1728 tmplud.lud_filter = NULL;
1729 if ( !ldap_is_ldapi_url( tmplud.lud_scheme ) ) {
1730 tmplud.lud_exts = NULL;
1731 tmplud.lud_crit_exts = 0;
1734 urllist[ i ] = ldap_url_desc2str( &tmplud );
1736 if ( urllist[ i ] == NULL ) {
1737 snprintf( c->cr_msg, sizeof( c->cr_msg),
1738 "unable to rebuild uri "
1739 "in \"uri <uri>\" statement "
1742 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1748 li->li_uri = ldap_charray2str( urllist, " " );
1749 for ( i = 0; urllist[ i ] != NULL; i++ ) {
1752 ber_str2bv( urllist[ i ], 0, 0, &bv );
1753 ber_bvarray_add( &li->li_bvuri, &bv );
1754 urllist[ i ] = NULL;
1756 ldap_memfree( urllist );
1761 ldap_charray_free( urllist );
1764 ldap_free_urllist( lud );
1766 if ( urlrc != LDAP_URL_SUCCESS ) {
1772 case LDAP_BACK_CFG_TLS:
1773 i = verb_to_mask( c->argv[1], tls_mode );
1774 if ( BER_BVISNULL( &tls_mode[i].word ) ) {
1777 li->li_flags &= ~LDAP_BACK_F_TLS_MASK;
1778 li->li_flags |= tls_mode[i].mask;
1779 if ( c->argc > 2 ) {
1780 for ( i=2; i<c->argc; i++ ) {
1781 if ( bindconf_tls_parse( c->argv[i], &li->li_tls ))
1784 bindconf_tls_defaults( &li->li_tls );
1788 case LDAP_BACK_CFG_ACL_AUTHCDN:
1789 switch ( li->li_acl_authmethod ) {
1790 case LDAP_AUTH_NONE:
1791 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1794 case LDAP_AUTH_SIMPLE:
1798 snprintf( c->cr_msg, sizeof( c->cr_msg),
1799 "\"acl-authcDN <DN>\" incompatible "
1800 "with auth method %d",
1801 li->li_acl_authmethod );
1802 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1805 if ( !BER_BVISNULL( &li->li_acl_authcDN ) ) {
1806 free( li->li_acl_authcDN.bv_val );
1808 ber_memfree_x( c->value_dn.bv_val, NULL );
1809 li->li_acl_authcDN = c->value_ndn;
1810 BER_BVZERO( &c->value_dn );
1811 BER_BVZERO( &c->value_ndn );
1814 case LDAP_BACK_CFG_ACL_PASSWD:
1815 switch ( li->li_acl_authmethod ) {
1816 case LDAP_AUTH_NONE:
1817 li->li_acl_authmethod = LDAP_AUTH_SIMPLE;
1820 case LDAP_AUTH_SIMPLE:
1824 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1825 "\"acl-passwd <cred>\" incompatible "
1826 "with auth method %d",
1827 li->li_acl_authmethod );
1828 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1831 if ( !BER_BVISNULL( &li->li_acl_passwd ) ) {
1832 free( li->li_acl_passwd.bv_val );
1834 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_acl_passwd );
1837 case LDAP_BACK_CFG_ACL_METHOD:
1838 case LDAP_BACK_CFG_ACL_BIND:
1839 for ( i = 1; i < c->argc; i++ ) {
1840 if ( bindconf_parse( c->argv[ i ], &li->li_acl ) ) {
1844 bindconf_tls_defaults( &li->li_acl );
1847 case LDAP_BACK_CFG_IDASSERT_MODE:
1848 i = verb_to_mask( c->argv[1], idassert_mode );
1849 if ( BER_BVISNULL( &idassert_mode[i].word ) ) {
1850 if ( strncasecmp( c->argv[1], "u:", STRLENOF( "u:" ) ) == 0 ) {
1851 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERID;
1852 ber_str2bv( c->argv[1], 0, 1, &li->li_idassert_authzID );
1853 li->li_idassert_authzID.bv_val[ 0 ] = 'u';
1856 struct berval id, ndn;
1858 ber_str2bv( c->argv[1], 0, 0, &id );
1860 if ( strncasecmp( c->argv[1], "dn:", STRLENOF( "dn:" ) ) == 0 ) {
1861 id.bv_val += STRLENOF( "dn:" );
1862 id.bv_len -= STRLENOF( "dn:" );
1865 rc = dnNormalize( 0, NULL, NULL, &id, &ndn, NULL );
1866 if ( rc != LDAP_SUCCESS ) {
1867 Debug( LDAP_DEBUG_ANY,
1868 "%s: line %d: idassert ID \"%s\" is not a valid DN\n",
1869 c->fname, c->lineno, c->argv[1] );
1873 li->li_idassert_authzID.bv_len = STRLENOF( "dn:" ) + ndn.bv_len;
1874 li->li_idassert_authzID.bv_val = ch_malloc( li->li_idassert_authzID.bv_len + 1 );
1875 AC_MEMCPY( li->li_idassert_authzID.bv_val, "dn:", STRLENOF( "dn:" ) );
1876 AC_MEMCPY( &li->li_idassert_authzID.bv_val[ STRLENOF( "dn:" ) ], ndn.bv_val, ndn.bv_len + 1 );
1877 ch_free( ndn.bv_val );
1879 li->li_idassert_mode = LDAP_BACK_IDASSERT_OTHERDN;
1883 li->li_idassert_mode = idassert_mode[i].mask;
1886 if ( c->argc > 2 ) {
1889 for ( i = 2; i < c->argc; i++ ) {
1890 if ( strcasecmp( c->argv[ i ], "override" ) == 0 ) {
1891 li->li_idassert_flags |= LDAP_BACK_AUTH_OVERRIDE;
1893 } else if ( strcasecmp( c->argv[ i ], "prescriptive" ) == 0 ) {
1894 li->li_idassert_flags |= LDAP_BACK_AUTH_PRESCRIPTIVE;
1896 } else if ( strcasecmp( c->argv[ i ], "non-prescriptive" ) == 0 ) {
1897 li->li_idassert_flags &= ( ~LDAP_BACK_AUTH_PRESCRIPTIVE );
1899 } else if ( strcasecmp( c->argv[ i ], "obsolete-proxy-authz" ) == 0 ) {
1900 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND ) {
1901 Debug( LDAP_DEBUG_ANY,
1902 "%s: line %d: \"obsolete-proxy-authz\" flag "
1903 "in \"idassert-mode <args>\" "
1904 "incompatible with previously issued \"obsolete-encoding-workaround\" flag.\n",
1905 c->fname, c->lineno, 0 );
1908 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ;
1910 } else if ( strcasecmp( c->argv[ i ], "obsolete-encoding-workaround" ) == 0 ) {
1911 if ( li->li_idassert_flags & LDAP_BACK_AUTH_OBSOLETE_PROXY_AUTHZ ) {
1912 Debug( LDAP_DEBUG_ANY,
1913 "%s: line %d: \"obsolete-encoding-workaround\" flag "
1914 "in \"idassert-mode <args>\" "
1915 "incompatible with previously issued \"obsolete-proxy-authz\" flag.\n",
1916 c->fname, c->lineno, 0 );
1919 li->li_idassert_flags |= LDAP_BACK_AUTH_OBSOLETE_ENCODING_WORKAROUND;
1922 Debug( LDAP_DEBUG_ANY,
1923 "%s: line %d: unknown flag #%d "
1924 "in \"idassert-mode <args> "
1925 "[<flags>]\" line.\n",
1926 c->fname, c->lineno, i - 2 );
1933 case LDAP_BACK_CFG_IDASSERT_AUTHCDN:
1934 switch ( li->li_idassert_authmethod ) {
1935 case LDAP_AUTH_NONE:
1936 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1939 case LDAP_AUTH_SIMPLE:
1943 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1944 "\"idassert-authcDN <DN>\" incompatible "
1945 "with auth method %d",
1946 li->li_idassert_authmethod );
1947 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1950 if ( !BER_BVISNULL( &li->li_idassert_authcDN ) ) {
1951 free( li->li_idassert_authcDN.bv_val );
1953 ber_memfree_x( c->value_dn.bv_val, NULL );
1954 li->li_idassert_authcDN = c->value_ndn;
1955 BER_BVZERO( &c->value_dn );
1956 BER_BVZERO( &c->value_ndn );
1959 case LDAP_BACK_CFG_IDASSERT_PASSWD:
1960 switch ( li->li_idassert_authmethod ) {
1961 case LDAP_AUTH_NONE:
1962 li->li_idassert_authmethod = LDAP_AUTH_SIMPLE;
1965 case LDAP_AUTH_SIMPLE:
1969 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1970 "\"idassert-passwd <cred>\" incompatible "
1971 "with auth method %d",
1972 li->li_idassert_authmethod );
1973 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1976 if ( !BER_BVISNULL( &li->li_idassert_passwd ) ) {
1977 free( li->li_idassert_passwd.bv_val );
1979 ber_str2bv( c->argv[ 1 ], 0, 1, &li->li_idassert_passwd );
1982 case LDAP_BACK_CFG_IDASSERT_AUTHZFROM:
1983 rc = slap_idassert_authzfrom_parse( c, &li->li_idassert );
1986 case LDAP_BACK_CFG_IDASSERT_PASSTHRU:
1987 rc = slap_idassert_passthru_parse( c, &li->li_idassert );
1990 case LDAP_BACK_CFG_IDASSERT_METHOD:
1991 /* no longer supported */
1992 snprintf( c->cr_msg, sizeof( c->cr_msg ),
1993 "\"idassert-method <args>\": "
1994 "no longer supported; use \"idassert-bind\"" );
1995 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
1998 case LDAP_BACK_CFG_IDASSERT_BIND:
1999 rc = slap_idassert_parse( c, &li->li_idassert );
2002 case LDAP_BACK_CFG_REBIND:
2003 if ( c->argc == 1 || c->value_int ) {
2004 li->li_flags |= LDAP_BACK_F_SAVECRED;
2007 li->li_flags &= ~LDAP_BACK_F_SAVECRED;
2011 case LDAP_BACK_CFG_CHASE:
2012 if ( c->argc == 1 || c->value_int ) {
2013 li->li_flags |= LDAP_BACK_F_CHASE_REFERRALS;
2016 li->li_flags &= ~LDAP_BACK_F_CHASE_REFERRALS;
2020 case LDAP_BACK_CFG_T_F: {
2023 i = verb_to_mask( c->argv[1], t_f_mode );
2024 if ( BER_BVISNULL( &t_f_mode[i].word ) ) {
2028 mask = t_f_mode[i].mask;
2030 if ( LDAP_BACK_ISOPEN( li )
2031 && mask == LDAP_BACK_F_T_F_DISCOVER
2032 && !LDAP_BACK_T_F( li ) )
2034 slap_bindconf sb = { BER_BVNULL };
2037 if ( li->li_uri == NULL ) {
2038 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2039 "need URI to discover absolute filters support "
2040 "in \"t-f-support discover\"" );
2041 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2045 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
2046 sb.sb_version = li->li_version;
2047 sb.sb_method = LDAP_AUTH_SIMPLE;
2048 BER_BVSTR( &sb.sb_binddn, "" );
2050 rc = slap_discover_feature( &sb,
2051 slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
2052 LDAP_FEATURE_ABSOLUTE_FILTERS );
2053 if ( rc == LDAP_COMPARE_TRUE ) {
2054 mask |= LDAP_BACK_F_T_F;
2058 li->li_flags &= ~LDAP_BACK_F_T_F_MASK2;
2059 li->li_flags |= mask;
2062 case LDAP_BACK_CFG_WHOAMI:
2063 if ( c->argc == 1 || c->value_int ) {
2064 li->li_flags |= LDAP_BACK_F_PROXY_WHOAMI;
2065 load_extop( (struct berval *)&slap_EXOP_WHOAMI,
2066 0, ldap_back_exop_whoami );
2069 li->li_flags &= ~LDAP_BACK_F_PROXY_WHOAMI;
2073 case LDAP_BACK_CFG_TIMEOUT:
2074 for ( i = 1; i < c->argc; i++ ) {
2075 if ( isdigit( (unsigned char) c->argv[ i ][ 0 ] ) ) {
2079 if ( lutil_atoux( &u, c->argv[ i ], 0 ) != 0 ) {
2080 snprintf( c->cr_msg, sizeof( c->cr_msg),
2081 "unable to parse timeout \"%s\"",
2083 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2087 for ( j = 0; j < SLAP_OP_LAST; j++ ) {
2088 li->li_timeout[ j ] = u;
2094 if ( slap_cf_aux_table_parse( c->argv[ i ], li->li_timeout, timeout_table, "slapd-ldap timeout" ) ) {
2095 snprintf( c->cr_msg, sizeof( c->cr_msg),
2096 "unable to parse timeout \"%s\"",
2098 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2104 case LDAP_BACK_CFG_IDLE_TIMEOUT: {
2107 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2108 snprintf( c->cr_msg, sizeof( c->cr_msg),
2109 "unable to parse idle timeout \"%s\"",
2111 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2114 li->li_idle_timeout = (time_t)t;
2117 case LDAP_BACK_CFG_CONN_TTL: {
2120 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2121 snprintf( c->cr_msg, sizeof( c->cr_msg),
2122 "unable to parse conn ttl\"%s\"",
2124 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2127 li->li_conn_ttl = (time_t)t;
2130 case LDAP_BACK_CFG_NETWORK_TIMEOUT: {
2133 if ( lutil_parse_time( c->argv[ 1 ], &t ) != 0 ) {
2134 snprintf( c->cr_msg, sizeof( c->cr_msg),
2135 "unable to parse network timeout \"%s\"",
2137 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2140 li->li_network_timeout = (time_t)t;
2143 case LDAP_BACK_CFG_VERSION:
2144 if ( c->value_int != 0 && ( c->value_int < LDAP_VERSION_MIN || c->value_int > LDAP_VERSION_MAX ) ) {
2145 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2146 "unsupported version \"%s\" "
2147 "in \"protocol-version <version>\"",
2149 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2153 li->li_version = c->value_int;
2156 case LDAP_BACK_CFG_SINGLECONN:
2157 if ( c->value_int ) {
2158 li->li_flags |= LDAP_BACK_F_SINGLECONN;
2161 li->li_flags &= ~LDAP_BACK_F_SINGLECONN;
2165 case LDAP_BACK_CFG_USETEMP:
2166 if ( c->value_int ) {
2167 li->li_flags |= LDAP_BACK_F_USE_TEMPORARIES;
2170 li->li_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
2174 case LDAP_BACK_CFG_CONNPOOLMAX:
2175 if ( c->value_int < LDAP_BACK_CONN_PRIV_MIN
2176 || c->value_int > LDAP_BACK_CONN_PRIV_MAX )
2178 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2179 "invalid max size " "of privileged "
2180 "connections pool \"%s\" "
2181 "in \"conn-pool-max <n> "
2182 "(must be between %d and %d)\"",
2184 LDAP_BACK_CONN_PRIV_MIN,
2185 LDAP_BACK_CONN_PRIV_MAX );
2186 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2189 li->li_conn_priv_max = c->value_int;
2192 case LDAP_BACK_CFG_CANCEL: {
2195 i = verb_to_mask( c->argv[1], cancel_mode );
2196 if ( BER_BVISNULL( &cancel_mode[i].word ) ) {
2200 mask = cancel_mode[i].mask;
2202 if ( LDAP_BACK_ISOPEN( li )
2203 && mask == LDAP_BACK_F_CANCEL_EXOP_DISCOVER
2204 && !LDAP_BACK_CANCEL( li ) )
2206 slap_bindconf sb = { BER_BVNULL };
2209 if ( li->li_uri == NULL ) {
2210 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2211 "need URI to discover \"cancel\" support "
2212 "in \"cancel exop-discover\"" );
2213 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2217 ber_str2bv( li->li_uri, 0, 0, &sb.sb_uri );
2218 sb.sb_version = li->li_version;
2219 sb.sb_method = LDAP_AUTH_SIMPLE;
2220 BER_BVSTR( &sb.sb_binddn, "" );
2222 rc = slap_discover_feature( &sb,
2223 slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
2225 if ( rc == LDAP_COMPARE_TRUE ) {
2226 mask |= LDAP_BACK_F_CANCEL_EXOP;
2230 li->li_flags &= ~LDAP_BACK_F_CANCEL_MASK2;
2231 li->li_flags |= mask;
2234 case LDAP_BACK_CFG_QUARANTINE:
2235 if ( LDAP_BACK_QUARANTINE( li ) ) {
2236 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2237 "quarantine already defined" );
2238 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2241 rc = slap_retry_info_parse( c->argv[1], &li->li_quarantine,
2242 c->cr_msg, sizeof( c->cr_msg ) );
2244 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2247 ldap_pvt_thread_mutex_init( &li->li_quarantine_mutex );
2248 /* give it a chance to retry if the pattern gets reset
2249 * via back-config */
2250 li->li_isquarantined = 0;
2251 li->li_flags |= LDAP_BACK_F_QUARANTINE;
2255 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
2256 case LDAP_BACK_CFG_ST_REQUEST:
2257 if ( c->value_int ) {
2258 li->li_flags |= LDAP_BACK_F_ST_REQUEST;
2261 li->li_flags &= ~LDAP_BACK_F_ST_REQUEST;
2264 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
2266 case LDAP_BACK_CFG_NOREFS:
2267 if ( c->value_int ) {
2268 li->li_flags |= LDAP_BACK_F_NOREFS;
2271 li->li_flags &= ~LDAP_BACK_F_NOREFS;
2275 case LDAP_BACK_CFG_NOUNDEFFILTER:
2276 if ( c->value_int ) {
2277 li->li_flags |= LDAP_BACK_F_NOUNDEFFILTER;
2280 li->li_flags &= ~LDAP_BACK_F_NOUNDEFFILTER;
2284 case LDAP_BACK_CFG_ONERR:
2286 i = verb_to_mask( c->argv[1], onerr_mode );
2287 if ( BER_BVISNULL( &onerr_mode[i].word ) ) {
2288 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2289 "%s unknown argument \"%s\"",
2290 c->argv[0], c->argv[1] );
2291 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2294 li->li_flags &= ~LDAP_BACK_F_ONERR_STOP;
2295 li->li_flags |= onerr_mode[i].mask;
2298 case LDAP_BACK_CFG_REWRITE:
2299 snprintf( c->cr_msg, sizeof( c->cr_msg ),
2300 "rewrite/remap capabilities have been moved "
2301 "to the \"rwm\" overlay; see slapo-rwm(5) "
2302 "for details (hint: add \"overlay rwm\" "
2303 "and prefix all directives with \"rwm-\")" );
2304 Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 );
2307 case LDAP_BACK_CFG_OMIT_UNKNOWN_SCHEMA:
2308 if ( c->value_int ) {
2309 li->li_flags |= LDAP_BACK_F_OMIT_UNKNOWN_SCHEMA;
2312 li->li_flags &= ~LDAP_BACK_F_OMIT_UNKNOWN_SCHEMA;
2316 case LDAP_BACK_CFG_KEEPALIVE:
2317 slap_keepalive_parse( ber_bvstrdup(c->argv[1]),
2318 &li->li_tls.sb_keepalive, 0, 0, 0);
2322 /* FIXME: try to catch inconsistencies */
2331 ldap_back_init_cf( BackendInfo *bi )
2334 AttributeDescription *ad = NULL;
2337 /* Make sure we don't exceed the bits reserved for userland */
2338 config_check_userland( LDAP_BACK_CFG_LAST );
2340 bi->bi_cf_ocs = ldapocs;
2342 rc = config_register_schema( ldapcfg, ldapocs );
2347 /* setup olcDbAclPasswd and olcDbIDAssertPasswd
2348 * to be base64-encoded when written in LDIF form;
2349 * basically, we don't care if it fails */
2350 rc = slap_str2ad( "olcDbACLPasswd", &ad, &text );
2352 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
2353 "warning, unable to get \"olcDbACLPasswd\" "
2354 "attribute description: %d: %s\n",
2357 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
2358 ad->ad_type->sat_oid );
2362 rc = slap_str2ad( "olcDbIDAssertPasswd", &ad, &text );
2364 Debug( LDAP_DEBUG_ANY, "config_back_initialize: "
2365 "warning, unable to get \"olcDbIDAssertPasswd\" "
2366 "attribute description: %d: %s\n",
2369 (void)ldif_must_b64_encode_register( ad->ad_cname.bv_val,
2370 ad->ad_type->sat_oid );
2377 ldap_pbind_cf_gen( ConfigArgs *c )
2379 slap_overinst *on = (slap_overinst *)c->bi;
2380 void *private = c->be->be_private;
2383 c->be->be_private = on->on_bi.bi_private;
2384 rc = ldap_back_cf_gen( c );
2385 c->be->be_private = private;
2390 ldap_pbind_init_cf( BackendInfo *bi )
2392 bi->bi_cf_ocs = pbindocs;
2394 return config_register_schema( pbindcfg, pbindocs );
2398 ldap_back_exop_whoami(
2402 struct berval *bv = NULL;
2404 if ( op->oq_extended.rs_reqdata != NULL ) {
2405 /* no request data should be provided */
2406 rs->sr_text = "no request data expected";
2407 return rs->sr_err = LDAP_PROTOCOL_ERROR;
2410 Statslog( LDAP_DEBUG_STATS, "%s WHOAMI\n",
2411 op->o_log_prefix, 0, 0, 0, 0 );
2413 rs->sr_err = backend_check_restrictions( op, rs,
2414 (struct berval *)&slap_EXOP_WHOAMI );
2415 if( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err;
2417 /* if auth'd by back-ldap and request is proxied, forward it */
2418 if ( op->o_conn->c_authz_backend
2419 && !strcmp( op->o_conn->c_authz_backend->be_type, "ldap" )
2420 && !dn_match( &op->o_ndn, &op->o_conn->c_ndn ) )
2422 ldapconn_t *lc = NULL;
2423 LDAPControl c, *ctrls[2] = {NULL, NULL};
2425 Operation op2 = *op;
2431 op2.o_ndn = op->o_conn->c_ndn;
2432 if ( !ldap_back_dobind( &lc, &op2, rs, LDAP_BACK_SENDERR ) ) {
2435 c.ldctl_oid = LDAP_CONTROL_PROXY_AUTHZ;
2436 c.ldctl_iscritical = 1;
2437 c.ldctl_value.bv_val = op->o_tmpalloc(
2438 op->o_ndn.bv_len + STRLENOF( "dn:" ) + 1,
2440 c.ldctl_value.bv_len = op->o_ndn.bv_len + 3;
2441 ptr = c.ldctl_value.bv_val;
2442 ptr = lutil_strcopy( ptr, "dn:" );
2443 ptr = lutil_strncopy( ptr, op->o_ndn.bv_val, op->o_ndn.bv_len );
2447 rs->sr_err = ldap_whoami( lc->lc_ld, ctrls, NULL, &msgid );
2448 if ( rs->sr_err == LDAP_SUCCESS ) {
2449 /* by now, make sure no timeout is used (ITS#6282) */
2450 struct timeval tv = { -1, 0 };
2451 if ( ldap_result( lc->lc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) == -1 ) {
2452 ldap_get_option( lc->lc_ld, LDAP_OPT_ERROR_NUMBER,
2454 if ( rs->sr_err == LDAP_SERVER_DOWN && doretry ) {
2456 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
2462 /* NOTE: are we sure "bv" will be malloc'ed
2463 * with the appropriate memory? */
2464 rs->sr_err = ldap_parse_whoami( lc->lc_ld, res, &bv );
2468 op->o_tmpfree( c.ldctl_value.bv_val, op->o_tmpmemctx );
2469 if ( rs->sr_err != LDAP_SUCCESS ) {
2470 rs->sr_err = slap_map_api2result( rs );
2474 ldap_back_release_conn( (ldapinfo_t *)op2.o_bd->be_private, lc );
2478 /* else just do the same as before */
2479 bv = (struct berval *) ch_malloc( sizeof( struct berval ) );
2480 if ( !BER_BVISEMPTY( &op->o_dn ) ) {
2481 bv->bv_len = op->o_dn.bv_len + STRLENOF( "dn:" );
2482 bv->bv_val = ch_malloc( bv->bv_len + 1 );
2483 AC_MEMCPY( bv->bv_val, "dn:", STRLENOF( "dn:" ) );
2484 AC_MEMCPY( &bv->bv_val[ STRLENOF( "dn:" ) ], op->o_dn.bv_val,
2486 bv->bv_val[ bv->bv_len ] = '\0';
2494 rs->sr_rspdata = bv;