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 )
458 /* better than nothing... */
459 ber_bvfalse = BER_BVC( "(!(objectClass=*))" ),
460 ber_bvtf_false = BER_BVC( "(|)" ),
461 /* better than nothing... */
462 ber_bvtrue = BER_BVC( "(objectClass=*)" ),
463 ber_bvtf_true = BER_BVC( "(&)" ),
465 /* no longer needed; preserved for completeness */
466 ber_bvundefined = BER_BVC( "(?=undefined)" ),
468 ber_bverror = BER_BVC( "(?=error)" ),
469 ber_bvunknown = BER_BVC( "(?=unknown)" ),
470 ber_bvnone = BER_BVC( "(?=none)" );
473 assert( fstr != NULL );
477 ber_dupbv( fstr, &ber_bvnone );
481 switch ( f->f_choice ) {
482 case LDAP_FILTER_EQUALITY:
483 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
484 &f->f_av_value, &vtmp, RWM_MAP ) )
489 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(=)" );
490 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
492 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
493 atmp.bv_val, vtmp.bv_val );
495 ch_free( vtmp.bv_val );
499 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
500 &f->f_av_value, &vtmp, RWM_MAP ) )
505 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(>=)" );
506 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
508 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
509 atmp.bv_val, vtmp.bv_val );
511 ch_free( vtmp.bv_val );
515 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
516 &f->f_av_value, &vtmp, RWM_MAP ) )
521 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(<=)" );
522 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
524 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
525 atmp.bv_val, vtmp.bv_val );
527 ch_free( vtmp.bv_val );
530 case LDAP_FILTER_APPROX:
531 if ( map_attr_value( dc, &f->f_av_desc, &atmp,
532 &f->f_av_value, &vtmp, RWM_MAP ) )
537 fstr->bv_len = atmp.bv_len + vtmp.bv_len + STRLENOF( "(~=)" );
538 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
540 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
541 atmp.bv_val, vtmp.bv_val );
543 ch_free( vtmp.bv_val );
546 case LDAP_FILTER_SUBSTRINGS:
547 if ( map_attr_value( dc, &f->f_sub_desc, &atmp,
548 NULL, NULL, RWM_MAP ) )
553 /* cannot be a DN ... */
555 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
556 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
558 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
561 if ( !BER_BVISNULL( &f->f_sub_initial ) ) {
564 filter_escape_value( &f->f_sub_initial, &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 - 2], vtmp.bv_len + 3,
570 /* "(attr=" */ "%s*)",
573 ch_free( vtmp.bv_val );
576 if ( f->f_sub_any != NULL ) {
577 for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
579 filter_escape_value( &f->f_sub_any[i], &vtmp );
581 fstr->bv_len += vtmp.bv_len + 1;
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*)",
587 ch_free( vtmp.bv_val );
591 if ( !BER_BVISNULL( &f->f_sub_final ) ) {
594 filter_escape_value( &f->f_sub_final, &vtmp );
596 fstr->bv_len += vtmp.bv_len;
597 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
599 snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
600 /* "(attr=[init*][any*]" */ "%s)",
603 ch_free( vtmp.bv_val );
608 case LDAP_FILTER_PRESENT:
609 if ( map_attr_value( dc, &f->f_desc, &atmp,
610 NULL, NULL, RWM_MAP ) )
615 fstr->bv_len = atmp.bv_len + STRLENOF( "(=*)" );
616 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
618 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
622 case LDAP_FILTER_AND:
624 case LDAP_FILTER_NOT:
625 fstr->bv_len = STRLENOF( "(%)" );
626 fstr->bv_val = ch_malloc( fstr->bv_len + 128 );
628 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
629 f->f_choice == LDAP_FILTER_AND ? '&' :
630 f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
632 for ( p = f->f_list; p != NULL; p = p->f_next ) {
637 rc = rwm_int_filter_map_rewrite( op, dc, p, &vtmp );
638 if ( rc != LDAP_SUCCESS ) {
642 fstr->bv_len += vtmp.bv_len;
643 fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
645 snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2,
646 /*"("*/ "%s)", vtmp.bv_val );
648 ch_free( vtmp.bv_val );
653 case LDAP_FILTER_EXT: {
654 if ( f->f_mr_desc ) {
655 if ( map_attr_value( dc, &f->f_mr_desc, &atmp,
656 &f->f_mr_value, &vtmp, RWM_MAP ) )
662 BER_BVSTR( &atmp, "" );
663 filter_escape_value( &f->f_mr_value, &vtmp );
667 fstr->bv_len = atmp.bv_len +
668 ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
669 ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
670 vtmp.bv_len + STRLENOF( "(:=)" );
671 fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
673 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
675 f->f_mr_dnattrs ? ":dn" : "",
676 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
677 !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
679 ch_free( vtmp.bv_val );
685 filter_free_x( op, f );
686 f->f_choice = SLAPD_FILTER_COMPUTED;
687 f->f_result = SLAPD_COMPARE_UNDEFINED;
690 case SLAPD_FILTER_COMPUTED:
691 switch ( f->f_result ) {
692 case LDAP_COMPARE_FALSE:
693 /* FIXME: treat UNDEFINED as FALSE */
694 case SLAPD_COMPARE_UNDEFINED:
695 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
696 tmp = &ber_bvtf_false;
702 case LDAP_COMPARE_TRUE:
703 if ( dc->rwmap->rwm_flags & RWM_F_SUPPORT_T_F ) {
704 tmp = &ber_bvtf_true;
715 ber_dupbv( fstr, tmp );
719 ber_dupbv( fstr, &ber_bvunknown );
727 rwm_filter_map_rewrite(
731 struct berval *fstr )
737 rc = rwm_int_filter_map_rewrite( op, dc, f, fstr );
739 #ifdef ENABLE_REWRITE
747 fdc.ctx = "searchFilter";
749 switch ( rewrite_session( fdc.rwmap->rwm_rw, fdc.ctx,
750 ( !BER_BVISEMPTY( &ftmp ) ? ftmp.bv_val : "" ),
751 fdc.conn, &fstr->bv_val ) )
753 case REWRITE_REGEXEC_OK:
754 if ( !BER_BVISNULL( fstr ) ) {
755 fstr->bv_len = strlen( fstr->bv_val );
756 ch_free( ftmp.bv_val );
762 Debug( LDAP_DEBUG_ARGS,
763 "[rw] %s: \"%s\" -> \"%s\"\n",
764 fdc.ctx, ftmp.bv_val, fstr->bv_val );
768 case REWRITE_REGEXEC_UNWILLING:
770 fdc.rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
771 fdc.rs->sr_text = "Operation not allowed";
773 rc = LDAP_UNWILLING_TO_PERFORM;
776 case REWRITE_REGEXEC_ERR:
778 fdc.rs->sr_err = LDAP_OTHER;
779 fdc.rs->sr_text = "Rewrite error";
784 #endif /* ENABLE_REWRITE */
790 * I don't like this much, but we need two different
791 * functions because different heap managers may be
792 * in use in back-ldap/meta to reduce the amount of
793 * calls to malloc routines, and some of the free()
794 * routines may be macros with args
797 rwm_referral_rewrite(
802 BerVarray *pa_nvals )
804 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
805 struct ldaprwmap *rwmap =
806 (struct ldaprwmap *)on->on_bi.bi_private;
811 struct berval dn = BER_BVNULL,
814 assert( a_vals != NULL );
817 * Rewrite the dn if needed
820 #ifdef ENABLE_REWRITE
821 dc.conn = op->o_conn;
823 dc.ctx = (char *)cookie;
824 #else /* ! ENABLE_REWRITE */
825 dc.tofrom = ((int *)cookie)[0];
827 #endif /* ! ENABLE_REWRITE */
829 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ )
833 if ( pa_nvals != NULL ) {
834 if ( *pa_nvals == NULL ) {
835 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
836 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
840 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
841 struct berval olddn = BER_BVNULL,
847 rc = ldap_url_parse( oldval.bv_val, &ludp );
848 if ( rc != LDAP_URL_SUCCESS ) {
849 /* leave attr untouched if massage failed */
850 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
851 ber_dupbv( &(*pa_nvals)[i], &oldval );
856 /* FIXME: URLs like "ldap:///dc=suffix" if passed
857 * thru ldap_url_parse() and ldap_url_desc2str()
858 * get rewritten as "ldap:///dc=suffix??base";
859 * we don't want this to occur... */
860 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
861 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
864 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
869 rc = rwm_dn_massage_pretty_normalize( &dc, &olddn,
872 rc = rwm_dn_massage_pretty( &dc, &olddn, &dn );
876 case LDAP_UNWILLING_TO_PERFORM:
878 * FIXME: need to check if it may be considered
879 * legal to trim values when adding/modifying;
880 * it should be when searching (e.g. ACLs).
882 ch_free( a_vals[i].bv_val );
884 a_vals[i] = a_vals[last];
886 (*pa_nvals)[i] = (*pa_nvals)[last];
889 BER_BVZERO( &a_vals[last] );
891 BER_BVZERO( &(*pa_nvals)[last] );
897 if ( !BER_BVISNULL( &dn ) && dn.bv_val != olddn.bv_val ) {
900 ludp->lud_dn = dn.bv_val;
901 newurl = ldap_url_desc2str( ludp );
902 ludp->lud_dn = olddn.bv_val;
903 ch_free( dn.bv_val );
904 if ( newurl == NULL ) {
905 /* FIXME: leave attr untouched
906 * even if ldap_url_desc2str failed...
911 ber_str2bv( newurl, 0, 1, &a_vals[i] );
915 ludp->lud_dn = ndn.bv_val;
916 newurl = ldap_url_desc2str( ludp );
917 ludp->lud_dn = olddn.bv_val;
918 ch_free( ndn.bv_val );
919 if ( newurl == NULL ) {
920 /* FIXME: leave attr untouched
921 * even if ldap_url_desc2str failed...
923 ch_free( a_vals[i].bv_val );
928 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
929 ch_free( (*pa_nvals)[i].bv_val );
931 ber_str2bv( newurl, 0, 1, &(*pa_nvals)[i] );
935 ch_free( oldval.bv_val );
936 ludp->lud_dn = olddn.bv_val;
941 /* leave attr untouched if massage failed */
942 if ( pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
943 ber_dupbv( &(*pa_nvals)[i], &a_vals[i] );
947 ldap_free_urldesc( ludp );
954 * I don't like this much, but we need two different
955 * functions because different heap managers may be
956 * in use in back-ldap/meta to reduce the amount of
957 * calls to malloc routines, and some of the free()
958 * routines may be macros with args
966 BerVarray *pa_nvals )
968 slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
969 struct ldaprwmap *rwmap =
970 (struct ldaprwmap *)on->on_bi.bi_private;
975 struct berval dn = BER_BVNULL,
983 if ( pa_nvals == NULL || *pa_nvals == NULL ) {
990 * Rewrite the dn if needed
993 #ifdef ENABLE_REWRITE
994 dc.conn = op->o_conn;
996 dc.ctx = (char *)cookie;
997 #else /* ! ENABLE_REWRITE */
998 dc.tofrom = ((int *)cookie)[0];
1000 #endif /* ! ENABLE_REWRITE */
1002 for ( last = 0; !BER_BVISNULL( &in[last] ); last++ );
1004 if ( pa_nvals != NULL ) {
1005 if ( *pa_nvals == NULL ) {
1006 *pa_nvals = ch_malloc( ( last + 2 ) * sizeof(struct berval) );
1007 memset( *pa_nvals, 0, ( last + 2 ) * sizeof(struct berval) );
1011 for ( i = 0; !BER_BVISNULL( &in[i] ); i++ ) {
1017 ndn = (*pa_nvals)[i];
1018 rc = rwm_dn_massage_pretty_normalize( &dc, &in[i], &dn, &ndn );
1020 rc = rwm_dn_massage_pretty( &dc, &in[i], &dn );
1024 rc = rwm_dn_massage_normalize( &dc, &in[i], &ndn );
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( in[i].bv_val );
1037 if ( a_vals && pa_nvals ) {
1038 (*pa_nvals)[i] = (*pa_nvals)[last];
1041 BER_BVZERO( &in[last] );
1042 if ( a_vals && pa_nvals ) {
1043 BER_BVZERO( &(*pa_nvals)[last] );
1050 if ( !BER_BVISNULL( &dn ) && dn.bv_val != a_vals[i].bv_val ) {
1051 ch_free( a_vals[i].bv_val );
1055 if ( !BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1056 ch_free( (*pa_nvals)[i].bv_val );
1058 (*pa_nvals)[i] = ndn;
1063 if ( !BER_BVISNULL( &ndn ) && ndn.bv_val != (*pa_nvals)[i].bv_val ) {
1064 ch_free( (*pa_nvals)[i].bv_val );
1065 (*pa_nvals)[i] = ndn;
1071 /* leave attr untouched if massage failed */
1072 if ( a_vals && pa_nvals && BER_BVISNULL( &(*pa_nvals)[i] ) ) {
1073 dnNormalize( 0, NULL, NULL, &a_vals[i], &(*pa_nvals)[i], NULL );
1083 rwm_referral_result_rewrite(
1089 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1092 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1098 rc = ldap_url_parse( a_vals[i].bv_val, &ludp );
1099 if ( rc != LDAP_URL_SUCCESS ) {
1100 /* leave attr untouched if massage failed */
1104 /* FIXME: URLs like "ldap:///dc=suffix" if passed
1105 * thru ldap_url_parse() and ldap_url_desc2str()
1106 * get rewritten as "ldap:///dc=suffix??base";
1107 * we don't want this to occur... */
1108 if ( ludp->lud_scope == LDAP_SCOPE_BASE ) {
1109 ludp->lud_scope = LDAP_SCOPE_DEFAULT;
1112 ber_str2bv( ludp->lud_dn, 0, 0, &olddn );
1115 rc = rwm_dn_massage_pretty( dc, &olddn, &dn );
1117 case LDAP_UNWILLING_TO_PERFORM:
1119 * FIXME: need to check if it may be considered
1120 * legal to trim values when adding/modifying;
1121 * it should be when searching (e.g. ACLs).
1123 ch_free( a_vals[i].bv_val );
1125 a_vals[i] = a_vals[last];
1127 BER_BVZERO( &a_vals[last] );
1133 /* leave attr untouched if massage failed */
1134 if ( !BER_BVISNULL( &dn ) && olddn.bv_val != dn.bv_val ) {
1137 ludp->lud_dn = dn.bv_val;
1138 newurl = ldap_url_desc2str( ludp );
1139 if ( newurl == NULL ) {
1140 /* FIXME: leave attr untouched
1141 * even if ldap_url_desc2str failed...
1146 ch_free( a_vals[i].bv_val );
1147 ber_str2bv( newurl, 0, 1, &a_vals[i] );
1148 LDAP_FREE( newurl );
1149 ludp->lud_dn = olddn.bv_val;
1154 ldap_free_urldesc( ludp );
1161 rwm_dnattr_result_rewrite(
1167 for ( last = 0; !BER_BVISNULL( &a_vals[last] ); last++ );
1170 for ( i = 0; !BER_BVISNULL( &a_vals[i] ); i++ ) {
1175 rc = rwm_dn_massage_pretty( dc, &a_vals[i], &dn );
1177 case LDAP_UNWILLING_TO_PERFORM:
1179 * FIXME: need to check if it may be considered
1180 * legal to trim values when adding/modifying;
1181 * it should be when searching (e.g. ACLs).
1183 ch_free( a_vals[i].bv_val );
1185 a_vals[i] = a_vals[last];
1187 BER_BVZERO( &a_vals[last] );
1192 /* leave attr untouched if massage failed */
1193 if ( !BER_BVISNULL( &dn ) && a_vals[i].bv_val != dn.bv_val ) {
1194 ch_free( a_vals[i].bv_val );
1205 rwm_mapping_dst_free( void *v_mapping )
1207 struct ldapmapping *mapping = v_mapping;
1209 if ( BER_BVISEMPTY( &mapping[0].m_dst ) ) {
1210 rwm_mapping_free( &mapping[ -1 ] );
1215 rwm_mapping_free( void *v_mapping )
1217 struct ldapmapping *mapping = v_mapping;
1219 if ( !BER_BVISNULL( &mapping[0].m_src ) ) {
1220 ch_free( mapping[0].m_src.bv_val );
1223 if ( mapping[0].m_flags & RWMMAP_F_FREE_SRC ) {
1224 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1225 if ( mapping[0].m_src_oc ) {
1226 ch_free( mapping[0].m_src_oc );
1230 if ( mapping[0].m_src_ad ) {
1231 ch_free( mapping[0].m_src_ad );
1236 if ( !BER_BVISNULL( &mapping[0].m_dst ) ) {
1237 ch_free( mapping[0].m_dst.bv_val );
1240 if ( mapping[0].m_flags & RWMMAP_F_FREE_DST ) {
1241 if ( mapping[0].m_flags & RWMMAP_F_IS_OC ) {
1242 if ( mapping[0].m_dst_oc ) {
1243 ch_free( mapping[0].m_dst_oc );
1247 if ( mapping[0].m_dst_ad ) {
1248 ch_free( mapping[0].m_dst_ad );
1257 #endif /* SLAPD_OVER_RWM */