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_f = mi->mi_urllist_f;
174 mt->mt_urllist_p = mt;
176 mt->mt_nretries = mi->mi_nretries;
177 mt->mt_quarantine = mi->mi_quarantine;
178 if ( META_BACK_QUARANTINE( mi ) ) {
179 ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
181 mt->mt_flags = mi->mi_flags;
182 mt->mt_version = mi->mi_version;
183 mt->mt_network_timeout = mi->mi_network_timeout;
184 mt->mt_bind_timeout = mi->mi_bind_timeout;
185 for ( c = 0; c < SLAP_OP_LAST; c++ ) {
186 mt->mt_timeout[ c ] = mi->mi_timeout[ c ];
192 if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t",
193 LDAP_PVT_URL_PARSE_NONE ) != LDAP_SUCCESS )
195 Debug( LDAP_DEBUG_ANY,
196 "%s: line %d: unable to parse URI"
197 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
203 * uri MUST have the <dn> part!
205 if ( ludp->lud_dn == NULL ) {
206 Debug( LDAP_DEBUG_ANY,
207 "%s: line %d: missing <naming context> "
208 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
212 } else if ( ludp->lud_dn[ 0 ] == '\0' ) {
215 for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) {
216 if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) {
221 if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) {
222 Debug( LDAP_DEBUG_ANY,
223 "%s: line %d: missing <naming context> "
224 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
231 * copies and stores uri and suffix
233 ber_str2bv( ludp->lud_dn, 0, 0, &dn );
234 rc = dnPrettyNormal( NULL, &dn, &mt->mt_psuffix,
235 &mt->mt_nsuffix, NULL );
236 if( rc != LDAP_SUCCESS ) {
237 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
238 "target \"%s\" DN is invalid\n",
239 fname, lineno, argv[ 1 ] );
243 ludp->lud_dn[ 0 ] = '\0';
245 switch ( ludp->lud_scope ) {
246 case LDAP_SCOPE_DEFAULT:
247 mt->mt_scope = LDAP_SCOPE_SUBTREE;
250 case LDAP_SCOPE_SUBTREE:
251 case LDAP_SCOPE_SUBORDINATE:
252 mt->mt_scope = ludp->lud_scope;
256 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
257 "invalid scope for target \"%s\"\n",
258 fname, lineno, argv[ 1 ] );
262 /* check all, to apply the scope check on the first one */
263 for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) {
264 if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) {
265 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
266 "multiple URIs must have "
274 mt->mt_uri = ldap_url_list2urls( ludp );
275 ldap_free_urllist( ludp );
276 if ( mt->mt_uri == NULL) {
277 Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n",
283 * uri MUST be a branch of suffix!
285 #if 0 /* too strict a constraint */
286 if ( select_backend( &mt->mt_nsuffix, 0, 0 ) != be ) {
287 Debug( LDAP_DEBUG_ANY,
288 "%s: line %d: <naming context> of URI does not refer to current backend"
289 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
295 * uri MUST be a branch of a suffix!
297 if ( select_backend( &mt->mt_nsuffix, 0, 0 ) == NULL ) {
298 Debug( LDAP_DEBUG_ANY,
299 "%s: line %d: <naming context> of URI does not resolve to a backend"
300 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
306 /* subtree-exclude */
307 } else if ( strcasecmp( argv[ 0 ], "subtree-exclude" ) == 0 ) {
308 int i = mi->mi_ntargets - 1;
309 struct berval dn, ndn;
312 Debug( LDAP_DEBUG_ANY,
313 "%s: line %d: need \"uri\" directive first\n",
320 Debug( LDAP_DEBUG_ANY,
321 "%s: line %d: missing DN in \"subtree-exclude <DN>\" line\n",
329 Debug( LDAP_DEBUG_ANY,
330 "%s: line %d: too many args in \"subtree-exclude <DN>\" line\n",
335 ber_str2bv( argv[ 1 ], 0, 0, &dn );
336 if ( dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL )
339 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
340 "subtree-exclude DN=\"%s\" is invalid\n",
341 fname, lineno, argv[ 1 ] );
345 if ( !dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_nsuffix ) ) {
346 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
347 "subtree-exclude DN=\"%s\" "
348 "must be subtree of target\n",
349 fname, lineno, argv[ 1 ] );
350 ber_memfree( ndn.bv_val );
354 if ( mi->mi_targets[ i ]->mt_subtree_exclude != NULL ) {
357 for ( j = 0; !BER_BVISNULL( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ); j++ )
359 if ( dnIsSuffix( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ], &ndn ) ) {
360 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
361 "subtree-exclude DN=\"%s\" "
362 "is suffix of another subtree-exclude\n",
363 fname, lineno, argv[ 1 ] );
364 /* reject, because it might be superior
365 * to more than one subtree-exclude */
366 ber_memfree( ndn.bv_val );
369 } else if ( dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ) ) {
370 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
371 "another subtree-exclude is suffix of "
372 "subtree-exclude DN=\"%s\"\n",
373 fname, lineno, argv[ 1 ] );
374 ber_memfree( ndn.bv_val );
380 ber_bvarray_add( &mi->mi_targets[ i ]->mt_subtree_exclude, &ndn );
382 /* default target directive */
383 } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
384 int i = mi->mi_ntargets - 1;
388 Debug( LDAP_DEBUG_ANY,
389 "%s: line %d: \"default-target\" alone need be"
390 " inside a \"uri\" directive\n",
394 mi->mi_defaulttarget = i;
397 if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
399 Debug( LDAP_DEBUG_ANY,
400 "%s: line %d: \"default-target none\""
401 " should go before uri definitions\n",
404 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
408 if ( lutil_atoi( &mi->mi_defaulttarget, argv[ 1 ] ) != 0
409 || mi->mi_defaulttarget < 0
410 || mi->mi_defaulttarget >= i - 1 )
412 Debug( LDAP_DEBUG_ANY,
413 "%s: line %d: illegal target number %d\n",
414 fname, lineno, mi->mi_defaulttarget );
420 /* ttl of dn cache */
421 } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
423 Debug( LDAP_DEBUG_ANY,
424 "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
429 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
430 mi->mi_cache.ttl = META_DNCACHE_FOREVER;
432 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
433 mi->mi_cache.ttl = META_DNCACHE_DISABLED;
438 if ( lutil_parse_time( argv[ 1 ], &t ) != 0 ) {
439 Debug( LDAP_DEBUG_ANY,
440 "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
441 fname, lineno, argv[ 1 ] );
444 mi->mi_cache.ttl = (time_t)t;
447 /* network timeout when connecting to ldap servers */
448 } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
450 time_t *tp = mi->mi_ntargets ?
451 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_network_timeout
452 : &mi->mi_network_timeout;
455 Debug( LDAP_DEBUG_ANY,
456 "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
461 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
462 Debug( LDAP_DEBUG_ANY,
463 "%s: line %d: unable to parse timeout \"%s\" in \"network-timeout <seconds>\" line\n",
464 fname, lineno, argv[ 1 ] );
471 /* idle timeout when connecting to ldap servers */
472 } else if ( strcasecmp( argv[ 0 ], "idle-timeout" ) == 0 ) {
477 Debug( LDAP_DEBUG_ANY,
478 "%s: line %d: missing timeout value in \"idle-timeout <seconds>\" line\n",
484 Debug( LDAP_DEBUG_ANY,
485 "%s: line %d: extra cruft after timeout value in \"idle-timeout <seconds>\" line\n",
490 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
491 Debug( LDAP_DEBUG_ANY,
492 "%s: line %d: unable to parse timeout \"%s\" in \"idle-timeout <seconds>\" line\n",
493 fname, lineno, argv[ 1 ] );
498 mi->mi_idle_timeout = (time_t)t;
501 } else if ( strcasecmp( argv[ 0 ], "conn-ttl" ) == 0 ) {
506 Debug( LDAP_DEBUG_ANY,
507 "%s: line %d: missing ttl value in \"conn-ttl <seconds>\" line\n",
513 Debug( LDAP_DEBUG_ANY,
514 "%s: line %d: extra cruft after ttl value in \"conn-ttl <seconds>\" line\n",
519 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
520 Debug( LDAP_DEBUG_ANY,
521 "%s: line %d: unable to parse ttl \"%s\" in \"conn-ttl <seconds>\" line\n",
522 fname, lineno, argv[ 1 ] );
527 mi->mi_conn_ttl = (time_t)t;
529 /* bind timeout when connecting to ldap servers */
530 } else if ( strcasecmp( argv[ 0 ], "bind-timeout" ) == 0 ) {
532 struct timeval *tp = mi->mi_ntargets ?
533 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_bind_timeout
534 : &mi->mi_bind_timeout;
538 Debug( LDAP_DEBUG_ANY,
539 "%s: line %d: missing timeout value in \"bind-timeout <microseconds>\" line\n",
545 Debug( LDAP_DEBUG_ANY,
546 "%s: line %d: extra cruft after timeout value in \"bind-timeout <microseconds>\" line\n",
551 if ( lutil_atoul( &t, argv[ 1 ] ) != 0 ) {
552 Debug( LDAP_DEBUG_ANY,
553 "%s: line %d: unable to parse timeout \"%s\" in \"bind-timeout <microseconds>\" line\n",
554 fname, lineno, argv[ 1 ] );
559 tp->tv_sec = t/1000000;
560 tp->tv_usec = t%1000000;
562 /* name to use for meta_back_group */
563 } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
564 || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
566 int i = mi->mi_ntargets - 1;
570 Debug( LDAP_DEBUG_ANY,
571 "%s: line %d: need \"uri\" directive first\n",
577 Debug( LDAP_DEBUG_ANY,
578 "%s: line %d: missing name in \"binddn <name>\" line\n",
583 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
584 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
585 "\"binddn\" statement is deprecated; "
586 "use \"acl-authcDN\" instead\n",
588 /* FIXME: some day we'll need to throw an error */
591 ber_str2bv( argv[ 1 ], 0, 0, &dn );
592 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ]->mt_binddn,
593 NULL ) != LDAP_SUCCESS )
595 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
596 "bind DN '%s' is invalid\n",
597 fname, lineno, argv[ 1 ] );
601 /* password to use for meta_back_group */
602 } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
603 || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
605 int i = mi->mi_ntargets - 1;
608 Debug( LDAP_DEBUG_ANY,
609 "%s: line %d: need \"uri\" directive first\n",
615 Debug( LDAP_DEBUG_ANY,
616 "%s: line %d: missing password in \"bindpw <password>\" line\n",
621 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
622 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
623 "\"bindpw\" statement is deprecated; "
624 "use \"acl-passwd\" instead\n",
626 /* FIXME: some day we'll need to throw an error */
629 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ]->mt_bindpw );
631 /* save bind creds for referral rebinds? */
632 } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
634 Debug( LDAP_DEBUG_ANY,
635 "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
641 Debug( LDAP_DEBUG_ANY,
642 "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
644 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
647 switch ( check_true_false( argv[ 1 ] ) ) {
649 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
653 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
657 Debug( LDAP_DEBUG_ANY,
658 "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
659 fname, lineno, argv[ 1 ] );
664 } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
665 unsigned *flagsp = mi->mi_ntargets ?
666 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
670 Debug( LDAP_DEBUG_ANY,
671 "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
676 /* this is the default; we add it because the default might change... */
677 switch ( check_true_false( argv[ 1 ] ) ) {
679 *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
683 *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
687 Debug( LDAP_DEBUG_ANY,
688 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
689 fname, lineno, argv[ 1 ] );
693 } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
694 unsigned *flagsp = mi->mi_ntargets ?
695 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
699 Debug( LDAP_DEBUG_ANY,
700 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
706 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
707 *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
710 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
711 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
712 *flagsp |= LDAP_BACK_F_USE_TLS;
714 /* propagate start tls */
715 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
716 *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
719 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
720 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
721 *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
724 Debug( LDAP_DEBUG_ANY,
725 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
726 fname, lineno, argv[ 1 ] );
730 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
731 unsigned *flagsp = mi->mi_ntargets ?
732 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
736 Debug( LDAP_DEBUG_ANY,
737 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
742 switch ( check_true_false( argv[ 1 ] ) ) {
744 *flagsp &= ~LDAP_BACK_F_T_F_MASK2;
748 *flagsp |= LDAP_BACK_F_T_F;
752 if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
753 *flagsp |= LDAP_BACK_F_T_F_DISCOVER;
756 Debug( LDAP_DEBUG_ANY,
757 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
758 fname, lineno, argv[ 1 ] );
765 } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
767 Debug( LDAP_DEBUG_ANY,
768 "%s: line %d: \"onerr {CONTINUE|report|stop}\" takes 1 argument\n",
773 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
774 mi->mi_flags &= ~META_BACK_F_ONERR_MASK;
776 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
777 mi->mi_flags |= META_BACK_F_ONERR_STOP;
779 } else if ( strcasecmp( argv[ 1 ], "report" ) == 0 ) {
780 mi->mi_flags |= META_BACK_F_ONERR_REPORT;
783 Debug( LDAP_DEBUG_ANY,
784 "%s: line %d: \"onerr {CONTINUE|report|stop}\": invalid arg \"%s\".\n",
785 fname, lineno, argv[ 1 ] );
790 } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0
791 || strcasecmp( argv[ 0 ], "root-bind-defer" ) == 0 )
794 Debug( LDAP_DEBUG_ANY,
795 "%s: line %d: \"[pseudo]root-bind-defer {FALSE|true}\" takes 1 argument\n",
800 switch ( check_true_false( argv[ 1 ] ) ) {
802 mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
806 mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
810 Debug( LDAP_DEBUG_ANY,
811 "%s: line %d: \"[pseudo]root-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
812 fname, lineno, argv[ 1 ] );
817 } else if ( strcasecmp( argv[ 0 ], "single-conn" ) == 0 ) {
819 Debug( LDAP_DEBUG_ANY,
820 "%s: line %d: \"single-conn {FALSE|true}\" takes 1 argument\n",
825 if ( mi->mi_ntargets > 0 ) {
826 Debug( LDAP_DEBUG_ANY,
827 "%s: line %d: \"single-conn\" must appear before target definitions\n",
832 switch ( check_true_false( argv[ 1 ] ) ) {
834 mi->mi_flags &= ~LDAP_BACK_F_SINGLECONN;
838 mi->mi_flags |= LDAP_BACK_F_SINGLECONN;
842 Debug( LDAP_DEBUG_ANY,
843 "%s: line %d: \"single-conn {FALSE|true}\": invalid arg \"%s\".\n",
844 fname, lineno, argv[ 1 ] );
848 /* use-temporaries? */
849 } else if ( strcasecmp( argv[ 0 ], "use-temporary-conn" ) == 0 ) {
851 Debug( LDAP_DEBUG_ANY,
852 "%s: line %d: \"use-temporary-conn {FALSE|true}\" takes 1 argument\n",
857 if ( mi->mi_ntargets > 0 ) {
858 Debug( LDAP_DEBUG_ANY,
859 "%s: line %d: \"use-temporary-conn\" must appear before target definitions\n",
864 switch ( check_true_false( argv[ 1 ] ) ) {
866 mi->mi_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
870 mi->mi_flags |= LDAP_BACK_F_USE_TEMPORARIES;
874 Debug( LDAP_DEBUG_ANY,
875 "%s: line %d: \"use-temporary-conn {FALSE|true}\": invalid arg \"%s\".\n",
876 fname, lineno, argv[ 1 ] );
880 /* privileged connections pool max size ? */
881 } else if ( strcasecmp( argv[ 0 ], "conn-pool-max" ) == 0 ) {
883 Debug( LDAP_DEBUG_ANY,
884 "%s: line %d: \"conn-pool-max <n>\" takes 1 argument\n",
889 if ( mi->mi_ntargets > 0 ) {
890 Debug( LDAP_DEBUG_ANY,
891 "%s: line %d: \"conn-pool-max\" must appear before target definitions\n",
896 if ( lutil_atoi( &mi->mi_conn_priv_max, argv[1] )
897 || mi->mi_conn_priv_max < LDAP_BACK_CONN_PRIV_MIN
898 || mi->mi_conn_priv_max > LDAP_BACK_CONN_PRIV_MAX )
900 Debug( LDAP_DEBUG_ANY,
901 "%s: line %d: \"conn-pool-max <n>\": invalid arg \"%s\".\n",
902 fname, lineno, argv[ 1 ] );
906 } else if ( strcasecmp( argv[ 0 ], "cancel" ) == 0 ) {
908 unsigned *flagsp = mi->mi_ntargets ?
909 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
913 Debug( LDAP_DEBUG_ANY,
914 "%s: line %d: \"cancel {abandon|ignore|exop}\" takes 1 argument\n",
919 if ( strcasecmp( argv[ 1 ], "abandon" ) == 0 ) {
920 flag = LDAP_BACK_F_CANCEL_ABANDON;
922 } else if ( strcasecmp( argv[ 1 ], "ignore" ) == 0 ) {
923 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 #if 0 /* uses timelimit instead */
977 } else if ( strncasecmp( argv[ c ], "search", len ) == 0 ) {
978 t = &tv[ SLAP_OP_SEARCH ];
980 /* abandon makes little sense */
981 #if 0 /* not implemented yet */
982 } else if ( strncasecmp( argv[ c ], "extended", len ) == 0 ) {
983 t = &tv[ SLAP_OP_EXTENDED ];
986 char buf[ SLAP_TEXT_BUFLEN ];
987 snprintf( buf, sizeof( buf ),
988 "unknown/unhandled operation \"%s\" for timeout #%d",
990 Debug( LDAP_DEBUG_ANY,
991 "%s: line %d: %s.\n",
992 fname, lineno, buf );
1001 if ( lutil_parse_time( sep, &val ) != 0 ) {
1002 Debug( LDAP_DEBUG_ANY,
1003 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
1004 fname, lineno, sep );
1014 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1015 tv[ i ] = (time_t)val;
1020 /* name to use as pseudo-root dn */
1021 } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
1022 int i = mi->mi_ntargets - 1;
1025 Debug( LDAP_DEBUG_ANY,
1026 "%s: line %d: need \"uri\" directive first\n",
1032 Debug( LDAP_DEBUG_ANY,
1033 "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
1039 * exact replacement:
1042 idassert-bind bindmethod=simple
1043 binddn=<pseudorootdn>
1044 credentials=<pseudorootpw>
1046 flags=non-prescriptive
1047 idassert-authzFrom "dn:<rootdn>"
1049 * so that only when authc'd as <rootdn> the proxying occurs
1050 * rebinding as the <pseudorootdn> without proxyAuthz.
1053 Debug( LDAP_DEBUG_ANY,
1054 "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1055 "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1059 char binddn[ SLAP_TEXT_BUFLEN ];
1062 "bindmethod=simple",
1065 "flags=non-prescriptive",
1071 if ( BER_BVISNULL( &be->be_rootndn ) ) {
1072 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"rootdn\" must be defined first.\n",
1077 if ( snprintf( binddn, sizeof( binddn ), "binddn=%s", argv[ 1 ] ) >= sizeof( binddn ) ) {
1078 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootdn\" too long.\n",
1082 cargv[ 2 ] = binddn;
1084 rc = slap_idassert_parse_cf( fname, lineno, cargc, cargv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1088 if ( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz != NULL ) {
1089 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"idassert-authzFrom\" already defined (discarded).\n",
1091 ber_bvarray_free( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz );
1092 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz = NULL;
1095 assert( !BER_BVISNULL( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authcDN ) );
1097 bv.bv_len = STRLENOF( "dn:" ) + be->be_rootndn.bv_len;
1098 bv.bv_val = ber_memalloc( bv.bv_len + 1 );
1099 AC_MEMCPY( bv.bv_val, "dn:", STRLENOF( "dn:" ) );
1100 AC_MEMCPY( &bv.bv_val[ STRLENOF( "dn:" ) ], be->be_rootndn.bv_val, be->be_rootndn.bv_len + 1 );
1102 ber_bvarray_add( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz, &bv );
1108 /* password to use as pseudo-root */
1109 } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
1110 int i = mi->mi_ntargets - 1;
1113 Debug( LDAP_DEBUG_ANY,
1114 "%s: line %d: need \"uri\" directive first\n",
1120 Debug( LDAP_DEBUG_ANY,
1121 "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
1126 Debug( LDAP_DEBUG_ANY,
1127 "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1128 "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1131 if ( BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_authcDN ) ) {
1132 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"pseudorootdn\" must be defined first.\n",
1137 if ( !BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_passwd ) ) {
1138 memset( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val, 0,
1139 mi->mi_targets[ i ]->mt_idassert_passwd.bv_len );
1140 ber_memfree( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val );
1142 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_targets[ i ]->mt_idassert_passwd );
1145 } else if ( strcasecmp( argv[ 0 ], "idassert-bind" ) == 0 ) {
1146 if ( mi->mi_ntargets == 0 ) {
1147 Debug( LDAP_DEBUG_ANY,
1148 "%s: line %d: \"idassert-bind\" "
1149 "must appear inside a target specification.\n",
1154 return slap_idassert_parse_cf( fname, lineno, argc, argv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1156 /* idassert-authzFrom */
1157 } else if ( strcasecmp( argv[ 0 ], "idassert-authzFrom" ) == 0 ) {
1158 if ( mi->mi_ntargets == 0 ) {
1159 Debug( LDAP_DEBUG_ANY,
1160 "%s: line %d: \"idassert-bind\" "
1161 "must appear inside a target specification.\n",
1171 Debug( LDAP_DEBUG_ANY,
1172 "%s: line %d: missing <id> in \"idassert-authzFrom <id>\".\n",
1177 Debug( LDAP_DEBUG_ANY,
1178 "%s: line %d: extra cruft after <id> in \"idassert-authzFrom <id>\".\n",
1183 return slap_idassert_authzfrom_parse_cf( fname, lineno, argv[ 1 ], &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1186 } else if ( strcasecmp( argv[ 0 ], "quarantine" ) == 0 ) {
1187 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1188 slap_retry_info_t *ri = mi->mi_ntargets ?
1189 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine
1190 : &mi->mi_quarantine;
1192 if ( ( mi->mi_ntargets == 0 && META_BACK_QUARANTINE( mi ) )
1193 || ( mi->mi_ntargets > 0 && META_BACK_TGT_QUARANTINE( mi->mi_targets[ mi->mi_ntargets - 1 ] ) ) )
1195 Debug( LDAP_DEBUG_ANY,
1196 "%s: line %d: quarantine already defined.\n",
1206 Debug( LDAP_DEBUG_ANY,
1207 "%s: line %d: missing arg in \"quarantine <pattern list>\".\n",
1212 Debug( LDAP_DEBUG_ANY,
1213 "%s: line %d: extra cruft after \"quarantine <pattern list>\".\n",
1218 if ( ri != &mi->mi_quarantine ) {
1219 ri->ri_interval = NULL;
1223 if ( mi->mi_ntargets > 0 && !META_BACK_QUARANTINE( mi ) ) {
1224 ldap_pvt_thread_mutex_init( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine_mutex );
1227 if ( slap_retry_info_parse( argv[ 1 ], ri, buf, sizeof( buf ) ) ) {
1228 Debug( LDAP_DEBUG_ANY,
1229 "%s line %d: %s.\n",
1230 fname, lineno, buf );
1235 } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
1237 int i = mi->mi_ntargets - 1, rc;
1238 struct berval dn, nvnc, pvnc, nrnc, prnc;
1241 Debug( LDAP_DEBUG_ANY,
1242 "%s: line %d: need \"uri\" directive first\n",
1250 * suffixmassage <suffix> <massaged suffix>
1252 * the <suffix> field must be defined as a valid suffix
1253 * (or suffixAlias?) for the current database;
1254 * the <massaged suffix> shouldn't have already been
1255 * defined as a valid suffix or suffixAlias for the
1259 Debug( LDAP_DEBUG_ANY,
1260 "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
1265 ber_str2bv( argv[ 1 ], 0, 0, &dn );
1266 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1267 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1268 "suffix '%s' is invalid\n",
1269 fname, lineno, argv[ 1 ] );
1273 tmp_be = select_backend( &nvnc, 0, 0 );
1274 if ( tmp_be != NULL && tmp_be != be ) {
1275 Debug( LDAP_DEBUG_ANY,
1276 "%s: line %d: suffix already in use by another backend in"
1277 " \"suffixMassage <suffix> <massaged suffix>\"\n",
1279 free( pvnc.bv_val );
1280 free( nvnc.bv_val );
1284 ber_str2bv( argv[ 2 ], 0, 0, &dn );
1285 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1286 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1287 "massaged suffix '%s' is invalid\n",
1288 fname, lineno, argv[ 2 ] );
1289 free( pvnc.bv_val );
1290 free( nvnc.bv_val );
1295 tmp_be = select_backend( &nrnc, 0, 0 );
1296 if ( tmp_be != NULL ) {
1297 Debug( LDAP_DEBUG_ANY,
1298 "%s: line %d: massaged suffix already in use by another backend in"
1299 " \"suffixMassage <suffix> <massaged suffix>\"\n",
1301 free( pvnc.bv_val );
1302 free( nvnc.bv_val );
1303 free( prnc.bv_val );
1304 free( nrnc.bv_val );
1310 * The suffix massaging is emulated by means of the
1311 * rewrite capabilities
1312 * FIXME: no extra rewrite capabilities should be added
1315 rc = suffix_massage_config( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1316 &pvnc, &nvnc, &prnc, &nrnc );
1318 free( pvnc.bv_val );
1319 free( nvnc.bv_val );
1320 free( prnc.bv_val );
1321 free( nrnc.bv_val );
1325 /* rewrite stuff ... */
1326 } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
1327 int i = mi->mi_ntargets - 1;
1330 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"rewrite\" "
1331 "statement outside target definition.\n",
1336 return rewrite_parse( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1337 fname, lineno, argc, argv );
1339 /* objectclass/attribute mapping */
1340 } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
1341 int i = mi->mi_ntargets - 1;
1344 Debug( LDAP_DEBUG_ANY,
1345 "%s: line %d: need \"uri\" directive first\n",
1350 return ldap_back_map_config( &mi->mi_targets[ i ]->mt_rwmap.rwm_oc,
1351 &mi->mi_targets[ i ]->mt_rwmap.rwm_at,
1352 fname, lineno, argc, argv );
1354 } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
1355 int i = mi->mi_ntargets - 1;
1356 int nretries = META_RETRY_UNDEFINED;
1359 Debug( LDAP_DEBUG_ANY,
1360 "%s: line %d: need value in \"nretries <value>\"\n",
1365 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
1366 nretries = META_RETRY_FOREVER;
1368 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
1369 nretries = META_RETRY_NEVER;
1372 if ( lutil_atoi( &nretries, argv[ 1 ] ) != 0 ) {
1373 Debug( LDAP_DEBUG_ANY,
1374 "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
1375 fname, lineno, argv[ 1 ] );
1381 mi->mi_nretries = nretries;
1384 mi->mi_targets[ i ]->mt_nretries = nretries;
1387 } else if ( strcasecmp( argv[ 0 ], "protocol-version" ) == 0 ) {
1388 int *version = mi->mi_ntargets ?
1389 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_version
1393 Debug( LDAP_DEBUG_ANY,
1394 "%s: line %d: need value in \"protocol-version <version>\"\n",
1399 if ( lutil_atoi( version, argv[ 1 ] ) != 0 ) {
1400 Debug( LDAP_DEBUG_ANY,
1401 "%s: line %d: unable to parse version \"%s\" in \"protocol-version <version>\"\n",
1402 fname, lineno, argv[ 1 ] );
1406 if ( *version != 0 && ( *version < LDAP_VERSION_MIN || *version > LDAP_VERSION_MAX ) ) {
1407 Debug( LDAP_DEBUG_ANY,
1408 "%s: line %d: unsupported version \"%s\" in \"protocol-version <version>\"\n",
1409 fname, lineno, argv[ 1 ] );
1415 return SLAP_CONF_UNKNOWN;
1421 ldap_back_map_config(
1422 struct ldapmap *oc_map,
1423 struct ldapmap *at_map,
1429 struct ldapmap *map;
1430 struct ldapmapping *mapping;
1434 if ( argc < 3 || argc > 4 ) {
1435 Debug( LDAP_DEBUG_ANY,
1436 "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
1441 if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
1445 } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
1449 Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is "
1450 "\"map {objectclass | attribute} [<local> | *] "
1451 "{<foreign> | *}\"\n",
1456 if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
1457 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
1458 map->drop_missing = ( argc < 4 );
1459 goto success_return;
1461 src = dst = argv[ 3 ];
1463 } else if ( argc < 4 ) {
1469 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
1472 if ( ( map == at_map )
1473 && ( strcasecmp( src, "objectclass" ) == 0
1474 || strcasecmp( dst, "objectclass" ) == 0 ) )
1476 Debug( LDAP_DEBUG_ANY,
1477 "%s: line %d: objectclass attribute cannot be mapped\n",
1481 mapping = (struct ldapmapping *)ch_calloc( 2,
1482 sizeof(struct ldapmapping) );
1483 if ( mapping == NULL ) {
1484 Debug( LDAP_DEBUG_ANY,
1485 "%s: line %d: out of memory\n",
1489 ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
1490 ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
1491 mapping[ 1 ].src = mapping[ 0 ].dst;
1492 mapping[ 1 ].dst = mapping[ 0 ].src;
1498 if ( src[ 0 ] != '\0' ) {
1499 if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
1500 Debug( LDAP_DEBUG_ANY,
1501 "%s: line %d: warning, source objectClass '%s' "
1502 "should be defined in schema\n",
1503 fname, lineno, src );
1506 * FIXME: this should become an err
1512 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
1513 Debug( LDAP_DEBUG_ANY,
1514 "%s: line %d: warning, destination objectClass '%s' "
1515 "is not defined in schema\n",
1516 fname, lineno, dst );
1520 const char *text = NULL;
1521 AttributeDescription *ad = NULL;
1523 if ( src[ 0 ] != '\0' ) {
1524 rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
1525 if ( rc != LDAP_SUCCESS ) {
1526 Debug( LDAP_DEBUG_ANY,
1527 "%s: line %d: warning, source attributeType '%s' "
1528 "should be defined in schema\n",
1529 fname, lineno, src );
1532 * FIXME: this should become an err
1535 * we create a fake "proxied" ad
1539 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1540 &ad, &text, SLAP_AD_PROXIED );
1541 if ( rc != LDAP_SUCCESS ) {
1542 char buf[ SLAP_TEXT_BUFLEN ];
1544 snprintf( buf, sizeof( buf ),
1545 "source attributeType \"%s\": %d (%s)",
1546 src, rc, text ? text : "" );
1547 Debug( LDAP_DEBUG_ANY,
1548 "%s: line %d: %s\n",
1549 fname, lineno, buf );
1557 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1558 if ( rc != LDAP_SUCCESS ) {
1559 Debug( LDAP_DEBUG_ANY,
1560 "%s: line %d: warning, destination attributeType '%s' "
1561 "is not defined in schema\n",
1562 fname, lineno, dst );
1565 * we create a fake "proxied" ad
1569 rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1570 &ad, &text, SLAP_AD_PROXIED );
1571 if ( rc != LDAP_SUCCESS ) {
1572 char buf[ SLAP_TEXT_BUFLEN ];
1574 snprintf( buf, sizeof( buf ),
1575 "source attributeType \"%s\": %d (%s)\n",
1576 dst, rc, text ? text : "" );
1577 Debug( LDAP_DEBUG_ANY,
1578 "%s: line %d: %s\n",
1579 fname, lineno, buf );
1585 if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1586 || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1588 Debug( LDAP_DEBUG_ANY,
1589 "%s: line %d: duplicate mapping found.\n",
1594 if ( src[ 0 ] != '\0' ) {
1595 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1596 mapping_cmp, mapping_dup );
1598 avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1599 mapping_cmp, mapping_dup );
1602 if ( !is_oc && map->map == NULL ) {
1603 /* only init if required */
1604 ldap_back_map_init( map, &mapping );
1611 ch_free( mapping[ 0 ].src.bv_val );
1612 ch_free( mapping[ 0 ].dst.bv_val );
1620 #ifdef ENABLE_REWRITE
1622 suffix_massage_regexize( const char *s )
1628 if ( s[ 0 ] == '\0' ) {
1629 return ch_strdup( "^(.+)$" );
1633 ( r = strchr( p, ',' ) ) != NULL;
1637 res = ch_calloc( sizeof( char ),
1639 + STRLENOF( "((.+),)?" )
1640 + STRLENOF( "[ ]?" ) * i
1641 + STRLENOF( "$" ) + 1 );
1643 ptr = lutil_strcopy( res, "((.+),)?" );
1645 ( r = strchr( p, ',' ) ) != NULL;
1647 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1648 ptr = lutil_strcopy( ptr, "[ ]?" );
1650 if ( r[ 1 ] == ' ' ) {
1654 ptr = lutil_strcopy( ptr, p );
1663 suffix_massage_patternize( const char *s, const char *p )
1670 if ( s[ 0 ] == '\0' ) {
1674 res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1675 if ( res == NULL ) {
1679 ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1680 if ( s[ 0 ] == '\0' ) {
1684 lutil_strcopy( ptr, p );
1690 suffix_massage_config(
1691 struct rewrite_info *info,
1692 struct berval *pvnc,
1693 struct berval *nvnc,
1694 struct berval *prnc,
1701 rargv[ 0 ] = "rewriteEngine";
1704 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1706 rargv[ 0 ] = "rewriteContext";
1707 rargv[ 1 ] = "default";
1709 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1711 rargv[ 0 ] = "rewriteRule";
1712 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1713 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1716 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1717 ch_free( rargv[ 1 ] );
1718 ch_free( rargv[ 2 ] );
1720 if ( BER_BVISEMPTY( pvnc ) ) {
1721 rargv[ 0 ] = "rewriteRule";
1723 rargv[ 2 ] = prnc->bv_val;
1726 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1729 rargv[ 0 ] = "rewriteContext";
1730 rargv[ 1 ] = "searchEntryDN";
1732 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1734 rargv[ 0 ] = "rewriteRule";
1735 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1736 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1739 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1740 ch_free( rargv[ 1 ] );
1741 ch_free( rargv[ 2 ] );
1743 if ( BER_BVISEMPTY( prnc ) ) {
1744 rargv[ 0 ] = "rewriteRule";
1746 rargv[ 2 ] = pvnc->bv_val;
1749 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1752 /* backward compatibility */
1753 rargv[ 0 ] = "rewriteContext";
1754 rargv[ 1 ] = "searchResult";
1755 rargv[ 2 ] = "alias";
1756 rargv[ 3 ] = "searchEntryDN";
1758 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1760 rargv[ 0 ] = "rewriteContext";
1761 rargv[ 1 ] = "matchedDN";
1762 rargv[ 2 ] = "alias";
1763 rargv[ 3 ] = "searchEntryDN";
1765 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1767 rargv[ 0 ] = "rewriteContext";
1768 rargv[ 1 ] = "searchAttrDN";
1769 rargv[ 2 ] = "alias";
1770 rargv[ 3 ] = "searchEntryDN";
1772 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1774 /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1775 * see servers/slapd/overlays/rwm.h for details */
1776 rargv[ 0 ] = "rewriteContext";
1777 rargv[ 1 ] = "referralAttrDN";
1779 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1781 rargv[ 0 ] = "rewriteContext";
1782 rargv[ 1 ] = "referralDN";
1784 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1788 #endif /* ENABLE_REWRITE */