From eed02aea229de7f5c523dcb33481f39cf49ed62b Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 7 Apr 2003 17:51:42 +0000 Subject: [PATCH] need a second function because of different free() routines --- servers/slapd/back-ldap/back-ldap.h | 1 + servers/slapd/back-ldap/map.c | 72 ++++++++++++++++++++++++----- servers/slapd/back-ldap/search.c | 31 +------------ 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index d605d694f8..dc67f7e158 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -192,6 +192,7 @@ extern int suffix_massage_config( struct rewrite_info *info, struct berval *prnc, struct berval *nrnc); #endif /* ENABLE_REWRITE */ extern int ldap_dnattr_rewrite( dncookie *dc, BerVarray a_vals ); +extern int ldap_dnattr_result_rewrite( dncookie *dc, BerVarray a_vals ); LDAP_END_DECL diff --git a/servers/slapd/back-ldap/map.c b/servers/slapd/back-ldap/map.c index c74eee875e..007ed1b985 100644 --- a/servers/slapd/back-ldap/map.c +++ b/servers/slapd/back-ldap/map.c @@ -44,6 +44,9 @@ #include "slap.h" #include "back-ldap.h" +#undef ldap_debug /* silence a warning in ldap-int.h */ +#include "../../../libraries/libldap/ldap-int.h" + int mapping_cmp ( const void *c1, const void *c2 ) { @@ -468,6 +471,13 @@ ldap_back_filter_map_rewrite( return 0; } +/* + * I don't like this much, but we need two different + * functions because different heap managers may be + * in use in back-ldap/meta to reduce the amount of + * calls to malloc routines, and some of the free() + * routines may be macros with args + */ int ldap_dnattr_rewrite( dncookie *dc, @@ -482,21 +492,11 @@ ldap_dnattr_rewrite( for ( i = 0; a_vals[i].bv_val != NULL; i++ ) { switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) { - case LDAP_SUCCESS: - case LDAP_OTHER: /* ? */ - default: /* ??? */ - /* leave attr untouched if massage failed */ - if ( bv.bv_val && bv.bv_val != a_vals[i].bv_val ) { - ch_free( a_vals[i].bv_val ); - a_vals[i] = bv; - } - break; - case LDAP_UNWILLING_TO_PERFORM: /* * FIXME: need to check if it may be considered * legal to trim values when adding/modifying; - * it should be when searching (see ACLs). + * it should be when searching (e.g. ACLs). */ ch_free( a_vals[i].bv_val ); if (last > i ) { @@ -506,9 +506,59 @@ ldap_dnattr_rewrite( a_vals[last].bv_val = NULL; last--; break; + + default: + /* leave attr untouched if massage failed */ + if ( bv.bv_val && bv.bv_val != a_vals[i].bv_val ) { + ch_free( a_vals[i].bv_val ); + a_vals[i] = bv; + } + break; } } return 0; } +int +ldap_dnattr_result_rewrite( + dncookie *dc, + BerVarray a_vals +) +{ + struct berval bv; + int i, last; + + for ( last = 0; a_vals[last].bv_val; last++ ); + last--; + + for ( i = 0; a_vals[i].bv_val; i++ ) { + switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) { + case LDAP_UNWILLING_TO_PERFORM: + /* + * FIXME: need to check if it may be considered + * legal to trim values when adding/modifying; + * it should be when searching (e.g. ACLs). + */ + LBER_FREE( &a_vals[i].bv_val ); + if ( last > i ) { + a_vals[i] = a_vals[last]; + } + a_vals[last].bv_val = NULL; + a_vals[last].bv_len = 0; + last--; + break; + + default: + /* leave attr untouched if massage failed */ + if ( bv.bv_val && a_vals[i].bv_val != bv.bv_val ) { + LBER_FREE( a_vals[i].bv_val ); + a_vals[i] = bv; + } + break; + } + } + + return 0; +} + diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 39097d9071..c9827ae247 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -519,37 +519,8 @@ ldap_build_entry( */ } else if ( attr->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName ) { - int last, i; + ldap_dnattr_result_rewrite( &dc, attr->a_vals ); - /* - * FIXME: should use ldap_dnattr_rewrite(), - * but need a different free() callback ... - */ - - for ( last = 0; attr->a_vals[last].bv_val; last++ ); - - for ( i = 0; attr->a_vals[i].bv_val; i++ ) { - struct berval newval = { 0, NULL }; - - bv = &attr->a_vals[i]; - switch ( ldap_back_dn_massage( &dc, bv, &newval ) ) { - case LDAP_UNWILLING_TO_PERFORM: - LBER_FREE( bv->bv_val ); - if ( last > i ) { - *bv = attr->a_vals[last]; - } - attr->a_vals[last].bv_val = NULL; - last--; - break; - - default: - if ( newval.bv_val && bv->bv_val != newval.bv_val ) { - LBER_FREE( bv->bv_val ); - *bv = newval; - } - break; - } - } } if ( normalize && last && attr->a_desc->ad_type->sat_equality &&