BVarray fixes for ldap_dnattr_rewrite

This commit is contained in:
Howard Chu 2002-01-05 11:41:23 +00:00
parent 5fd983725e
commit 225fa32d8f
4 changed files with 27 additions and 13 deletions

View file

@ -164,6 +164,7 @@ ldap_back_add(
attrs[i]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *)); attrs[i]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
for (j=0; a->a_vals[j].bv_val; j++) for (j=0; a->a_vals[j].bv_val; j++)
attrs[i]->mod_vals.modv_bvals[j] = &a->a_vals[j]; attrs[i]->mod_vals.modv_bvals[j] = &a->a_vals[j];
attrs[i]->mod_vals.modv_bvals[j] = NULL;
i++; i++;
} }
attrs[i] = NULL; attrs[i] = NULL;
@ -185,15 +186,14 @@ ldap_back_add(
int int
ldap_dnattr_rewrite( ldap_dnattr_rewrite(
struct rewrite_info *rwinfo, struct rewrite_info *rwinfo,
struct berval **a_vals, BVarray a_vals,
void *cookie void *cookie
) )
{ {
int j;
char *mattr; char *mattr;
for ( j = 0; a_vals[ j ] != NULL; j++ ) { for ( ; a_vals->bv_val != NULL; a_vals++ ) {
switch ( rewrite_session( rwinfo, "bindDn", a_vals[ j ]->bv_val, switch ( rewrite_session( rwinfo, "bindDn", a_vals->bv_val,
cookie, &mattr )) { cookie, &mattr )) {
case REWRITE_REGEXEC_OK: case REWRITE_REGEXEC_OK:
if ( mattr == NULL ) { if ( mattr == NULL ) {
@ -204,17 +204,17 @@ ldap_dnattr_rewrite(
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"[rw] bindDn (in add of dn-valued" "[rw] bindDn (in add of dn-valued"
" attr): \"%s\" -> \"%s\"\n", " attr): \"%s\" -> \"%s\"\n",
a_vals[ j ]->bv_val, mattr )); a_vals->bv_val, mattr ));
#else /* !NEW_LOGGING */ #else /* !NEW_LOGGING */
Debug( LDAP_DEBUG_ARGS, Debug( LDAP_DEBUG_ARGS,
"rw> bindDn (in add of dn-valued attr):" "rw> bindDn (in add of dn-valued attr):"
" \"%s\" -> \"%s\"\n%s", " \"%s\" -> \"%s\"\n%s",
a_vals[ j ]->bv_val, mattr, "" ); a_vals->bv_val, mattr, "" );
#endif /* !NEW_LOGGING */ #endif /* !NEW_LOGGING */
free( a_vals[ j ]->bv_val ); free( a_vals->bv_val );
a_vals[ j ]->bv_val = mattr; a_vals->bv_val = mattr;
a_vals[ j ]->bv_len = strlen( mattr ); a_vals->bv_len = strlen( mattr );
break; break;

View file

@ -122,7 +122,7 @@ extern void mapping_free ( struct ldapmapping *mapping );
#ifdef ENABLE_REWRITE #ifdef ENABLE_REWRITE
extern int suffix_massage_config( struct rewrite_info *info, int argc, char **argv ); extern int suffix_massage_config( struct rewrite_info *info, int argc, char **argv );
extern int ldap_dnattr_rewrite( struct rewrite_info *rwinfo, struct berval **a_vals, void *cookie ); extern int ldap_dnattr_rewrite( struct rewrite_info *rwinfo, BVarray a_vals, void *cookie );
#endif /* ENABLE_REWRITE */ #endif /* ENABLE_REWRITE */
LDAP_END_DECL LDAP_END_DECL

View file

@ -149,6 +149,7 @@ meta_back_add(
attrs = ch_malloc( sizeof( LDAPMod * )*i ); attrs = ch_malloc( sizeof( LDAPMod * )*i );
for ( i = 0, a = e->e_attrs; a; a = a->a_next ) { for ( i = 0, a = e->e_attrs; a; a = a->a_next ) {
int j;
/* /*
* lastmod should always be <off>, so that * lastmod should always be <off>, so that
* creation/modification operational attrs * creation/modification operational attrs
@ -192,13 +193,18 @@ meta_back_add(
a->a_vals, conn ); a->a_vals, conn );
} }
attrs[ i ]->mod_vals.modv_bvals = a->a_vals; for (j=0; a->a_vals[ j ].bv_val; j++);
attrs[ i ]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
for (j=0; a->a_vals[ j ].bv_val; j++)
attrs[ i ]->mod_vals.modv_bvals[ j ] = &a->a_vals[ j ];
attrs[ i ]->mod_vals.modv_bvals[ j ] = NULL;
i++; i++;
} }
attrs[ i ] = NULL; attrs[ i ] = NULL;
ldap_add_s( lc->conns[ candidate ]->ld, mdn.bv_val, attrs ); ldap_add_s( lc->conns[ candidate ]->ld, mdn.bv_val, attrs );
for ( --i; i >= 0; --i ) { for ( --i; i >= 0; --i ) {
free( attrs[ i ]->mod_vals.modv_bvals );
free( attrs[ i ] ); free( attrs[ i ] );
} }
free( attrs ); free( attrs );

View file

@ -152,6 +152,7 @@ meta_back_modify(
} }
for ( i = 0, ml = modlist; ml; ml = ml->sml_next ) { for ( i = 0, ml = modlist; ml; ml = ml->sml_next ) {
int j;
/* /*
* lastmod should always be <off> * lastmod should always be <off>
*/ */
@ -189,8 +190,13 @@ meta_back_modify(
li->targets[ candidate ]->rwinfo, li->targets[ candidate ]->rwinfo,
ml->sml_bvalues, conn ); ml->sml_bvalues, conn );
} }
mods[ i ].mod_bvalues = ml->sml_bvalues; for (j = 0; ml->sml_bvalues[ j ].bv_val; j++);
mods[ i ].mod_bvalues = (struct berval **)ch_malloc((j+1) *
sizeof(struct berval *));
for (j = 0; ml->sml_bvalues[ j ].bv_val; j++)
mods[ i ].mod_bvalues[ j ] = &ml->sml_bvalues[j];
mods[ i ].mod_bvalues[ j ] = NULL;
i++; i++;
} }
modv[ i ] = 0; modv[ i ] = 0;
@ -200,6 +206,8 @@ meta_back_modify(
if ( mdn != dn->bv_val ) { if ( mdn != dn->bv_val ) {
free( mdn ); free( mdn );
} }
for ( i=0; modv[ i ]; i++)
free( modv[ i ]->mod_bvalues );
free( mods ); free( mods );
free( modv ); free( modv );
return meta_back_op_result( lc, op ); return meta_back_op_result( lc, op );