Commit fde1f80a authored by Ondrej Kuznik's avatar Ondrej Kuznik Committed by Howard Chu
Browse files

ITS#7256 Add some necessary checks.

parent 304c0cbb
...@@ -282,107 +282,85 @@ slapmodify( int argc, char **argv ) ...@@ -282,107 +282,85 @@ slapmodify( int argc, char **argv )
e = e_tmp; e = e_tmp;
} }
for ( n = 0; lr.lrop_mods[ n ] != NULL; n++ ) { if ( lr.lrop_mods ) {
LDAPMod *mod = lr.lrop_mods[ n ]; for ( n = 0; lr.lrop_mods && lr.lrop_mods[ n ] != NULL; n++ ) {
Modification mods = { 0 }; LDAPMod *mod = lr.lrop_mods[ n ];
unsigned i = 0; Modification mods = { 0 };
int bin = (mod->mod_op & LDAP_MOD_BVALUES); unsigned i = 0;
int pretty = 0; int bin = (mod->mod_op & LDAP_MOD_BVALUES);
int normalize = 0; int pretty = 0;
int normalize = 0;
local_rc = slap_str2ad( mod->mod_type, &mods.sm_desc, &text );
if ( local_rc != LDAP_SUCCESS ) { local_rc = slap_str2ad( mod->mod_type, &mods.sm_desc, &text );
fprintf( stderr, "%s: slap_str2ad(\"%s\") failed for entry \"%s\" (%d: %s, lineno=%lu)\n", if ( local_rc != LDAP_SUCCESS ) {
progname, mod->mod_type, lr.lr_dn.bv_val, local_rc, text, lineno ); fprintf( stderr, "%s: slap_str2ad(\"%s\") failed for entry \"%s\" (%d: %s, lineno=%lu)\n",
rc = EXIT_FAILURE; progname, mod->mod_type, lr.lr_dn.bv_val, local_rc, text, lineno );
mod_err = 1; rc = EXIT_FAILURE;
if( continuemode ) continue; mod_err = 1;
SLAP_FREE( ndn.bv_val ); if( continuemode ) continue;
ldap_ldif_record_done( &lr ); SLAP_FREE( ndn.bv_val );
entry_free( e ); ldap_ldif_record_done( &lr );
goto done; entry_free( e );
} goto done;
}
mods.sm_type = mods.sm_desc->ad_cname;
if ( mods.sm_desc->ad_type->sat_syntax->ssyn_pretty ) { mods.sm_type = mods.sm_desc->ad_cname;
pretty = 1;
} else { if ( mods.sm_desc->ad_type->sat_syntax->ssyn_pretty ) {
assert( mods.sm_desc->ad_type->sat_syntax->ssyn_validate != NULL ); pretty = 1;
}
if ( mods.sm_desc->ad_type->sat_equality && } else {
mods.sm_desc->ad_type->sat_equality->smr_normalize ) assert( mods.sm_desc->ad_type->sat_syntax->ssyn_validate != NULL );
{ }
normalize = 1;
}
if ( bin && mod->mod_bvalues ) {
for ( i = 0; mod->mod_bvalues[ i ] != NULL; i++ )
;
} else if ( !bin && mod->mod_values ) { if ( mods.sm_desc->ad_type->sat_equality &&
for ( i = 0; mod->mod_values[ i ] != NULL; i++ ) mods.sm_desc->ad_type->sat_equality->smr_normalize )
; {
} normalize = 1;
}
mods.sm_values = SLAP_CALLOC( sizeof( struct berval ), i + 1 ); if ( bin && mod->mod_bvalues ) {
if ( normalize ) { for ( i = 0; mod->mod_bvalues[ i ] != NULL; i++ )
mods.sm_nvalues = SLAP_CALLOC( sizeof( struct berval ), i + 1 ); ;
} else {
mods.sm_nvalues = NULL;
}
mods.sm_numvals = i;
for ( i = 0; i < mods.sm_numvals; i++ ) { } else if ( !bin && mod->mod_values ) {
struct berval bv; for ( i = 0; mod->mod_values[ i ] != NULL; i++ )
;
}
if ( bin ) { if ( i != 0 )
bv = *mod->mod_bvalues[ i ]; {
} else { mods.sm_values = SLAP_CALLOC( sizeof( struct berval ), i + 1 );
ber_str2bv( mod->mod_values[ i ], 0, 0, &bv ); if ( normalize ) {
mods.sm_nvalues = SLAP_CALLOC( sizeof( struct berval ), i + 1 );
} else {
mods.sm_nvalues = NULL;
}
} }
mods.sm_numvals = i;
if ( pretty ) { for ( i = 0; i < mods.sm_numvals; i++ ) {
local_rc = ordered_value_pretty( mods.sm_desc, struct berval bv;
&bv, &mods.sm_values[i], NULL );
} else { if ( bin ) {
local_rc = ordered_value_validate( mods.sm_desc, bv = *mod->mod_bvalues[ i ];
&bv, 0 ); } else {
} ber_str2bv( mod->mod_values[ i ], 0, 0, &bv );
}
if ( local_rc != LDAP_SUCCESS ) { if ( pretty ) {
fprintf( stderr, "%s: DN=\"%s\": unable to %s attr=%s value #%d\n", local_rc = ordered_value_pretty( mods.sm_desc,
progname, e->e_dn, pretty ? "prettify" : "validate", &bv, &mods.sm_values[i], NULL );
mods.sm_desc->ad_cname.bv_val, i );
/* handle error */
mod_err = 1;
rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
goto done;
}
if ( !pretty ) { } else {
ber_dupbv( &mods.sm_values[i], &bv ); local_rc = ordered_value_validate( mods.sm_desc,
} &bv, 0 );
}
if ( normalize ) {
local_rc = ordered_value_normalize(
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
mods.sm_desc,
mods.sm_desc->ad_type->sat_equality,
&mods.sm_values[i], &mods.sm_nvalues[i],
NULL );
if ( local_rc != LDAP_SUCCESS ) { if ( local_rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: DN=\"%s\": unable to normalize attr=%s value #%d\n", fprintf( stderr, "%s: DN=\"%s\": unable to %s attr=%s value #%d\n",
progname, e->e_dn, mods.sm_desc->ad_cname.bv_val, i ); progname, e->e_dn, pretty ? "prettify" : "validate",
mods.sm_desc->ad_cname.bv_val, i );
/* handle error */ /* handle error */
mod_err = 1; mod_err = 1;
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
...@@ -394,62 +372,89 @@ slapmodify( int argc, char **argv ) ...@@ -394,62 +372,89 @@ slapmodify( int argc, char **argv )
entry_free( e ); entry_free( e );
goto done; goto done;
} }
}
}
mods.sm_op = (mod->mod_op & ~LDAP_MOD_BVALUES); if ( !pretty ) {
mods.sm_flags = 0; ber_dupbv( &mods.sm_values[i], &bv );
}
if ( mods.sm_desc == slap_schema.si_ad_objectClass ) { if ( normalize ) {
is_oc = 1; local_rc = ordered_value_normalize(
} SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
mods.sm_desc,
mods.sm_desc->ad_type->sat_equality,
&mods.sm_values[i], &mods.sm_nvalues[i],
NULL );
if ( local_rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: DN=\"%s\": unable to normalize attr=%s value #%d\n",
progname, e->e_dn, mods.sm_desc->ad_cname.bv_val, i );
/* handle error */
mod_err = 1;
rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
goto done;
}
}
}
switch ( mods.sm_op ) { mods.sm_op = (mod->mod_op & ~LDAP_MOD_BVALUES);
case LDAP_MOD_ADD: mods.sm_flags = 0;
local_rc = modify_add_values( e, &mods,
0, &text, textbuf, textlen );
break;
case LDAP_MOD_DELETE: if ( mods.sm_desc == slap_schema.si_ad_objectClass ) {
local_rc = modify_delete_values( e, &mods, is_oc = 1;
0, &text, textbuf, textlen ); }
break;
case LDAP_MOD_REPLACE: switch ( mods.sm_op ) {
local_rc = modify_replace_values( e, &mods, case LDAP_MOD_ADD:
0, &text, textbuf, textlen ); local_rc = modify_add_values( e, &mods,
break; 0, &text, textbuf, textlen );
break;
case LDAP_MOD_DELETE:
local_rc = modify_delete_values( e, &mods,
0, &text, textbuf, textlen );
break;
case LDAP_MOD_REPLACE:
local_rc = modify_replace_values( e, &mods,
0, &text, textbuf, textlen );
break;
case LDAP_MOD_INCREMENT:
local_rc = modify_increment_values( e, &mods,
0, &text, textbuf, textlen );
break;
}
case LDAP_MOD_INCREMENT: if ( local_rc != LDAP_SUCCESS ) {
local_rc = modify_increment_values( e, &mods, fprintf( stderr, "%s: DN=\"%s\": unable to modify attr=%s\n",
0, &text, textbuf, textlen ); progname, e->e_dn, mods.sm_desc->ad_cname.bv_val );
break; rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
goto done;
}
} }
if ( local_rc != LDAP_SUCCESS ) { rc = slap_tool_entry_check( progname, op, e, lineno, &text, textbuf, textlen );
fprintf( stderr, "%s: DN=\"%s\": unable to modify attr=%s\n", if ( rc != LDAP_SUCCESS ) {
progname, e->e_dn, mods.sm_desc->ad_cname.bv_val );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue;
SLAP_FREE( ndn.bv_val ); SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr ); ldap_ldif_record_done( &lr );
if( continuemode ) continue;
entry_free( e ); entry_free( e );
goto done; break;
} }
} }
rc = slap_tool_entry_check( progname, op, e, lineno, &text, textbuf, textlen );
if ( rc != LDAP_SUCCESS ) {
rc = EXIT_FAILURE;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
if( continuemode ) continue;
entry_free( e );
break;
}
if ( SLAP_LASTMOD(be) ) { if ( SLAP_LASTMOD(be) ) {
time_t now = slap_get_time(); time_t now = slap_get_time();
char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ]; char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment