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

ITS#7256 Consolidate cleanup code at one location.

parent 07c563b8
...@@ -135,7 +135,7 @@ slapmodify( int argc, char **argv ) ...@@ -135,7 +135,7 @@ slapmodify( int argc, char **argv )
Entry *e_orig = NULL, *e = NULL; Entry *e_orig = NULL, *e = NULL;
struct berval rbuf; struct berval rbuf;
LDIFRecord lr; LDIFRecord lr;
struct berval ndn; struct berval ndn = BER_BVNULL;
int n; int n;
int is_oc = 0; int is_oc = 0;
int local_rc; int local_rc;
...@@ -191,12 +191,11 @@ slapmodify( int argc, char **argv ) ...@@ -191,12 +191,11 @@ slapmodify( int argc, char **argv )
fprintf( stderr, "%s: request 0x%lx not supported (line=%lu)\n", fprintf( stderr, "%s: request 0x%lx not supported (line=%lu)\n",
progname, (unsigned long)lr.lr_op, lineno ); progname, (unsigned long)lr.lr_op, lineno );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
if( continuemode ) continue; goto cleanup;
goto done;
default: default:
/* record skipped e.g. version: or comment or something we don't handle yet */ /* record skipped e.g. version: or comment or something we don't handle yet */
continue; goto cleanup;
} }
local_rc = dnNormalize( 0, NULL, NULL, &lr.lr_dn, &ndn, NULL ); local_rc = dnNormalize( 0, NULL, NULL, &lr.lr_dn, &ndn, NULL );
...@@ -204,8 +203,7 @@ slapmodify( int argc, char **argv ) ...@@ -204,8 +203,7 @@ slapmodify( int argc, char **argv )
fprintf( stderr, "%s: DN=\"%s\" normalization failed (line=%lu)\n", fprintf( stderr, "%s: DN=\"%s\" normalization failed (line=%lu)\n",
progname, lr.lr_dn.bv_val, lineno ); progname, lr.lr_dn.bv_val, lineno );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
if( continuemode ) continue; goto cleanup;
break;
} }
/* make sure the DN is not empty */ /* make sure the DN is not empty */
...@@ -233,10 +231,7 @@ slapmodify( int argc, char **argv ) ...@@ -233,10 +231,7 @@ slapmodify( int argc, char **argv )
} }
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
SLAP_FREE( ndn.bv_val ); goto cleanup;
ldap_ldif_record_done( &lr );
if( continuemode ) continue;
break;
} }
/* check backend */ /* check backend */
...@@ -267,10 +262,7 @@ slapmodify( int argc, char **argv ) ...@@ -267,10 +262,7 @@ slapmodify( int argc, char **argv )
} }
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
SLAP_FREE( ndn.bv_val ); goto cleanup;
ldap_ldif_record_done( &lr );
if( continuemode ) continue;
break;
} }
/* get id and/or entry */ /* get id and/or entry */
...@@ -297,9 +289,7 @@ slapmodify( int argc, char **argv ) ...@@ -297,9 +289,7 @@ slapmodify( int argc, char **argv )
fprintf( stderr, "%s: no such entry \"%s\" in database (lineno=%d)\n", fprintf( stderr, "%s: no such entry \"%s\" in database (lineno=%d)\n",
progname, ndn.bv_val, lineno ); progname, ndn.bv_val, lineno );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
SLAP_FREE( ndn.bv_val ); goto cleanup;
if( continuemode ) continue;
goto done;
} }
if ( lr.lrop_mods ) { if ( lr.lrop_mods ) {
...@@ -316,13 +306,7 @@ slapmodify( int argc, char **argv ) ...@@ -316,13 +306,7 @@ slapmodify( int argc, char **argv )
fprintf( stderr, "%s: slap_str2ad(\"%s\") failed for entry \"%s\" (%d: %s, lineno=%lu)\n", fprintf( stderr, "%s: slap_str2ad(\"%s\") failed for entry \"%s\" (%d: %s, lineno=%lu)\n",
progname, mod->mod_type, lr.lr_dn.bv_val, local_rc, text, lineno ); progname, mod->mod_type, lr.lr_dn.bv_val, local_rc, text, lineno );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
mod_err = 1; goto cleanup;
if( continuemode ) continue;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
be_entry_release_w( op, e_orig );
goto done;
} }
mods.sm_type = mods.sm_desc->ad_cname; mods.sm_type = mods.sm_desc->ad_cname;
...@@ -383,16 +367,10 @@ slapmodify( int argc, char **argv ) ...@@ -383,16 +367,10 @@ slapmodify( int argc, char **argv )
progname, e->e_dn, pretty ? "prettify" : "validate", progname, e->e_dn, pretty ? "prettify" : "validate",
mods.sm_desc->ad_cname.bv_val, i ); mods.sm_desc->ad_cname.bv_val, i );
/* handle error */ /* handle error */
mod_err = 1;
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values ); ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues ); ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue; goto cleanup;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
be_entry_release_w( op, e_orig );
goto done;
} }
if ( !pretty ) { if ( !pretty ) {
...@@ -410,16 +388,10 @@ slapmodify( int argc, char **argv ) ...@@ -410,16 +388,10 @@ slapmodify( int argc, char **argv )
fprintf( stderr, "%s: DN=\"%s\": unable to normalize attr=%s value #%d\n", 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 ); progname, e->e_dn, mods.sm_desc->ad_cname.bv_val, i );
/* handle error */ /* handle error */
mod_err = 1;
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values ); ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues ); ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue; goto cleanup;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
be_entry_release_w( op, e_orig );
goto done;
} }
} }
} }
...@@ -459,23 +431,14 @@ slapmodify( int argc, char **argv ) ...@@ -459,23 +431,14 @@ slapmodify( int argc, char **argv )
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
ber_bvarray_free( mods.sm_values ); ber_bvarray_free( mods.sm_values );
ber_bvarray_free( mods.sm_nvalues ); ber_bvarray_free( mods.sm_nvalues );
if( continuemode ) continue; goto cleanup;
SLAP_FREE( ndn.bv_val );
ldap_ldif_record_done( &lr );
entry_free( e );
be_entry_release_w( op, e_orig );
goto done;
} }
} }
rc = slap_tool_entry_check( progname, op, e, lineno, &text, textbuf, textlen ); rc = slap_tool_entry_check( progname, op, e, lineno, &text, textbuf, textlen );
if ( rc != LDAP_SUCCESS ) { if ( rc != LDAP_SUCCESS ) {
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
SLAP_FREE( ndn.bv_val ); goto cleanup;
ldap_ldif_record_done( &lr );
if( continuemode ) continue;
entry_free( e );
break;
} }
} }
...@@ -580,8 +543,6 @@ slapmodify( int argc, char **argv ) ...@@ -580,8 +543,6 @@ slapmodify( int argc, char **argv )
} }
} }
if ( mod_err ) break;
/* check schema, objectClass etc */ /* check schema, objectClass etc */
if ( !dryrun ) { if ( !dryrun ) {
...@@ -608,9 +569,7 @@ slapmodify( int argc, char **argv ) ...@@ -608,9 +569,7 @@ slapmodify( int argc, char **argv )
"(line=%lu): %s\n", progname, request, e->e_dn, "(line=%lu): %s\n", progname, request, e->e_dn,
lineno, bvtext.bv_val ); lineno, bvtext.bv_val );
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
entry_free( e ); goto cleanup;
if( continuemode ) continue;
break;
} }
sid = slap_tool_update_ctxcsn_check( progname, e ); sid = slap_tool_update_ctxcsn_check( progname, e );
...@@ -624,13 +583,14 @@ slapmodify( int argc, char **argv ) ...@@ -624,13 +583,14 @@ slapmodify( int argc, char **argv )
request, e->e_dn ); request, e->e_dn );
} }
cleanup:;
ldap_ldif_record_done( &lr ); ldap_ldif_record_done( &lr );
SLAP_FREE( ndn.bv_val );
if ( e ) entry_free( e ); if ( e ) entry_free( e );
if ( e_orig ) be_entry_release_w( op, e_orig ); if ( e_orig ) be_entry_release_w( op, e_orig );
if ( rc != LDAP_SUCCESS && !continuemode ) break; if ( rc != LDAP_SUCCESS && !continuemode ) break;
} }
done:;
if ( ldifrc < 0 ) if ( ldifrc < 0 )
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
......
Supports Markdown
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