1 /* rwmmap.c - rewrite/mapping routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2006 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;
146 ( void )rwm_mapping( map, s, &mapping, remap );
147 if ( mapping != NULL ) {
148 if ( !BER_BVISNULL( &mapping->m_dst ) ) {
149 *bv = mapping->m_dst;
154 if ( !map->drop_missing ) {
160 * Map attribute names in place
164 struct ldapmap *at_map,
165 struct ldapmap *oc_map,
172 assert( anp != NULL );
180 for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
182 *anp = ch_malloc( ( i + 1 )* sizeof( AttributeName ) );
183 if ( *anp == NULL ) {
184 return LDAP_NO_MEMORY;
187 for ( i = 0, j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
188 struct ldapmapping *m;
189 int at_drop_missing = 0,
192 if ( an[i].an_desc ) {
194 /* FIXME: better leave as is? */
198 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
199 if ( at_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
210 if ( remap == RWM_MAP ) {
211 (*anp)[j].an_name = m->m_dst;
212 (*anp)[j].an_desc = m->m_dst_ad;
214 (*anp)[j].an_name = m->m_src;
215 (*anp)[j].an_desc = m->m_src_ad;
222 } else if ( an[i].an_oc ) {
224 /* FIXME: better leave as is? */
228 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
230 if ( oc_drop_missing || ( m && BER_BVISNULL( &m->m_dst ) ) ) {
241 if ( remap == RWM_MAP ) {
242 (*anp)[j].an_name = m->m_dst;
243 (*anp)[j].an_oc = m->m_dst_oc;
245 (*anp)[j].an_name = m->m_src;
246 (*anp)[j].an_oc = m->m_src_oc;
250 at_drop_missing = rwm_mapping( at_map, &an[i].an_name, &m, remap );
252 if ( at_drop_missing || !m ) {
253 oc_drop_missing = rwm_mapping( oc_map, &an[i].an_name, &m, remap );
255 /* if both at_map and oc_map required to drop missing,
257 if ( oc_drop_missing && at_drop_missing ) {
261 /* if no oc_map mapping was found and at_map required
262 * to drop missing, then do it; otherwise, at_map wins
263 * and an is considered an attr and is left unchanged */
265 if ( at_drop_missing ) {
273 if ( BER_BVISNULL( &m->m_dst ) ) {
278 if ( remap == RWM_MAP ) {
279 (*anp)[j].an_name = m->m_dst;
280 (*anp)[j].an_oc = m->m_dst_oc;
282 (*anp)[j].an_name = m->m_src;
283 (*anp)[j].an_oc = m->m_src_oc;
289 if ( !BER_BVISNULL( &m->m_dst ) ) {
291 if ( remap == RWM_MAP ) {
292 (*anp)[j].an_name = m->m_dst;
293 (*anp)[j].an_desc = m->m_dst_ad;
295 (*anp)[j].an_name = m->m_src;
296 (*anp)[j].an_desc = m->m_src_ad;
304 if ( j == 0 && i != 0 ) {
305 memset( &(*anp)[0], 0, sizeof( AttributeName ) );
306 BER_BVSTR( &(*anp)[0].an_name, LDAP_NO_ATTRS );
309 memset( &(*anp)[j], 0, sizeof( AttributeName ) );
316 struct ldapmap *at_map,
319 char ***mapped_attrs )
325 *mapped_attrs = NULL;
329 for ( i = 0; !BER_BVISNULL( &an[ i ].an_name ); i++ )
332 na = (char **)ch_calloc( i + 1, sizeof( char * ) );
334 *mapped_attrs = NULL;
335 return LDAP_NO_MEMORY;
338 for ( i = j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
339 struct ldapmapping *mapping;
341 if ( rwm_mapping( at_map, &an[i].an_name, &mapping, remap ) ) {
346 na[ j++ ] = an[ i ].an_name.bv_val;
348 } else if ( !BER_BVISNULL( &mapping->m_dst ) ) {
349 na[ j++ ] = mapping->m_dst.bv_val;
353 if ( j == 0 && i != 0 ) {
354 na[ j++ ] = LDAP_NO_ATTRS;
367 AttributeDescription **adp,
368 struct berval *mapped_attr,
369 struct berval *value,
370 struct berval *mapped_value,
373 struct berval vtmp = BER_BVNULL;
375 AttributeDescription *ad = *adp;
376 struct ldapmapping *mapping = NULL;
378 rwm_mapping( &dc->rwmap->rwm_at, &ad->ad_cname, &mapping, remap );
379 if ( mapping == NULL ) {
380 if ( dc->rwmap->rwm_at.drop_missing ) {
384 *mapped_attr = ad->ad_cname;
387 *mapped_attr = mapping->m_dst;
390 if ( value != NULL ) {
391 assert( mapped_value != NULL );
393 if ( ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName
394 || ( mapping != NULL && mapping->m_dst_ad->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) )
399 #ifdef ENABLE_REWRITE
400 fdc.ctx = "searchFilterAttrDN";
401 #endif /* ENABLE_REWRITE */
404 rc = rwm_dn_massage_normalize( &fdc, value, &vtmp );
407 if ( vtmp.bv_val != value->bv_val ) {
412 case LDAP_UNWILLING_TO_PERFORM:
418 } else if ( ad == slap_schema.si_ad_objectClass
419 || ad == slap_schema.si_ad_structuralObjectClass )
421 rwm_map( &dc->rwmap->rwm_oc, value, &vtmp, remap );
422 if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
430 filter_escape_value( &vtmp, mapped_value );
433 ch_free( vtmp.bv_val );
437 if ( mapping != NULL ) {
438 assert( mapping->m_dst_ad != NULL );
439 *adp = mapping->m_dst_ad;
446 rwm_int_filter_map_rewrite(
450 struct berval *fstr )
454 AttributeDescription *ad;
459 /* better than nothing... */
460 ber_bvfalse = BER_BVC( "(!(objectClass=*))" ),
461 ber_bvtf_false = BER_BVC( "(|)" ),
462 /* better than nothing... */
463 ber_bvtrue = BER_BVC( "(objectClass=*)" ),
464 ber_bvtf_true = BER_BVC( "(&)" ),
466 /* no longer needed; preserved for completeness */
467 ber_bvundefined = BER_BVC( "(?=undefined)" ),
469 ber_bverror = BER_BVC( "(?=error)" ),
470 ber_bvunknown = BER_BVC( "(?=unknown)" ),
471 ber_bvnone = BER_BVC( "(?=none)" );
474 assert( fstr != NULL );
478 ber_dupbv( fstr, &ber_bvnone );
482 switch ( f->f_choice & SLAPD_FILTER_MASK ) {
483 case LDAP_FILTER_EQUALITY:
485 if ( map_attr_value( dc, &ad, &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 );
502 if ( map_attr_value( dc, &ad, &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 );
519 if ( map_attr_value( dc, &ad, &atmp,
520 &f->f_av_value, &vtmp, RWM_MAP ) )
525 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
526 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
528 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
529 atmp.bv_val, vtmp.bv_val );
531 ch_free( vtmp.bv_val );
534 case LDAP_FILTER_APPROX:
536 if ( map_attr_value( dc, &ad, &atmp,
537 &f->f_av_value, &vtmp, RWM_MAP ) )
542 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
543 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
545 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
546 atmp.bv_val, vtmp.bv_val );
548 ch_free( vtmp.bv_val );
551 case LDAP_FILTER_SUBSTRINGS:
553 if ( map_attr_value( dc, &ad, &atmp,
554 NULL, NULL, RWM_MAP ) )
559 /* cannot be a DN ... */
561 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
562 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
564 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
567 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
570 filter_escape_value( &f->f_sub_initial, &vtmp );
572 fstr->bv_len += vtmp.bv_len;
573 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
575 snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
576 /* "(attr=" */ "%s*)",
579 ch_free( vtmp.bv_val );
582 if ( f->f_sub_any != NULL ) {
583 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
585 filter_escape_value( &f->f_sub_any[i], &vtmp );
587 fstr->bv_len += vtmp.bv_len + 1;
588 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
590 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
591 /* "(attr=[init]*[any*]" */ "%s*)",
593 ch_free( vtmp.bv_val );
597 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
600 filter_escape_value( &f->f_sub_final, &vtmp );
602 fstr->bv_len += vtmp.bv_len;
603 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
605 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
606 /* "(attr=[init*][any*]" */ "%s)",
609 ch_free( vtmp.bv_val );
614 case LDAP_FILTER_PRESENT:
616 if ( map_attr_value( dc, &ad, &atmp,
617 NULL, NULL, RWM_MAP ) )
622 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
623 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
625 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
629 case LDAP_FILTER_AND:
631 case LDAP_FILTER_NOT:
632 fstr->bv_len = STRLENOF( "(%)" );
633 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
635 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
636 f->f_choice == LDAP_FILTER_AND ? '&' :
637 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
639 for ( p = f->f_list; p != NULL; p = p->f_next ) {
644 rc = rwm_int_filter_map_rewrite( op, dc, p, &vtmp );
645 if ( rc != LDAP_SUCCESS ) {
649 fstr->bv_len += vtmp.bv_len;
650 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
652 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
653 /*"("*/ "%s)", vtmp.bv_val );
655 ch_free( vtmp.bv_val );
660 case LDAP_FILTER_EXT: {
661 if ( f->f_mr_desc ) {
663 if ( map_attr_value( dc, &ad, &atmp,
664 &f->f_mr_value, &vtmp, RWM_MAP ) )
670 BER_BVSTR( &atmp, "" );
671 filter_escape_value( &f->f_mr_value, &vtmp );
675 fstr->bv_len = atmp.bv_len +
676 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
677 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
678 vtmp.bv_len + STRLENOF( "(:=)" );
679 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
681 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
683 f->f_mr_dnattrs ? ":dn" : "",
684 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
685 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
687 ch_free( vtmp.bv_val );
693 filter_free_x( op, f );
694 f->f_choice = SLAPD_FILTER_COMPUTED;
695 f->f_result = SLAPD_COMPARE_UNDEFINED;
698 case SLAPD_FILTER_COMPUTED:
699 switch ( f->f_result ) {
700 case LDAP_COMPARE_FALSE:
701 /* FIXME: treat UNDEFINED as FALSE */
702 case SLAPD_COMPARE_UNDEFINED:
703 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
704 tmp = &ber_bvtf_false;
710 case LDAP_COMPARE_TRUE:
711 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
712 tmp = &ber_bvtf_true;
723 ber_dupbv( fstr, tmp );
727 ber_dupbv( fstr, &ber_bvunknown );
735 rwm_filter_map_rewrite(
739 struct berval *fstr )
745 rc = rwm_int_filter_map_rewrite( op, dc, f, fstr );
747 #ifdef ENABLE_REWRITE
755 fdc.ctx = "searchFilter";
757 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
758 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
759 fdc.conn, &fstr->bv_val ) )
761 case REWRITE_REGEXEC_OK:
762 if ( !BER_BVISNULL( fstr ) ) {
763 fstr->bv_len = strlen( fstr->bv_val );
764 ch_free( ftmp.bv_val );
770 Debug( LDAP_DEBUG_ARGS,
771 "[rw] %s: \"%s\" -> \"%s\"\n",
772 fdc.ctx, ftmp.bv_val, fstr->bv_val );
776 case REWRITE_REGEXEC_UNWILLING:
778 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
779 fdc.rs->sr_text = "Operation not allowed";
781 rc = LDAP_UNWILLING_TO_PERFORM;
784 case REWRITE_REGEXEC_ERR:
786 fdc.rs->sr_err = LDAP_OTHER;
787 fdc.rs->sr_text = "Rewrite error";
792 #endif /* ENABLE_REWRITE */
798 * I don't like this much, but we need two different
799 * functions because different heap managers may be
800 * in use in back-ldap/meta to reduce the amount of
801 * calls to malloc routines, and some of the free()
802 * routines may be macros with args
805 rwm_referral_rewrite(
810 BerVarray *pa_nvals )
812 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
813 struct ldaprwmap *rwmap =
814 (struct ldaprwmap *)on->on_bi.bi_private;
819 struct berval dn = BER_BVNULL,
822 assert( a_vals != NULL );
825 * Rewrite the dn if needed
828 #ifdef ENABLE_REWRITE
829 dc.conn = op->o_conn;
831 dc.ctx = (char *)cookie;
832 #else /* ! ENABLE_REWRITE */
833 dc.tofrom = ((int *)cookie)[0];
835 #endif /* ! ENABLE_REWRITE */
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 #ifdef ENABLE_REWRITE
1002 dc.conn = op->o_conn;
1004 dc.ctx = (char *)cookie;
1005 #else /* ! ENABLE_REWRITE */
1006 dc.tofrom = ((int *)cookie)[0];
1008 #endif /* ! ENABLE_REWRITE */
1010 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
1012 if ( pa_nvals != NULL ) {
1013 if ( *pa_nvals == NULL ) {
1014 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
1015 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
1019 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
1025 ndn = (*pa_nvals)[i];
1026 rc = rwm_dn_massage_pretty_normalize( &dc, &in[i], &dn, &ndn );
1028 rc = rwm_dn_massage_pretty( &dc, &in[i], &dn );
1032 rc = rwm_dn_massage_normalize( &dc, &in[i], &ndn );
1036 case LDAP_UNWILLING_TO_PERFORM:
1038 * FIXME: need to check if it may be considered
1039 * legal to trim values when adding/modifying;
1040 * it should be when searching (e.g. ACLs).
1042 ch_free( in[i].bv_val );
1045 if ( a_vals && pa_nvals ) {
1046 (*pa_nvals)[i] = (*pa_nvals)[last];
1049 BER_BVZERO( &in[last] );
1050 if ( a_vals && pa_nvals ) {
1051 BER_BVZERO( &(*pa_nvals)[last] );
1058 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
1059 ch_free( a_vals[i].bv_val );
1063 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1064 ch_free( (*pa_nvals)[i].bv_val );
1066 (*pa_nvals)[i] = ndn;
1071 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
1072 ch_free( (*pa_nvals)[i].bv_val );
1073 (*pa_nvals)[i] = ndn;
1079 /* leave attr untouched if massage failed */
1080 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1081 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1091 rwm_referral_result_rewrite(
1097 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1100 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1106 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1107 if ( rc != LDAP_URL_SUCCESS ) {
1108 /* leave attr untouched if massage failed */
1112 /* FIXME: URLs like "ldap:///dc=suffix" if passed
1113 * thru ldap_url_parse() and ldap_url_desc2str()
1114 * get rewritten as "ldap:///dc=suffix??base";
1115 * we don't want this to occur... */
1116 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
1117 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
1120 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1123 rc = rwm_dn_massage_pretty( dc, &olddn, &dn );
1125 case LDAP_UNWILLING_TO_PERFORM:
1127 * FIXME: need to check if it may be considered
1128 * legal to trim values when adding/modifying;
1129 * it should be when searching (e.g. ACLs).
1131 ch_free( a_vals[i].bv_val );
1133 a_vals[i] = a_vals[last];
1135 BER_BVZERO( &a_vals[last] );
1141 /* leave attr untouched if massage failed */
1142 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1145 ludp->lud_dn = dn.bv_val;
1146 newurl = ldap_url_desc2str( ludp );
1147 if ( newurl == NULL ) {
1148 /* FIXME: leave attr untouched
1149 * even if ldap_url_desc2str failed...
1154 ch_free( a_vals[i].bv_val );
1155 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1156 LDAP_FREE( newurl );
1157 ludp->lud_dn = olddn.bv_val;
1162 ldap_free_urldesc( ludp );
1169 rwm_dnattr_result_rewrite(
1175 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1178 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1183 rc = rwm_dn_massage_pretty( dc, &a_vals[i], &dn );
1185 case LDAP_UNWILLING_TO_PERFORM:
1187 * FIXME: need to check if it may be considered
1188 * legal to trim values when adding/modifying;
1189 * it should be when searching (e.g. ACLs).
1191 ch_free( a_vals[i].bv_val );
1193 a_vals[i] = a_vals[last];
1195 BER_BVZERO( &a_vals[last] );
1200 /* leave attr untouched if massage failed */
1201 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1202 ch_free( a_vals[i].bv_val );
1213 rwm_mapping_dst_free( void *v_mapping )
1215 struct ldapmapping *mapping = v_mapping;
1217 if ( BER_BVISEMPTY( &mapping[0].m_dst ) ) {
1218 rwm_mapping_free( &mapping[ -1 ] );
1223 rwm_mapping_free( void *v_mapping )
1225 struct ldapmapping *mapping = v_mapping;
1227 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1228 ch_free( mapping[0].m_src.bv_val );
1231 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1232 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1233 if ( mapping[0].m_src_oc ) {
1234 ch_free( mapping[0].m_src_oc );
1238 if ( mapping[0].m_src_ad ) {
1239 ch_free( mapping[0].m_src_ad );
1244 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1245 ch_free( mapping[0].m_dst.bv_val );
1248 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1249 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1250 if ( mapping[0].m_dst_oc ) {
1251 ch_free( mapping[0].m_dst_oc );
1255 if ( mapping[0].m_dst_ad ) {
1256 ch_free( mapping[0].m_dst_ad );
1265 #endif /* SLAPD_OVER_RWM */