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 *mapping;
337 if ( rwm_mapping( at_map, &an[i].an_name, &mapping, remap ) ) {
342 na[ j++ ] = an[ i ].an_name.bv_val;
344 } else if ( !BER_BVISNULL( &mapping->m_dst ) ) {
345 na[ j++ ] = mapping->m_dst.bv_val;
349 if ( j == 0 && i != 0 ) {
350 na[ j++ ] = LDAP_NO_ATTRS;
363 AttributeDescription **adp,
364 struct berval *mapped_attr,
365 struct berval *value,
366 struct berval *mapped_value,
369 struct berval vtmp = BER_BVNULL;
371 AttributeDescription *ad = *adp;
372 struct ldapmapping *mapping = NULL;
374 rwm_mapping( &dc->rwmap->rwm_at, &ad->ad_cname, &mapping, remap );
375 if ( mapping == NULL ) {
376 if ( dc->rwmap->rwm_at.drop_missing ) {
380 *mapped_attr = ad->ad_cname;
383 *mapped_attr = mapping->m_dst;
386 if ( value != NULL ) {
387 assert( mapped_value != NULL );
389 if ( ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
390 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
395 #ifdef ENABLE_REWRITE
396 fdc.ctx = "searchFilterAttrDN";
397 #endif /* ENABLE_REWRITE */
400 rc = rwm_dn_massage_normalize( &fdc, value, &vtmp );
403 if ( vtmp.bv_val != value->bv_val ) {
408 case LDAP_UNWILLING_TO_PERFORM:
414 } else if ( ad == slap_schema.si_ad_objectClass
415 || ad == slap_schema.si_ad_structuralObjectClass )
417 rwm_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
418 if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
426 filter_escape_value( &vtmp, mapped_value );
429 ch_free( vtmp.bv_val );
433 if ( mapping != NULL ) {
434 assert( mapping->m_dst_ad != NULL );
435 *adp = mapping->m_dst_ad;
442 rwm_int_filter_map_rewrite(
445 struct berval *fstr )
453 ber_bvfalse = BER_BVC( "(?=false)" ),
454 ber_bvtrue = BER_BVC( "(?=true)" ),
455 ber_bvundefined = BER_BVC( "(?=undefined)" ),
456 ber_bverror = BER_BVC( "(?=error)" ),
457 ber_bvunknown = BER_BVC( "(?=unknown)" ),
458 ber_bvnone = BER_BVC( "(?=none)" );
462 ber_dupbv( fstr, &ber_bvnone );
466 switch ( f->f_choice ) {
467 case LDAP_FILTER_EQUALITY:
468 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
469 &f->f_av_value, &vtmp, RWM_MAP ) )
474 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(=)" );
475 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
477 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
478 atmp.bv_val, vtmp.bv_val );
480 ch_free( vtmp.bv_val );
484 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
485 &f->f_av_value, &vtmp, RWM_MAP ) )
490 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(>=)" );
491 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
493 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
494 atmp.bv_val, vtmp.bv_val );
496 ch_free( vtmp.bv_val );
500 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
501 &f->f_av_value, &vtmp, RWM_MAP ) )
506 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
507 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
509 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
510 atmp.bv_val, vtmp.bv_val );
512 ch_free( vtmp.bv_val );
515 case LDAP_FILTER_APPROX:
516 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
517 &f->f_av_value, &vtmp, RWM_MAP ) )
522 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
523 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
525 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
526 atmp.bv_val, vtmp.bv_val );
528 ch_free( vtmp.bv_val );
531 case LDAP_FILTER_SUBSTRINGS:
532 if ( map_attr_value( dc, &f->f_sub_desc, &atmp,
533 NULL, NULL, RWM_MAP ) )
538 /* cannot be a DN ... */
540 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
541 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
543 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
546 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
549 filter_escape_value( &f->f_sub_initial, &vtmp );
551 fstr->bv_len += vtmp.bv_len;
552 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
554 snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
555 /* "(attr=" */ "%s*)",
558 ch_free( vtmp.bv_val );
561 if ( f->f_sub_any != NULL ) {
562 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
564 filter_escape_value( &f->f_sub_any[i], &vtmp );
566 fstr->bv_len += vtmp.bv_len + 1;
567 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
569 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
570 /* "(attr=[init]*[any*]" */ "%s*)",
572 ch_free( vtmp.bv_val );
576 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
579 filter_escape_value( &f->f_sub_final, &vtmp );
581 fstr->bv_len += vtmp.bv_len;
582 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
584 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
585 /* "(attr=[init*][any*]" */ "%s)",
588 ch_free( vtmp.bv_val );
593 case LDAP_FILTER_PRESENT:
594 if ( map_attr_value( dc, &f->f_desc, &atmp,
595 NULL, NULL, RWM_MAP ) )
600 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
601 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
603 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
607 case LDAP_FILTER_AND:
609 case LDAP_FILTER_NOT:
610 fstr->bv_len = STRLENOF( "(%)" );
611 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
613 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
614 f->f_choice == LDAP_FILTER_AND ? '&' :
615 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
617 for ( p = f->f_list; p != NULL; p = p->f_next ) {
620 if ( rwm_int_filter_map_rewrite( dc, p, &vtmp ) )
625 fstr->bv_len += vtmp.bv_len;
626 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
628 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
629 /*"("*/ "%s)", vtmp.bv_val );
631 ch_free( vtmp.bv_val );
636 case LDAP_FILTER_EXT: {
637 if ( f->f_mr_desc ) {
638 if ( map_attr_value( dc, &f->f_mr_desc, &atmp,
639 &f->f_mr_value, &vtmp, RWM_MAP ) )
645 BER_BVSTR( &atmp, "" );
646 filter_escape_value( &f->f_mr_value, &vtmp );
650 fstr->bv_len = atmp.bv_len +
651 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
652 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
653 vtmp.bv_len + STRLENOF( "(:=)" );
654 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
656 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
658 f->f_mr_dnattrs ? ":dn" : "",
659 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
660 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
662 ch_free( vtmp.bv_val );
666 case SLAPD_FILTER_COMPUTED:
667 switch ( f->f_result ) {
668 case LDAP_COMPARE_FALSE:
672 case LDAP_COMPARE_TRUE:
676 case SLAPD_COMPARE_UNDEFINED:
677 tmp = ber_bvundefined;
685 ber_dupbv( fstr, &tmp );
689 ber_dupbv( fstr, &ber_bvunknown );
697 rwm_filter_map_rewrite(
700 struct berval *fstr )
706 rc = rwm_int_filter_map_rewrite( dc, f, fstr );
708 #ifdef ENABLE_REWRITE
709 if ( rc != LDAP_SUCCESS ) {
716 fdc.ctx = "searchFilter";
718 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
719 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
720 fdc.conn, &fstr->bv_val ) )
722 case REWRITE_REGEXEC_OK:
723 if ( !BER_BVISNULL( fstr ) ) {
724 fstr->bv_len = strlen( fstr->bv_val );
725 ch_free( ftmp.bv_val );
731 Debug( LDAP_DEBUG_ARGS,
732 "[rw] %s: \"%s\" -> \"%s\"\n",
733 fdc.ctx, ftmp.bv_val, fstr->bv_val );
737 case REWRITE_REGEXEC_UNWILLING:
739 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
740 fdc.rs->sr_text = "Operation not allowed";
742 rc = LDAP_UNWILLING_TO_PERFORM;
745 case REWRITE_REGEXEC_ERR:
747 fdc.rs->sr_err = LDAP_OTHER;
748 fdc.rs->sr_text = "Rewrite error";
754 #endif /* ENABLE_REWRITE */
759 * I don't like this much, but we need two different
760 * functions because different heap managers may be
761 * in use in back-ldap/meta to reduce the amount of
762 * calls to malloc routines, and some of the free()
763 * routines may be macros with args
766 rwm_referral_rewrite(
771 BerVarray *pa_nvals )
773 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
774 struct ldaprwmap *rwmap =
775 (struct ldaprwmap *)on->on_bi.bi_private;
780 struct berval dn = BER_BVNULL,
786 * Rewrite the dn if needed
789 #ifdef ENABLE_REWRITE
790 dc.conn = op->o_conn;
792 dc.ctx = (char *)cookie;
793 #else /* ! ENABLE_REWRITE */
794 dc.tofrom = ((int *)cookie)[0];
796 #endif /* ! ENABLE_REWRITE */
798 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
802 if ( pa_nvals != NULL ) {
803 if ( *pa_nvals == NULL ) {
804 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
805 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
809 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
810 struct berval olddn = BER_BVNULL,
816 rc = ldap_url_parse( oldval.bv_val, &ludp );
817 if ( rc != LDAP_URL_SUCCESS ) {
818 /* leave attr untouched if massage failed */
819 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
820 ber_dupbv( &(*pa_nvals)[i], &oldval );
825 /* FIXME: URLs like "ldap:///dc=suffix" if passed
826 * thru ldap_url_parse() and ldap_url_desc2str()
827 * get rewritten as "ldap:///dc=suffix??base";
828 * we don't want this to occur... */
829 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
830 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
833 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
838 rc = rwm_dn_massage_pretty_normalize( &dc, &olddn,
841 rc = rwm_dn_massage_pretty( &dc, &olddn, &dn );
845 case LDAP_UNWILLING_TO_PERFORM:
847 * FIXME: need to check if it may be considered
848 * legal to trim values when adding/modifying;
849 * it should be when searching (e.g. ACLs).
851 ch_free( a_vals[i].bv_val );
853 a_vals[i] = a_vals[last];
855 (*pa_nvals)[i] = (*pa_nvals)[last];
858 BER_BVZERO( &a_vals[last] );
860 BER_BVZERO( &(*pa_nvals)[last] );
866 if ( !BER_BVISNULL( &dn ) && dn.bv_val != olddn.bv_val ) {
869 ludp->lud_dn = dn.bv_val;
870 newurl = ldap_url_desc2str( ludp );
871 ludp->lud_dn = olddn.bv_val;
872 ch_free( dn.bv_val );
873 if ( newurl == NULL ) {
874 /* FIXME: leave attr untouched
875 * even if ldap_url_desc2str failed...
880 ber_str2bv( newurl, 0, 1, &a_vals[i] );
884 ludp->lud_dn = ndn.bv_val;
885 newurl = ldap_url_desc2str( ludp );
886 ludp->lud_dn = olddn.bv_val;
887 ch_free( ndn.bv_val );
888 if ( newurl == NULL ) {
889 /* FIXME: leave attr untouched
890 * even if ldap_url_desc2str failed...
892 ch_free( a_vals[i].bv_val );
897 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
898 ch_free( (*pa_nvals)[i].bv_val );
900 ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
904 ch_free( oldval.bv_val );
905 ludp->lud_dn = olddn.bv_val;
910 /* leave attr untouched if massage failed */
911 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
912 ber_dupbv( &(*pa_nvals)[i], &a_vals[i] );
916 ldap_free_urldesc( ludp );
923 * I don't like this much, but we need two different
924 * functions because different heap managers may be
925 * in use in back-ldap/meta to reduce the amount of
926 * calls to malloc routines, and some of the free()
927 * routines may be macros with args
935 BerVarray *pa_nvals )
937 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
938 struct ldaprwmap *rwmap =
939 (struct ldaprwmap *)on->on_bi.bi_private;
944 struct berval dn = BER_BVNULL,
952 if ( pa_nvals == NULL || *pa_nvals == NULL ) {
959 * Rewrite the dn if needed
962 #ifdef ENABLE_REWRITE
963 dc.conn = op->o_conn;
965 dc.ctx = (char *)cookie;
966 #else /* ! ENABLE_REWRITE */
967 dc.tofrom = ((int *)cookie)[0];
969 #endif /* ! ENABLE_REWRITE */
971 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
973 if ( pa_nvals != NULL ) {
974 if ( *pa_nvals == NULL ) {
975 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
976 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
980 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
986 ndn = (*pa_nvals)[i];
987 rc = rwm_dn_massage_pretty_normalize( &dc, &in[i], &dn, &ndn );
989 rc = rwm_dn_massage_pretty( &dc, &in[i], &dn );
993 rc = rwm_dn_massage_normalize( &dc, &in[i], &ndn );
997 case LDAP_UNWILLING_TO_PERFORM:
999 * FIXME: need to check if it may be considered
1000 * legal to trim values when adding/modifying;
1001 * it should be when searching (e.g. ACLs).
1003 ch_free( in[i].bv_val );
1006 if ( a_vals && pa_nvals ) {
1007 (*pa_nvals)[i] = (*pa_nvals)[last];
1010 BER_BVZERO( &in[last] );
1011 if ( a_vals && pa_nvals ) {
1012 BER_BVZERO( &(*pa_nvals)[last] );
1019 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
1020 ch_free( a_vals[i].bv_val );
1024 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1025 ch_free( (*pa_nvals)[i].bv_val );
1027 (*pa_nvals)[i] = ndn;
1032 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
1033 ch_free( (*pa_nvals)[i].bv_val );
1034 (*pa_nvals)[i] = ndn;
1040 /* leave attr untouched if massage failed */
1041 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1042 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1052 rwm_referral_result_rewrite(
1059 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1062 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1068 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1069 if ( rc != LDAP_URL_SUCCESS ) {
1070 /* leave attr untouched if massage failed */
1074 /* FIXME: URLs like "ldap:///dc=suffix" if passed
1075 * thru ldap_url_parse() and ldap_url_desc2str()
1076 * get rewritten as "ldap:///dc=suffix??base";
1077 * we don't want this to occur... */
1078 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
1079 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
1082 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1085 rc = rwm_dn_massage_pretty( dc, &olddn, &dn );
1087 case LDAP_UNWILLING_TO_PERFORM:
1089 * FIXME: need to check if it may be considered
1090 * legal to trim values when adding/modifying;
1091 * it should be when searching (e.g. ACLs).
1093 ch_free( a_vals[i].bv_val );
1095 a_vals[i] = a_vals[last];
1097 BER_BVZERO( &a_vals[last] );
1103 /* leave attr untouched if massage failed */
1104 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1107 ludp->lud_dn = dn.bv_val;
1108 newurl = ldap_url_desc2str( ludp );
1109 if ( newurl == NULL ) {
1110 /* FIXME: leave attr untouched
1111 * even if ldap_url_desc2str failed...
1116 ch_free( a_vals[i].bv_val );
1117 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1118 LDAP_FREE( newurl );
1119 ludp->lud_dn = olddn.bv_val;
1124 ldap_free_urldesc( ludp );
1131 rwm_dnattr_result_rewrite(
1138 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1141 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1146 rc = rwm_dn_massage_pretty( dc, &a_vals[i], &dn );
1148 case LDAP_UNWILLING_TO_PERFORM:
1150 * FIXME: need to check if it may be considered
1151 * legal to trim values when adding/modifying;
1152 * it should be when searching (e.g. ACLs).
1154 ch_free( a_vals[i].bv_val );
1156 a_vals[i] = a_vals[last];
1158 BER_BVZERO( &a_vals[last] );
1163 /* leave attr untouched if massage failed */
1164 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1165 ch_free( a_vals[i].bv_val );
1176 rwm_mapping_free( void *v_mapping )
1178 struct ldapmapping *mapping = v_mapping;
1180 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1181 ch_free( mapping[0].m_src.bv_val );
1184 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1185 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1186 if ( mapping[0].m_src_oc ) {
1187 ch_free( mapping[0].m_src_oc );
1191 if ( mapping[0].m_src_ad ) {
1192 ch_free( mapping[0].m_src_ad );
1197 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1198 ch_free( mapping[0].m_dst.bv_val );
1201 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1202 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1203 if ( mapping[0].m_dst_oc ) {
1204 ch_free( mapping[0].m_dst_oc );
1208 if ( mapping[0].m_dst_ad ) {
1209 ch_free( mapping[0].m_dst_ad );
1218 #endif /* SLAPD_OVER_RWM */