need a second function because of different free() routines

This commit is contained in:
Pierangelo Masarati 2003-04-07 17:51:42 +00:00
parent 243311d56a
commit eed02aea22
3 changed files with 63 additions and 41 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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 &&