Update '-c' error handling, so error in any operation returns error from main.

This commit is contained in:
Hallvard Furuseth 2002-12-09 11:02:28 +00:00
parent 56ebd53e51
commit a42908f2e7
2 changed files with 17 additions and 9 deletions

View File

@ -99,7 +99,8 @@ main( int argc, char **argv )
{ {
char buf[ 4096 ]; char buf[ 4096 ];
FILE *fp; FILE *fp;
int i, rc, authmethod, referrals, want_bindpw, version, debug, manageDSAit, noop, crit; int i, rc, retval, authmethod, referrals, want_bindpw;
int version, debug, manageDSAit, noop, crit;
char *pw_file; char *pw_file;
char *control, *cvalue; char *control, *cvalue;
char *authzid = NULL; char *authzid = NULL;
@ -770,14 +771,17 @@ main( int argc, char **argv )
} }
} }
rc = 0; retval = rc = 0;
if ( fp == NULL ) { if ( fp == NULL ) {
for ( ; optind < argc; ++optind ) { for ( ; optind < argc; ++optind ) {
rc = dodelete( ld, argv[ optind ] ); rc = dodelete( ld, argv[ optind ] );
/* Stop on error and no -c option */ /* Stop on error and no -c option */
if( rc != 0 && contoper == 0) break; if( rc != 0 ) {
retval = rc;
if( contoper == 0 ) break;
}
} }
} else { } else {
while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) { while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) {
@ -785,13 +789,15 @@ main( int argc, char **argv )
if ( *buf != '\0' ) { if ( *buf != '\0' ) {
rc = dodelete( ld, buf ); rc = dodelete( ld, buf );
if ( rc != 0 )
retval = rc;
} }
} }
} }
ldap_unbind( ld ); ldap_unbind( ld );
return( rc ); return( retval );
} }

View File

@ -112,7 +112,8 @@ main(int argc, char **argv)
{ {
char *infile, *entrydn = NULL, *rdn = NULL, buf[ 4096 ]; char *infile, *entrydn = NULL, *rdn = NULL, buf[ 4096 ];
FILE *fp; FILE *fp;
int rc, i, remove, havedn, authmethod, version, want_bindpw, debug, manageDSAit, noop, crit; int rc, retval, i, remove, havedn, authmethod, version;
int want_bindpw, debug, manageDSAit, noop, crit;
int referrals; int referrals;
char *newSuperior=NULL; char *newSuperior=NULL;
char *pw_file = NULL; char *pw_file = NULL;
@ -805,9 +806,9 @@ main(int argc, char **argv)
} }
} }
rc = 0; retval = rc = 0;
if (havedn) if (havedn)
rc = domodrdn( ld, entrydn, rdn, newSuperior, remove ); retval = domodrdn( ld, entrydn, rdn, newSuperior, remove );
else while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) { else while ((rc == 0 || contoper) && fgets(buf, sizeof(buf), fp) != NULL) {
if ( *buf != '\0' ) { /* blank lines optional, skip */ if ( *buf != '\0' ) { /* blank lines optional, skip */
buf[ strlen( buf ) - 1 ] = '\0'; /* remove nl */ buf[ strlen( buf ) - 1 ] = '\0'; /* remove nl */
@ -818,6 +819,8 @@ main(int argc, char **argv)
return( EXIT_FAILURE ); return( EXIT_FAILURE );
} }
rc = domodrdn(ld, entrydn, rdn, newSuperior, remove ); rc = domodrdn(ld, entrydn, rdn, newSuperior, remove );
if ( rc != 0 )
retval = rc;
havedn = 0; havedn = 0;
} else if ( !havedn ) { /* don't have DN yet */ } else if ( !havedn ) { /* don't have DN yet */
if (( entrydn = strdup( buf )) == NULL ) { if (( entrydn = strdup( buf )) == NULL ) {
@ -831,8 +834,7 @@ main(int argc, char **argv)
ldap_unbind( ld ); ldap_unbind( ld );
/* UNREACHABLE */ return( retval );
return( rc );
} }
static int domodrdn( static int domodrdn(