From: Pierangelo Masarati Date: Tue, 6 Jul 2004 22:14:41 +0000 (+0000) Subject: validate/pretty before normalizing... (ITS#3218) X-Git-Tag: OPENLDAP_REL_ENG_2_2_15~34 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4221ec38086bddc206bc9e391aaab48ca87ebdb7;p=openldap validate/pretty before normalizing... (ITS#3218) --- diff --git a/CHANGES b/CHANGES index 1e6f36d1b5..db6596061f 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ OpenLDAP 2.2.15 Engineering Fixed back-bdb DB_DEADLOCK memory leak bug (ITS#3213) Fixed back-bdb dbcache locking bug (ITS#3201) Fixed back-bdb ctxcsn locking bug + Fixed back-ldap validate/pretty values (ITS#3218) Fixed slapd oidValidate 0 bug (ITS#3211) Fixed slapd uniqueMember/nameUID bugs (ITS#3210) Fixed slapd operational attribute log message bug (ITS#3205) diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index a4d1cf4754..bce3827aad 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -386,27 +386,33 @@ ldap_build_entry( dc.ctx = "searchAttrDN"; #endif while ( ber_scanf( &ber, "{m", &a ) != LBER_ERROR ) { - ldap_back_map(&li->rwmap.rwm_at, &a, &mapped, BACKLDAP_REMAP); - if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') + int i; + slap_syntax_validate_func *validate = + attr->a_desc->ad_type->sat_syntax->ssyn_validate; + slap_syntax_transform_func *pretty = + attr->a_desc->ad_type->sat_syntax->ssyn_pretty; + + ldap_back_map( &li->rwmap.rwm_at, &a, &mapped, BACKLDAP_REMAP ); + if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) continue; - attr = (Attribute *)ch_malloc( sizeof(Attribute) ); - if (attr == NULL) + attr = (Attribute *)ch_malloc( sizeof( Attribute ) ); + if ( attr == NULL ) continue; attr->a_flags = 0; attr->a_next = 0; attr->a_desc = NULL; - if (slap_bv2ad(&mapped, &attr->a_desc, &text) != LDAP_SUCCESS) { - if (slap_bv2undef_ad(&mapped, &attr->a_desc, &text) - != LDAP_SUCCESS) { + if ( slap_bv2ad( &mapped, &attr->a_desc, &text ) != LDAP_SUCCESS ) { + if ( slap_bv2undef_ad( &mapped, &attr->a_desc, &text ) + != LDAP_SUCCESS ) + { #ifdef NEW_LOGGING LDAP_LOG( BACK_LDAP, DETAIL1, "slap_bv2undef_ad(%s): %s\n", mapped.bv_val, text, 0 ); #else /* !NEW_LOGGING */ Debug( LDAP_DEBUG_ANY, - "slap_bv2undef_ad(%s): " - "%s\n%s", mapped.bv_val, text, "" ); + "slap_bv2undef_ad(%s): %s\n", mapped.bv_val, text, 0 ); #endif /* !NEW_LOGGING */ - ch_free(attr); + ch_free( attr ); continue; } } @@ -428,36 +434,39 @@ ldap_build_entry( } if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR - || attr->a_vals == NULL ) { + || attr->a_vals == NULL ) + { /* * Note: attr->a_vals can be null when using * values result filter */ - if (private) { + if ( private ) { attr->a_vals = &dummy; } else { - attr->a_vals = ch_malloc(sizeof(struct berval)); - attr->a_vals->bv_val = NULL; - attr->a_vals->bv_len = 0; + attr->a_vals = ch_malloc( sizeof( struct berval ) ); + BER_BVZERO( &attr->a_vals[0] ); } last = 0; + } else { - for ( last = 0; attr->a_vals[last].bv_val; last++ ); + for ( last = 0; !BER_BVISNULL( &attr->a_vals[last] ); last++ ); } + if ( last == 0 ) { /* empty */ } else if ( attr->a_desc == slap_schema.si_ad_objectClass - || attr->a_desc == slap_schema.si_ad_structuralObjectClass ) { - for ( bv = attr->a_vals; bv->bv_val; bv++ ) { - ldap_back_map(&li->rwmap.rwm_oc, bv, &mapped, - BACKLDAP_REMAP); - if (mapped.bv_val == NULL || mapped.bv_val[0] == '\0') { - LBER_FREE(bv->bv_val); - bv->bv_val = NULL; + || attr->a_desc == slap_schema.si_ad_structuralObjectClass ) + { + for ( bv = attr->a_vals; !BER_BVISNULL( bv ); bv++ ) { + ldap_back_map( &li->rwmap.rwm_oc, bv, &mapped, + BACKLDAP_REMAP ); + if ( BER_BVISNULL( &mapped ) || BER_BVISEMPTY( &mapped ) ) { + LBER_FREE( bv->bv_val ); + BER_BVZERO( bv ); if (--last < 0) break; *bv = attr->a_vals[last]; - attr->a_vals[last].bv_val = NULL; + BER_BVZERO( &attr->a_vals[last] ); bv--; } else if ( mapped.bv_val != bv->bv_val ) { @@ -466,7 +475,7 @@ ldap_build_entry( * the value is replaced by * ch_alloc'ed memory */ - LBER_FREE(bv->bv_val); + LBER_FREE( bv->bv_val ); ber_dupbv( bv, &mapped ); } } @@ -483,35 +492,83 @@ ldap_build_entry( * everything pass thru the ldap backend. */ } else if ( attr->a_desc->ad_type->sat_syntax == - slap_schema.si_syn_distinguishedName ) { + slap_schema.si_syn_distinguishedName ) + { ldap_dnattr_result_rewrite( &dc, attr->a_vals ); } - if ( last && attr->a_desc->ad_type->sat_equality && - attr->a_desc->ad_type->sat_equality->smr_normalize ) { - int i; + validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate; + pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty; + + if ( !validate && !pretty ) { + attr->a_nvals = NULL; + attr_free( attr ); + goto next_attr; + } + + for ( i = 0; i < last; i++ ) { + struct berval pval; + int rc; + + if ( pretty ) { + rc = pretty( attr->a_desc->ad_type->sat_syntax, + &attr->a_vals[i], &pval, NULL ); + } else { + rc = validate( attr->a_desc->ad_type->sat_syntax, + &attr->a_vals[i] ); + } + + if ( rc != LDAP_SUCCESS ) { + attr->a_nvals = NULL; + attr_free( attr ); + goto next_attr; + } + + if ( pretty ) { + LBER_FREE( attr->a_vals[i].bv_val ); + attr->a_vals[i] = pval; + } + } - attr->a_nvals = ch_malloc((last+1)*sizeof(struct berval)); - for (i=0; ia_desc->ad_type->sat_equality->smr_normalize( + if ( last && attr->a_desc->ad_type->sat_equality && + attr->a_desc->ad_type->sat_equality->smr_normalize ) + { + attr->a_nvals = ch_malloc( ( last + 1 )*sizeof( struct berval ) ); + for ( i = 0; i < last; i++ ) { + int rc; + + /* + * check that each value is valid per syntax + * and pretty if appropriate + */ + rc = attr->a_desc->ad_type->sat_equality->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, attr->a_desc->ad_type->sat_syntax, attr->a_desc->ad_type->sat_equality, &attr->a_vals[i], &attr->a_nvals[i], NULL /* op->o_tmpmemctx */ ); + + if ( rc != LDAP_SUCCESS ) { + BER_BVZERO( &attr->a_nvals[i] ); + ch_free( attr ); + goto next_attr; + } } - attr->a_nvals[i].bv_val = NULL; - attr->a_nvals[i].bv_len = 0; + BER_BVZERO( &attr->a_nvals[i] ); + } else { attr->a_nvals = attr->a_vals; } *attrp = attr; attrp = &attr->a_next; + +next_attr:; } /* make sure it's free'able */ - if (!private && ent->e_name.bv_val == bdn->bv_val) + if ( !private && ent->e_name.bv_val == bdn->bv_val ) { ber_dupbv( &ent->e_name, bdn ); + } return LDAP_SUCCESS; }