1 /* rwmmap.c - rewrite/mapping routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2007 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 ) {
91 mapping[0].m_dst_ad = mapping[0].m_src_ad;
92 ber_dupbv( &mapping[0].m_src, &mapping[0].m_src_ad->ad_cname );
93 ber_dupbv( &mapping[0].m_dst, &mapping[0].m_src );
95 mapping[1].m_src = mapping[0].m_src;
96 mapping[1].m_dst = mapping[0].m_dst;
97 mapping[1].m_src_ad = mapping[0].m_src_ad;
98 mapping[1].m_dst_ad = mapping[1].m_src_ad;
100 avl_insert( &lm->map, (caddr_t)&mapping[0],
101 rwm_mapping_cmp, rwm_mapping_dup );
102 avl_insert( &lm->remap, (caddr_t)&mapping[1],
103 rwm_mapping_cmp, rwm_mapping_dup );
111 rwm_mapping( struct ldapmap *map, struct berval *s, struct ldapmapping **m, int remap )
114 struct ldapmapping fmapping;
122 if ( remap == RWM_REMAP ) {
130 *m = (struct ldapmapping *)avl_find( tree, (caddr_t)&fmapping,
134 return map->drop_missing;
141 rwm_map( struct ldapmap *map, struct berval *s, struct berval *bv, int remap )
143 struct ldapmapping *mapping;
145 /* map->map may be NULL when mapping is configured,
146 * but map->remap can't */
147 if ( map->remap == NULL ) {
153 ( void )rwm_mapping( map, s, &mapping, remap );
154 if ( mapping != NULL ) {
155 if ( !BER_BVISNULL( &mapping->m_dst ) ) {
156 *bv = mapping->m_dst;
161 if ( !map->drop_missing ) {
167 * Map attribute names in place
171 struct ldapmap *at_map,
172 struct ldapmap *oc_map,
179 assert( anp != NULL );
187 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
189 *anp = ch_malloc( ( i + 1 )* sizeof( AttributeName ) );
190 if ( *anp == NULL ) {
191 return LDAP_NO_MEMORY;
194 for ( i = 0, j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
195 struct ldapmapping *m;
196 int at_drop_missing = 0,
199 if ( an[i].an_desc ) {
201 /* FIXME: better leave as is? */
205 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
206 if ( at_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
217 if ( remap == RWM_MAP ) {
218 (*anp)[j].an_name = m->m_dst;
219 (*anp)[j].an_desc = m->m_dst_ad;
221 (*anp)[j].an_name = m->m_src;
222 (*anp)[j].an_desc = m->m_src_ad;
229 } else if ( an[i].an_oc ) {
231 /* FIXME: better leave as is? */
235 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
237 if ( oc_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
248 if ( remap == RWM_MAP ) {
249 (*anp)[j].an_name = m->m_dst;
250 (*anp)[j].an_oc = m->m_dst_oc;
252 (*anp)[j].an_name = m->m_src;
253 (*anp)[j].an_oc = m->m_src_oc;
257 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
259 if ( at_drop_missing || !m ) {
260 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
262 /* if both at_map and oc_map required to drop missing,
264 if ( oc_drop_missing && at_drop_missing ) {
268 /* if no oc_map mapping was found and at_map required
269 * to drop missing, then do it; otherwise, at_map wins
270 * and an is considered an attr and is left unchanged */
272 if ( at_drop_missing ) {
280 if ( BER_BVISNULL( &m->m_dst ) ) {
285 if ( remap == RWM_MAP ) {
286 (*anp)[j].an_name = m->m_dst;
287 (*anp)[j].an_oc = m->m_dst_oc;
289 (*anp)[j].an_name = m->m_src;
290 (*anp)[j].an_oc = m->m_src_oc;
296 if ( !BER_BVISNULL( &m->m_dst ) ) {
298 if ( remap == RWM_MAP ) {
299 (*anp)[j].an_name = m->m_dst;
300 (*anp)[j].an_desc = m->m_dst_ad;
302 (*anp)[j].an_name = m->m_src;
303 (*anp)[j].an_desc = m->m_src_ad;
311 if ( j == 0 && i != 0 ) {
312 memset( &(*anp)[0], 0, sizeof( AttributeName ) );
313 BER_BVSTR( &(*anp)[0].an_name, LDAP_NO_ATTRS );
316 memset( &(*anp)[j], 0, sizeof( AttributeName ) );
323 struct ldapmap *at_map,
326 char ***mapped_attrs )
332 *mapped_attrs = NULL;
336 for ( i = 0; !BER_BVISNULL( &an[ i ].an_name ); i++ )
339 na = (char **)ch_calloc( i + 1, sizeof( char * ) );
341 *mapped_attrs = NULL;
342 return LDAP_NO_MEMORY;
345 for ( i = j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
346 struct ldapmapping *mapping;
348 if ( rwm_mapping( at_map, &an[i].an_name, &mapping, remap ) ) {
353 na[ j++ ] = an[ i ].an_name.bv_val;
355 } else if ( !BER_BVISNULL( &mapping->m_dst ) ) {
356 na[ j++ ] = mapping->m_dst.bv_val;
360 if ( j == 0 && i != 0 ) {
361 na[ j++ ] = LDAP_NO_ATTRS;
374 AttributeDescription **adp,
375 struct berval *mapped_attr,
376 struct berval *value,
377 struct berval *mapped_value,
380 struct berval vtmp = BER_BVNULL;
382 AttributeDescription *ad = *adp;
383 struct ldapmapping *mapping = NULL;
385 rwm_mapping( &dc->rwmap->rwm_at, &ad->ad_cname, &mapping, remap );
386 if ( mapping == NULL ) {
387 if ( dc->rwmap->rwm_at.drop_missing ) {
391 *mapped_attr = ad->ad_cname;
394 *mapped_attr = mapping->m_dst;
397 if ( value != NULL ) {
398 assert( mapped_value != NULL );
400 if ( ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
401 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
406 fdc.ctx = "searchFilterAttrDN";
409 rc = rwm_dn_massage_normalize( &fdc, value, &vtmp );
412 if ( vtmp.bv_val != value->bv_val ) {
417 case LDAP_UNWILLING_TO_PERFORM:
423 } else if ( ad == slap_schema.si_ad_objectClass
424 || ad == slap_schema.si_ad_structuralObjectClass )
426 rwm_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
427 if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
435 filter_escape_value( &vtmp, mapped_value );
438 ch_free( vtmp.bv_val );
442 if ( mapping != NULL ) {
443 assert( mapping->m_dst_ad != NULL );
444 *adp = mapping->m_dst_ad;
451 rwm_int_filter_map_rewrite(
455 struct berval *fstr )
459 AttributeDescription *ad;
464 /* better than nothing... */
465 ber_bvfalse = BER_BVC( "(!(objectClass=*))" ),
466 ber_bvtf_false = BER_BVC( "(|)" ),
467 /* better than nothing... */
468 ber_bvtrue = BER_BVC( "(objectClass=*)" ),
469 ber_bvtf_true = BER_BVC( "(&)" ),
471 /* no longer needed; preserved for completeness */
472 ber_bvundefined = BER_BVC( "(?=undefined)" ),
474 ber_bverror = BER_BVC( "(?=error)" ),
475 ber_bvunknown = BER_BVC( "(?=unknown)" ),
476 ber_bvnone = BER_BVC( "(?=none)" );
479 assert( fstr != NULL );
483 ber_dupbv( fstr, &ber_bvnone );
487 switch ( f->f_choice & SLAPD_FILTER_MASK ) {
488 case LDAP_FILTER_EQUALITY:
490 if ( map_attr_value( dc, &ad, &atmp,
491 &f->f_av_value, &vtmp, RWM_MAP ) )
496 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(=)" );
497 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
499 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
500 atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
502 ch_free( vtmp.bv_val );
507 if ( map_attr_value( dc, &ad, &atmp,
508 &f->f_av_value, &vtmp, RWM_MAP ) )
513 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(>=)" );
514 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
516 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
517 atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
519 ch_free( vtmp.bv_val );
524 if ( map_attr_value( dc, &ad, &atmp,
525 &f->f_av_value, &vtmp, RWM_MAP ) )
530 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
531 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
533 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
534 atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
536 ch_free( vtmp.bv_val );
539 case LDAP_FILTER_APPROX:
541 if ( map_attr_value( dc, &ad, &atmp,
542 &f->f_av_value, &vtmp, RWM_MAP ) )
547 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
548 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
550 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
551 atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
553 ch_free( vtmp.bv_val );
556 case LDAP_FILTER_SUBSTRINGS:
558 if ( map_attr_value( dc, &ad, &atmp,
559 NULL, NULL, RWM_MAP ) )
564 /* cannot be a DN ... */
566 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
567 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
569 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
572 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
575 filter_escape_value( &f->f_sub_initial, &vtmp );
577 fstr->bv_len += vtmp.bv_len;
578 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
580 snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
581 /* "(attr=" */ "%s*)",
582 vtmp.bv_len ? vtmp.bv_val : "" );
584 ch_free( vtmp.bv_val );
587 if ( f->f_sub_any != NULL ) {
588 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
590 filter_escape_value( &f->f_sub_any[i], &vtmp );
592 fstr->bv_len += vtmp.bv_len + 1;
593 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
595 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
596 /* "(attr=[init]*[any*]" */ "%s*)",
597 vtmp.bv_len ? vtmp.bv_val : "" );
598 ch_free( vtmp.bv_val );
602 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
605 filter_escape_value( &f->f_sub_final, &vtmp );
607 fstr->bv_len += vtmp.bv_len;
608 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
610 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
611 /* "(attr=[init*][any*]" */ "%s)",
612 vtmp.bv_len ? vtmp.bv_val : "" );
614 ch_free( vtmp.bv_val );
619 case LDAP_FILTER_PRESENT:
621 if ( map_attr_value( dc, &ad, &atmp,
622 NULL, NULL, RWM_MAP ) )
627 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
628 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
630 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
634 case LDAP_FILTER_AND:
636 case LDAP_FILTER_NOT:
637 fstr->bv_len = STRLENOF( "(%)" );
638 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
640 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
641 f->f_choice == LDAP_FILTER_AND ? '&' :
642 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
644 for ( p = f->f_list; p != NULL; p = p->f_next ) {
649 rc = rwm_int_filter_map_rewrite( op, dc, p, &vtmp );
650 if ( rc != LDAP_SUCCESS ) {
654 fstr->bv_len += vtmp.bv_len;
655 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
657 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
658 /*"("*/ "%s)", vtmp.bv_len ? vtmp.bv_val : "" );
660 ch_free( vtmp.bv_val );
665 case LDAP_FILTER_EXT: {
666 if ( f->f_mr_desc ) {
668 if ( map_attr_value( dc, &ad, &atmp,
669 &f->f_mr_value, &vtmp, RWM_MAP ) )
675 BER_BVSTR( &atmp, "" );
676 filter_escape_value( &f->f_mr_value, &vtmp );
680 fstr->bv_len = atmp.bv_len +
681 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
682 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
683 vtmp.bv_len + STRLENOF( "(:=)" );
684 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
686 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
688 f->f_mr_dnattrs ? ":dn" : "",
689 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
690 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
691 vtmp.bv_len ? vtmp.bv_val : "" );
692 ch_free( vtmp.bv_val );
698 filter_free_x( op, f );
699 f->f_choice = SLAPD_FILTER_COMPUTED;
700 f->f_result = SLAPD_COMPARE_UNDEFINED;
703 case SLAPD_FILTER_COMPUTED:
704 switch ( f->f_result ) {
705 case LDAP_COMPARE_FALSE:
706 /* FIXME: treat UNDEFINED as FALSE */
707 case SLAPD_COMPARE_UNDEFINED:
708 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
709 tmp = &ber_bvtf_false;
715 case LDAP_COMPARE_TRUE:
716 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
717 tmp = &ber_bvtf_true;
728 ber_dupbv( fstr, tmp );
732 ber_dupbv( fstr, &ber_bvunknown );
740 rwm_filter_map_rewrite(
744 struct berval *fstr )
750 rc = rwm_int_filter_map_rewrite( op, dc, f, fstr );
759 fdc.ctx = "searchFilter";
761 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
762 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
763 fdc.conn, &fstr->bv_val ) )
765 case REWRITE_REGEXEC_OK:
766 if ( !BER_BVISNULL( fstr ) ) {
767 fstr->bv_len = strlen( fstr->bv_val );
768 if ( fstr->bv_val != ftmp.bv_val ) {
769 ch_free( ftmp.bv_val );
776 Debug( LDAP_DEBUG_ARGS,
777 "[rw] %s: \"%s\" -> \"%s\"\n",
778 fdc.ctx, ftmp.bv_val, fstr->bv_val );
782 case REWRITE_REGEXEC_UNWILLING:
784 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
785 fdc.rs->sr_text = "Operation not allowed";
787 rc = LDAP_UNWILLING_TO_PERFORM;
790 case REWRITE_REGEXEC_ERR:
792 fdc.rs->sr_err = LDAP_OTHER;
793 fdc.rs->sr_text = "Rewrite error";
803 * I don't like this much, but we need two different
804 * functions because different heap managers may be
805 * in use in back-ldap/meta to reduce the amount of
806 * calls to malloc routines, and some of the free()
807 * routines may be macros with args
810 rwm_referral_rewrite(
815 BerVarray *pa_nvals )
817 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
818 struct ldaprwmap *rwmap =
819 (struct ldaprwmap *)on->on_bi.bi_private;
824 struct berval dn = BER_BVNULL,
827 assert( a_vals != NULL );
830 * Rewrite the dn if needed
833 dc.conn = op->o_conn;
835 dc.ctx = (char *)cookie;
837 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
841 if ( pa_nvals != NULL ) {
842 if ( *pa_nvals == NULL ) {
843 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
844 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
848 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
849 struct berval olddn = BER_BVNULL,
855 rc = ldap_url_parse( oldval.bv_val, &ludp );
856 if ( rc != LDAP_URL_SUCCESS ) {
857 /* leave attr untouched if massage failed */
858 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
859 ber_dupbv( &(*pa_nvals)[i], &oldval );
864 /* FIXME: URLs like "ldap:///dc=suffix" if passed
865 * thru ldap_url_parse() and ldap_url_desc2str()
866 * get rewritten as "ldap:///dc=suffix??base";
867 * we don't want this to occur... */
868 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
869 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
872 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
877 rc = rwm_dn_massage_pretty_normalize( &dc, &olddn,
880 rc = rwm_dn_massage_pretty( &dc, &olddn, &dn );
884 case LDAP_UNWILLING_TO_PERFORM:
886 * FIXME: need to check if it may be considered
887 * legal to trim values when adding/modifying;
888 * it should be when searching (e.g. ACLs).
890 ch_free( a_vals[i].bv_val );
892 a_vals[i] = a_vals[last];
894 (*pa_nvals)[i] = (*pa_nvals)[last];
897 BER_BVZERO( &a_vals[last] );
899 BER_BVZERO( &(*pa_nvals)[last] );
905 if ( !BER_BVISNULL( &dn ) && dn.bv_val != olddn.bv_val ) {
908 ludp->lud_dn = dn.bv_val;
909 newurl = ldap_url_desc2str( ludp );
910 ludp->lud_dn = olddn.bv_val;
911 ch_free( dn.bv_val );
912 if ( newurl == NULL ) {
913 /* FIXME: leave attr untouched
914 * even if ldap_url_desc2str failed...
919 ber_str2bv( newurl, 0, 1, &a_vals[i] );
923 ludp->lud_dn = ndn.bv_val;
924 newurl = ldap_url_desc2str( ludp );
925 ludp->lud_dn = olddn.bv_val;
926 ch_free( ndn.bv_val );
927 if ( newurl == NULL ) {
928 /* FIXME: leave attr untouched
929 * even if ldap_url_desc2str failed...
931 ch_free( a_vals[i].bv_val );
936 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
937 ch_free( (*pa_nvals)[i].bv_val );
939 ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
943 ch_free( oldval.bv_val );
944 ludp->lud_dn = olddn.bv_val;
949 /* leave attr untouched if massage failed */
950 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
951 ber_dupbv( &(*pa_nvals)[i], &a_vals[i] );
955 ldap_free_urldesc( ludp );
962 * I don't like this much, but we need two different
963 * functions because different heap managers may be
964 * in use in back-ldap/meta to reduce the amount of
965 * calls to malloc routines, and some of the free()
966 * routines may be macros with args
974 BerVarray *pa_nvals )
976 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
977 struct ldaprwmap *rwmap =
978 (struct ldaprwmap *)on->on_bi.bi_private;
983 struct berval dn = BER_BVNULL,
991 if ( pa_nvals == NULL || *pa_nvals == NULL ) {
998 * Rewrite the dn if needed
1001 dc.conn = op->o_conn;
1003 dc.ctx = (char *)cookie;
1005 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
1007 if ( pa_nvals != NULL ) {
1008 if ( *pa_nvals == NULL ) {
1009 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
1010 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
1014 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
1020 ndn = (*pa_nvals)[i];
1021 rc = rwm_dn_massage_pretty_normalize( &dc, &in[i], &dn, &ndn );
1023 rc = rwm_dn_massage_pretty( &dc, &in[i], &dn );
1027 rc = rwm_dn_massage_normalize( &dc, &in[i], &ndn );
1031 case LDAP_UNWILLING_TO_PERFORM:
1033 * FIXME: need to check if it may be considered
1034 * legal to trim values when adding/modifying;
1035 * it should be when searching (e.g. ACLs).
1037 ch_free( in[i].bv_val );
1040 if ( a_vals && pa_nvals ) {
1041 (*pa_nvals)[i] = (*pa_nvals)[last];
1044 BER_BVZERO( &in[last] );
1045 if ( a_vals && pa_nvals ) {
1046 BER_BVZERO( &(*pa_nvals)[last] );
1053 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
1054 ch_free( a_vals[i].bv_val );
1058 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1059 ch_free( (*pa_nvals)[i].bv_val );
1061 (*pa_nvals)[i] = ndn;
1066 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
1067 ch_free( (*pa_nvals)[i].bv_val );
1068 (*pa_nvals)[i] = ndn;
1074 /* leave attr untouched if massage failed */
1075 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1076 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1086 rwm_referral_result_rewrite(
1092 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1095 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1101 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1102 if ( rc != LDAP_URL_SUCCESS ) {
1103 /* leave attr untouched if massage failed */
1107 /* FIXME: URLs like "ldap:///dc=suffix" if passed
1108 * thru ldap_url_parse() and ldap_url_desc2str()
1109 * get rewritten as "ldap:///dc=suffix??base";
1110 * we don't want this to occur... */
1111 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
1112 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
1115 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1118 rc = rwm_dn_massage_pretty( dc, &olddn, &dn );
1120 case LDAP_UNWILLING_TO_PERFORM:
1122 * FIXME: need to check if it may be considered
1123 * legal to trim values when adding/modifying;
1124 * it should be when searching (e.g. ACLs).
1126 ch_free( a_vals[i].bv_val );
1128 a_vals[i] = a_vals[last];
1130 BER_BVZERO( &a_vals[last] );
1136 /* leave attr untouched if massage failed */
1137 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1140 ludp->lud_dn = dn.bv_val;
1141 newurl = ldap_url_desc2str( ludp );
1142 if ( newurl == NULL ) {
1143 /* FIXME: leave attr untouched
1144 * even if ldap_url_desc2str failed...
1149 ch_free( a_vals[i].bv_val );
1150 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1151 LDAP_FREE( newurl );
1152 ludp->lud_dn = olddn.bv_val;
1157 ldap_free_urldesc( ludp );
1164 rwm_dnattr_result_rewrite(
1170 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1173 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1178 rc = rwm_dn_massage_pretty( dc, &a_vals[i], &dn );
1180 case LDAP_UNWILLING_TO_PERFORM:
1182 * FIXME: need to check if it may be considered
1183 * legal to trim values when adding/modifying;
1184 * it should be when searching (e.g. ACLs).
1186 ch_free( a_vals[i].bv_val );
1188 a_vals[i] = a_vals[last];
1190 BER_BVZERO( &a_vals[last] );
1195 /* leave attr untouched if massage failed */
1196 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1197 ch_free( a_vals[i].bv_val );
1208 rwm_mapping_dst_free( void *v_mapping )
1210 struct ldapmapping *mapping = v_mapping;
1212 if ( BER_BVISEMPTY( &mapping[0].m_dst ) ) {
1213 rwm_mapping_free( &mapping[ -1 ] );
1218 rwm_mapping_free( void *v_mapping )
1220 struct ldapmapping *mapping = v_mapping;
1222 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1223 ch_free( mapping[0].m_src.bv_val );
1226 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1227 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1228 if ( mapping[0].m_src_oc ) {
1229 ch_free( mapping[0].m_src_oc );
1233 if ( mapping[0].m_src_ad ) {
1234 ch_free( mapping[0].m_src_ad );
1239 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1240 ch_free( mapping[0].m_dst.bv_val );
1243 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1244 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1245 if ( mapping[0].m_dst_oc ) {
1246 ch_free( mapping[0].m_dst_oc );
1250 if ( mapping[0].m_dst_ad ) {
1251 ch_free( mapping[0].m_dst_ad );
1260 #endif /* SLAPD_OVER_RWM */