2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2007 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/string.h>
28 #include <ac/socket.h>
32 #include "../back-ldap/back-ldap.h"
33 #undef ldap_debug /* silence a warning in ldap-int.h */
34 #include "../../../libraries/libldap/ldap-int.h"
35 #include "back-meta.h"
46 mt = ch_calloc( sizeof( metatarget_t ), 1 );
48 mt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
49 if ( mt->mt_rwmap.rwm_rw == NULL ) {
55 * the filter rewrite as a string must be disabled
56 * by default; it can be re-enabled by adding rules;
57 * this creates an empty rewriteContext
59 rargv[ 0 ] = "rewriteContext";
60 rargv[ 1 ] = "searchFilter";
62 rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
64 rargv[ 0 ] = "rewriteContext";
65 rargv[ 1 ] = "default";
67 rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
69 ldap_pvt_thread_mutex_init( &mt->mt_uri_mutex );
71 mt->mt_idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
72 mt->mt_idassert_authmethod = LDAP_AUTH_NONE;
73 mt->mt_idassert_tls = SB_TLS_DEFAULT;
75 /* by default, use proxyAuthz control on each operation */
76 mt->mt_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
84 check_true_false( char *str )
86 if ( strcasecmp( str, "true" ) == 0 || strcasecmp( str, "yes" ) == 0 ) {
90 if ( strcasecmp( str, "false" ) == 0 || strcasecmp( str, "no" ) == 0 ) {
107 metainfo_t *mi = ( metainfo_t * )be->be_private;
109 assert( mi != NULL );
111 /* URI of server to query */
112 if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
113 int i = mi->mi_ntargets;
116 #endif /* uncomment if uri MUST be a branch of suffix */
117 LDAPURLDesc *ludp, *tmpludp;
126 Debug( LDAP_DEBUG_ANY,
127 "%s: line %d: missing URI "
128 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
136 Debug( LDAP_DEBUG_ANY,
137 "%s: line %d: too many args "
138 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
143 if ( be->be_nsuffix == NULL ) {
144 Debug( LDAP_DEBUG_ANY,
145 "%s: line %d: the suffix must be defined before any target.\n",
152 mi->mi_targets = ( metatarget_t ** )ch_realloc( mi->mi_targets,
153 sizeof( metatarget_t * ) * mi->mi_ntargets );
154 if ( mi->mi_targets == NULL ) {
155 Debug( LDAP_DEBUG_ANY,
156 "%s: line %d: out of memory while storing server name"
157 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
162 if ( meta_back_new_target( &mi->mi_targets[ i ] ) != 0 ) {
163 Debug( LDAP_DEBUG_ANY,
164 "%s: line %d: unable to init server"
165 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
170 mt = mi->mi_targets[ i ];
172 mt->mt_rebind_f = mi->mi_rebind_f;
173 mt->mt_urllist_p = mt;
175 mt->mt_nretries = mi->mi_nretries;
176 mt->mt_quarantine = mi->mi_quarantine;
177 if ( META_BACK_QUARANTINE( mi ) ) {
178 ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
180 mt->mt_flags = mi->mi_flags;
181 mt->mt_version = mi->mi_version;
182 mt->mt_network_timeout = mi->mi_network_timeout;
183 mt->mt_bind_timeout = mi->mi_bind_timeout;
184 for ( c = 0; c < SLAP_OP_LAST; c++ ) {
185 mt->mt_timeout[ c ] = mi->mi_timeout[ c ];
191 if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t" ) != LDAP_SUCCESS )
193 Debug( LDAP_DEBUG_ANY,
194 "%s: line %d: unable to parse URI"
195 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
201 * uri MUST have the <dn> part!
203 if ( ludp->lud_dn == NULL ) {
204 Debug( LDAP_DEBUG_ANY,
205 "%s: line %d: missing <naming context> "
206 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
210 } else if ( ludp->lud_dn[ 0 ] == '\0' ) {
213 for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) {
214 if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) {
219 if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) {
220 Debug( LDAP_DEBUG_ANY,
221 "%s: line %d: missing <naming context> "
222 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
229 * copies and stores uri and suffix
231 ber_str2bv( ludp->lud_dn, 0, 0, &dn );
232 rc = dnPrettyNormal( NULL, &dn, &mt->mt_psuffix,
233 &mt->mt_nsuffix, NULL );
234 if( rc != LDAP_SUCCESS ) {
235 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
236 "target \"%s\" DN is invalid\n",
237 fname, lineno, argv[ 1 ] );
241 ludp->lud_dn[ 0 ] = '\0';
243 switch ( ludp->lud_scope ) {
244 case LDAP_SCOPE_DEFAULT:
245 mt->mt_scope = LDAP_SCOPE_SUBTREE;
248 case LDAP_SCOPE_SUBTREE:
249 case LDAP_SCOPE_SUBORDINATE:
250 mt->mt_scope = ludp->lud_scope;
254 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
255 "invalid scope for target \"%s\"\n",
256 fname, lineno, argv[ 1 ] );
260 /* check all, to apply the scope check on the first one */
261 for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) {
262 if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) {
263 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
264 "multiple URIs must have "
272 mt->mt_uri = ldap_url_list2urls( ludp );
273 ldap_free_urllist( ludp );
274 if ( mt->mt_uri == NULL) {
275 Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n",
281 * uri MUST be a branch of suffix!
283 #if 0 /* too strict a constraint */
284 if ( select_backend( &mt->mt_nsuffix, 0, 0 ) != be ) {
285 Debug( LDAP_DEBUG_ANY,
286 "%s: line %d: <naming context> of URI does not refer to current backend"
287 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
293 * uri MUST be a branch of a suffix!
295 if ( select_backend( &mt->mt_nsuffix, 0, 0 ) == NULL ) {
296 Debug( LDAP_DEBUG_ANY,
297 "%s: line %d: <naming context> of URI does not resolve to a backend"
298 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
304 /* subtree-exclude */
305 } else if ( strcasecmp( argv[ 0 ], "subtree-exclude" ) == 0 ) {
306 int i = mi->mi_ntargets - 1;
307 struct berval dn, ndn;
310 Debug( LDAP_DEBUG_ANY,
311 "%s: line %d: need \"uri\" directive first\n",
318 Debug( LDAP_DEBUG_ANY,
319 "%s: line %d: missing DN in \"subtree-exclude <DN>\" line\n",
327 Debug( LDAP_DEBUG_ANY,
328 "%s: line %d: too many args in \"subtree-exclude <DN>\" line\n",
333 ber_str2bv( argv[ 1 ], 0, 0, &dn );
334 if ( dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL )
337 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
338 "subtree-exclude DN=\"%s\" is invalid\n",
339 fname, lineno, argv[ 1 ] );
343 if ( !dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_nsuffix ) ) {
344 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
345 "subtree-exclude DN=\"%s\" "
346 "must be subtree of target\n",
347 fname, lineno, argv[ 1 ] );
348 ber_memfree( ndn.bv_val );
352 if ( mi->mi_targets[ i ]->mt_subtree_exclude != NULL ) {
355 for ( j = 0; !BER_BVISNULL( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ); j++ )
357 if ( dnIsSuffix( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ], &ndn ) ) {
358 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
359 "subtree-exclude DN=\"%s\" "
360 "is suffix of another subtree-exclude\n",
361 fname, lineno, argv[ 1 ] );
362 /* reject, because it might be superior
363 * to more than one subtree-exclude */
364 ber_memfree( ndn.bv_val );
367 } else if ( dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ) ) {
368 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
369 "another subtree-exclude is suffix of "
370 "subtree-exclude DN=\"%s\"\n",
371 fname, lineno, argv[ 1 ] );
372 ber_memfree( ndn.bv_val );
378 ber_bvarray_add( &mi->mi_targets[ i ]->mt_subtree_exclude, &ndn );
380 /* default target directive */
381 } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
382 int i = mi->mi_ntargets - 1;
386 Debug( LDAP_DEBUG_ANY,
387 "%s: line %d: \"default-target\" alone need be"
388 " inside a \"uri\" directive\n",
392 mi->mi_defaulttarget = i;
395 if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
397 Debug( LDAP_DEBUG_ANY,
398 "%s: line %d: \"default-target none\""
399 " should go before uri definitions\n",
402 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
406 if ( lutil_atoi( &mi->mi_defaulttarget, argv[ 1 ] ) != 0
407 || mi->mi_defaulttarget < 0
408 || mi->mi_defaulttarget >= i - 1 )
410 Debug( LDAP_DEBUG_ANY,
411 "%s: line %d: illegal target number %d\n",
412 fname, lineno, mi->mi_defaulttarget );
418 /* ttl of dn cache */
419 } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
421 Debug( LDAP_DEBUG_ANY,
422 "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
427 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
428 mi->mi_cache.ttl = META_DNCACHE_FOREVER;
430 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
431 mi->mi_cache.ttl = META_DNCACHE_DISABLED;
436 if ( lutil_parse_time( argv[ 1 ], &t ) != 0 ) {
437 Debug( LDAP_DEBUG_ANY,
438 "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
439 fname, lineno, argv[ 1 ] );
442 mi->mi_cache.ttl = (time_t)t;
445 /* network timeout when connecting to ldap servers */
446 } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
448 time_t *tp = mi->mi_ntargets ?
449 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_network_timeout
450 : &mi->mi_network_timeout;
453 Debug( LDAP_DEBUG_ANY,
454 "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
459 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
460 Debug( LDAP_DEBUG_ANY,
461 "%s: line %d: unable to parse timeout \"%s\" in \"network-timeout <seconds>\" line\n",
462 fname, lineno, argv[ 1 ] );
469 /* idle timeout when connecting to ldap servers */
470 } else if ( strcasecmp( argv[ 0 ], "idle-timeout" ) == 0 ) {
475 Debug( LDAP_DEBUG_ANY,
476 "%s: line %d: missing timeout value in \"idle-timeout <seconds>\" line\n",
482 Debug( LDAP_DEBUG_ANY,
483 "%s: line %d: extra cruft after timeout value in \"idle-timeout <seconds>\" line\n",
488 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
489 Debug( LDAP_DEBUG_ANY,
490 "%s: line %d: unable to parse timeout \"%s\" in \"idle-timeout <seconds>\" line\n",
491 fname, lineno, argv[ 1 ] );
496 mi->mi_idle_timeout = (time_t)t;
499 } else if ( strcasecmp( argv[ 0 ], "conn-ttl" ) == 0 ) {
504 Debug( LDAP_DEBUG_ANY,
505 "%s: line %d: missing ttl value in \"conn-ttl <seconds>\" line\n",
511 Debug( LDAP_DEBUG_ANY,
512 "%s: line %d: extra cruft after ttl value in \"conn-ttl <seconds>\" line\n",
517 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
518 Debug( LDAP_DEBUG_ANY,
519 "%s: line %d: unable to parse ttl \"%s\" in \"conn-ttl <seconds>\" line\n",
520 fname, lineno, argv[ 1 ] );
525 mi->mi_conn_ttl = (time_t)t;
527 /* bind timeout when connecting to ldap servers */
528 } else if ( strcasecmp( argv[ 0 ], "bind-timeout" ) == 0 ) {
530 struct timeval *tp = mi->mi_ntargets ?
531 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_bind_timeout
532 : &mi->mi_bind_timeout;
536 Debug( LDAP_DEBUG_ANY,
537 "%s: line %d: missing timeout value in \"bind-timeout <microseconds>\" line\n",
543 Debug( LDAP_DEBUG_ANY,
544 "%s: line %d: extra cruft after timeout value in \"bind-timeout <microseconds>\" line\n",
549 if ( lutil_atoul( &t, argv[ 1 ] ) != 0 ) {
550 Debug( LDAP_DEBUG_ANY,
551 "%s: line %d: unable to parse timeout \"%s\" in \"bind-timeout <microseconds>\" line\n",
552 fname, lineno, argv[ 1 ] );
557 tp->tv_sec = t/1000000;
558 tp->tv_usec = t%1000000;
560 /* name to use for meta_back_group */
561 } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
562 || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
564 int i = mi->mi_ntargets - 1;
568 Debug( LDAP_DEBUG_ANY,
569 "%s: line %d: need \"uri\" directive first\n",
575 Debug( LDAP_DEBUG_ANY,
576 "%s: line %d: missing name in \"binddn <name>\" line\n",
581 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
582 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
583 "\"binddn\" statement is deprecated; "
584 "use \"acl-authcDN\" instead\n",
586 /* FIXME: some day we'll need to throw an error */
589 ber_str2bv( argv[ 1 ], 0, 0, &dn );
590 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ]->mt_binddn,
591 NULL ) != LDAP_SUCCESS )
593 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
594 "bind DN '%s' is invalid\n",
595 fname, lineno, argv[ 1 ] );
599 /* password to use for meta_back_group */
600 } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
601 || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
603 int i = mi->mi_ntargets - 1;
606 Debug( LDAP_DEBUG_ANY,
607 "%s: line %d: need \"uri\" directive first\n",
613 Debug( LDAP_DEBUG_ANY,
614 "%s: line %d: missing password in \"bindpw <password>\" line\n",
619 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
620 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
621 "\"bindpw\" statement is deprecated; "
622 "use \"acl-passwd\" instead\n",
624 /* FIXME: some day we'll need to throw an error */
627 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ]->mt_bindpw );
629 /* save bind creds for referral rebinds? */
630 } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
632 Debug( LDAP_DEBUG_ANY,
633 "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
639 Debug( LDAP_DEBUG_ANY,
640 "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
642 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
645 switch ( check_true_false( argv[ 1 ] ) ) {
647 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
651 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
655 Debug( LDAP_DEBUG_ANY,
656 "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
657 fname, lineno, argv[ 1 ] );
662 } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
663 unsigned *flagsp = mi->mi_ntargets ?
664 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
668 Debug( LDAP_DEBUG_ANY,
669 "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
674 /* this is the default; we add it because the default might change... */
675 switch ( check_true_false( argv[ 1 ] ) ) {
677 *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
681 *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
685 Debug( LDAP_DEBUG_ANY,
686 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
687 fname, lineno, argv[ 1 ] );
691 } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
692 unsigned *flagsp = mi->mi_ntargets ?
693 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
697 Debug( LDAP_DEBUG_ANY,
698 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
704 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
705 *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
708 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
709 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
710 *flagsp |= LDAP_BACK_F_USE_TLS;
712 /* propagate start tls */
713 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
714 *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
717 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
718 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
719 *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
722 Debug( LDAP_DEBUG_ANY,
723 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
724 fname, lineno, argv[ 1 ] );
728 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
729 unsigned *flagsp = mi->mi_ntargets ?
730 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
734 Debug( LDAP_DEBUG_ANY,
735 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
740 switch ( check_true_false( argv[ 1 ] ) ) {
742 *flagsp &= ~LDAP_BACK_F_T_F_MASK2;
746 *flagsp |= LDAP_BACK_F_T_F;
750 if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
751 *flagsp |= LDAP_BACK_F_T_F_DISCOVER;
754 Debug( LDAP_DEBUG_ANY,
755 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
756 fname, lineno, argv[ 1 ] );
763 } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
765 Debug( LDAP_DEBUG_ANY,
766 "%s: line %d: \"onerr {CONTINUE|report|stop}\" takes 1 argument\n",
771 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
772 mi->mi_flags &= ~META_BACK_F_ONERR_MASK;
774 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
775 mi->mi_flags |= META_BACK_F_ONERR_STOP;
777 } else if ( strcasecmp( argv[ 1 ], "report" ) == 0 ) {
778 mi->mi_flags |= META_BACK_F_ONERR_REPORT;
781 Debug( LDAP_DEBUG_ANY,
782 "%s: line %d: \"onerr {CONTINUE|report|stop}\": invalid arg \"%s\".\n",
783 fname, lineno, argv[ 1 ] );
788 } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0
789 || strcasecmp( argv[ 0 ], "root-bind-defer" ) == 0 )
792 Debug( LDAP_DEBUG_ANY,
793 "%s: line %d: \"[pseudo]root-bind-defer {FALSE|true}\" takes 1 argument\n",
798 switch ( check_true_false( argv[ 1 ] ) ) {
800 mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
804 mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
808 Debug( LDAP_DEBUG_ANY,
809 "%s: line %d: \"[pseudo]root-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
810 fname, lineno, argv[ 1 ] );
815 } else if ( strcasecmp( argv[ 0 ], "single-conn" ) == 0 ) {
817 Debug( LDAP_DEBUG_ANY,
818 "%s: line %d: \"single-conn {FALSE|true}\" takes 1 argument\n",
823 if ( mi->mi_ntargets > 0 ) {
824 Debug( LDAP_DEBUG_ANY,
825 "%s: line %d: \"single-conn\" must appear before target definitions\n",
830 switch ( check_true_false( argv[ 1 ] ) ) {
832 mi->mi_flags &= ~LDAP_BACK_F_SINGLECONN;
836 mi->mi_flags |= LDAP_BACK_F_SINGLECONN;
840 Debug( LDAP_DEBUG_ANY,
841 "%s: line %d: \"single-conn {FALSE|true}\": invalid arg \"%s\".\n",
842 fname, lineno, argv[ 1 ] );
846 /* use-temporaries? */
847 } else if ( strcasecmp( argv[ 0 ], "use-temporary-conn" ) == 0 ) {
849 Debug( LDAP_DEBUG_ANY,
850 "%s: line %d: \"use-temporary-conn {FALSE|true}\" takes 1 argument\n",
855 if ( mi->mi_ntargets > 0 ) {
856 Debug( LDAP_DEBUG_ANY,
857 "%s: line %d: \"use-temporary-conn\" must appear before target definitions\n",
862 switch ( check_true_false( argv[ 1 ] ) ) {
864 mi->mi_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
868 mi->mi_flags |= LDAP_BACK_F_USE_TEMPORARIES;
872 Debug( LDAP_DEBUG_ANY,
873 "%s: line %d: \"use-temporary-conn {FALSE|true}\": invalid arg \"%s\".\n",
874 fname, lineno, argv[ 1 ] );
878 /* privileged connections pool max size ? */
879 } else if ( strcasecmp( argv[ 0 ], "conn-pool-max" ) == 0 ) {
881 Debug( LDAP_DEBUG_ANY,
882 "%s: line %d: \"conn-pool-max <n>\" takes 1 argument\n",
887 if ( mi->mi_ntargets > 0 ) {
888 Debug( LDAP_DEBUG_ANY,
889 "%s: line %d: \"conn-pool-max\" must appear before target definitions\n",
894 if ( lutil_atoi( &mi->mi_conn_priv_max, argv[1] )
895 || mi->mi_conn_priv_max < LDAP_BACK_CONN_PRIV_MIN
896 || mi->mi_conn_priv_max > LDAP_BACK_CONN_PRIV_MAX )
898 Debug( LDAP_DEBUG_ANY,
899 "%s: line %d: \"conn-pool-max <n>\": invalid arg \"%s\".\n",
900 fname, lineno, argv[ 1 ] );
904 } else if ( strcasecmp( argv[ 0 ], "cancel" ) == 0 ) {
906 unsigned *flagsp = mi->mi_ntargets ?
907 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
911 Debug( LDAP_DEBUG_ANY,
912 "%s: line %d: \"cancel {abandon|ignore|exop}\" takes 1 argument\n",
917 if ( strcasecmp( argv[ 1 ], "abandon" ) == 0 ) {
918 flag = LDAP_BACK_F_CANCEL_ABANDON;
920 #if 0 /* needs ldap_int_discard(), 2.4 */
921 } else if ( strcasecmp( argv[ 1 ], "ignore" ) == 0 ) {
922 flag = LDAP_BACK_F_CANCEL_IGNORE;
925 } else if ( strcasecmp( argv[ 1 ], "exop" ) == 0 ) {
926 flag = LDAP_BACK_F_CANCEL_EXOP;
928 } else if ( strcasecmp( argv[ 1 ], "exop-discover" ) == 0 ) {
929 flag = LDAP_BACK_F_CANCEL_EXOP_DISCOVER;
932 Debug( LDAP_DEBUG_ANY,
933 "%s: line %d: \"cancel {abandon|ignore|exop[-discover]}\": unknown mode \"%s\" \n",
934 fname, lineno, argv[ 1 ] );
938 *flagsp &= ~LDAP_BACK_F_CANCEL_MASK2;
941 } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
943 time_t *tv = mi->mi_ntargets ?
944 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_timeout
949 Debug( LDAP_DEBUG_ANY,
950 "%s: line %d: \"timeout [{add|bind|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
955 for ( c = 1; c < argc; c++ ) {
959 sep = strchr( argv[ c ], '=' );
961 size_t len = sep - argv[ c ];
963 if ( strncasecmp( argv[ c ], "bind", len ) == 0 ) {
964 t = &tv[ SLAP_OP_BIND ];
965 /* unbind makes little sense */
966 } else if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
967 t = &tv[ SLAP_OP_ADD ];
968 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
969 t = &tv[ SLAP_OP_DELETE ];
970 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
971 t = &tv[ SLAP_OP_MODRDN ];
972 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
973 t = &tv[ SLAP_OP_MODIFY ];
974 } else if ( strncasecmp( argv[ c ], "compare", len ) == 0 ) {
975 t = &tv[ SLAP_OP_COMPARE ];
976 } else if ( strncasecmp( argv[ c ], "search", len ) == 0 ) {
977 t = &tv[ SLAP_OP_SEARCH ];
978 /* abandon makes little sense */
979 #if 0 /* not implemented yet */
980 } else if ( strncasecmp( argv[ c ], "extended", len ) == 0 ) {
981 t = &tv[ SLAP_OP_EXTENDED ];
984 char buf[ SLAP_TEXT_BUFLEN ];
985 snprintf( buf, sizeof( buf ),
986 "unknown/unhandled operation \"%s\" for timeout #%d",
988 Debug( LDAP_DEBUG_ANY,
989 "%s: line %d: %s.\n",
990 fname, lineno, buf );
999 if ( lutil_parse_time( sep, &val ) != 0 ) {
1000 Debug( LDAP_DEBUG_ANY,
1001 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
1002 fname, lineno, sep );
1012 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1013 tv[ i ] = (time_t)val;
1018 /* name to use as pseudo-root dn */
1019 } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
1020 int i = mi->mi_ntargets - 1;
1023 Debug( LDAP_DEBUG_ANY,
1024 "%s: line %d: need \"uri\" directive first\n",
1030 Debug( LDAP_DEBUG_ANY,
1031 "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
1037 * exact replacement:
1040 idassert-bind bindmethod=simple
1041 binddn=<pseudorootdn>
1042 credentials=<pseudorootpw>
1044 flags=non-prescriptive
1045 idassert-authzFrom "dn:<rootdn>"
1047 * so that only when authc'd as <rootdn> the proxying occurs
1048 * rebinding as the <pseudorootdn> without proxyAuthz.
1051 Debug( LDAP_DEBUG_ANY,
1052 "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1053 "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1057 char binddn[ SLAP_TEXT_BUFLEN ];
1060 "bindmethod=simple",
1063 "flags=non-prescriptive",
1069 if ( BER_BVISNULL( &be->be_rootndn ) ) {
1070 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"rootdn\" must be defined first.\n",
1075 if ( snprintf( binddn, sizeof( binddn ), "binddn=%s", argv[ 1 ] ) >= sizeof( binddn ) ) {
1076 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootdn\" too long.\n",
1080 cargv[ 2 ] = binddn;
1082 rc = slap_idassert_parse_cf( fname, lineno, cargc, cargv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1086 if ( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz != NULL ) {
1087 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"idassert-authzFrom\" already defined (discarded).\n",
1089 ber_bvarray_free( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz );
1090 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz = NULL;
1093 assert( !BER_BVISNULL( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authcDN ) );
1095 bv.bv_len = STRLENOF( "dn:" ) + be->be_rootndn.bv_len;
1096 bv.bv_val = ber_memalloc( bv.bv_len + 1 );
1097 AC_MEMCPY( bv.bv_val, "dn:", STRLENOF( "dn:" ) );
1098 AC_MEMCPY( &bv.bv_val[ STRLENOF( "dn:" ) ], be->be_rootndn.bv_val, be->be_rootndn.bv_len + 1 );
1100 ber_bvarray_add( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz, &bv );
1106 /* password to use as pseudo-root */
1107 } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
1108 int i = mi->mi_ntargets - 1;
1111 Debug( LDAP_DEBUG_ANY,
1112 "%s: line %d: need \"uri\" directive first\n",
1118 Debug( LDAP_DEBUG_ANY,
1119 "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
1124 Debug( LDAP_DEBUG_ANY,
1125 "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1126 "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1129 if ( BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_authcDN ) ) {
1130 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"pseudorootdn\" must be defined first.\n",
1135 if ( !BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_passwd ) ) {
1136 memset( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val, 0,
1137 mi->mi_targets[ i ]->mt_idassert_passwd.bv_len );
1138 ber_memfree( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val );
1140 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_targets[ i ]->mt_idassert_passwd );
1143 } else if ( strcasecmp( argv[ 0 ], "idassert-bind" ) == 0 ) {
1144 if ( mi->mi_ntargets == 0 ) {
1145 Debug( LDAP_DEBUG_ANY,
1146 "%s: line %d: \"idassert-bind\" "
1147 "must appear inside a target specification.\n",
1152 return slap_idassert_parse_cf( fname, lineno, argc, argv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1154 /* idassert-authzFrom */
1155 } else if ( strcasecmp( argv[ 0 ], "idassert-authzFrom" ) == 0 ) {
1156 if ( mi->mi_ntargets == 0 ) {
1157 Debug( LDAP_DEBUG_ANY,
1158 "%s: line %d: \"idassert-bind\" "
1159 "must appear inside a target specification.\n",
1169 Debug( LDAP_DEBUG_ANY,
1170 "%s: line %d: missing <id> in \"idassert-authzFrom <id>\".\n",
1175 Debug( LDAP_DEBUG_ANY,
1176 "%s: line %d: extra cruft after <id> in \"idassert-authzFrom <id>\".\n",
1181 return slap_idassert_authzfrom_parse_cf( fname, lineno, argv[ 1 ], &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1184 } else if ( strcasecmp( argv[ 0 ], "quarantine" ) == 0 ) {
1185 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1186 slap_retry_info_t *ri = mi->mi_ntargets ?
1187 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine
1188 : &mi->mi_quarantine;
1190 if ( ( mi->mi_ntargets == 0 && META_BACK_QUARANTINE( mi ) )
1191 || ( mi->mi_ntargets > 0 && META_BACK_TGT_QUARANTINE( mi->mi_targets[ mi->mi_ntargets - 1 ] ) ) )
1193 Debug( LDAP_DEBUG_ANY,
1194 "%s: line %d: quarantine already defined.\n",
1204 Debug( LDAP_DEBUG_ANY,
1205 "%s: line %d: missing arg in \"quarantine <pattern list>\".\n",
1210 Debug( LDAP_DEBUG_ANY,
1211 "%s: line %d: extra cruft after \"quarantine <pattern list>\".\n",
1216 if ( ri != &mi->mi_quarantine ) {
1217 ri->ri_interval = NULL;
1221 if ( mi->mi_ntargets > 0 && !META_BACK_QUARANTINE( mi ) ) {
1222 ldap_pvt_thread_mutex_init( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine_mutex );
1225 if ( slap_retry_info_parse( argv[ 1 ], ri, buf, sizeof( buf ) ) ) {
1226 Debug( LDAP_DEBUG_ANY,
1227 "%s line %d: %s.\n",
1228 fname, lineno, buf );
1232 if ( mi->mi_ntargets ) {
1233 mi->mi_flags |= LDAP_BACK_F_QUARANTINE;
1236 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags |= LDAP_BACK_F_QUARANTINE;
1240 } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
1242 int i = mi->mi_ntargets - 1, rc;
1243 struct berval dn, nvnc, pvnc, nrnc, prnc;
1246 Debug( LDAP_DEBUG_ANY,
1247 "%s: line %d: need \"uri\" directive first\n",
1255 * suffixmassage <suffix> <massaged suffix>
1257 * the <suffix> field must be defined as a valid suffix
1258 * (or suffixAlias?) for the current database;
1259 * the <massaged suffix> shouldn't have already been
1260 * defined as a valid suffix or suffixAlias for the
1264 Debug( LDAP_DEBUG_ANY,
1265 "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
1270 ber_str2bv( argv[ 1 ], 0, 0, &dn );
1271 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1272 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1273 "suffix '%s' is invalid\n",
1274 fname, lineno, argv[ 1 ] );
1278 tmp_be = select_backend( &nvnc, 0, 0 );
1279 if ( tmp_be != NULL && tmp_be != be ) {
1280 Debug( LDAP_DEBUG_ANY,
1281 "%s: line %d: suffix already in use by another backend in"
1282 " \"suffixMassage <suffix> <massaged suffix>\"\n",
1284 free( pvnc.bv_val );
1285 free( nvnc.bv_val );
1289 ber_str2bv( argv[ 2 ], 0, 0, &dn );
1290 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1291 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1292 "massaged suffix '%s' is invalid\n",
1293 fname, lineno, argv[ 2 ] );
1294 free( pvnc.bv_val );
1295 free( nvnc.bv_val );
1300 tmp_be = select_backend( &nrnc, 0, 0 );
1301 if ( tmp_be != NULL ) {
1302 Debug( LDAP_DEBUG_ANY,
1303 "%s: line %d: massaged suffix already in use by another backend in"
1304 " \"suffixMassage <suffix> <massaged suffix>\"\n",
1306 free( pvnc.bv_val );
1307 free( nvnc.bv_val );
1308 free( prnc.bv_val );
1309 free( nrnc.bv_val );
1315 * The suffix massaging is emulated by means of the
1316 * rewrite capabilities
1317 * FIXME: no extra rewrite capabilities should be added
1320 rc = suffix_massage_config( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1321 &pvnc, &nvnc, &prnc, &nrnc );
1323 free( pvnc.bv_val );
1324 free( nvnc.bv_val );
1325 free( prnc.bv_val );
1326 free( nrnc.bv_val );
1330 /* rewrite stuff ... */
1331 } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
1332 int i = mi->mi_ntargets - 1;
1335 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"rewrite\" "
1336 "statement outside target definition.\n",
1341 return rewrite_parse( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1342 fname, lineno, argc, argv );
1344 /* objectclass/attribute mapping */
1345 } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
1346 int i = mi->mi_ntargets - 1;
1349 Debug( LDAP_DEBUG_ANY,
1350 "%s: line %d: need \"uri\" directive first\n",
1355 return ldap_back_map_config( &mi->mi_targets[ i ]->mt_rwmap.rwm_oc,
1356 &mi->mi_targets[ i ]->mt_rwmap.rwm_at,
1357 fname, lineno, argc, argv );
1359 } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
1360 int i = mi->mi_ntargets - 1;
1361 int nretries = META_RETRY_UNDEFINED;
1364 Debug( LDAP_DEBUG_ANY,
1365 "%s: line %d: need value in \"nretries <value>\"\n",
1370 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
1371 nretries = META_RETRY_FOREVER;
1373 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
1374 nretries = META_RETRY_NEVER;
1377 if ( lutil_atoi( &nretries, argv[ 1 ] ) != 0 ) {
1378 Debug( LDAP_DEBUG_ANY,
1379 "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
1380 fname, lineno, argv[ 1 ] );
1386 mi->mi_nretries = nretries;
1389 mi->mi_targets[ i ]->mt_nretries = nretries;
1392 } else if ( strcasecmp( argv[ 0 ], "protocol-version" ) == 0 ) {
1393 int *version = mi->mi_ntargets ?
1394 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_version
1398 Debug( LDAP_DEBUG_ANY,
1399 "%s: line %d: need value in \"protocol-version <version>\"\n",
1404 if ( lutil_atoi( version, argv[ 1 ] ) != 0 ) {
1405 Debug( LDAP_DEBUG_ANY,
1406 "%s: line %d: unable to parse version \"%s\" in \"protocol-version <version>\"\n",
1407 fname, lineno, argv[ 1 ] );
1411 if ( *version != 0 && ( *version < LDAP_VERSION_MIN || *version > LDAP_VERSION_MAX ) ) {
1412 Debug( LDAP_DEBUG_ANY,
1413 "%s: line %d: unsupported version \"%s\" in \"protocol-version <version>\"\n",
1414 fname, lineno, argv[ 1 ] );
1420 return SLAP_CONF_UNKNOWN;
1426 ldap_back_map_config(
1427 struct ldapmap *oc_map,
1428 struct ldapmap *at_map,
1434 struct ldapmap *map;
1435 struct ldapmapping *mapping;
1439 if ( argc < 3 || argc > 4 ) {
1440 Debug( LDAP_DEBUG_ANY,
1441 "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
1446 if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
1450 } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
1454 Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is "
1455 "\"map {objectclass | attribute} [<local> | *] "
1456 "{<foreign> | *}\"\n",
1461 if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
1462 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
1463 map->drop_missing = ( argc < 4 );
1464 goto success_return;
1466 src = dst = argv[ 3 ];
1468 } else if ( argc < 4 ) {
1474 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
1477 if ( ( map == at_map )
1478 && ( strcasecmp( src, "objectclass" ) == 0
1479 || strcasecmp( dst, "objectclass" ) == 0 ) )
1481 Debug( LDAP_DEBUG_ANY,
1482 "%s: line %d: objectclass attribute cannot be mapped\n",
1486 mapping = (struct ldapmapping *)ch_calloc( 2,
1487 sizeof(struct ldapmapping) );
1488 if ( mapping == NULL ) {
1489 Debug( LDAP_DEBUG_ANY,
1490 "%s: line %d: out of memory\n",
1494 ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
1495 ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
1496 mapping[ 1 ].src = mapping[ 0 ].dst;
1497 mapping[ 1 ].dst = mapping[ 0 ].src;
1503 if ( src[ 0 ] != '\0' ) {
1504 if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
1505 Debug( LDAP_DEBUG_ANY,
1506 "%s: line %d: warning, source objectClass '%s' "
1507 "should be defined in schema\n",
1508 fname, lineno, src );
1511 * FIXME: this should become an err
1517 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
1518 Debug( LDAP_DEBUG_ANY,
1519 "%s: line %d: warning, destination objectClass '%s' "
1520 "is not defined in schema\n",
1521 fname, lineno, dst );
1525 const char *text = NULL;
1526 AttributeDescription *ad = NULL;
1528 if ( src[ 0 ] != '\0' ) {
1529 rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
1530 if ( rc != LDAP_SUCCESS ) {
1531 Debug( LDAP_DEBUG_ANY,
1532 "%s: line %d: warning, source attributeType '%s' "
1533 "should be defined in schema\n",
1534 fname, lineno, src );
1537 * FIXME: this should become an err
1540 * we create a fake "proxied" ad
1544 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1545 &ad, &text, SLAP_AD_PROXIED );
1546 if ( rc != LDAP_SUCCESS ) {
1547 char buf[ SLAP_TEXT_BUFLEN ];
1549 snprintf( buf, sizeof( buf ),
1550 "source attributeType \"%s\": %d (%s)",
1551 src, rc, text ? text : "" );
1552 Debug( LDAP_DEBUG_ANY,
1553 "%s: line %d: %s\n",
1554 fname, lineno, buf );
1562 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1563 if ( rc != LDAP_SUCCESS ) {
1564 Debug( LDAP_DEBUG_ANY,
1565 "%s: line %d: warning, destination attributeType '%s' "
1566 "is not defined in schema\n",
1567 fname, lineno, dst );
1570 * we create a fake "proxied" ad
1574 rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1575 &ad, &text, SLAP_AD_PROXIED );
1576 if ( rc != LDAP_SUCCESS ) {
1577 char buf[ SLAP_TEXT_BUFLEN ];
1579 snprintf( buf, sizeof( buf ),
1580 "source attributeType \"%s\": %d (%s)\n",
1581 dst, rc, text ? text : "" );
1582 Debug( LDAP_DEBUG_ANY,
1583 "%s: line %d: %s\n",
1584 fname, lineno, buf );
1590 if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1591 || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1593 Debug( LDAP_DEBUG_ANY,
1594 "%s: line %d: duplicate mapping found.\n",
1599 if ( src[ 0 ] != '\0' ) {
1600 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1601 mapping_cmp, mapping_dup );
1603 avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1604 mapping_cmp, mapping_dup );
1607 if ( !is_oc && map->map == NULL ) {
1608 /* only init if required */
1609 ldap_back_map_init( map, &mapping );
1616 ch_free( mapping[ 0 ].src.bv_val );
1617 ch_free( mapping[ 0 ].dst.bv_val );
1625 #ifdef ENABLE_REWRITE
1627 suffix_massage_regexize( const char *s )
1633 if ( s[ 0 ] == '\0' ) {
1634 return ch_strdup( "^(.+)$" );
1638 ( r = strchr( p, ',' ) ) != NULL;
1642 res = ch_calloc( sizeof( char ),
1644 + STRLENOF( "((.+),)?" )
1645 + STRLENOF( "[ ]?" ) * i
1646 + STRLENOF( "$" ) + 1 );
1648 ptr = lutil_strcopy( res, "((.+),)?" );
1650 ( r = strchr( p, ',' ) ) != NULL;
1652 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1653 ptr = lutil_strcopy( ptr, "[ ]?" );
1655 if ( r[ 1 ] == ' ' ) {
1659 ptr = lutil_strcopy( ptr, p );
1668 suffix_massage_patternize( const char *s, const char *p )
1675 if ( s[ 0 ] == '\0' ) {
1679 res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1680 if ( res == NULL ) {
1684 ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1685 if ( s[ 0 ] == '\0' ) {
1689 lutil_strcopy( ptr, p );
1695 suffix_massage_config(
1696 struct rewrite_info *info,
1697 struct berval *pvnc,
1698 struct berval *nvnc,
1699 struct berval *prnc,
1706 rargv[ 0 ] = "rewriteEngine";
1709 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1711 rargv[ 0 ] = "rewriteContext";
1712 rargv[ 1 ] = "default";
1714 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1716 rargv[ 0 ] = "rewriteRule";
1717 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1718 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1721 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1722 ch_free( rargv[ 1 ] );
1723 ch_free( rargv[ 2 ] );
1725 if ( BER_BVISEMPTY( pvnc ) ) {
1726 rargv[ 0 ] = "rewriteRule";
1728 rargv[ 2 ] = prnc->bv_val;
1731 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1734 rargv[ 0 ] = "rewriteContext";
1735 rargv[ 1 ] = "searchEntryDN";
1737 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1739 rargv[ 0 ] = "rewriteRule";
1740 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1741 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1744 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1745 ch_free( rargv[ 1 ] );
1746 ch_free( rargv[ 2 ] );
1748 if ( BER_BVISEMPTY( prnc ) ) {
1749 rargv[ 0 ] = "rewriteRule";
1751 rargv[ 2 ] = pvnc->bv_val;
1754 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1757 /* backward compatibility */
1758 rargv[ 0 ] = "rewriteContext";
1759 rargv[ 1 ] = "searchResult";
1760 rargv[ 2 ] = "alias";
1761 rargv[ 3 ] = "searchEntryDN";
1763 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1765 rargv[ 0 ] = "rewriteContext";
1766 rargv[ 1 ] = "matchedDN";
1767 rargv[ 2 ] = "alias";
1768 rargv[ 3 ] = "searchEntryDN";
1770 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1772 rargv[ 0 ] = "rewriteContext";
1773 rargv[ 1 ] = "searchAttrDN";
1774 rargv[ 2 ] = "alias";
1775 rargv[ 3 ] = "searchEntryDN";
1777 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1779 /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1780 * see servers/slapd/overlays/rwm.h for details */
1781 rargv[ 0 ] = "rewriteContext";
1782 rargv[ 1 ] = "referralAttrDN";
1784 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1786 rargv[ 0 ] = "rewriteContext";
1787 rargv[ 1 ] = "referralDN";
1789 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1793 #endif /* ENABLE_REWRITE */