1 /* rwmmap.c - rewrite/mapping routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2004 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 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,
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 */
391 rc = rwm_dn_massage( &fdc, value, NULL, &vtmp );
394 if ( vtmp.bv_val != value->bv_val ) {
399 case LDAP_UNWILLING_TO_PERFORM:
405 } else if ( ad == slap_schema.si_ad_objectClass
406 || ad == slap_schema.si_ad_structuralObjectClass )
408 rwm_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
409 if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
417 filter_escape_value( &vtmp, mapped_value );
420 ch_free( vtmp.bv_val );
427 rwm_int_filter_map_rewrite(
430 struct berval *fstr )
438 ber_bvfalse = BER_BVC( "(?=false)" ),
439 ber_bvtrue = BER_BVC( "(?=true)" ),
440 ber_bvundefined = BER_BVC( "(?=undefined)" ),
441 ber_bverror = BER_BVC( "(?=error)" ),
442 ber_bvunknown = BER_BVC( "(?=unknown)" ),
443 ber_bvnone = BER_BVC( "(?=none)" );
447 ber_dupbv( fstr, &ber_bvnone );
451 switch ( f->f_choice ) {
452 case LDAP_FILTER_EQUALITY:
453 if ( map_attr_value( dc, f->f_av_desc, &atmp,
454 &f->f_av_value, &vtmp, RWM_MAP ) )
459 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(=)" );
460 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
462 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
463 atmp.bv_val, vtmp.bv_val );
465 ch_free( vtmp.bv_val );
469 if ( map_attr_value( dc, f->f_av_desc, &atmp,
470 &f->f_av_value, &vtmp, RWM_MAP ) )
475 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(>=)" );
476 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
478 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
479 atmp.bv_val, vtmp.bv_val );
481 ch_free( vtmp.bv_val );
485 if ( map_attr_value( dc, f->f_av_desc, &atmp,
486 &f->f_av_value, &vtmp, RWM_MAP ) )
491 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
492 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
494 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
495 atmp.bv_val, vtmp.bv_val );
497 ch_free( vtmp.bv_val );
500 case LDAP_FILTER_APPROX:
501 if ( map_attr_value( dc, f->f_av_desc, &atmp,
502 &f->f_av_value, &vtmp, RWM_MAP ) )
507 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
508 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
510 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
511 atmp.bv_val, vtmp.bv_val );
513 ch_free( vtmp.bv_val );
516 case LDAP_FILTER_SUBSTRINGS:
517 if ( map_attr_value( dc, f->f_sub_desc, &atmp,
518 NULL, NULL, RWM_MAP ) )
523 /* cannot be a DN ... */
525 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
526 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
528 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
531 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
534 filter_escape_value( &f->f_sub_initial, &vtmp );
536 fstr->bv_len += vtmp.bv_len;
537 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
539 snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
540 /* "(attr=" */ "%s*)",
543 ch_free( vtmp.bv_val );
546 if ( f->f_sub_any != NULL ) {
547 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
549 filter_escape_value( &f->f_sub_any[i], &vtmp );
551 fstr->bv_len += vtmp.bv_len + 1;
552 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
554 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
555 /* "(attr=[init]*[any*]" */ "%s*)",
557 ch_free( vtmp.bv_val );
561 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
564 filter_escape_value( &f->f_sub_final, &vtmp );
566 fstr->bv_len += vtmp.bv_len;
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)",
573 ch_free( vtmp.bv_val );
578 case LDAP_FILTER_PRESENT:
579 if ( map_attr_value( dc, f->f_desc, &atmp,
580 NULL, NULL, RWM_MAP ) )
585 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
586 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
588 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
592 case LDAP_FILTER_AND:
594 case LDAP_FILTER_NOT:
595 fstr->bv_len = STRLENOF( "(%)" );
596 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
598 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
599 f->f_choice == LDAP_FILTER_AND ? '&' :
600 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
602 for ( p = f->f_list; p != NULL; p = p->f_next ) {
605 if ( rwm_int_filter_map_rewrite( dc, p, &vtmp ) )
610 fstr->bv_len += vtmp.bv_len;
611 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
613 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
614 /*"("*/ "%s)", vtmp.bv_val );
616 ch_free( vtmp.bv_val );
621 case LDAP_FILTER_EXT: {
622 if ( f->f_mr_desc ) {
623 if ( map_attr_value( dc, f->f_mr_desc, &atmp,
624 &f->f_mr_value, &vtmp, RWM_MAP ) )
630 BER_BVSTR( &atmp, "" );
631 filter_escape_value( &f->f_mr_value, &vtmp );
635 fstr->bv_len = atmp.bv_len +
636 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
637 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
638 vtmp.bv_len + STRLENOF( "(:=)" );
639 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
641 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
643 f->f_mr_dnattrs ? ":dn" : "",
644 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
645 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
647 ch_free( vtmp.bv_val );
651 case SLAPD_FILTER_COMPUTED:
652 switch ( f->f_result ) {
653 case LDAP_COMPARE_FALSE:
657 case LDAP_COMPARE_TRUE:
661 case SLAPD_COMPARE_UNDEFINED:
662 tmp = ber_bvundefined;
670 ber_dupbv( fstr, &tmp );
674 ber_dupbv( fstr, &ber_bvunknown );
682 rwm_filter_map_rewrite(
685 struct berval *fstr )
691 rc = rwm_int_filter_map_rewrite( dc, f, fstr );
693 #ifdef ENABLE_REWRITE
694 if ( rc != LDAP_SUCCESS ) {
701 fdc.ctx = "searchFilter";
703 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
704 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
705 fdc.conn, &fstr->bv_val )) {
706 case REWRITE_REGEXEC_OK:
707 if ( !BER_BVISNULL( fstr ) ) {
708 fstr->bv_len = strlen( fstr->bv_val );
709 ch_free( ftmp.bv_val );
715 Debug( LDAP_DEBUG_ARGS,
716 "[rw] %s: \"%s\" -> \"%s\"\n",
717 dc->ctx, ftmp.bv_val, fstr->bv_val );
721 case REWRITE_REGEXEC_UNWILLING:
723 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
724 fdc.rs->sr_text = "Operation not allowed";
726 rc = LDAP_UNWILLING_TO_PERFORM;
729 case REWRITE_REGEXEC_ERR:
731 fdc.rs->sr_err = LDAP_OTHER;
732 fdc.rs->sr_text = "Rewrite error";
738 #endif /* ENABLE_REWRITE */
743 * I don't like this much, but we need two different
744 * functions because different heap managers may be
745 * in use in back-ldap/meta to reduce the amount of
746 * calls to malloc routines, and some of the free()
747 * routines may be macros with args
750 rwm_referral_rewrite(
755 BerVarray *pa_nvals )
757 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
758 struct ldaprwmap *rwmap =
759 (struct ldaprwmap *)on->on_bi.bi_private;
764 struct berval dn, ndn, *ndnp = NULL;
769 * Rewrite the dn if needed
772 #ifdef ENABLE_REWRITE
773 dc.conn = op->o_conn;
775 dc.ctx = (char *)cookie;
776 #else /* ! ENABLE_REWRITE */
777 dc.tofrom = ((int *)cookie)[0];
779 #endif /* ! ENABLE_REWRITE */
781 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
782 if ( pa_nvals != NULL ) {
785 if ( *pa_nvals == NULL ) {
786 *pa_nvals = ch_malloc( last * sizeof(struct berval) );
787 memset( *pa_nvals, 0, last * sizeof(struct berval) );
792 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
793 struct berval olddn, oldval;
798 rc = ldap_url_parse( oldval.bv_val, &ludp );
799 if ( rc != LDAP_URL_SUCCESS ) {
800 /* leave attr untouched if massage failed */
801 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
802 ber_dupbv( &(*pa_nvals)[i], &oldval );
806 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
808 rc = rwm_dn_massage( &dc, &olddn, &dn, ndnp );
810 case LDAP_UNWILLING_TO_PERFORM:
812 * FIXME: need to check if it may be considered
813 * legal to trim values when adding/modifying;
814 * it should be when searching (e.g. ACLs).
816 ch_free( a_vals[i].bv_val );
818 a_vals[i] = a_vals[last];
820 (*pa_nvals)[i] = (*pa_nvals)[last];
823 BER_BVZERO( &a_vals[last] );
825 BER_BVZERO( &(*pa_nvals)[last] );
831 if ( !BER_BVISNULL( &dn ) && dn.bv_val != olddn.bv_val ) {
834 ludp->lud_dn = dn.bv_val;
835 newurl = ldap_url_desc2str( ludp );
836 if ( newurl == NULL ) {
837 /* FIXME: leave attr untouched
838 * even if ldap_url_desc2str failed... */
842 ber_str2bv( newurl, 0, 1, &a_vals[i] );
846 ludp->lud_dn = ndn.bv_val;
847 newurl = ldap_url_desc2str( ludp );
848 if ( newurl == NULL ) {
849 /* FIXME: leave attr untouched
850 * even if ldap_url_desc2str failed... */
851 ch_free( a_vals[i].bv_val );
856 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
857 ch_free( (*pa_nvals)[i].bv_val );
859 ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
863 ch_free( oldval.bv_val );
864 ludp->lud_dn = olddn.bv_val;
869 /* leave attr untouched if massage failed */
870 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
871 ber_dupbv( &(*pa_nvals)[i], &a_vals[i] );
875 ldap_free_urldesc( ludp );
882 * I don't like this much, but we need two different
883 * functions because different heap managers may be
884 * in use in back-ldap/meta to reduce the amount of
885 * calls to malloc routines, and some of the free()
886 * routines may be macros with args
894 BerVarray *pa_nvals )
896 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
897 struct ldaprwmap *rwmap =
898 (struct ldaprwmap *)on->on_bi.bi_private;
903 struct berval dn, *dnp = NULL, ndn, *ndnp = NULL;
911 if ( pa_nvals == NULL || *pa_nvals == NULL ) {
918 * Rewrite the dn if needed
921 #ifdef ENABLE_REWRITE
922 dc.conn = op->o_conn;
924 dc.ctx = (char *)cookie;
925 #else /* ! ENABLE_REWRITE */
926 dc.tofrom = ((int *)cookie)[0];
928 #endif /* ! ENABLE_REWRITE */
930 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
931 if ( pa_nvals != NULL ) {
934 if ( *pa_nvals == NULL ) {
935 *pa_nvals = ch_malloc( last * sizeof(struct berval) );
936 memset( *pa_nvals, 0, last * sizeof(struct berval) );
941 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
944 rc = rwm_dn_massage( &dc, &in[i], dnp, ndnp );
946 case LDAP_UNWILLING_TO_PERFORM:
948 * FIXME: need to check if it may be considered
949 * legal to trim values when adding/modifying;
950 * it should be when searching (e.g. ACLs).
952 ch_free( in[i].bv_val );
955 if ( a_vals && pa_nvals ) {
956 (*pa_nvals)[i] = (*pa_nvals)[last];
959 BER_BVZERO( &in[last] );
960 if ( a_vals && pa_nvals ) {
961 BER_BVZERO( &(*pa_nvals)[last] );
968 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
969 ch_free( a_vals[i].bv_val );
973 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
974 ch_free( (*pa_nvals)[i].bv_val );
976 (*pa_nvals)[i] = ndn;
981 assert( ndnp != NULL );
983 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
984 ch_free( (*pa_nvals)[i].bv_val );
985 (*pa_nvals)[i] = ndn;
991 /* leave attr untouched if massage failed */
992 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
993 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1003 rwm_referral_result_rewrite(
1010 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1013 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1014 struct berval dn, olddn;
1018 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1019 if ( rc != LDAP_URL_SUCCESS ) {
1020 /* leave attr untouched if massage failed */
1024 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1026 rc = rwm_dn_massage( dc, &olddn, &dn, NULL );
1028 case LDAP_UNWILLING_TO_PERFORM:
1030 * FIXME: need to check if it may be considered
1031 * legal to trim values when adding/modifying;
1032 * it should be when searching (e.g. ACLs).
1034 ch_free( &a_vals[i].bv_val );
1036 a_vals[i] = a_vals[last];
1038 BER_BVZERO( &a_vals[last] );
1043 /* leave attr untouched if massage failed */
1044 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1047 ludp->lud_dn = dn.bv_val;
1048 newurl = ldap_url_desc2str( ludp );
1049 if ( newurl == NULL ) {
1050 /* FIXME: leave attr untouched
1051 * even if ldap_url_desc2str failed... */
1055 ch_free( a_vals[i].bv_val );
1056 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1057 LDAP_FREE( newurl );
1058 ludp->lud_dn = olddn.bv_val;
1063 ldap_free_urldesc( ludp );
1070 rwm_dnattr_result_rewrite(
1077 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1080 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1084 rc = rwm_dn_massage( dc, &a_vals[i], &dn, NULL );
1086 case LDAP_UNWILLING_TO_PERFORM:
1088 * FIXME: need to check if it may be considered
1089 * legal to trim values when adding/modifying;
1090 * it should be when searching (e.g. ACLs).
1092 ch_free( &a_vals[i].bv_val );
1094 a_vals[i] = a_vals[last];
1096 BER_BVZERO( &a_vals[last] );
1101 /* leave attr untouched if massage failed */
1102 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1103 ch_free( a_vals[i].bv_val );
1114 rwm_mapping_free( void *v_mapping )
1116 struct ldapmapping *mapping = v_mapping;
1118 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1119 ch_free( mapping[0].m_src.bv_val );
1122 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1123 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1124 if ( mapping[0].m_src_oc ) {
1125 ch_free( mapping[0].m_src_oc );
1129 if ( mapping[0].m_src_ad ) {
1130 ch_free( mapping[0].m_src_ad );
1135 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1136 ch_free( mapping[0].m_dst.bv_val );
1139 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1140 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1141 if ( mapping[0].m_dst_oc ) {
1142 ch_free( mapping[0].m_dst_oc );
1146 if ( mapping[0].m_dst_ad ) {
1147 ch_free( mapping[0].m_dst_ad );
1156 #endif /* SLAPD_OVER_RWM */