2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2009 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;
124 Debug( LDAP_DEBUG_ANY,
125 "%s: line %d: missing URI "
126 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
131 if ( be->be_nsuffix == NULL ) {
132 Debug( LDAP_DEBUG_ANY,
133 "%s: line %d: the suffix must be defined before any target.\n",
140 mi->mi_targets = ( metatarget_t ** )ch_realloc( mi->mi_targets,
141 sizeof( metatarget_t * ) * mi->mi_ntargets );
142 if ( mi->mi_targets == NULL ) {
143 Debug( LDAP_DEBUG_ANY,
144 "%s: line %d: out of memory while storing server name"
145 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
150 if ( meta_back_new_target( &mi->mi_targets[ i ] ) != 0 ) {
151 Debug( LDAP_DEBUG_ANY,
152 "%s: line %d: unable to init server"
153 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
158 mt = mi->mi_targets[ i ];
160 mt->mt_rebind_f = mi->mi_rebind_f;
161 mt->mt_urllist_f = mi->mi_urllist_f;
162 mt->mt_urllist_p = mt;
164 mt->mt_nretries = mi->mi_nretries;
165 mt->mt_quarantine = mi->mi_quarantine;
166 if ( META_BACK_QUARANTINE( mi ) ) {
167 ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
169 mt->mt_flags = mi->mi_flags;
170 mt->mt_version = mi->mi_version;
171 mt->mt_network_timeout = mi->mi_network_timeout;
172 mt->mt_bind_timeout = mi->mi_bind_timeout;
173 for ( c = 0; c < SLAP_OP_LAST; c++ ) {
174 mt->mt_timeout[ c ] = mi->mi_timeout[ c ];
177 for ( c = 1; c < argc; c++ ) {
178 char **tmpuris = ldap_str2charray( argv[ c ], "\t" );
180 if ( tmpuris == NULL ) {
181 Debug( LDAP_DEBUG_ANY,
182 "%s: line %d: unable to parse URIs #%d"
183 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
184 fname, lineno, c - 1 );
192 ldap_charray_merge( &uris, tmpuris );
193 ldap_charray_free( tmpuris );
197 for ( c = 0; uris[ c ] != NULL; c++ ) {
203 if ( ldap_url_parselist_ext( &ludp, uris[ c ], "\t",
204 LDAP_PVT_URL_PARSE_NONE ) != LDAP_SUCCESS
205 || ludp->lud_next != NULL )
207 Debug( LDAP_DEBUG_ANY,
208 "%s: line %d: unable to parse URI #%d"
209 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
211 ldap_charray_free( uris );
218 * uri MUST have the <dn> part!
220 if ( ludp->lud_dn == NULL ) {
221 Debug( LDAP_DEBUG_ANY,
222 "%s: line %d: missing <naming context> "
223 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
225 ldap_free_urllist( ludp );
226 ldap_charray_free( uris );
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 ] );
240 ldap_free_urllist( ludp );
241 ldap_charray_free( uris );
245 ludp->lud_dn[ 0 ] = '\0';
247 switch ( ludp->lud_scope ) {
248 case LDAP_SCOPE_DEFAULT:
249 mt->mt_scope = LDAP_SCOPE_SUBTREE;
252 case LDAP_SCOPE_SUBTREE:
253 case LDAP_SCOPE_SUBORDINATE:
254 mt->mt_scope = ludp->lud_scope;
258 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
259 "invalid scope for target \"%s\"\n",
260 fname, lineno, argv[ 1 ] );
261 ldap_free_urllist( ludp );
262 ldap_charray_free( uris );
267 /* check all, to apply the scope check on the first one */
268 if ( ludp->lud_dn != NULL && ludp->lud_dn[ 0 ] != '\0' ) {
269 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
270 "multiple URIs must have "
273 ldap_free_urllist( ludp );
274 ldap_charray_free( uris );
280 tmpuri = ldap_url_list2urls( ludp );
281 ldap_free_urllist( ludp );
282 if ( tmpuri == NULL ) {
283 Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n",
285 ldap_charray_free( uris );
288 ldap_memfree( uris[ c ] );
292 mt->mt_uri = ldap_charray2str( uris, " " );
293 ldap_charray_free( uris );
294 if ( mt->mt_uri == NULL) {
295 Debug( LDAP_DEBUG_ANY, "%s: line %d: no memory?\n",
301 * uri MUST be a branch of suffix!
303 for ( c = 0; !BER_BVISNULL( &be->be_nsuffix[ c ] ); c++ ) {
304 if ( dnIsSuffix( &mt->mt_nsuffix, &be->be_nsuffix[ c ] ) ) {
309 if ( BER_BVISNULL( &be->be_nsuffix[ c ] ) ) {
310 Debug( LDAP_DEBUG_ANY,
311 "%s: line %d: <naming context> of URI must be within the naming context of this database.\n",
316 /* subtree-exclude */
317 } else if ( strcasecmp( argv[ 0 ], "subtree-exclude" ) == 0 ) {
318 int i = mi->mi_ntargets - 1;
319 struct berval dn, ndn;
322 Debug( LDAP_DEBUG_ANY,
323 "%s: line %d: need \"uri\" directive first\n",
330 Debug( LDAP_DEBUG_ANY,
331 "%s: line %d: missing DN in \"subtree-exclude <DN>\" line\n",
339 Debug( LDAP_DEBUG_ANY,
340 "%s: line %d: too many args in \"subtree-exclude <DN>\" line\n",
345 ber_str2bv( argv[ 1 ], 0, 0, &dn );
346 if ( dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL )
349 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
350 "subtree-exclude DN=\"%s\" is invalid\n",
351 fname, lineno, argv[ 1 ] );
355 if ( !dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_nsuffix ) ) {
356 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
357 "subtree-exclude DN=\"%s\" "
358 "must be subtree of target\n",
359 fname, lineno, argv[ 1 ] );
360 ber_memfree( ndn.bv_val );
364 if ( mi->mi_targets[ i ]->mt_subtree_exclude != NULL ) {
367 for ( j = 0; !BER_BVISNULL( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ); j++ )
369 if ( dnIsSuffix( &mi->mi_targets[ i ]->mt_subtree_exclude[ j ], &ndn ) ) {
370 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
371 "subtree-exclude DN=\"%s\" "
372 "is suffix of another subtree-exclude\n",
373 fname, lineno, argv[ 1 ] );
374 /* reject, because it might be superior
375 * to more than one subtree-exclude */
376 ber_memfree( ndn.bv_val );
379 } else if ( dnIsSuffix( &ndn, &mi->mi_targets[ i ]->mt_subtree_exclude[ j ] ) ) {
380 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
381 "another subtree-exclude is suffix of "
382 "subtree-exclude DN=\"%s\"\n",
383 fname, lineno, argv[ 1 ] );
384 ber_memfree( ndn.bv_val );
390 ber_bvarray_add( &mi->mi_targets[ i ]->mt_subtree_exclude, &ndn );
392 /* default target directive */
393 } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
394 int i = mi->mi_ntargets - 1;
398 Debug( LDAP_DEBUG_ANY,
399 "%s: line %d: \"default-target\" alone need be"
400 " inside a \"uri\" directive\n",
404 mi->mi_defaulttarget = i;
407 if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
409 Debug( LDAP_DEBUG_ANY,
410 "%s: line %d: \"default-target none\""
411 " should go before uri definitions\n",
414 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
418 if ( lutil_atoi( &mi->mi_defaulttarget, argv[ 1 ] ) != 0
419 || mi->mi_defaulttarget < 0
420 || mi->mi_defaulttarget >= i - 1 )
422 Debug( LDAP_DEBUG_ANY,
423 "%s: line %d: illegal target number %d\n",
424 fname, lineno, mi->mi_defaulttarget );
430 /* ttl of dn cache */
431 } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
433 Debug( LDAP_DEBUG_ANY,
434 "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
439 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
440 mi->mi_cache.ttl = META_DNCACHE_FOREVER;
442 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
443 mi->mi_cache.ttl = META_DNCACHE_DISABLED;
448 if ( lutil_parse_time( argv[ 1 ], &t ) != 0 ) {
449 Debug( LDAP_DEBUG_ANY,
450 "%s: line %d: unable to parse ttl \"%s\" in \"dncache-ttl <ttl>\" line\n",
451 fname, lineno, argv[ 1 ] );
454 mi->mi_cache.ttl = (time_t)t;
457 /* network timeout when connecting to ldap servers */
458 } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
460 time_t *tp = mi->mi_ntargets ?
461 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_network_timeout
462 : &mi->mi_network_timeout;
465 Debug( LDAP_DEBUG_ANY,
466 "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
471 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
472 Debug( LDAP_DEBUG_ANY,
473 "%s: line %d: unable to parse timeout \"%s\" in \"network-timeout <seconds>\" line\n",
474 fname, lineno, argv[ 1 ] );
481 /* idle timeout when connecting to ldap servers */
482 } else if ( strcasecmp( argv[ 0 ], "idle-timeout" ) == 0 ) {
487 Debug( LDAP_DEBUG_ANY,
488 "%s: line %d: missing timeout value in \"idle-timeout <seconds>\" line\n",
494 Debug( LDAP_DEBUG_ANY,
495 "%s: line %d: extra cruft after timeout value in \"idle-timeout <seconds>\" line\n",
500 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
501 Debug( LDAP_DEBUG_ANY,
502 "%s: line %d: unable to parse timeout \"%s\" in \"idle-timeout <seconds>\" line\n",
503 fname, lineno, argv[ 1 ] );
508 mi->mi_idle_timeout = (time_t)t;
511 } else if ( strcasecmp( argv[ 0 ], "conn-ttl" ) == 0 ) {
516 Debug( LDAP_DEBUG_ANY,
517 "%s: line %d: missing ttl value in \"conn-ttl <seconds>\" line\n",
523 Debug( LDAP_DEBUG_ANY,
524 "%s: line %d: extra cruft after ttl value in \"conn-ttl <seconds>\" line\n",
529 if ( lutil_parse_time( argv[ 1 ], &t ) ) {
530 Debug( LDAP_DEBUG_ANY,
531 "%s: line %d: unable to parse ttl \"%s\" in \"conn-ttl <seconds>\" line\n",
532 fname, lineno, argv[ 1 ] );
537 mi->mi_conn_ttl = (time_t)t;
539 /* bind timeout when connecting to ldap servers */
540 } else if ( strcasecmp( argv[ 0 ], "bind-timeout" ) == 0 ) {
542 struct timeval *tp = mi->mi_ntargets ?
543 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_bind_timeout
544 : &mi->mi_bind_timeout;
548 Debug( LDAP_DEBUG_ANY,
549 "%s: line %d: missing timeout value in \"bind-timeout <microseconds>\" line\n",
555 Debug( LDAP_DEBUG_ANY,
556 "%s: line %d: extra cruft after timeout value in \"bind-timeout <microseconds>\" line\n",
561 if ( lutil_atoul( &t, argv[ 1 ] ) != 0 ) {
562 Debug( LDAP_DEBUG_ANY,
563 "%s: line %d: unable to parse timeout \"%s\" in \"bind-timeout <microseconds>\" line\n",
564 fname, lineno, argv[ 1 ] );
569 tp->tv_sec = t/1000000;
570 tp->tv_usec = t%1000000;
572 /* name to use for meta_back_group */
573 } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
574 || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
576 int i = mi->mi_ntargets - 1;
580 Debug( LDAP_DEBUG_ANY,
581 "%s: line %d: need \"uri\" directive first\n",
587 Debug( LDAP_DEBUG_ANY,
588 "%s: line %d: missing name in \"binddn <name>\" line\n",
593 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
594 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
595 "\"binddn\" statement is deprecated; "
596 "use \"acl-authcDN\" instead\n",
598 /* FIXME: some day we'll need to throw an error */
601 ber_str2bv( argv[ 1 ], 0, 0, &dn );
602 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ]->mt_binddn,
603 NULL ) != LDAP_SUCCESS )
605 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
606 "bind DN '%s' is invalid\n",
607 fname, lineno, argv[ 1 ] );
611 /* password to use for meta_back_group */
612 } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
613 || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
615 int i = mi->mi_ntargets - 1;
618 Debug( LDAP_DEBUG_ANY,
619 "%s: line %d: need \"uri\" directive first\n",
625 Debug( LDAP_DEBUG_ANY,
626 "%s: line %d: missing password in \"bindpw <password>\" line\n",
631 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
632 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
633 "\"bindpw\" statement is deprecated; "
634 "use \"acl-passwd\" instead\n",
636 /* FIXME: some day we'll need to throw an error */
639 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ]->mt_bindpw );
641 /* save bind creds for referral rebinds? */
642 } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
644 Debug( LDAP_DEBUG_ANY,
645 "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
651 Debug( LDAP_DEBUG_ANY,
652 "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
654 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
657 switch ( check_true_false( argv[ 1 ] ) ) {
659 mi->mi_flags &= ~LDAP_BACK_F_SAVECRED;
663 mi->mi_flags |= LDAP_BACK_F_SAVECRED;
667 Debug( LDAP_DEBUG_ANY,
668 "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
669 fname, lineno, argv[ 1 ] );
674 } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
675 unsigned *flagsp = mi->mi_ntargets ?
676 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
680 Debug( LDAP_DEBUG_ANY,
681 "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
686 /* this is the default; we add it because the default might change... */
687 switch ( check_true_false( argv[ 1 ] ) ) {
689 *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
693 *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
697 Debug( LDAP_DEBUG_ANY,
698 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
699 fname, lineno, argv[ 1 ] );
703 } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
704 unsigned *flagsp = mi->mi_ntargets ?
705 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
709 Debug( LDAP_DEBUG_ANY,
710 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
716 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
717 *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
720 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
721 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
722 *flagsp |= LDAP_BACK_F_USE_TLS;
724 /* propagate start tls */
725 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
726 *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
729 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
730 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
731 *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
734 Debug( LDAP_DEBUG_ANY,
735 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
736 fname, lineno, argv[ 1 ] );
740 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
741 unsigned *flagsp = mi->mi_ntargets ?
742 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
746 Debug( LDAP_DEBUG_ANY,
747 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
752 switch ( check_true_false( argv[ 1 ] ) ) {
754 *flagsp &= ~LDAP_BACK_F_T_F_MASK2;
758 *flagsp |= LDAP_BACK_F_T_F;
762 if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
763 *flagsp |= LDAP_BACK_F_T_F_DISCOVER;
766 Debug( LDAP_DEBUG_ANY,
767 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
768 fname, lineno, argv[ 1 ] );
775 } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
777 Debug( LDAP_DEBUG_ANY,
778 "%s: line %d: \"onerr {CONTINUE|report|stop}\" takes 1 argument\n",
783 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
784 mi->mi_flags &= ~META_BACK_F_ONERR_MASK;
786 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
787 mi->mi_flags |= META_BACK_F_ONERR_STOP;
789 } else if ( strcasecmp( argv[ 1 ], "report" ) == 0 ) {
790 mi->mi_flags |= META_BACK_F_ONERR_REPORT;
793 Debug( LDAP_DEBUG_ANY,
794 "%s: line %d: \"onerr {CONTINUE|report|stop}\": invalid arg \"%s\".\n",
795 fname, lineno, argv[ 1 ] );
800 } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0
801 || strcasecmp( argv[ 0 ], "root-bind-defer" ) == 0 )
804 Debug( LDAP_DEBUG_ANY,
805 "%s: line %d: \"[pseudo]root-bind-defer {TRUE|false}\" takes 1 argument\n",
810 switch ( check_true_false( argv[ 1 ] ) ) {
812 mi->mi_flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
816 mi->mi_flags |= META_BACK_F_DEFER_ROOTDN_BIND;
820 Debug( LDAP_DEBUG_ANY,
821 "%s: line %d: \"[pseudo]root-bind-defer {TRUE|false}\": invalid arg \"%s\".\n",
822 fname, lineno, argv[ 1 ] );
827 } else if ( strcasecmp( argv[ 0 ], "single-conn" ) == 0 ) {
829 Debug( LDAP_DEBUG_ANY,
830 "%s: line %d: \"single-conn {FALSE|true}\" takes 1 argument\n",
835 if ( mi->mi_ntargets > 0 ) {
836 Debug( LDAP_DEBUG_ANY,
837 "%s: line %d: \"single-conn\" must appear before target definitions\n",
842 switch ( check_true_false( argv[ 1 ] ) ) {
844 mi->mi_flags &= ~LDAP_BACK_F_SINGLECONN;
848 mi->mi_flags |= LDAP_BACK_F_SINGLECONN;
852 Debug( LDAP_DEBUG_ANY,
853 "%s: line %d: \"single-conn {FALSE|true}\": invalid arg \"%s\".\n",
854 fname, lineno, argv[ 1 ] );
858 /* use-temporaries? */
859 } else if ( strcasecmp( argv[ 0 ], "use-temporary-conn" ) == 0 ) {
861 Debug( LDAP_DEBUG_ANY,
862 "%s: line %d: \"use-temporary-conn {FALSE|true}\" takes 1 argument\n",
867 if ( mi->mi_ntargets > 0 ) {
868 Debug( LDAP_DEBUG_ANY,
869 "%s: line %d: \"use-temporary-conn\" must appear before target definitions\n",
874 switch ( check_true_false( argv[ 1 ] ) ) {
876 mi->mi_flags &= ~LDAP_BACK_F_USE_TEMPORARIES;
880 mi->mi_flags |= LDAP_BACK_F_USE_TEMPORARIES;
884 Debug( LDAP_DEBUG_ANY,
885 "%s: line %d: \"use-temporary-conn {FALSE|true}\": invalid arg \"%s\".\n",
886 fname, lineno, argv[ 1 ] );
890 /* privileged connections pool max size ? */
891 } else if ( strcasecmp( argv[ 0 ], "conn-pool-max" ) == 0 ) {
893 Debug( LDAP_DEBUG_ANY,
894 "%s: line %d: \"conn-pool-max <n>\" takes 1 argument\n",
899 if ( mi->mi_ntargets > 0 ) {
900 Debug( LDAP_DEBUG_ANY,
901 "%s: line %d: \"conn-pool-max\" must appear before target definitions\n",
906 if ( lutil_atoi( &mi->mi_conn_priv_max, argv[1] )
907 || mi->mi_conn_priv_max < LDAP_BACK_CONN_PRIV_MIN
908 || mi->mi_conn_priv_max > LDAP_BACK_CONN_PRIV_MAX )
910 Debug( LDAP_DEBUG_ANY,
911 "%s: line %d: \"conn-pool-max <n>\": invalid arg \"%s\".\n",
912 fname, lineno, argv[ 1 ] );
916 } else if ( strcasecmp( argv[ 0 ], "cancel" ) == 0 ) {
918 unsigned *flagsp = mi->mi_ntargets ?
919 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
923 Debug( LDAP_DEBUG_ANY,
924 "%s: line %d: \"cancel {abandon|ignore|exop}\" takes 1 argument\n",
929 if ( strcasecmp( argv[ 1 ], "abandon" ) == 0 ) {
930 flag = LDAP_BACK_F_CANCEL_ABANDON;
932 } else if ( strcasecmp( argv[ 1 ], "ignore" ) == 0 ) {
933 flag = LDAP_BACK_F_CANCEL_IGNORE;
935 } else if ( strcasecmp( argv[ 1 ], "exop" ) == 0 ) {
936 flag = LDAP_BACK_F_CANCEL_EXOP;
938 } else if ( strcasecmp( argv[ 1 ], "exop-discover" ) == 0 ) {
939 flag = LDAP_BACK_F_CANCEL_EXOP_DISCOVER;
942 Debug( LDAP_DEBUG_ANY,
943 "%s: line %d: \"cancel {abandon|ignore|exop[-discover]}\": unknown mode \"%s\" \n",
944 fname, lineno, argv[ 1 ] );
948 *flagsp &= ~LDAP_BACK_F_CANCEL_MASK2;
951 } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
953 time_t *tv = mi->mi_ntargets ?
954 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_timeout
959 Debug( LDAP_DEBUG_ANY,
960 "%s: line %d: \"timeout [{add|bind|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
965 for ( c = 1; c < argc; c++ ) {
969 sep = strchr( argv[ c ], '=' );
971 size_t len = sep - argv[ c ];
973 if ( strncasecmp( argv[ c ], "bind", len ) == 0 ) {
974 t = &tv[ SLAP_OP_BIND ];
975 /* unbind makes little sense */
976 } else if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
977 t = &tv[ SLAP_OP_ADD ];
978 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
979 t = &tv[ SLAP_OP_DELETE ];
980 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
981 t = &tv[ SLAP_OP_MODRDN ];
982 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
983 t = &tv[ SLAP_OP_MODIFY ];
984 } else if ( strncasecmp( argv[ c ], "compare", len ) == 0 ) {
985 t = &tv[ SLAP_OP_COMPARE ];
986 } else if ( strncasecmp( argv[ c ], "search", len ) == 0 ) {
987 t = &tv[ SLAP_OP_SEARCH ];
988 /* abandon makes little sense */
989 #if 0 /* not implemented yet */
990 } else if ( strncasecmp( argv[ c ], "extended", len ) == 0 ) {
991 t = &tv[ SLAP_OP_EXTENDED ];
994 char buf[ SLAP_TEXT_BUFLEN ];
995 snprintf( buf, sizeof( buf ),
996 "unknown/unhandled operation \"%s\" for timeout #%d",
998 Debug( LDAP_DEBUG_ANY,
999 "%s: line %d: %s.\n",
1000 fname, lineno, buf );
1009 if ( lutil_parse_time( sep, &val ) != 0 ) {
1010 Debug( LDAP_DEBUG_ANY,
1011 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
1012 fname, lineno, sep );
1022 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
1023 tv[ i ] = (time_t)val;
1028 /* name to use as pseudo-root dn */
1029 } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
1030 int i = mi->mi_ntargets - 1;
1033 Debug( LDAP_DEBUG_ANY,
1034 "%s: line %d: need \"uri\" directive first\n",
1040 Debug( LDAP_DEBUG_ANY,
1041 "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
1047 * exact replacement:
1050 idassert-bind bindmethod=simple
1051 binddn=<pseudorootdn>
1052 credentials=<pseudorootpw>
1054 flags=non-prescriptive
1055 idassert-authzFrom "dn:<rootdn>"
1057 * so that only when authc'd as <rootdn> the proxying occurs
1058 * rebinding as the <pseudorootdn> without proxyAuthz.
1061 Debug( LDAP_DEBUG_ANY,
1062 "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1063 "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1067 char binddn[ SLAP_TEXT_BUFLEN ];
1070 "bindmethod=simple",
1073 "flags=non-prescriptive",
1079 if ( BER_BVISNULL( &be->be_rootndn ) ) {
1080 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"rootdn\" must be defined first.\n",
1085 if ( sizeof( binddn ) <= (unsigned) snprintf( binddn,
1086 sizeof( binddn ), "binddn=%s", argv[ 1 ] ))
1088 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootdn\" too long.\n",
1092 cargv[ 2 ] = binddn;
1094 rc = mi->mi_ldap_extra->idassert_parse_cf( fname, lineno, cargc, cargv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1098 if ( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz != NULL ) {
1099 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"idassert-authzFrom\" already defined (discarded).\n",
1101 ber_bvarray_free( mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz );
1102 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz = NULL;
1105 assert( !BER_BVISNULL( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authcDN ) );
1107 bv.bv_len = STRLENOF( "dn:" ) + be->be_rootndn.bv_len;
1108 bv.bv_val = ber_memalloc( bv.bv_len + 1 );
1109 AC_MEMCPY( bv.bv_val, "dn:", STRLENOF( "dn:" ) );
1110 AC_MEMCPY( &bv.bv_val[ STRLENOF( "dn:" ) ], be->be_rootndn.bv_val, be->be_rootndn.bv_len + 1 );
1112 ber_bvarray_add( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert_authz, &bv );
1118 /* password to use as pseudo-root */
1119 } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
1120 int i = mi->mi_ntargets - 1;
1123 Debug( LDAP_DEBUG_ANY,
1124 "%s: line %d: need \"uri\" directive first\n",
1130 Debug( LDAP_DEBUG_ANY,
1131 "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
1136 Debug( LDAP_DEBUG_ANY,
1137 "%s: line %d: \"pseudorootdn\", \"pseudorootpw\" are no longer supported; "
1138 "use \"idassert-bind\" and \"idassert-authzFrom\" instead.\n",
1141 if ( BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_authcDN ) ) {
1142 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"pseudorootpw\": \"pseudorootdn\" must be defined first.\n",
1147 if ( !BER_BVISNULL( &mi->mi_targets[ i ]->mt_idassert_passwd ) ) {
1148 memset( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val, 0,
1149 mi->mi_targets[ i ]->mt_idassert_passwd.bv_len );
1150 ber_memfree( mi->mi_targets[ i ]->mt_idassert_passwd.bv_val );
1152 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_targets[ i ]->mt_idassert_passwd );
1155 } else if ( strcasecmp( argv[ 0 ], "idassert-bind" ) == 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",
1164 return mi->mi_ldap_extra->idassert_parse_cf( fname, lineno, argc, argv, &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1166 /* idassert-authzFrom */
1167 } else if ( strcasecmp( argv[ 0 ], "idassert-authzFrom" ) == 0 ) {
1168 if ( mi->mi_ntargets == 0 ) {
1169 Debug( LDAP_DEBUG_ANY,
1170 "%s: line %d: \"idassert-bind\" "
1171 "must appear inside a target specification.\n",
1181 Debug( LDAP_DEBUG_ANY,
1182 "%s: line %d: missing <id> in \"idassert-authzFrom <id>\".\n",
1187 Debug( LDAP_DEBUG_ANY,
1188 "%s: line %d: extra cruft after <id> in \"idassert-authzFrom <id>\".\n",
1193 return mi->mi_ldap_extra->idassert_authzfrom_parse_cf( fname, lineno, argv[ 1 ], &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_idassert );
1196 } else if ( strcasecmp( argv[ 0 ], "quarantine" ) == 0 ) {
1197 char buf[ SLAP_TEXT_BUFLEN ] = { '\0' };
1198 slap_retry_info_t *ri = mi->mi_ntargets ?
1199 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine
1200 : &mi->mi_quarantine;
1202 if ( ( mi->mi_ntargets == 0 && META_BACK_QUARANTINE( mi ) )
1203 || ( mi->mi_ntargets > 0 && META_BACK_TGT_QUARANTINE( mi->mi_targets[ mi->mi_ntargets - 1 ] ) ) )
1205 Debug( LDAP_DEBUG_ANY,
1206 "%s: line %d: quarantine already defined.\n",
1216 Debug( LDAP_DEBUG_ANY,
1217 "%s: line %d: missing arg in \"quarantine <pattern list>\".\n",
1222 Debug( LDAP_DEBUG_ANY,
1223 "%s: line %d: extra cruft after \"quarantine <pattern list>\".\n",
1228 if ( ri != &mi->mi_quarantine ) {
1229 ri->ri_interval = NULL;
1233 if ( mi->mi_ntargets > 0 && !META_BACK_QUARANTINE( mi ) ) {
1234 ldap_pvt_thread_mutex_init( &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_quarantine_mutex );
1237 if ( mi->mi_ldap_extra->retry_info_parse( argv[ 1 ], ri, buf, sizeof( buf ) ) ) {
1238 Debug( LDAP_DEBUG_ANY,
1239 "%s line %d: %s.\n",
1240 fname, lineno, buf );
1244 if ( mi->mi_ntargets == 0 ) {
1245 mi->mi_flags |= LDAP_BACK_F_QUARANTINE;
1248 mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags |= LDAP_BACK_F_QUARANTINE;
1251 #ifdef SLAP_CONTROL_X_SESSION_TRACKING
1252 /* session tracking request */
1253 } else if ( strcasecmp( argv[ 0 ], "session-tracking-request" ) == 0 ) {
1254 unsigned *flagsp = mi->mi_ntargets ?
1255 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
1259 Debug( LDAP_DEBUG_ANY,
1260 "%s: line %d: \"session-tracking-request {TRUE|false}\" needs 1 argument.\n",
1265 /* this is the default; we add it because the default might change... */
1266 switch ( check_true_false( argv[ 1 ] ) ) {
1268 *flagsp |= LDAP_BACK_F_ST_REQUEST;
1272 *flagsp &= ~LDAP_BACK_F_ST_REQUEST;
1276 Debug( LDAP_DEBUG_ANY,
1277 "%s: line %d: \"session-tracking-request {TRUE|false}\": unknown argument \"%s\".\n",
1278 fname, lineno, argv[ 1 ] );
1281 #endif /* SLAP_CONTROL_X_SESSION_TRACKING */
1284 } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
1286 int i = mi->mi_ntargets - 1, c, rc;
1287 struct berval dn, nvnc, pvnc, nrnc, prnc;
1290 Debug( LDAP_DEBUG_ANY,
1291 "%s: line %d: need \"uri\" directive first\n",
1299 * suffixmassage <suffix> <massaged suffix>
1301 * the <suffix> field must be defined as a valid suffix
1302 * (or suffixAlias?) for the current database;
1303 * the <massaged suffix> shouldn't have already been
1304 * defined as a valid suffix or suffixAlias for the
1308 Debug( LDAP_DEBUG_ANY,
1309 "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
1314 ber_str2bv( argv[ 1 ], 0, 0, &dn );
1315 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
1316 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1317 "suffix \"%s\" is invalid\n",
1318 fname, lineno, argv[ 1 ] );
1322 for ( c = 0; !BER_BVISNULL( &be->be_nsuffix[ c ] ); c++ ) {
1323 if ( dnIsSuffix( &nvnc, &be->be_nsuffix[ 0 ] ) ) {
1328 if ( BER_BVISNULL( &be->be_nsuffix[ c ] ) ) {
1329 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1330 "<suffix> \"%s\" must be within the database naming context, in "
1331 "\"suffixMassage <suffix> <massaged suffix>\"\n",
1332 fname, lineno, pvnc.bv_val );
1333 free( pvnc.bv_val );
1334 free( nvnc.bv_val );
1338 ber_str2bv( argv[ 2 ], 0, 0, &dn );
1339 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
1340 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
1341 "massaged suffix \"%s\" is invalid\n",
1342 fname, lineno, argv[ 2 ] );
1343 free( pvnc.bv_val );
1344 free( nvnc.bv_val );
1348 tmp_bd = select_backend( &nrnc, 0 );
1349 if ( tmp_bd != NULL && tmp_bd->be_private == be->be_private ) {
1350 Debug( LDAP_DEBUG_ANY,
1351 "%s: line %d: warning: <massaged suffix> \"%s\" resolves to this database, in "
1352 "\"suffixMassage <suffix> <massaged suffix>\"\n",
1353 fname, lineno, prnc.bv_val );
1357 * The suffix massaging is emulated by means of the
1358 * rewrite capabilities
1360 rc = suffix_massage_config( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1361 &pvnc, &nvnc, &prnc, &nrnc );
1363 free( pvnc.bv_val );
1364 free( nvnc.bv_val );
1365 free( prnc.bv_val );
1366 free( nrnc.bv_val );
1370 /* rewrite stuff ... */
1371 } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
1372 int i = mi->mi_ntargets - 1;
1375 Debug( LDAP_DEBUG_ANY, "%s: line %d: \"rewrite\" "
1376 "statement outside target definition.\n",
1381 return rewrite_parse( mi->mi_targets[ i ]->mt_rwmap.rwm_rw,
1382 fname, lineno, argc, argv );
1384 /* objectclass/attribute mapping */
1385 } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
1386 int i = mi->mi_ntargets - 1;
1389 Debug( LDAP_DEBUG_ANY,
1390 "%s: line %d: need \"uri\" directive first\n",
1395 return ldap_back_map_config( &mi->mi_targets[ i ]->mt_rwmap.rwm_oc,
1396 &mi->mi_targets[ i ]->mt_rwmap.rwm_at,
1397 fname, lineno, argc, argv );
1399 } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
1400 int i = mi->mi_ntargets - 1;
1401 int nretries = META_RETRY_UNDEFINED;
1404 Debug( LDAP_DEBUG_ANY,
1405 "%s: line %d: need value in \"nretries <value>\"\n",
1410 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
1411 nretries = META_RETRY_FOREVER;
1413 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
1414 nretries = META_RETRY_NEVER;
1417 if ( lutil_atoi( &nretries, argv[ 1 ] ) != 0 ) {
1418 Debug( LDAP_DEBUG_ANY,
1419 "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
1420 fname, lineno, argv[ 1 ] );
1426 mi->mi_nretries = nretries;
1429 mi->mi_targets[ i ]->mt_nretries = nretries;
1432 } else if ( strcasecmp( argv[ 0 ], "protocol-version" ) == 0 ) {
1433 int *version = mi->mi_ntargets ?
1434 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_version
1438 Debug( LDAP_DEBUG_ANY,
1439 "%s: line %d: need value in \"protocol-version <version>\"\n",
1444 if ( lutil_atoi( version, argv[ 1 ] ) != 0 ) {
1445 Debug( LDAP_DEBUG_ANY,
1446 "%s: line %d: unable to parse version \"%s\" in \"protocol-version <version>\"\n",
1447 fname, lineno, argv[ 1 ] );
1451 if ( *version != 0 && ( *version < LDAP_VERSION_MIN || *version > LDAP_VERSION_MAX ) ) {
1452 Debug( LDAP_DEBUG_ANY,
1453 "%s: line %d: unsupported version \"%s\" in \"protocol-version <version>\"\n",
1454 fname, lineno, argv[ 1 ] );
1458 /* do not return search references */
1459 } else if ( strcasecmp( argv[ 0 ], "norefs" ) == 0 ) {
1460 unsigned *flagsp = mi->mi_ntargets ?
1461 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
1465 Debug( LDAP_DEBUG_ANY,
1466 "%s: line %d: \"norefs {TRUE|false}\" needs 1 argument.\n",
1471 /* this is the default; we add it because the default might change... */
1472 switch ( check_true_false( argv[ 1 ] ) ) {
1474 *flagsp |= LDAP_BACK_F_NOREFS;
1478 *flagsp &= ~LDAP_BACK_F_NOREFS;
1482 Debug( LDAP_DEBUG_ANY,
1483 "%s: line %d: \"norefs {TRUE|false}\": unknown argument \"%s\".\n",
1484 fname, lineno, argv[ 1 ] );
1488 /* do not propagate undefined search filters */
1489 } else if ( strcasecmp( argv[ 0 ], "noundeffilter" ) == 0 ) {
1490 unsigned *flagsp = mi->mi_ntargets ?
1491 &mi->mi_targets[ mi->mi_ntargets - 1 ]->mt_flags
1495 Debug( LDAP_DEBUG_ANY,
1496 "%s: line %d: \"noundeffilter {TRUE|false}\" needs 1 argument.\n",
1501 /* this is the default; we add it because the default might change... */
1502 switch ( check_true_false( argv[ 1 ] ) ) {
1504 *flagsp |= LDAP_BACK_F_NOUNDEFFILTER;
1508 *flagsp &= ~LDAP_BACK_F_NOUNDEFFILTER;
1512 Debug( LDAP_DEBUG_ANY,
1513 "%s: line %d: \"noundeffilter {TRUE|false}\": unknown argument \"%s\".\n",
1514 fname, lineno, argv[ 1 ] );
1520 return SLAP_CONF_UNKNOWN;
1526 ldap_back_map_config(
1527 struct ldapmap *oc_map,
1528 struct ldapmap *at_map,
1534 struct ldapmap *map;
1535 struct ldapmapping *mapping;
1539 if ( argc < 3 || argc > 4 ) {
1540 Debug( LDAP_DEBUG_ANY,
1541 "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
1546 if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
1550 } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
1554 Debug( LDAP_DEBUG_ANY, "%s: line %d: syntax is "
1555 "\"map {objectclass | attribute} [<local> | *] "
1556 "{<foreign> | *}\"\n",
1561 if ( !is_oc && map->map == NULL ) {
1562 /* only init if required */
1563 ldap_back_map_init( map, &mapping );
1566 if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
1567 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
1568 map->drop_missing = ( argc < 4 );
1569 goto success_return;
1571 src = dst = argv[ 3 ];
1573 } else if ( argc < 4 ) {
1579 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
1582 if ( ( map == at_map )
1583 && ( strcasecmp( src, "objectclass" ) == 0
1584 || strcasecmp( dst, "objectclass" ) == 0 ) )
1586 Debug( LDAP_DEBUG_ANY,
1587 "%s: line %d: objectclass attribute cannot be mapped\n",
1591 mapping = (struct ldapmapping *)ch_calloc( 2,
1592 sizeof(struct ldapmapping) );
1593 if ( mapping == NULL ) {
1594 Debug( LDAP_DEBUG_ANY,
1595 "%s: line %d: out of memory\n",
1599 ber_str2bv( src, 0, 1, &mapping[ 0 ].src );
1600 ber_str2bv( dst, 0, 1, &mapping[ 0 ].dst );
1601 mapping[ 1 ].src = mapping[ 0 ].dst;
1602 mapping[ 1 ].dst = mapping[ 0 ].src;
1608 if ( src[ 0 ] != '\0' ) {
1609 if ( oc_bvfind( &mapping[ 0 ].src ) == NULL ) {
1610 Debug( LDAP_DEBUG_ANY,
1611 "%s: line %d: warning, source objectClass '%s' "
1612 "should be defined in schema\n",
1613 fname, lineno, src );
1616 * FIXME: this should become an err
1622 if ( oc_bvfind( &mapping[ 0 ].dst ) == NULL ) {
1623 Debug( LDAP_DEBUG_ANY,
1624 "%s: line %d: warning, destination objectClass '%s' "
1625 "is not defined in schema\n",
1626 fname, lineno, dst );
1630 const char *text = NULL;
1631 AttributeDescription *ad = NULL;
1633 if ( src[ 0 ] != '\0' ) {
1634 rc = slap_bv2ad( &mapping[ 0 ].src, &ad, &text );
1635 if ( rc != LDAP_SUCCESS ) {
1636 Debug( LDAP_DEBUG_ANY,
1637 "%s: line %d: warning, source attributeType '%s' "
1638 "should be defined in schema\n",
1639 fname, lineno, src );
1642 * FIXME: this should become an err
1645 * we create a fake "proxied" ad
1649 rc = slap_bv2undef_ad( &mapping[ 0 ].src,
1650 &ad, &text, SLAP_AD_PROXIED );
1651 if ( rc != LDAP_SUCCESS ) {
1652 char buf[ SLAP_TEXT_BUFLEN ];
1654 snprintf( buf, sizeof( buf ),
1655 "source attributeType \"%s\": %d (%s)",
1656 src, rc, text ? text : "" );
1657 Debug( LDAP_DEBUG_ANY,
1658 "%s: line %d: %s\n",
1659 fname, lineno, buf );
1667 rc = slap_bv2ad( &mapping[ 0 ].dst, &ad, &text );
1668 if ( rc != LDAP_SUCCESS ) {
1669 Debug( LDAP_DEBUG_ANY,
1670 "%s: line %d: warning, destination attributeType '%s' "
1671 "is not defined in schema\n",
1672 fname, lineno, dst );
1675 * we create a fake "proxied" ad
1679 rc = slap_bv2undef_ad( &mapping[ 0 ].dst,
1680 &ad, &text, SLAP_AD_PROXIED );
1681 if ( rc != LDAP_SUCCESS ) {
1682 char buf[ SLAP_TEXT_BUFLEN ];
1684 snprintf( buf, sizeof( buf ),
1685 "source attributeType \"%s\": %d (%s)\n",
1686 dst, rc, text ? text : "" );
1687 Debug( LDAP_DEBUG_ANY,
1688 "%s: line %d: %s\n",
1689 fname, lineno, buf );
1695 if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)&mapping[ 0 ], mapping_cmp ) != NULL)
1696 || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1698 Debug( LDAP_DEBUG_ANY,
1699 "%s: line %d: duplicate mapping found.\n",
1704 if ( src[ 0 ] != '\0' ) {
1705 avl_insert( &map->map, (caddr_t)&mapping[ 0 ],
1706 mapping_cmp, mapping_dup );
1708 avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1709 mapping_cmp, mapping_dup );
1716 ch_free( mapping[ 0 ].src.bv_val );
1717 ch_free( mapping[ 0 ].dst.bv_val );
1725 #ifdef ENABLE_REWRITE
1727 suffix_massage_regexize( const char *s )
1733 if ( s[ 0 ] == '\0' ) {
1734 return ch_strdup( "^(.+)$" );
1738 ( r = strchr( p, ',' ) ) != NULL;
1742 res = ch_calloc( sizeof( char ),
1744 + STRLENOF( "((.+),)?" )
1745 + STRLENOF( "[ ]?" ) * i
1746 + STRLENOF( "$" ) + 1 );
1748 ptr = lutil_strcopy( res, "((.+),)?" );
1750 ( r = strchr( p, ',' ) ) != NULL;
1752 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1753 ptr = lutil_strcopy( ptr, "[ ]?" );
1755 if ( r[ 1 ] == ' ' ) {
1759 ptr = lutil_strcopy( ptr, p );
1768 suffix_massage_patternize( const char *s, const char *p )
1775 if ( s[ 0 ] == '\0' ) {
1779 res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1780 if ( res == NULL ) {
1784 ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1785 if ( s[ 0 ] == '\0' ) {
1789 lutil_strcopy( ptr, p );
1795 suffix_massage_config(
1796 struct rewrite_info *info,
1797 struct berval *pvnc,
1798 struct berval *nvnc,
1799 struct berval *prnc,
1806 rargv[ 0 ] = "rewriteEngine";
1809 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1811 rargv[ 0 ] = "rewriteContext";
1812 rargv[ 1 ] = "default";
1814 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1816 rargv[ 0 ] = "rewriteRule";
1817 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1818 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1821 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1822 ch_free( rargv[ 1 ] );
1823 ch_free( rargv[ 2 ] );
1825 if ( BER_BVISEMPTY( pvnc ) ) {
1826 rargv[ 0 ] = "rewriteRule";
1828 rargv[ 2 ] = prnc->bv_val;
1831 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1834 rargv[ 0 ] = "rewriteContext";
1835 rargv[ 1 ] = "searchEntryDN";
1837 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1839 rargv[ 0 ] = "rewriteRule";
1840 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1841 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1844 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1845 ch_free( rargv[ 1 ] );
1846 ch_free( rargv[ 2 ] );
1848 if ( BER_BVISEMPTY( prnc ) ) {
1849 rargv[ 0 ] = "rewriteRule";
1851 rargv[ 2 ] = pvnc->bv_val;
1854 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1857 /* backward compatibility */
1858 rargv[ 0 ] = "rewriteContext";
1859 rargv[ 1 ] = "searchResult";
1860 rargv[ 2 ] = "alias";
1861 rargv[ 3 ] = "searchEntryDN";
1863 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1865 rargv[ 0 ] = "rewriteContext";
1866 rargv[ 1 ] = "matchedDN";
1867 rargv[ 2 ] = "alias";
1868 rargv[ 3 ] = "searchEntryDN";
1870 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1872 rargv[ 0 ] = "rewriteContext";
1873 rargv[ 1 ] = "searchAttrDN";
1874 rargv[ 2 ] = "alias";
1875 rargv[ 3 ] = "searchEntryDN";
1877 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1879 /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1880 * see servers/slapd/overlays/rwm.h for details */
1881 rargv[ 0 ] = "rewriteContext";
1882 rargv[ 1 ] = "referralAttrDN";
1884 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1886 rargv[ 0 ] = "rewriteContext";
1887 rargv[ 1 ] = "referralDN";
1889 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1893 #endif /* ENABLE_REWRITE */