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[0].m_src_ad, &text );
86 if ( rc != LDAP_SUCCESS ) {
90 mapping[0].m_dst_ad = mapping[0].m_src_ad;
91 ber_dupbv( &mapping[0].m_src, &mapping[0].m_src_ad->ad_cname );
92 ber_dupbv( &mapping[0].m_dst, &mapping[0].m_src );
94 mapping[1].m_src = mapping[0].m_src;
95 mapping[1].m_dst = mapping[0].m_dst;
96 mapping[1].m_src_ad = mapping[0].m_src_ad;
97 mapping[1].m_dst_ad = mapping[1].m_src_ad;
99 avl_insert( &lm->map, (caddr_t)&mapping[0],
100 rwm_mapping_cmp, rwm_mapping_dup );
101 avl_insert( &lm->remap, (caddr_t)&mapping[1],
102 rwm_mapping_cmp, rwm_mapping_dup );
110 rwm_mapping( struct ldapmap *map, struct berval *s, struct ldapmapping **m, int remap )
113 struct ldapmapping fmapping;
117 if ( remap == RWM_REMAP ) {
125 *m = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping,
129 return map->drop_missing;
136 rwm_map( struct ldapmap *map, struct berval *s, struct berval *bv, int remap )
138 struct ldapmapping *mapping;
141 ( void )rwm_mapping( map, s, &mapping, remap );
142 if ( mapping != NULL ) {
143 if ( !BER_BVISNULL( &mapping->m_dst ) ) {
144 *bv = mapping->m_dst;
149 if ( !map->drop_missing ) {
155 * Map attribute names in place
159 struct ldapmap *at_map,
160 struct ldapmap *oc_map,
168 assert( anp != NULL );
176 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
178 *anp = ch_malloc( ( i + 1 )* sizeof( AttributeName ) );
179 if ( *anp == NULL ) {
180 return LDAP_NO_MEMORY;
183 for ( i = 0, j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
184 struct ldapmapping *m;
185 int at_drop_missing = 0,
188 if ( an[i].an_desc ) {
190 /* FIXME: better leave as is? */
194 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
195 if ( at_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
206 if ( remap == RWM_MAP ) {
207 (*anp)[j].an_name = m->m_dst;
208 (*anp)[j].an_desc = m->m_dst_ad;
210 (*anp)[j].an_name = m->m_src;
211 (*anp)[j].an_desc = m->m_src_ad;
218 } else if ( an[i].an_oc ) {
220 /* FIXME: better leave as is? */
224 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
226 if ( oc_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
237 if ( remap == RWM_MAP ) {
238 (*anp)[j].an_name = m->m_dst;
239 (*anp)[j].an_oc = m->m_dst_oc;
241 (*anp)[j].an_name = m->m_src;
242 (*anp)[j].an_oc = m->m_src_oc;
246 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
248 if ( at_drop_missing || !m ) {
250 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
252 /* if both at_map and oc_map required to drop missing,
254 if ( oc_drop_missing && at_drop_missing ) {
258 /* if no oc_map mapping was found and at_map required
259 * to drop missing, then do it; otherwise, at_map wins
260 * and an is considered an attr and is left unchanged */
262 if ( at_drop_missing ) {
270 if ( BER_BVISNULL( &m->m_dst ) ) {
275 if ( remap == RWM_MAP ) {
276 (*anp)[j].an_name = m->m_dst;
277 (*anp)[j].an_oc = m->m_dst_oc;
279 (*anp)[j].an_name = m->m_src;
280 (*anp)[j].an_oc = m->m_src_oc;
286 if ( !BER_BVISNULL( &m->m_dst ) ) {
288 if ( remap == RWM_MAP ) {
289 (*anp)[j].an_name = m->m_dst;
290 (*anp)[j].an_desc = m->m_dst_ad;
292 (*anp)[j].an_name = m->m_src;
293 (*anp)[j].an_desc = m->m_src_ad;
301 if ( j == 0 && i != 0 ) {
302 memset( &(*anp)[0], 0, sizeof( AttributeName ) );
303 BER_BVSTR( &(*anp)[0].an_name, LDAP_NO_ATTRS );
305 memset( &(*anp)[j], 0, sizeof( AttributeName ) );
312 struct ldapmap *at_map,
322 *mapped_attrs = NULL;
326 for ( i = 0; !BER_BVISNULL( &an[ i ].an_name ); i++ ) {
330 na = (char **)ch_calloc( i + 1, sizeof( char * ) );
332 *mapped_attrs = NULL;
333 return LDAP_NO_MEMORY;
336 for ( i = j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
337 struct ldapmapping *mapping;
339 if ( rwm_mapping( at_map, &an[i].an_name, &mapping, remap ) ) {
344 na[ j++ ] = an[ i ].an_name.bv_val;
346 } else if ( !BER_BVISNULL( &mapping->m_dst ) ) {
347 na[ j++ ] = mapping->m_dst.bv_val;
351 if ( j == 0 && i != 0 ) {
352 na[ j++ ] = LDAP_NO_ATTRS;
365 AttributeDescription **adp,
366 struct berval *mapped_attr,
367 struct berval *value,
368 struct berval *mapped_value,
371 struct berval vtmp = BER_BVNULL;
373 AttributeDescription *ad = *adp;
374 struct ldapmapping *mapping = NULL;
376 rwm_mapping( &dc->rwmap->rwm_at, &ad->ad_cname, &mapping, remap );
377 if ( mapping == NULL ) {
378 if ( dc->rwmap->rwm_at.drop_missing ) {
382 *mapped_attr = ad->ad_cname;
385 *mapped_attr = mapping->m_dst;
388 if ( value != NULL ) {
389 assert( mapped_value != NULL );
391 if ( ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
392 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
397 #ifdef ENABLE_REWRITE
398 fdc.ctx = "searchFilterAttrDN";
399 #endif /* ENABLE_REWRITE */
402 rc = rwm_dn_massage_normalize( &fdc, value, &vtmp );
405 if ( vtmp.bv_val != value->bv_val ) {
410 case LDAP_UNWILLING_TO_PERFORM:
416 } else if ( ad == slap_schema.si_ad_objectClass
417 || ad == slap_schema.si_ad_structuralObjectClass )
419 rwm_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
420 if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
428 filter_escape_value( &vtmp, mapped_value );
431 ch_free( vtmp.bv_val );
435 if ( mapping != NULL ) {
436 assert( mapping->m_dst_ad != NULL );
437 *adp = mapping->m_dst_ad;
444 rwm_int_filter_map_rewrite(
447 struct berval *fstr )
455 /* better than nothing... */
456 ber_bvfalse = BER_BVC( "(!(objectClass=*))" ),
457 ber_bvtf_false = BER_BVC( "(|)" ),
458 /* better than nothing... */
459 ber_bvtrue = BER_BVC( "(objectClass=*)" ),
460 ber_bvtf_true = BER_BVC( "(&)" ),
462 /* no longer needed; preserved for completeness */
463 ber_bvundefined = BER_BVC( "(?=undefined)" ),
465 ber_bverror = BER_BVC( "(?=error)" ),
466 ber_bvunknown = BER_BVC( "(?=unknown)" ),
467 ber_bvnone = BER_BVC( "(?=none)" );
471 ber_dupbv( fstr, &ber_bvnone );
475 switch ( f->f_choice ) {
476 case LDAP_FILTER_EQUALITY:
477 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
478 &f->f_av_value, &vtmp, RWM_MAP ) )
483 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(=)" );
484 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
486 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
487 atmp.bv_val, vtmp.bv_val );
489 ch_free( vtmp.bv_val );
493 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
494 &f->f_av_value, &vtmp, RWM_MAP ) )
499 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(>=)" );
500 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
502 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
503 atmp.bv_val, vtmp.bv_val );
505 ch_free( vtmp.bv_val );
509 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
510 &f->f_av_value, &vtmp, RWM_MAP ) )
515 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
516 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
518 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
519 atmp.bv_val, vtmp.bv_val );
521 ch_free( vtmp.bv_val );
524 case LDAP_FILTER_APPROX:
525 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
526 &f->f_av_value, &vtmp, RWM_MAP ) )
531 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
532 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
534 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
535 atmp.bv_val, vtmp.bv_val );
537 ch_free( vtmp.bv_val );
540 case LDAP_FILTER_SUBSTRINGS:
541 if ( map_attr_value( dc, &f->f_sub_desc, &atmp,
542 NULL, NULL, RWM_MAP ) )
547 /* cannot be a DN ... */
549 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
550 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
552 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
555 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
558 filter_escape_value( &f->f_sub_initial, &vtmp );
560 fstr->bv_len += vtmp.bv_len;
561 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
563 snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
564 /* "(attr=" */ "%s*)",
567 ch_free( vtmp.bv_val );
570 if ( f->f_sub_any != NULL ) {
571 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
573 filter_escape_value( &f->f_sub_any[i], &vtmp );
575 fstr->bv_len += vtmp.bv_len + 1;
576 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
578 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
579 /* "(attr=[init]*[any*]" */ "%s*)",
581 ch_free( vtmp.bv_val );
585 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
588 filter_escape_value( &f->f_sub_final, &vtmp );
590 fstr->bv_len += vtmp.bv_len;
591 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
593 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
594 /* "(attr=[init*][any*]" */ "%s)",
597 ch_free( vtmp.bv_val );
602 case LDAP_FILTER_PRESENT:
603 if ( map_attr_value( dc, &f->f_desc, &atmp,
604 NULL, NULL, RWM_MAP ) )
609 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
610 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
612 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
616 case LDAP_FILTER_AND:
618 case LDAP_FILTER_NOT:
619 fstr->bv_len = STRLENOF( "(%)" );
620 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
622 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
623 f->f_choice == LDAP_FILTER_AND ? '&' :
624 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
626 for ( p = f->f_list; p != NULL; p = p->f_next ) {
629 if ( rwm_int_filter_map_rewrite( dc, p, &vtmp ) )
634 fstr->bv_len += vtmp.bv_len;
635 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
637 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
638 /*"("*/ "%s)", vtmp.bv_val );
640 ch_free( vtmp.bv_val );
645 case LDAP_FILTER_EXT: {
646 if ( f->f_mr_desc ) {
647 if ( map_attr_value( dc, &f->f_mr_desc, &atmp,
648 &f->f_mr_value, &vtmp, RWM_MAP ) )
654 BER_BVSTR( &atmp, "" );
655 filter_escape_value( &f->f_mr_value, &vtmp );
659 fstr->bv_len = atmp.bv_len +
660 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
661 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
662 vtmp.bv_len + STRLENOF( "(:=)" );
663 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
665 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
667 f->f_mr_dnattrs ? ":dn" : "",
668 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
669 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
671 ch_free( vtmp.bv_val );
675 case SLAPD_FILTER_COMPUTED:
676 switch ( f->f_result ) {
677 case LDAP_COMPARE_FALSE:
678 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
679 tmp = ber_bvtf_false;
684 case SLAPD_COMPARE_UNDEFINED:
688 case LDAP_COMPARE_TRUE:
689 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
701 ber_dupbv( fstr, &tmp );
705 ber_dupbv( fstr, &ber_bvunknown );
713 rwm_filter_map_rewrite(
716 struct berval *fstr )
722 rc = rwm_int_filter_map_rewrite( dc, f, fstr );
724 #ifdef ENABLE_REWRITE
725 if ( rc != LDAP_SUCCESS ) {
732 fdc.ctx = "searchFilter";
734 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
735 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
736 fdc.conn, &fstr->bv_val ) )
738 case REWRITE_REGEXEC_OK:
739 if ( !BER_BVISNULL( fstr ) ) {
740 fstr->bv_len = strlen( fstr->bv_val );
741 ch_free( ftmp.bv_val );
747 Debug( LDAP_DEBUG_ARGS,
748 "[rw] %s: \"%s\" -> \"%s\"\n",
749 fdc.ctx, ftmp.bv_val, fstr->bv_val );
753 case REWRITE_REGEXEC_UNWILLING:
755 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
756 fdc.rs->sr_text = "Operation not allowed";
758 rc = LDAP_UNWILLING_TO_PERFORM;
761 case REWRITE_REGEXEC_ERR:
763 fdc.rs->sr_err = LDAP_OTHER;
764 fdc.rs->sr_text = "Rewrite error";
770 #endif /* ENABLE_REWRITE */
775 * I don't like this much, but we need two different
776 * functions because different heap managers may be
777 * in use in back-ldap/meta to reduce the amount of
778 * calls to malloc routines, and some of the free()
779 * routines may be macros with args
782 rwm_referral_rewrite(
787 BerVarray *pa_nvals )
789 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
790 struct ldaprwmap *rwmap =
791 (struct ldaprwmap *)on->on_bi.bi_private;
796 struct berval dn = BER_BVNULL,
799 assert( a_vals != NULL );
802 * Rewrite the dn if needed
805 #ifdef ENABLE_REWRITE
806 dc.conn = op->o_conn;
808 dc.ctx = (char *)cookie;
809 #else /* ! ENABLE_REWRITE */
810 dc.tofrom = ((int *)cookie)[0];
812 #endif /* ! ENABLE_REWRITE */
814 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
818 if ( pa_nvals != NULL ) {
819 if ( *pa_nvals == NULL ) {
820 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
821 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
825 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
826 struct berval olddn = BER_BVNULL,
832 rc = ldap_url_parse( oldval.bv_val, &ludp );
833 if ( rc != LDAP_URL_SUCCESS ) {
834 /* leave attr untouched if massage failed */
835 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
836 ber_dupbv( &(*pa_nvals)[i], &oldval );
841 /* FIXME: URLs like "ldap:///dc=suffix" if passed
842 * thru ldap_url_parse() and ldap_url_desc2str()
843 * get rewritten as "ldap:///dc=suffix??base";
844 * we don't want this to occur... */
845 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
846 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
849 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
854 rc = rwm_dn_massage_pretty_normalize( &dc, &olddn,
857 rc = rwm_dn_massage_pretty( &dc, &olddn, &dn );
861 case LDAP_UNWILLING_TO_PERFORM:
863 * FIXME: need to check if it may be considered
864 * legal to trim values when adding/modifying;
865 * it should be when searching (e.g. ACLs).
867 ch_free( a_vals[i].bv_val );
869 a_vals[i] = a_vals[last];
871 (*pa_nvals)[i] = (*pa_nvals)[last];
874 BER_BVZERO( &a_vals[last] );
876 BER_BVZERO( &(*pa_nvals)[last] );
882 if ( !BER_BVISNULL( &dn ) && dn.bv_val != olddn.bv_val ) {
885 ludp->lud_dn = dn.bv_val;
886 newurl = ldap_url_desc2str( ludp );
887 ludp->lud_dn = olddn.bv_val;
888 ch_free( dn.bv_val );
889 if ( newurl == NULL ) {
890 /* FIXME: leave attr untouched
891 * even if ldap_url_desc2str failed...
896 ber_str2bv( newurl, 0, 1, &a_vals[i] );
900 ludp->lud_dn = ndn.bv_val;
901 newurl = ldap_url_desc2str( ludp );
902 ludp->lud_dn = olddn.bv_val;
903 ch_free( ndn.bv_val );
904 if ( newurl == NULL ) {
905 /* FIXME: leave attr untouched
906 * even if ldap_url_desc2str failed...
908 ch_free( a_vals[i].bv_val );
913 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
914 ch_free( (*pa_nvals)[i].bv_val );
916 ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
920 ch_free( oldval.bv_val );
921 ludp->lud_dn = olddn.bv_val;
926 /* leave attr untouched if massage failed */
927 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
928 ber_dupbv( &(*pa_nvals)[i], &a_vals[i] );
932 ldap_free_urldesc( ludp );
939 * I don't like this much, but we need two different
940 * functions because different heap managers may be
941 * in use in back-ldap/meta to reduce the amount of
942 * calls to malloc routines, and some of the free()
943 * routines may be macros with args
951 BerVarray *pa_nvals )
953 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
954 struct ldaprwmap *rwmap =
955 (struct ldaprwmap *)on->on_bi.bi_private;
960 struct berval dn = BER_BVNULL,
968 if ( pa_nvals == NULL || *pa_nvals == NULL ) {
975 * Rewrite the dn if needed
978 #ifdef ENABLE_REWRITE
979 dc.conn = op->o_conn;
981 dc.ctx = (char *)cookie;
982 #else /* ! ENABLE_REWRITE */
983 dc.tofrom = ((int *)cookie)[0];
985 #endif /* ! ENABLE_REWRITE */
987 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
989 if ( pa_nvals != NULL ) {
990 if ( *pa_nvals == NULL ) {
991 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
992 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
996 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
1002 ndn = (*pa_nvals)[i];
1003 rc = rwm_dn_massage_pretty_normalize( &dc, &in[i], &dn, &ndn );
1005 rc = rwm_dn_massage_pretty( &dc, &in[i], &dn );
1009 rc = rwm_dn_massage_normalize( &dc, &in[i], &ndn );
1013 case LDAP_UNWILLING_TO_PERFORM:
1015 * FIXME: need to check if it may be considered
1016 * legal to trim values when adding/modifying;
1017 * it should be when searching (e.g. ACLs).
1019 ch_free( in[i].bv_val );
1022 if ( a_vals && pa_nvals ) {
1023 (*pa_nvals)[i] = (*pa_nvals)[last];
1026 BER_BVZERO( &in[last] );
1027 if ( a_vals && pa_nvals ) {
1028 BER_BVZERO( &(*pa_nvals)[last] );
1035 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
1036 ch_free( a_vals[i].bv_val );
1040 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1041 ch_free( (*pa_nvals)[i].bv_val );
1043 (*pa_nvals)[i] = ndn;
1048 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
1049 ch_free( (*pa_nvals)[i].bv_val );
1050 (*pa_nvals)[i] = ndn;
1056 /* leave attr untouched if massage failed */
1057 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1058 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1068 rwm_referral_result_rewrite(
1075 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1078 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1084 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1085 if ( rc != LDAP_URL_SUCCESS ) {
1086 /* leave attr untouched if massage failed */
1090 /* FIXME: URLs like "ldap:///dc=suffix" if passed
1091 * thru ldap_url_parse() and ldap_url_desc2str()
1092 * get rewritten as "ldap:///dc=suffix??base";
1093 * we don't want this to occur... */
1094 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
1095 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
1098 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1101 rc = rwm_dn_massage_pretty( dc, &olddn, &dn );
1103 case LDAP_UNWILLING_TO_PERFORM:
1105 * FIXME: need to check if it may be considered
1106 * legal to trim values when adding/modifying;
1107 * it should be when searching (e.g. ACLs).
1109 ch_free( a_vals[i].bv_val );
1111 a_vals[i] = a_vals[last];
1113 BER_BVZERO( &a_vals[last] );
1119 /* leave attr untouched if massage failed */
1120 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1123 ludp->lud_dn = dn.bv_val;
1124 newurl = ldap_url_desc2str( ludp );
1125 if ( newurl == NULL ) {
1126 /* FIXME: leave attr untouched
1127 * even if ldap_url_desc2str failed...
1132 ch_free( a_vals[i].bv_val );
1133 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1134 LDAP_FREE( newurl );
1135 ludp->lud_dn = olddn.bv_val;
1140 ldap_free_urldesc( ludp );
1147 rwm_dnattr_result_rewrite(
1154 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1157 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1162 rc = rwm_dn_massage_pretty( dc, &a_vals[i], &dn );
1164 case LDAP_UNWILLING_TO_PERFORM:
1166 * FIXME: need to check if it may be considered
1167 * legal to trim values when adding/modifying;
1168 * it should be when searching (e.g. ACLs).
1170 ch_free( a_vals[i].bv_val );
1172 a_vals[i] = a_vals[last];
1174 BER_BVZERO( &a_vals[last] );
1179 /* leave attr untouched if massage failed */
1180 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1181 ch_free( a_vals[i].bv_val );
1192 rwm_mapping_free( void *v_mapping )
1194 struct ldapmapping *mapping = v_mapping;
1196 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1197 ch_free( mapping[0].m_src.bv_val );
1200 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1201 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1202 if ( mapping[0].m_src_oc ) {
1203 ch_free( mapping[0].m_src_oc );
1207 if ( mapping[0].m_src_ad ) {
1208 ch_free( mapping[0].m_src_ad );
1213 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1214 ch_free( mapping[0].m_dst.bv_val );
1217 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1218 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1219 if ( mapping[0].m_dst_oc ) {
1220 ch_free( mapping[0].m_dst_oc );
1224 if ( mapping[0].m_dst_ad ) {
1225 ch_free( mapping[0].m_dst_ad );
1234 #endif /* SLAPD_OVER_RWM */