1 /* rwmmap.c - rewrite/mapping routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2005 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
30 #include <ac/string.h>
31 #include <ac/socket.h>
36 #undef ldap_debug /* silence a warning in ldap-int.h */
37 #include "../../../libraries/libldap/ldap-int.h"
40 rwm_mapping_cmp( const void *c1, const void *c2 )
42 struct ldapmapping *map1 = (struct ldapmapping *)c1;
43 struct ldapmapping *map2 = (struct ldapmapping *)c2;
44 int rc = map1->m_src.bv_len - map2->m_src.bv_len;
50 return strcasecmp( map1->m_src.bv_val, map2->m_src.bv_val );
54 rwm_mapping_dup( void *c1, void *c2 )
56 struct ldapmapping *map1 = (struct ldapmapping *)c1;
57 struct ldapmapping *map2 = (struct ldapmapping *)c2;
58 int rc = map1->m_src.bv_len - map2->m_src.bv_len;
64 return ( ( strcasecmp( map1->m_src.bv_val, map2->m_src.bv_val ) == 0 ) ? -1 : 0 );
68 rwm_map_init( struct ldapmap *lm, struct ldapmapping **m )
70 struct ldapmapping *mapping;
78 mapping = (struct ldapmapping *)ch_calloc( 2,
79 sizeof( struct ldapmapping ) );
80 if ( mapping == NULL ) {
81 return LDAP_NO_MEMORY;
84 /* FIXME: I don't think this is needed any more... */
85 rc = slap_str2ad( "objectClass", &mapping->m_src_ad, &text );
86 if ( rc != LDAP_SUCCESS ) {
90 mapping->m_dst_ad = mapping->m_src_ad;
91 ber_dupbv( &mapping->m_dst, &mapping->m_src_ad->ad_cname );
92 ber_dupbv( &mapping->m_dst, &mapping->m_src );
94 mapping[1].m_src = mapping->m_src;
95 mapping[1].m_dst = mapping->m_dst;
97 avl_insert( &lm->map, (caddr_t)mapping,
98 rwm_mapping_cmp, rwm_mapping_dup );
99 avl_insert( &lm->remap, (caddr_t)&mapping[1],
100 rwm_mapping_cmp, rwm_mapping_dup );
108 rwm_mapping( struct ldapmap *map, struct berval *s, struct ldapmapping **m, int remap )
111 struct ldapmapping fmapping;
115 if ( remap == RWM_REMAP ) {
123 *m = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping,
127 return map->drop_missing;
134 rwm_map( struct ldapmap *map, struct berval *s, struct berval *bv, int remap )
136 struct ldapmapping *mapping;
139 ( void )rwm_mapping( map, s, &mapping, remap );
140 if ( mapping != NULL ) {
141 if ( !BER_BVISNULL( &mapping->m_dst ) ) {
142 *bv = mapping->m_dst;
147 if ( !map->drop_missing ) {
153 * Map attribute names in place
157 struct ldapmap *at_map,
158 struct ldapmap *oc_map,
174 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
176 *anp = ch_malloc( ( i + 1 )* sizeof( AttributeName ) );
177 if ( *anp == NULL ) {
178 return LDAP_NO_MEMORY;
181 for ( i = 0, j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
182 struct ldapmapping *m;
183 int at_drop_missing = 0,
186 if ( an[i].an_desc ) {
188 /* FIXME: better leave as is? */
192 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
193 if ( at_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
204 if ( remap == RWM_MAP ) {
205 (*anp)[j].an_name = m->m_dst;
206 (*anp)[j].an_desc = m->m_dst_ad;
208 (*anp)[j].an_name = m->m_src;
209 (*anp)[j].an_desc = m->m_src_ad;
216 } else if ( an[i].an_oc ) {
218 /* FIXME: better leave as is? */
222 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
224 if ( oc_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
235 if ( remap == RWM_MAP ) {
236 (*anp)[j].an_name = m->m_dst;
237 (*anp)[j].an_oc = m->m_dst_oc;
239 (*anp)[j].an_name = m->m_src;
240 (*anp)[j].an_oc = m->m_src_oc;
244 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
246 if ( at_drop_missing || !m ) {
248 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
250 /* if both at_map and oc_map required to drop missing,
252 if ( oc_drop_missing && at_drop_missing ) {
256 /* if no oc_map mapping was found and at_map required
257 * to drop missing, then do it; otherwise, at_map wins
258 * and an is considered an attr and is left unchanged */
260 if ( at_drop_missing ) {
268 if ( BER_BVISNULL( &m->m_dst ) ) {
273 if ( remap == RWM_MAP ) {
274 (*anp)[j].an_name = m->m_dst;
275 (*anp)[j].an_oc = m->m_dst_oc;
277 (*anp)[j].an_name = m->m_src;
278 (*anp)[j].an_oc = m->m_src_oc;
284 if ( !BER_BVISNULL( &m->m_dst ) ) {
286 if ( remap == RWM_MAP ) {
287 (*anp)[j].an_name = m->m_dst;
288 (*anp)[j].an_desc = m->m_dst_ad;
290 (*anp)[j].an_name = m->m_src;
291 (*anp)[j].an_desc = m->m_src_ad;
299 if ( j == 0 && i != 0 ) {
300 memset( &(*anp)[0], 0, sizeof( AttributeName ) );
301 BER_BVSTR( &(*anp)[0].an_name, LDAP_NO_ATTRS );
303 memset( &(*anp)[j], 0, sizeof( AttributeName ) );
310 struct ldapmap *at_map,
320 *mapped_attrs = NULL;
324 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
328 na = (char **)ch_calloc( i + 1, sizeof( char * ) );
330 *mapped_attrs = NULL;
331 return LDAP_NO_MEMORY;
334 for ( i = j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
335 struct ldapmapping *m;
337 if ( rwm_mapping( at_map, &an[i].an_name, &m, remap ) ) {
341 if ( !m || ( m && !BER_BVISNULL( &m->m_dst ) ) ) {
342 na[j++] = m->m_dst.bv_val;
345 if ( j == 0 && i != 0 ) {
346 na[j++] = LDAP_NO_ATTRS;
357 AttributeDescription *ad,
358 struct berval *mapped_attr,
359 struct berval *value,
360 struct berval *mapped_value,
363 struct berval vtmp = BER_BVNULL;
366 rwm_map( &dc->rwmap->rwm_at, &ad->ad_cname, mapped_attr, remap );
367 if ( BER_BVISNULL( mapped_attr ) || BER_BVISEMPTY( mapped_attr ) ) {
369 * FIXME: are we sure we need to search oc_map if at_map fails?
371 rwm_map( &dc->rwmap->rwm_oc, &ad->ad_cname, mapped_attr, remap );
372 if ( BER_BVISNULL( mapped_attr ) || BER_BVISEMPTY( mapped_attr ) )
374 *mapped_attr = ad->ad_cname;
378 if ( value == NULL ) {
382 if ( ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
387 #ifdef ENABLE_REWRITE
388 fdc.ctx = "searchFilterAttrDN";
389 #endif /* ENABLE_REWRITE */
392 rc = rwm_dn_massage_normalize( &fdc, value, &vtmp );
395 if ( vtmp.bv_val != value->bv_val ) {
400 case LDAP_UNWILLING_TO_PERFORM:
406 } else if ( ad == slap_schema.si_ad_objectClass
407 || ad == slap_schema.si_ad_structuralObjectClass )
409 rwm_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
410 if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
418 filter_escape_value( &vtmp, mapped_value );
421 ch_free( vtmp.bv_val );
428 rwm_int_filter_map_rewrite(
431 struct berval *fstr )
439 ber_bvfalse = BER_BVC( "(?=false)" ),
440 ber_bvtrue = BER_BVC( "(?=true)" ),
441 ber_bvundefined = BER_BVC( "(?=undefined)" ),
442 ber_bverror = BER_BVC( "(?=error)" ),
443 ber_bvunknown = BER_BVC( "(?=unknown)" ),
444 ber_bvnone = BER_BVC( "(?=none)" );
448 ber_dupbv( fstr, &ber_bvnone );
452 switch ( f->f_choice ) {
453 case LDAP_FILTER_EQUALITY:
454 if ( map_attr_value( dc, f->f_av_desc, &atmp,
455 &f->f_av_value, &vtmp, RWM_MAP ) )
460 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(=)" );
461 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
463 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
464 atmp.bv_val, vtmp.bv_val );
466 ch_free( vtmp.bv_val );
470 if ( map_attr_value( dc, f->f_av_desc, &atmp,
471 &f->f_av_value, &vtmp, RWM_MAP ) )
476 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(>=)" );
477 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
479 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
480 atmp.bv_val, vtmp.bv_val );
482 ch_free( vtmp.bv_val );
486 if ( map_attr_value( dc, f->f_av_desc, &atmp,
487 &f->f_av_value, &vtmp, RWM_MAP ) )
492 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
493 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
495 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
496 atmp.bv_val, vtmp.bv_val );
498 ch_free( vtmp.bv_val );
501 case LDAP_FILTER_APPROX:
502 if ( map_attr_value( dc, f->f_av_desc, &atmp,
503 &f->f_av_value, &vtmp, RWM_MAP ) )
508 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
509 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
511 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
512 atmp.bv_val, vtmp.bv_val );
514 ch_free( vtmp.bv_val );
517 case LDAP_FILTER_SUBSTRINGS:
518 if ( map_attr_value( dc, f->f_sub_desc, &atmp,
519 NULL, NULL, RWM_MAP ) )
524 /* cannot be a DN ... */
526 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
527 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
529 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
532 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
535 filter_escape_value( &f->f_sub_initial, &vtmp );
537 fstr->bv_len += vtmp.bv_len;
538 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
540 snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
541 /* "(attr=" */ "%s*)",
544 ch_free( vtmp.bv_val );
547 if ( f->f_sub_any != NULL ) {
548 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
550 filter_escape_value( &f->f_sub_any[i], &vtmp );
552 fstr->bv_len += vtmp.bv_len + 1;
553 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
555 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
556 /* "(attr=[init]*[any*]" */ "%s*)",
558 ch_free( vtmp.bv_val );
562 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
565 filter_escape_value( &f->f_sub_final, &vtmp );
567 fstr->bv_len += vtmp.bv_len;
568 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
570 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
571 /* "(attr=[init*][any*]" */ "%s)",
574 ch_free( vtmp.bv_val );
579 case LDAP_FILTER_PRESENT:
580 if ( map_attr_value( dc, f->f_desc, &atmp,
581 NULL, NULL, RWM_MAP ) )
586 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
587 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
589 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
593 case LDAP_FILTER_AND:
595 case LDAP_FILTER_NOT:
596 fstr->bv_len = STRLENOF( "(%)" );
597 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
599 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
600 f->f_choice == LDAP_FILTER_AND ? '&' :
601 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
603 for ( p = f->f_list; p != NULL; p = p->f_next ) {
606 if ( rwm_int_filter_map_rewrite( dc, p, &vtmp ) )
611 fstr->bv_len += vtmp.bv_len;
612 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
614 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
615 /*"("*/ "%s)", vtmp.bv_val );
617 ch_free( vtmp.bv_val );
622 case LDAP_FILTER_EXT: {
623 if ( f->f_mr_desc ) {
624 if ( map_attr_value( dc, f->f_mr_desc, &atmp,
625 &f->f_mr_value, &vtmp, RWM_MAP ) )
631 BER_BVSTR( &atmp, "" );
632 filter_escape_value( &f->f_mr_value, &vtmp );
636 fstr->bv_len = atmp.bv_len +
637 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
638 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
639 vtmp.bv_len + STRLENOF( "(:=)" );
640 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
642 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
644 f->f_mr_dnattrs ? ":dn" : "",
645 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
646 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
648 ch_free( vtmp.bv_val );
652 case SLAPD_FILTER_COMPUTED:
653 switch ( f->f_result ) {
654 case LDAP_COMPARE_FALSE:
658 case LDAP_COMPARE_TRUE:
662 case SLAPD_COMPARE_UNDEFINED:
663 tmp = ber_bvundefined;
671 ber_dupbv( fstr, &tmp );
675 ber_dupbv( fstr, &ber_bvunknown );
683 rwm_filter_map_rewrite(
686 struct berval *fstr )
692 rc = rwm_int_filter_map_rewrite( dc, f, fstr );
694 #ifdef ENABLE_REWRITE
695 if ( rc != LDAP_SUCCESS ) {
702 fdc.ctx = "searchFilter";
704 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
705 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
706 fdc.conn, &fstr->bv_val ) )
708 case REWRITE_REGEXEC_OK:
709 if ( !BER_BVISNULL( fstr ) ) {
710 fstr->bv_len = strlen( fstr->bv_val );
711 ch_free( ftmp.bv_val );
717 Debug( LDAP_DEBUG_ARGS,
718 "[rw] %s: \"%s\" -> \"%s\"\n",
719 fdc.ctx, ftmp.bv_val, fstr->bv_val );
723 case REWRITE_REGEXEC_UNWILLING:
725 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
726 fdc.rs->sr_text = "Operation not allowed";
728 rc = LDAP_UNWILLING_TO_PERFORM;
731 case REWRITE_REGEXEC_ERR:
733 fdc.rs->sr_err = LDAP_OTHER;
734 fdc.rs->sr_text = "Rewrite error";
740 #endif /* ENABLE_REWRITE */
745 * I don't like this much, but we need two different
746 * functions because different heap managers may be
747 * in use in back-ldap/meta to reduce the amount of
748 * calls to malloc routines, and some of the free()
749 * routines may be macros with args
752 rwm_referral_rewrite(
757 BerVarray *pa_nvals )
759 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
760 struct ldaprwmap *rwmap =
761 (struct ldaprwmap *)on->on_bi.bi_private;
766 struct berval dn = BER_BVNULL,
772 * Rewrite the dn if needed
775 #ifdef ENABLE_REWRITE
776 dc.conn = op->o_conn;
778 dc.ctx = (char *)cookie;
779 #else /* ! ENABLE_REWRITE */
780 dc.tofrom = ((int *)cookie)[0];
782 #endif /* ! ENABLE_REWRITE */
784 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
788 if ( pa_nvals != NULL ) {
789 if ( *pa_nvals == NULL ) {
790 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
791 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
795 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
796 struct berval olddn, oldval;
801 rc = ldap_url_parse( oldval.bv_val, &ludp );
802 if ( rc != LDAP_URL_SUCCESS ) {
803 /* leave attr untouched if massage failed */
804 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
805 ber_dupbv( &(*pa_nvals)[i], &oldval );
810 /* FIXME: URLs like "ldap:///dc=suffix" if passed
811 * thru ldap_url_parse() and ldap_url_desc2str()
812 * get rewritten as "ldap:///dc=suffix??base";
813 * we don't want this to occur... */
814 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
815 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
818 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
823 rc = rwm_dn_massage_pretty_normalize( &dc, &olddn,
826 rc = rwm_dn_massage_pretty( &dc, &olddn, &dn );
830 case LDAP_UNWILLING_TO_PERFORM:
832 * FIXME: need to check if it may be considered
833 * legal to trim values when adding/modifying;
834 * it should be when searching (e.g. ACLs).
836 ch_free( a_vals[i].bv_val );
838 a_vals[i] = a_vals[last];
840 (*pa_nvals)[i] = (*pa_nvals)[last];
843 BER_BVZERO( &a_vals[last] );
845 BER_BVZERO( &(*pa_nvals)[last] );
851 if ( !BER_BVISNULL( &dn ) && dn.bv_val != olddn.bv_val ) {
854 ludp->lud_dn = dn.bv_val;
855 newurl = ldap_url_desc2str( ludp );
856 ludp->lud_dn = olddn.bv_val;
857 ch_free( dn.bv_val );
858 if ( newurl == NULL ) {
859 /* FIXME: leave attr untouched
860 * even if ldap_url_desc2str failed...
865 ber_str2bv( newurl, 0, 1, &a_vals[i] );
869 ludp->lud_dn = ndn.bv_val;
870 newurl = ldap_url_desc2str( ludp );
871 ludp->lud_dn = olddn.bv_val;
872 ch_free( ndn.bv_val );
873 if ( newurl == NULL ) {
874 /* FIXME: leave attr untouched
875 * even if ldap_url_desc2str failed...
877 ch_free( a_vals[i].bv_val );
882 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
883 ch_free( (*pa_nvals)[i].bv_val );
885 ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
889 ch_free( oldval.bv_val );
890 ludp->lud_dn = olddn.bv_val;
895 /* leave attr untouched if massage failed */
896 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
897 ber_dupbv( &(*pa_nvals)[i], &a_vals[i] );
901 ldap_free_urldesc( ludp );
908 * I don't like this much, but we need two different
909 * functions because different heap managers may be
910 * in use in back-ldap/meta to reduce the amount of
911 * calls to malloc routines, and some of the free()
912 * routines may be macros with args
920 BerVarray *pa_nvals )
922 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
923 struct ldaprwmap *rwmap =
924 (struct ldaprwmap *)on->on_bi.bi_private;
929 struct berval dn = BER_BVNULL,
937 if ( pa_nvals == NULL || *pa_nvals == NULL ) {
944 * Rewrite the dn if needed
947 #ifdef ENABLE_REWRITE
948 dc.conn = op->o_conn;
950 dc.ctx = (char *)cookie;
951 #else /* ! ENABLE_REWRITE */
952 dc.tofrom = ((int *)cookie)[0];
954 #endif /* ! ENABLE_REWRITE */
956 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
958 if ( pa_nvals != NULL ) {
959 if ( *pa_nvals == NULL ) {
960 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
961 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
965 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
971 ndn = (*pa_nvals)[i];
972 rc = rwm_dn_massage_pretty_normalize( &dc, &in[i], &dn, &ndn );
974 rc = rwm_dn_massage_pretty( &dc, &in[i], &dn );
978 rc = rwm_dn_massage_normalize( &dc, &in[i], &ndn );
982 case LDAP_UNWILLING_TO_PERFORM:
984 * FIXME: need to check if it may be considered
985 * legal to trim values when adding/modifying;
986 * it should be when searching (e.g. ACLs).
988 ch_free( in[i].bv_val );
991 if ( a_vals && pa_nvals ) {
992 (*pa_nvals)[i] = (*pa_nvals)[last];
995 BER_BVZERO( &in[last] );
996 if ( a_vals && pa_nvals ) {
997 BER_BVZERO( &(*pa_nvals)[last] );
1004 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
1005 ch_free( a_vals[i].bv_val );
1009 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1010 ch_free( (*pa_nvals)[i].bv_val );
1012 (*pa_nvals)[i] = ndn;
1017 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
1018 ch_free( (*pa_nvals)[i].bv_val );
1019 (*pa_nvals)[i] = ndn;
1025 /* leave attr untouched if massage failed */
1026 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1027 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1037 rwm_referral_result_rewrite(
1044 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1047 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1048 struct berval dn, olddn;
1052 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1053 if ( rc != LDAP_URL_SUCCESS ) {
1054 /* leave attr untouched if massage failed */
1058 /* FIXME: URLs like "ldap:///dc=suffix" if passed
1059 * thru ldap_url_parse() and ldap_url_desc2str()
1060 * get rewritten as "ldap:///dc=suffix??base";
1061 * we don't want this to occur... */
1062 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
1063 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
1066 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1069 rc = rwm_dn_massage_pretty( dc, &olddn, &dn );
1071 case LDAP_UNWILLING_TO_PERFORM:
1073 * FIXME: need to check if it may be considered
1074 * legal to trim values when adding/modifying;
1075 * it should be when searching (e.g. ACLs).
1077 ch_free( a_vals[i].bv_val );
1079 a_vals[i] = a_vals[last];
1081 BER_BVZERO( &a_vals[last] );
1087 /* leave attr untouched if massage failed */
1088 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1091 ludp->lud_dn = dn.bv_val;
1092 newurl = ldap_url_desc2str( ludp );
1093 if ( newurl == NULL ) {
1094 /* FIXME: leave attr untouched
1095 * even if ldap_url_desc2str failed...
1100 ch_free( a_vals[i].bv_val );
1101 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1102 LDAP_FREE( newurl );
1103 ludp->lud_dn = olddn.bv_val;
1108 ldap_free_urldesc( ludp );
1115 rwm_dnattr_result_rewrite(
1122 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1125 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1130 rc = rwm_dn_massage_pretty( dc, &a_vals[i], &dn );
1132 case LDAP_UNWILLING_TO_PERFORM:
1134 * FIXME: need to check if it may be considered
1135 * legal to trim values when adding/modifying;
1136 * it should be when searching (e.g. ACLs).
1138 ch_free( a_vals[i].bv_val );
1140 a_vals[i] = a_vals[last];
1142 BER_BVZERO( &a_vals[last] );
1147 /* leave attr untouched if massage failed */
1148 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1149 ch_free( a_vals[i].bv_val );
1160 rwm_mapping_free( void *v_mapping )
1162 struct ldapmapping *mapping = v_mapping;
1164 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1165 ch_free( mapping[0].m_src.bv_val );
1168 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1169 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1170 if ( mapping[0].m_src_oc ) {
1171 ch_free( mapping[0].m_src_oc );
1175 if ( mapping[0].m_src_ad ) {
1176 ch_free( mapping[0].m_src_ad );
1181 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1182 ch_free( mapping[0].m_dst.bv_val );
1185 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1186 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1187 if ( mapping[0].m_dst_oc ) {
1188 ch_free( mapping[0].m_dst_oc );
1192 if ( mapping[0].m_dst_ad ) {
1193 ch_free( mapping[0].m_dst_ad );
1202 #endif /* SLAPD_OVER_RWM */