X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fmods.c;h=20721784ce0b0a75537c936e45b2abd5c7be14f2;hb=17f95a3fd30247a0735a3526d85b46178304748d;hp=528f6f1437afdb65431850993b139e6dd27c5d21;hpb=b8240724ad38abca68d3ba1a554e1041796ee2aa;p=openldap diff --git a/servers/slapd/mods.c b/servers/slapd/mods.c index 528f6f1437..20721784ce 100644 --- a/servers/slapd/mods.c +++ b/servers/slapd/mods.c @@ -1,5 +1,5 @@ /* - * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ /* @@ -29,7 +29,7 @@ modify_check_duplicates( { int i, j, numvals = 0, nummods, rc = LDAP_SUCCESS; - BerVarray nvals = NULL, nmods; + BerVarray nvals = NULL, nmods = NULL; /* * FIXME: better do the following @@ -73,7 +73,17 @@ modify_check_duplicates( /* count existing values */ ; if ( numvals < nummods ) { - nvals = ch_calloc( numvals + 1, sizeof( struct berval ) ); + nvals = SLAP_CALLOC( numvals + 1, sizeof( struct berval ) ); + if( nvals == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG( OPERATION, ERR, + "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 ); +#else + Debug( LDAP_DEBUG_ANY, + "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 ); +#endif + goto return_results; + } /* normalize the existing values first */ for ( j = 0; vals[ j ].bv_val != NULL; j++ ) { @@ -98,7 +108,17 @@ modify_check_duplicates( * values and test each new value against them first, * then to other already normalized values */ - nmods = ch_calloc( nummods + 1, sizeof( struct berval ) ); + nmods = SLAP_CALLOC( nummods + 1, sizeof( struct berval ) ); + if ( nmods == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG( OPERATION, ERR, + "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 ); +#else + Debug( LDAP_DEBUG_ANY, + "modify_check_duplicates: SLAP_CALLOC failed", 0, 0, 0 ); +#endif + goto return_results; + } for ( i = 0; mods[ i ].bv_val != NULL; i++ ) { rc = value_normalize( ad, SLAP_MR_EQUALITY, @@ -119,10 +139,15 @@ modify_check_duplicates( mr, &nmods[ i ], &nvals[ j ] ); if ( rc != LDAP_SUCCESS ) { nmods[ i + 1 ].bv_val = NULL; + *text = textbuf; + snprintf( textbuf, textlen, + "%s: matching rule failed", + ad->ad_cname.bv_val ); goto return_results; } if ( match == 0 ) { + *text = textbuf; snprintf( textbuf, textlen, "%s: value #%d provided more than once", ad->ad_cname.bv_val, i ); @@ -142,10 +167,15 @@ modify_check_duplicates( mr, &nmods[ i ], &nmods[ j ] ); if ( rc != LDAP_SUCCESS ) { nmods[ i + 1 ].bv_val = NULL; + *text = textbuf; + snprintf( textbuf, textlen, + "%s: matching rule failed", + ad->ad_cname.bv_val ); goto return_results; } if ( match == 0 ) { + *text = textbuf; snprintf( textbuf, textlen, "%s: value #%d provided more than once", ad->ad_cname.bv_val, j ); @@ -183,10 +213,15 @@ modify_check_duplicates( ad->ad_type->sat_syntax, mr, &nmods[ i ], &asserted ); if ( rc != LDAP_SUCCESS ) { + *text = textbuf; + snprintf( textbuf, textlen, + "%s: matching rule failed", + ad->ad_cname.bv_val ); goto return_results; } if ( match == 0 ) { + *text = textbuf; snprintf( textbuf, textlen, "%s: value #%d provided more than once", ad->ad_cname.bv_val, j ); @@ -281,7 +316,6 @@ modify_add_values( } } else { - /* * The original code performs ( n ) normalizations * and ( n * ( n - 1 ) / 2 ) matches, which hide @@ -310,8 +344,6 @@ modify_add_values( */ int rc; - const char *text = NULL; - char textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' }; if ( mod->sm_bvalues[ 1 ].bv_val == 0 ) { if ( a != NULL ) { @@ -319,7 +351,7 @@ modify_add_values( int i; rc = value_normalize( mod->sm_desc, SLAP_MR_EQUALITY, - &mod->sm_bvalues[ 0 ], &asserted, &text ); + &mod->sm_bvalues[ 0 ], &asserted, text ); if ( rc != LDAP_SUCCESS ) { return rc; @@ -330,10 +362,14 @@ modify_add_values( rc = value_match( &match, mod->sm_desc, mr, SLAP_MR_VALUE_SYNTAX_MATCH, - &a->a_vals[ i ], &asserted, &text ); + &a->a_vals[ i ], &asserted, text ); if( rc == LDAP_SUCCESS && match == 0 ) { free( asserted.bv_val ); + *text = textbuf; + snprintf( textbuf, textlen, + "modify/%s: %s: value #0 already exists", + op, mod->sm_desc->ad_cname.bv_val, 0 ); return LDAP_TYPE_OR_VALUE_EXISTS; } } @@ -342,7 +378,7 @@ modify_add_values( } else { rc = modify_check_duplicates( mod->sm_desc, mr, a ? a->a_vals : NULL, mod->sm_bvalues, - &text, textbuf, sizeof( textbuf ) ); + text, textbuf, textlen ); if ( rc != LDAP_SUCCESS ) { return rc; @@ -414,7 +450,17 @@ modify_delete_values( for ( j = 0; a->a_vals[ j ].bv_val != NULL; j++ ) /* count existing values */ ; - nvals = (BerVarray)ch_calloc( j + 1, sizeof ( struct berval ) ); + nvals = (BerVarray)SLAP_CALLOC( j + 1, sizeof ( struct berval ) ); + if( nvals == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG( OPERATION, ERR, + "modify_delete_values: SLAP_CALLOC failed", 0, 0, 0 ); +#else + Debug( LDAP_DEBUG_ANY, + "modify_delete_values: SLAP_CALLOC failed", 0, 0, 0 ); +#endif + goto return_results; + } /* normalize existing values */ for ( j = 0; a->a_vals[ j ].bv_val != NULL; j++ ) { @@ -454,6 +500,10 @@ modify_delete_values( if ( rc != LDAP_SUCCESS ) { free( asserted.bv_val ); + *text = textbuf; + snprintf( textbuf, textlen, + "%s: matching rule failed", + mod->sm_desc->ad_cname.bv_val ); goto return_results; }