2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 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"
41 struct ldapmapping *mapping;
44 memset( mt, 0, sizeof( metatarget_t ) );
46 mt->mt_rwmap.rwm_rw = rewrite_info_init( REWRITE_MODE_USE_DEFAULT );
47 if ( mt->mt_rwmap.rwm_rw == NULL ) {
53 * the filter rewrite as a string must be disabled
54 * by default; it can be re-enabled by adding rules;
55 * this creates an empty rewriteContext
57 rargv[ 0 ] = "rewriteContext";
58 rargv[ 1 ] = "searchFilter";
60 rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
62 rargv[ 0 ] = "rewriteContext";
63 rargv[ 1 ] = "default";
65 rewrite_parse( mt->mt_rwmap.rwm_rw, "<suffix massage>", 1, 2, rargv );
67 ldap_back_map_init( &mt->mt_rwmap.rwm_at, &mapping );
73 check_true_false( char *str )
75 if ( strcasecmp( str, "true" ) == 0 || strcasecmp( str, "yes" ) == 0 ) {
79 if ( strcasecmp( str, "false" ) == 0 || strcasecmp( str, "no" ) == 0 ) {
96 metainfo_t *mi = ( metainfo_t * )be->be_private;
100 "%s: line %d: meta backend info is null!\n",
105 /* URI of server to query */
106 if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
107 int i = mi->mi_ntargets;
110 #endif /* uncomment if uri MUST be a branch of suffix */
111 LDAPURLDesc *ludp, *tmpludp;
119 "%s: line %d: missing URI "
120 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
129 "%s: line %d: too many args "
130 "in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
135 if ( be->be_nsuffix == NULL ) {
137 "%s: line %d: the suffix must be defined before any target.\n",
144 mi->mi_targets = ( metatarget_t * )ch_realloc( mi->mi_targets,
145 sizeof( metatarget_t ) * mi->mi_ntargets );
146 if ( mi->mi_targets == NULL ) {
148 "%s: line %d: out of memory while storing server name"
149 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
154 if ( new_target( &mi->mi_targets[ i ] ) != 0 ) {
156 "%s: line %d: unable to init server"
157 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
162 mi->mi_targets[ i ].mt_nretries = mi->mi_nretries;
163 mi->mi_targets[ i ].mt_flags = mi->flags;
164 mi->mi_targets[ i ].mt_version = mi->mi_version;
166 for ( c = 0; c < META_OP_LAST; c++ ) {
167 mi->mi_targets[ i ].mt_timeout[ c ] = mi->mi_timeout[ c ];
173 if ( ldap_url_parselist_ext( &ludp, argv[ 1 ], "\t" ) != LDAP_SUCCESS ) {
175 "%s: line %d: unable to parse URI"
176 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
182 * uri MUST have the <dn> part!
184 if ( ludp->lud_dn == NULL ) {
186 "%s: line %d: missing <naming context> "
187 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
191 } else if ( ludp->lud_dn[ 0 ] == '\0' ) {
194 for ( j = 0; !BER_BVISNULL( &be->be_nsuffix[ j ] ); j++ ) {
195 if ( BER_BVISEMPTY( &be->be_nsuffix[ j ] ) ) {
200 if ( BER_BVISNULL( &be->be_nsuffix[ j ] ) ) {
202 "%s: line %d: missing <naming context> "
203 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
210 * copies and stores uri and suffix
212 ber_str2bv( ludp->lud_dn, 0, 0, &dn );
213 rc = dnPrettyNormal( NULL, &dn, &mi->mi_targets[ i ].mt_psuffix,
214 &mi->mi_targets[ i ].mt_nsuffix, NULL );
215 if( rc != LDAP_SUCCESS ) {
216 fprintf( stderr, "%s: line %d: "
217 "target '%s' DN is invalid\n",
218 fname, lineno, argv[ 1 ] );
222 ludp->lud_dn[ 0 ] = '\0';
224 switch ( ludp->lud_scope ) {
225 case LDAP_SCOPE_DEFAULT:
226 mi->mi_targets[ i ].mt_scope = LDAP_SCOPE_SUBTREE;
229 case LDAP_SCOPE_SUBTREE:
230 #ifdef LDAP_SCOPE_SUBORDINATE
231 case LDAP_SCOPE_SUBORDINATE:
232 #endif /* LDAP_SCOPE_SUBORDINATE */
233 mi->mi_targets[ i ].mt_scope = ludp->lud_scope;
237 fprintf( stderr, "%s: line %d: "
238 "invalid scope for target '%s'\n",
239 fname, lineno, argv[ 1 ] );
243 /* check all, to apply the scope check on the first one */
244 for ( tmpludp = ludp; tmpludp; tmpludp = tmpludp->lud_next ) {
245 if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) {
246 fprintf( stderr, "%s: line %d: "
247 "multiple URIs must have "
255 mi->mi_targets[ i ].mt_uri = ldap_url_list2urls( ludp );
256 ldap_free_urllist( ludp );
257 if ( mi->mi_targets[ i ].mt_uri == NULL) {
258 fprintf( stderr, "%s: line %d: no memory?\n",
264 * uri MUST be a branch of suffix!
266 #if 0 /* too strict a constraint */
267 if ( select_backend( &mi->mi_targets[ i ].suffix, 0, 0 ) != be ) {
269 "%s: line %d: <naming context> of URI does not refer to current backend"
270 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
276 * uri MUST be a branch of a suffix!
278 if ( select_backend( &mi->mi_targets[ i ].mt_nsuffix, 0, 0 ) == NULL ) {
280 "%s: line %d: <naming context> of URI does not resolve to a backend"
281 " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
287 /* default target directive */
288 } else if ( strcasecmp( argv[ 0 ], "default-target" ) == 0 ) {
289 int i = mi->mi_ntargets - 1;
294 "%s: line %d: \"default-target\" alone need be"
295 " inside a \"uri\" directive\n",
299 mi->mi_defaulttarget = i;
301 if ( strcasecmp( argv[ 1 ], "none" ) == 0 ) {
304 "%s: line %d: \"default-target none\""
305 " should go before uri definitions\n",
308 mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
312 int n = strtol( argv[ 1 ], &next, 10 );
313 if ( n < 0 || n >= i - 1 ) {
315 "%s: line %d: illegal target number %d\n",
319 mi->mi_defaulttarget = n;
323 /* ttl of dn cache */
324 } else if ( strcasecmp( argv[ 0 ], "dncache-ttl" ) == 0 ) {
327 "%s: line %d: missing ttl in \"dncache-ttl <ttl>\" line\n",
332 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
333 mi->mi_cache.ttl = META_DNCACHE_FOREVER;
334 } else if ( strcasecmp( argv[ 1 ], "disabled" ) == 0 ) {
335 mi->mi_cache.ttl = META_DNCACHE_DISABLED;
337 mi->mi_cache.ttl = atol( argv[ 1 ] );
340 /* network timeout when connecting to ldap servers */
341 } else if ( strcasecmp( argv[ 0 ], "network-timeout" ) == 0 ) {
344 "%s: line %d: missing network timeout in \"network-timeout <seconds>\" line\n",
348 mi->mi_network_timeout = atol(argv[ 1 ]);
350 /* name to use for meta_back_group */
351 } else if ( strcasecmp( argv[ 0 ], "acl-authcDN" ) == 0
352 || strcasecmp( argv[ 0 ], "binddn" ) == 0 )
354 int i = mi->mi_ntargets - 1;
359 "%s: line %d: need \"uri\" directive first\n",
366 "%s: line %d: missing name in \"binddn <name>\" line\n",
371 if ( strcasecmp( argv[ 0 ], "binddn" ) == 0 ) {
372 fprintf( stderr, "%s: line %d: "
373 "\"binddn\" statement is deprecated; "
374 "use \"acl-authcDN\" instead\n",
376 /* FIXME: some day we'll need to throw an error */
379 dn.bv_val = argv[ 1 ];
380 dn.bv_len = strlen( argv[ 1 ] );
381 if ( dnNormalize( 0, NULL, NULL, &dn, &mi->mi_targets[ i ].mt_binddn,
382 NULL ) != LDAP_SUCCESS )
384 fprintf( stderr, "%s: line %d: "
385 "bind DN '%s' is invalid\n",
386 fname, lineno, argv[ 1 ] );
390 /* password to use for meta_back_group */
391 } else if ( strcasecmp( argv[ 0 ], "acl-passwd" ) == 0
392 || strcasecmp( argv[ 0 ], "bindpw" ) == 0 )
394 int i = mi->mi_ntargets - 1;
398 "%s: line %d: need \"uri\" directive first\n",
405 "%s: line %d: missing password in \"bindpw <password>\" line\n",
410 if ( strcasecmp( argv[ 0 ], "bindpw" ) == 0 ) {
411 fprintf( stderr, "%s: line %d: "
412 "\"bindpw\" statement is deprecated; "
413 "use \"acl-passwd\" instead\n",
415 /* FIXME: some day we'll need to throw an error */
418 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_bindpw );
420 /* save bind creds for referral rebinds? */
421 } else if ( strcasecmp( argv[ 0 ], "rebind-as-user" ) == 0 ) {
424 "%s: line %d: \"rebind-as-user {NO|yes}\" takes 1 argument.\n",
431 "%s: line %d: deprecated use of \"rebind-as-user {FALSE|true}\" with no arguments.\n",
433 mi->flags |= LDAP_BACK_F_SAVECRED;
436 switch ( check_true_false( argv[ 1 ] ) ) {
438 mi->flags &= ~LDAP_BACK_F_SAVECRED;
442 mi->flags |= LDAP_BACK_F_SAVECRED;
447 "%s: line %d: \"rebind-as-user {FALSE|true}\" unknown argument \"%s\".\n",
448 fname, lineno, argv[ 1 ] );
453 } else if ( strcasecmp( argv[ 0 ], "chase-referrals" ) == 0 ) {
454 unsigned *flagsp = mi->mi_ntargets ?
455 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
460 "%s: line %d: \"chase-referrals {TRUE|false}\" needs 1 argument.\n",
465 /* this is the default; we add it because the default might change... */
466 switch ( check_true_false( argv[ 1 ] ) ) {
468 *flagsp |= LDAP_BACK_F_CHASE_REFERRALS;
472 *flagsp &= ~LDAP_BACK_F_CHASE_REFERRALS;
477 "%s: line %d: \"chase-referrals {TRUE|false}\": unknown argument \"%s\".\n",
478 fname, lineno, argv[ 1 ] );
482 } else if ( strcasecmp( argv[ 0 ], "tls" ) == 0 ) {
483 unsigned *flagsp = mi->mi_ntargets ?
484 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
489 "%s: line %d: \"tls <what>\" needs 1 argument.\n",
495 if ( strcasecmp( argv[ 1 ], "start" ) == 0 ) {
496 *flagsp |= ( LDAP_BACK_F_USE_TLS | LDAP_BACK_F_TLS_CRITICAL );
499 } else if ( strcasecmp( argv[ 1 ], "try-start" ) == 0 ) {
500 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
501 *flagsp |= LDAP_BACK_F_USE_TLS;
503 /* propagate start tls */
504 } else if ( strcasecmp( argv[ 1 ], "propagate" ) == 0 ) {
505 *flagsp |= ( LDAP_BACK_F_PROPAGATE_TLS | LDAP_BACK_F_TLS_CRITICAL );
508 } else if ( strcasecmp( argv[ 1 ], "try-propagate" ) == 0 ) {
509 *flagsp &= ~LDAP_BACK_F_TLS_CRITICAL;
510 *flagsp |= LDAP_BACK_F_PROPAGATE_TLS;
514 "%s: line %d: \"tls <what>\": unknown argument \"%s\".\n",
515 fname, lineno, argv[ 1 ] );
519 } else if ( strcasecmp( argv[ 0 ], "t-f-support" ) == 0 ) {
520 unsigned *flagsp = mi->mi_ntargets ?
521 &mi->mi_targets[ mi->mi_ntargets - 1 ].mt_flags
526 "%s: line %d: \"t-f-support {FALSE|true|discover}\" needs 1 argument.\n",
531 switch ( check_true_false( argv[ 1 ] ) ) {
533 *flagsp &= ~(LDAP_BACK_F_SUPPORT_T_F|LDAP_BACK_F_SUPPORT_T_F_DISCOVER);
537 *flagsp |= LDAP_BACK_F_SUPPORT_T_F;
541 if ( strcasecmp( argv[ 1 ], "discover" ) == 0 ) {
542 *flagsp |= LDAP_BACK_F_SUPPORT_T_F_DISCOVER;
546 "%s: line %d: unknown value \"%s\" for \"t-f-support {no|yes|discover}\".\n",
547 fname, lineno, argv[ 1 ] );
554 } else if ( strcasecmp( argv[ 0 ], "onerr" ) == 0 ) {
557 "%s: line %d: \"onerr {CONTINUE|stop}\" takes 1 argument\n",
562 if ( strcasecmp( argv[ 1 ], "continue" ) == 0 ) {
563 mi->flags &= ~META_BACK_F_ONERR_STOP;
565 } else if ( strcasecmp( argv[ 1 ], "stop" ) == 0 ) {
566 mi->flags |= META_BACK_F_ONERR_STOP;
570 "%s: line %d: \"onerr {CONTINUE|stop}\": invalid arg \"%s\".\n",
571 fname, lineno, argv[ 1 ] );
576 } else if ( strcasecmp( argv[ 0 ], "pseudoroot-bind-defer" ) == 0 ) {
579 "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\" takes 1 argument\n",
584 switch ( check_true_false( argv[ 1 ] ) ) {
586 mi->flags &= ~META_BACK_F_DEFER_ROOTDN_BIND;
590 mi->flags |= META_BACK_F_DEFER_ROOTDN_BIND;
595 "%s: line %d: \"pseudoroot-bind-defer {FALSE|true}\": invalid arg \"%s\".\n",
596 fname, lineno, argv[ 1 ] );
600 } else if ( strcasecmp( argv[ 0 ], "timeout" ) == 0 ) {
602 time_t *tv = mi->mi_ntargets ?
603 mi->mi_targets[ mi->mi_ntargets - 1 ].mt_timeout
609 "%s: line %d: \"timeout [{add|delete|modify|modrdn}=]<val> [...]\" takes at least 1 argument\n",
614 for ( c = 1; c < argc; c++ ) {
615 time_t *t = NULL, val;
617 sep = strchr( argv[ c ], '=' );
619 size_t len = sep - argv[ c ];
621 if ( strncasecmp( argv[ c ], "add", len ) == 0 ) {
622 t = &tv[ META_OP_ADD ];
623 } else if ( strncasecmp( argv[ c ], "delete", len ) == 0 ) {
624 t = &tv[ META_OP_DELETE ];
625 } else if ( strncasecmp( argv[ c ], "modify", len ) == 0 ) {
626 t = &tv[ META_OP_MODIFY ];
627 } else if ( strncasecmp( argv[ c ], "modrdn", len ) == 0 ) {
628 t = &tv[ META_OP_MODRDN ];
631 "%s: line %d: unknown operation \"%s\" for timeout #%d.\n",
632 fname, lineno, argv[ c ], c );
641 val = strtoul( sep, &next, 10 );
642 if ( next == sep || next[ 0 ] != '\0' ) {
644 "%s: line %d: unable to parse value \"%s\" for timeout.\n",
645 fname, lineno, sep );
655 for ( i = 0; i < META_OP_LAST; i++ ) {
661 /* name to use as pseudo-root dn */
662 } else if ( strcasecmp( argv[ 0 ], "pseudorootdn" ) == 0 ) {
663 int i = mi->mi_ntargets - 1;
668 "%s: line %d: need \"uri\" directive first\n",
675 "%s: line %d: missing name in \"pseudorootdn <name>\" line\n",
680 dn.bv_val = argv[ 1 ];
681 dn.bv_len = strlen( argv[ 1 ] );
682 if ( dnNormalize( 0, NULL, NULL, &dn,
683 &mi->mi_targets[ i ].mt_pseudorootdn, NULL ) != LDAP_SUCCESS )
685 fprintf( stderr, "%s: line %d: "
686 "pseudoroot DN '%s' is invalid\n",
687 fname, lineno, argv[ 1 ] );
691 /* password to use as pseudo-root */
692 } else if ( strcasecmp( argv[ 0 ], "pseudorootpw" ) == 0 ) {
693 int i = mi->mi_ntargets - 1;
697 "%s: line %d: need \"uri\" directive first\n",
704 "%s: line %d: missing password in \"pseudorootpw <password>\" line\n",
708 ber_str2bv( argv[ 1 ], 0L, 1, &mi->mi_targets[ i ].mt_pseudorootpw );
711 } else if ( strcasecmp( argv[ 0 ], "suffixmassage" ) == 0 ) {
713 int i = mi->mi_ntargets - 1, rc;
714 struct berval dn, nvnc, pvnc, nrnc, prnc;
718 "%s: line %d: need \"uri\" directive first\n",
726 * suffixmassage <suffix> <massaged suffix>
728 * the <suffix> field must be defined as a valid suffix
729 * (or suffixAlias?) for the current database;
730 * the <massaged suffix> shouldn't have already been
731 * defined as a valid suffix or suffixAlias for the
736 "%s: line %d: syntax is \"suffixMassage <suffix> <massaged suffix>\"\n",
741 ber_str2bv( argv[ 1 ], 0, 0, &dn );
742 if ( dnPrettyNormal( NULL, &dn, &pvnc, &nvnc, NULL ) != LDAP_SUCCESS ) {
743 fprintf( stderr, "%s: line %d: "
744 "suffix '%s' is invalid\n",
745 fname, lineno, argv[ 1 ] );
749 tmp_be = select_backend( &nvnc, 0, 0 );
750 if ( tmp_be != NULL && tmp_be != be ) {
752 "%s: line %d: suffix already in use by another backend in"
753 " \"suffixMassage <suffix> <massaged suffix>\"\n",
760 ber_str2bv( argv[ 2 ], 0, 0, &dn );
761 if ( dnPrettyNormal( NULL, &dn, &prnc, &nrnc, NULL ) != LDAP_SUCCESS ) {
762 fprintf( stderr, "%s: line %d: "
763 "massaged suffix '%s' is invalid\n",
764 fname, lineno, argv[ 2 ] );
771 tmp_be = select_backend( &nrnc, 0, 0 );
772 if ( tmp_be != NULL ) {
774 "%s: line %d: massaged suffix already in use by another backend in"
775 " \"suffixMassage <suffix> <massaged suffix>\"\n",
786 * The suffix massaging is emulated by means of the
787 * rewrite capabilities
788 * FIXME: no extra rewrite capabilities should be added
791 rc = suffix_massage_config( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
792 &pvnc, &nvnc, &prnc, &nrnc );
801 /* rewrite stuff ... */
802 } else if ( strncasecmp( argv[ 0 ], "rewrite", 7 ) == 0 ) {
803 int i = mi->mi_ntargets - 1;
806 fprintf( stderr, "%s: line %d: \"rewrite\" "
807 "statement outside target definition.\n",
812 return rewrite_parse( mi->mi_targets[ i ].mt_rwmap.rwm_rw,
813 fname, lineno, argc, argv );
815 /* objectclass/attribute mapping */
816 } else if ( strcasecmp( argv[ 0 ], "map" ) == 0 ) {
817 int i = mi->mi_ntargets - 1;
821 "%s: line %d: need \"uri\" directive first\n",
826 return ldap_back_map_config( &mi->mi_targets[ i ].mt_rwmap.rwm_oc,
827 &mi->mi_targets[ i ].mt_rwmap.rwm_at,
828 fname, lineno, argc, argv );
830 } else if ( strcasecmp( argv[ 0 ], "nretries" ) == 0 ) {
831 int i = mi->mi_ntargets - 1;
832 int nretries = META_RETRY_UNDEFINED;
836 "%s: line %d: need value in \"nretries <value>\"\n",
841 if ( strcasecmp( argv[ 1 ], "forever" ) == 0 ) {
842 nretries = META_RETRY_FOREVER;
844 } else if ( strcasecmp( argv[ 1 ], "never" ) == 0 ) {
845 nretries = META_RETRY_NEVER;
850 nretries = strtol( argv[ 1 ], &next, 10 );
851 if ( next == argv[ 1 ] || next[ 0 ] != '\0' ) {
853 "%s: line %d: unable to parse value \"%s\" in \"nretries <value>\"\n",
854 fname, lineno, argv[ 1 ] );
860 mi->mi_nretries = nretries;
863 mi->mi_targets[ i ].mt_nretries = nretries;
868 return SLAP_CONF_UNKNOWN;
874 ldap_back_map_config(
875 struct ldapmap *oc_map,
876 struct ldapmap *at_map,
883 struct ldapmapping *mapping;
887 if ( argc < 3 || argc > 4 ) {
889 "%s: line %d: syntax is \"map {objectclass | attribute} [<local> | *] {<foreign> | *}\"\n",
894 if ( strcasecmp( argv[ 1 ], "objectclass" ) == 0 ) {
898 } else if ( strcasecmp( argv[ 1 ], "attribute" ) == 0 ) {
902 fprintf( stderr, "%s: line %d: syntax is "
903 "\"map {objectclass | attribute} [<local> | *] "
904 "{<foreign> | *}\"\n",
909 if ( strcmp( argv[ 2 ], "*" ) == 0 ) {
910 if ( argc < 4 || strcmp( argv[ 3 ], "*" ) == 0 ) {
911 map->drop_missing = ( argc < 4 );
914 src = dst = argv[ 3 ];
916 } else if ( argc < 4 ) {
922 dst = ( strcmp( argv[ 3 ], "*" ) == 0 ? src : argv[ 3 ] );
925 if ( ( map == at_map )
926 && ( strcasecmp( src, "objectclass" ) == 0
927 || strcasecmp( dst, "objectclass" ) == 0 ) )
930 "%s: line %d: objectclass attribute cannot be mapped\n",
934 mapping = (struct ldapmapping *)ch_calloc( 2,
935 sizeof(struct ldapmapping) );
936 if ( mapping == NULL ) {
938 "%s: line %d: out of memory\n",
942 ber_str2bv( src, 0, 1, &mapping->src );
943 ber_str2bv( dst, 0, 1, &mapping->dst );
944 mapping[ 1 ].src = mapping->dst;
945 mapping[ 1 ].dst = mapping->src;
951 if ( src[ 0 ] != '\0' ) {
952 if ( oc_bvfind( &mapping->src ) == NULL ) {
954 "%s: line %d: warning, source objectClass '%s' "
955 "should be defined in schema\n",
956 fname, lineno, src );
959 * FIXME: this should become an err
965 if ( oc_bvfind( &mapping->dst ) == NULL ) {
967 "%s: line %d: warning, destination objectClass '%s' "
968 "is not defined in schema\n",
969 fname, lineno, dst );
973 const char *text = NULL;
974 AttributeDescription *ad = NULL;
976 if ( src[ 0 ] != '\0' ) {
977 rc = slap_bv2ad( &mapping->src, &ad, &text );
978 if ( rc != LDAP_SUCCESS ) {
980 "%s: line %d: warning, source attributeType '%s' "
981 "should be defined in schema\n",
982 fname, lineno, src );
985 * FIXME: this should become an err
988 * we create a fake "proxied" ad
992 rc = slap_bv2undef_ad( &mapping->src,
993 &ad, &text, SLAP_AD_PROXIED );
994 if ( rc != LDAP_SUCCESS ) {
996 "%s: line %d: source attributeType '%s': %d (%s)\n",
998 rc, text ? text : "" );
1006 rc = slap_bv2ad( &mapping->dst, &ad, &text );
1007 if ( rc != LDAP_SUCCESS ) {
1009 "%s: line %d: warning, destination attributeType '%s' "
1010 "is not defined in schema\n",
1011 fname, lineno, dst );
1014 * we create a fake "proxied" ad
1018 rc = slap_bv2undef_ad( &mapping->dst,
1019 &ad, &text, SLAP_AD_PROXIED );
1020 if ( rc != LDAP_SUCCESS ) {
1022 "%s: line %d: source attributeType '%s': %d (%s)\n",
1024 rc, text ? text : "" );
1030 if ( (src[ 0 ] != '\0' && avl_find( map->map, (caddr_t)mapping, mapping_cmp ) != NULL)
1031 || avl_find( map->remap, (caddr_t)&mapping[ 1 ], mapping_cmp ) != NULL)
1034 "%s: line %d: duplicate mapping found" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
1039 if ( src[ 0 ] != '\0' ) {
1040 avl_insert( &map->map, (caddr_t)mapping,
1041 mapping_cmp, mapping_dup );
1043 avl_insert( &map->remap, (caddr_t)&mapping[ 1 ],
1044 mapping_cmp, mapping_dup );
1050 ch_free( mapping->src.bv_val );
1051 ch_free( mapping->dst.bv_val );
1059 #ifdef ENABLE_REWRITE
1061 suffix_massage_regexize( const char *s )
1067 if ( s[ 0 ] == '\0' ) {
1068 return ch_strdup( "^(.+)$" );
1072 ( r = strchr( p, ',' ) ) != NULL;
1076 res = ch_calloc( sizeof( char ),
1078 + STRLENOF( "((.+),)?" )
1079 + STRLENOF( "[ ]?" ) * i
1080 + STRLENOF( "$" ) + 1 );
1082 ptr = lutil_strcopy( res, "((.+),)?" );
1084 ( r = strchr( p, ',' ) ) != NULL;
1086 ptr = lutil_strncopy( ptr, p, r - p + 1 );
1087 ptr = lutil_strcopy( ptr, "[ ]?" );
1089 if ( r[ 1 ] == ' ' ) {
1093 ptr = lutil_strcopy( ptr, p );
1102 suffix_massage_patternize( const char *s, const char *p )
1109 if ( s[ 0 ] == '\0' ) {
1113 res = ch_calloc( sizeof( char ), len + STRLENOF( "%1" ) + 1 );
1114 if ( res == NULL ) {
1118 ptr = lutil_strcopy( res, ( p[ 0 ] == '\0' ? "%2" : "%1" ) );
1119 if ( s[ 0 ] == '\0' ) {
1123 lutil_strcopy( ptr, p );
1129 suffix_massage_config(
1130 struct rewrite_info *info,
1131 struct berval *pvnc,
1132 struct berval *nvnc,
1133 struct berval *prnc,
1140 rargv[ 0 ] = "rewriteEngine";
1143 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1145 rargv[ 0 ] = "rewriteContext";
1146 rargv[ 1 ] = "default";
1148 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1150 rargv[ 0 ] = "rewriteRule";
1151 rargv[ 1 ] = suffix_massage_regexize( pvnc->bv_val );
1152 rargv[ 2 ] = suffix_massage_patternize( pvnc->bv_val, prnc->bv_val );
1155 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1156 ch_free( rargv[ 1 ] );
1157 ch_free( rargv[ 2 ] );
1159 if ( BER_BVISEMPTY( pvnc ) ) {
1160 rargv[ 0 ] = "rewriteRule";
1162 rargv[ 2 ] = prnc->bv_val;
1165 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1168 rargv[ 0 ] = "rewriteContext";
1169 rargv[ 1 ] = "searchEntryDN";
1171 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1173 rargv[ 0 ] = "rewriteRule";
1174 rargv[ 1 ] = suffix_massage_regexize( prnc->bv_val );
1175 rargv[ 2 ] = suffix_massage_patternize( prnc->bv_val, pvnc->bv_val );
1178 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1179 ch_free( rargv[ 1 ] );
1180 ch_free( rargv[ 2 ] );
1182 if ( BER_BVISEMPTY( prnc ) ) {
1183 rargv[ 0 ] = "rewriteRule";
1185 rargv[ 2 ] = pvnc->bv_val;
1188 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1191 /* backward compatibility */
1192 rargv[ 0 ] = "rewriteContext";
1193 rargv[ 1 ] = "searchResult";
1194 rargv[ 2 ] = "alias";
1195 rargv[ 3 ] = "searchEntryDN";
1197 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1199 rargv[ 0 ] = "rewriteContext";
1200 rargv[ 1 ] = "matchedDN";
1201 rargv[ 2 ] = "alias";
1202 rargv[ 3 ] = "searchEntryDN";
1204 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1206 rargv[ 0 ] = "rewriteContext";
1207 rargv[ 1 ] = "searchAttrDN";
1208 rargv[ 2 ] = "alias";
1209 rargv[ 3 ] = "searchEntryDN";
1211 rewrite_parse( info, "<suffix massage>", ++line, 4, rargv );
1213 /* NOTE: this corresponds to #undef'ining RWM_REFERRAL_REWRITE;
1214 * see servers/slapd/overlays/rwm.h for details */
1215 rargv[ 0 ] = "rewriteContext";
1216 rargv[ 1 ] = "referralAttrDN";
1218 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1220 rargv[ 0 ] = "rewriteContext";
1221 rargv[ 1 ] = "referralDN";
1223 rewrite_parse( info, "<suffix massage>", ++line, 2, rargv );
1227 #endif /* ENABLE_REWRITE */