diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-08-30 09:26:32 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-08-30 09:26:32 +0200 |
commit | 8edf3bcfc07914d465cc462b28bb5f8b07a3ec5b (patch) | |
tree | 2f8b35ac29dbc92ecf95c7d449e645d7e6e5422f | |
parent | b8f09498388d4d167ec0add5ec27c3c75551a940 (diff) | |
download | cssh-8edf3bcfc07914d465cc462b28bb5f8b07a3ec5b.tar.gz cssh-8edf3bcfc07914d465cc462b28bb5f8b07a3ec5b.tar.bz2 |
some error handling fixing and introducing a scp read state
-rw-r--r-- | src/cssh.c | 204 |
1 files changed, 119 insertions, 85 deletions
@@ -18,6 +18,55 @@ #define BUFSIZE 4096 +typedef enum auth_state_e { + CSSH_AUTH_INIT, + CSSH_AUTH_VERIFY_HOST_DONE, + CSSH_AUTH_NONE_DONE, + CSSH_AUTH_BANNER_DONE, + CSSH_AUTH_PUBKEY_DONE_SUCCESS, + CSSH_AUTH_PUBKEY_DONE_FAILED, + CSSH_AUTH_PASSWORD_DONE_SUCCESS, + CSSH_AUTH_PASSWORD_DONE_FAILED, + CSSH_AUTH_DONE_SUCCESS, + CSSH_AUTH_DONE_FAILED +} auth_state_e; + +typedef enum execution_mode_e { + CSSH_EXECUTE_UNKNOWN, + CSSH_EXECUTE_AS_SSH, + CSSH_EXECUTE_AS_SCP +} execution_mode_e; + +typedef enum copy_direction_e { + CSSH_COPY_DIRECTION_UPLOAD, + CSSH_COPY_DIRECTION_DOWNLOAD +} copy_direction_e; + +typedef enum scp_read_state_e { + CSSH_SCP_READ_STATE_IDLE, + CSSH_SCP_READ_STATE_READING, + CSSH_SCP_READ_STATE_EOF +} scp_read_state_e; + +static execution_mode_e determine_execution_mode( const char *argv0 ) +{ + char *b = ssh_basename( argv0 ); + if( b == NULL ) { + return CSSH_EXECUTE_UNKNOWN; + } + + if( strcmp( b, "cssh" ) == 0 ) { + free( b ); + return CSSH_EXECUTE_AS_SSH; + } else if( strcmp( b, "cscp" ) == 0 ) { + free( b ); + return CSSH_EXECUTE_AS_SCP; + } + + free( b ); + return CSSH_EXECUTE_UNKNOWN; +} + static int parse_options_and_arguments( int argc, char *argv[], struct gengetopt_args_info *args_info ) { cmdline_parser_init( args_info ); @@ -278,7 +327,7 @@ static int read_hosts_file( const char *hosts_file, unsigned short default_port, return 0; } -static void cleanup_sessions( ssh_session **session, ssh_channel **channel, ssh_scp **scp, char ***buf, char **host, unsigned short *port, const int nof_sessions, bool verbose ) +static void cleanup_sessions( ssh_session **session, ssh_channel **channel, ssh_scp **scp, scp_read_state_e **read_state, char ***buf, char **host, unsigned short *port, const int nof_sessions, bool verbose ) { for( unsigned int i = 0; i < nof_sessions; i++ ) { if( ssh_is_connected( (*session)[i] ) ) { @@ -312,6 +361,9 @@ static void cleanup_sessions( ssh_session **session, ssh_channel **channel, ssh_ if( scp != NULL ) { free( *scp ); } + if( read_state != NULL ) { + free( *read_state ); + } if( buf != NULL ) { free( *buf ); } @@ -320,36 +372,6 @@ static void cleanup_sessions( ssh_session **session, ssh_channel **channel, ssh_ free( port ); } -typedef enum execution_mode_e { - CSSH_EXECUTE_UNKNOWN, - CSSH_EXECUTE_AS_SSH, - CSSH_EXECUTE_AS_SCP -} execution_mode_e; - -typedef enum copy_direction_e { - CSSH_COPY_DIRECTION_UPLOAD, - CSSH_COPY_DIRECTION_DOWNLOAD -} copy_direction_e; - -static execution_mode_e determine_execution_mode( const char *argv0 ) -{ - char *b = ssh_basename( argv0 ); - if( b == NULL ) { - return CSSH_EXECUTE_UNKNOWN; - } - - if( strcmp( b, "cssh" ) == 0 ) { - free( b ); - return CSSH_EXECUTE_AS_SSH; - } else if( strcmp( b, "cscp" ) == 0 ) { - free( b ); - return CSSH_EXECUTE_AS_SCP; - } - - free( b ); - return CSSH_EXECUTE_UNKNOWN; -} - int main( int argc, char *argv[] ) { struct gengetopt_args_info args_info; @@ -417,7 +439,7 @@ int main( int argc, char *argv[] ) session = (ssh_session *)malloc( nof_sessions * sizeof( ssh_session ) ); if( session == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for ssh_sessions" ); - return -1; + exit( EXIT_SUCCESS ); } for( unsigned int i = 0; i < nof_sessions; i++ ) { session[i] = ssh_new( ); @@ -451,7 +473,8 @@ int main( int argc, char *argv[] ) bool *is_connected = (bool *)malloc( ( nof_sessions + 1 ) * sizeof( bool ) ); if( is_connected == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for 'is_connected'" ); - return -1; + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_SUCCESS ); } memset( is_connected, false, ( nof_sessions + 1 ) * sizeof( bool ) ); while( !all_connected ) { @@ -469,7 +492,7 @@ int main( int argc, char *argv[] ) } else { fprintf( stderr, "ERROR: error connecting to '%s', port '%d': %s\n", host[i], port[i], ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -486,22 +509,11 @@ int main( int argc, char *argv[] ) } bool all_authenticated = false; - typedef enum auth_state_e { - CSSH_AUTH_INIT, - CSSH_AUTH_VERIFY_HOST_DONE, - CSSH_AUTH_NONE_DONE, - CSSH_AUTH_BANNER_DONE, - CSSH_AUTH_PUBKEY_DONE_SUCCESS, - CSSH_AUTH_PUBKEY_DONE_FAILED, - CSSH_AUTH_PASSWORD_DONE_SUCCESS, - CSSH_AUTH_PASSWORD_DONE_FAILED, - CSSH_AUTH_DONE_SUCCESS, - CSSH_AUTH_DONE_FAILED - } auth_state_e; auth_state_e *auth_state = (auth_state_e *)malloc( ( nof_sessions + 1 ) * sizeof( auth_state_e ) ); if( auth_state == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for 'auth_state'" ); - return -1; + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); } memset( auth_state, CSSH_AUTH_INIT, ( nof_sessions + 1 ) * sizeof( auth_state_e ) ); while( !all_authenticated ) { @@ -511,7 +523,7 @@ int main( int argc, char *argv[] ) if( verify_knownhost( session[i] ) < 0 ) { fprintf( stderr, "ERROR: closing connection to '%s', port '%d' due to security reasons\n", host[i], port[i] ); - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } auth_state[i] = CSSH_AUTH_VERIFY_HOST_DONE; @@ -532,7 +544,7 @@ int main( int argc, char *argv[] ) } else { fprintf( stderr, "ERROR: ssh_userauth_none to '%s', port '%d' failed: %s\n", host[i], port[i], ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } break; @@ -557,7 +569,7 @@ int main( int argc, char *argv[] ) } else if( rc == SSH_AUTH_DENIED ) { auth_state[i] = CSSH_AUTH_PUBKEY_DONE_FAILED; } else { - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } break; @@ -576,7 +588,7 @@ int main( int argc, char *argv[] ) } else if( rc == SSH_AUTH_DENIED ) { auth_state[i] = CSSH_AUTH_PASSWORD_DONE_FAILED; } else { - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } break; @@ -596,7 +608,7 @@ int main( int argc, char *argv[] ) case CSSH_AUTH_DONE_FAILED: // one authentication failed, bail out for now fprintf( stderr, "ERROR: authentication failed for one host ('%s'), aborting now", host[i] ); - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -619,7 +631,7 @@ int main( int argc, char *argv[] ) memset( channel, 0, nof_sessions + 1 ); if( channel == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for ssh_channels" ); - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } for( unsigned int i = 0; i < nof_sessions; i++ ) { @@ -627,7 +639,7 @@ int main( int argc, char *argv[] ) if( channel[i] == NULL ) { fprintf( stderr, "ERROR: Unable to open SSH channel: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -635,7 +647,7 @@ int main( int argc, char *argv[] ) for( unsigned int i = 0; i < nof_sessions; i++ ) { rc = ssh_channel_open_session( channel[i] ); if( rc != SSH_OK ) { - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -653,7 +665,7 @@ int main( int argc, char *argv[] ) } if( cmd[0] == '\0' ) { fprintf( stderr, "ERROR: Empty command, no interactive CLI supported currently\n" ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } @@ -663,7 +675,7 @@ int main( int argc, char *argv[] ) if( rc != SSH_OK ) { fprintf( stderr, "ERROR: Executing SSH command '%s' failed: %s\n", cmd, ssh_get_error( session[i] ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -672,13 +684,16 @@ int main( int argc, char *argv[] ) bool *eof_sent = (bool *)malloc( ( nof_sessions + 1 ) * sizeof( bool ) ); if( eof_sent == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for 'eof_sent'" ); - return -1; + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); } memset( eof_sent, false, ( nof_sessions + 1 ) * sizeof( bool ) ); bool *is_eof = (bool *)malloc( ( nof_sessions + 1 ) * sizeof( bool ) ); if( is_eof == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for 'is_eof'" ); - return -1; + free( eof_sent ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); } memset( is_eof, false, ( nof_sessions + 1 ) * sizeof( bool ) ); @@ -706,7 +721,9 @@ int main( int argc, char *argv[] ) if( rc == SSH_ERROR ) { fprintf( stderr, "ERROR: ssh_channel_poll on stdout failed: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } @@ -715,7 +732,9 @@ int main( int argc, char *argv[] ) if( nread == SSH_ERROR ) { fprintf( stderr, "ERROR: ssh_channel_read_nonblocking on stdout failed: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } @@ -728,14 +747,18 @@ int main( int argc, char *argv[] ) if( wrc < 0 ) { fprintf( stderr, "ERROR: while writing to stdout: %s\n", strerror( errno ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } if( wrc != nread ) { fprintf( stderr, "ERROR: Write mismatch on stdout (%zu != %d)\n", wrc, nread ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -745,7 +768,9 @@ int main( int argc, char *argv[] ) if( rc == SSH_ERROR ) { fprintf( stderr, "ERROR: ssh_channel_poll on stderr failed: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } @@ -754,7 +779,9 @@ int main( int argc, char *argv[] ) if( nread == SSH_ERROR ) { fprintf( stderr, "ERROR: ssh_channel_read_nonblocking on stderr failed: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } @@ -763,14 +790,18 @@ int main( int argc, char *argv[] ) if( wrc < 0 ) { fprintf( stderr, "ERROR: while writting to stderr: %s\n", strerror( errno ) ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } if( wrc != nread ) { fprintf( stderr, "ERROR: Write mismatch on stderr (%zu != %d)\n", wrc, nread ); - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -784,7 +815,9 @@ int main( int argc, char *argv[] ) cssh_msleep( 1 ); } - cleanup_sessions( &session, &channel, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + free( eof_sent ); + free( is_eof ); + cleanup_sessions( &session, &channel, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); } break; @@ -801,7 +834,7 @@ int main( int argc, char *argv[] ) memset( scp, 0, nof_sessions + 1 ); if( scp == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for ssh_scp" ); - cleanup_sessions( &session, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, NULL, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } for( unsigned int i = 0; i < nof_sessions; i++ ) { @@ -812,7 +845,7 @@ int main( int argc, char *argv[] ) if( scp[i] == NULL ) { fprintf( stderr, "ERROR: Unable to open SCP channel: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, &scp, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -822,7 +855,7 @@ int main( int argc, char *argv[] ) if( rc != SSH_OK ) { fprintf( stderr, "ERROR: Unable to initialize SCP sessions: %s\n", ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, &scp, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } @@ -830,7 +863,7 @@ int main( int argc, char *argv[] ) char **buf = (char **)malloc( ( nof_sessions + 1 ) * sizeof( char * ) ); if( buf == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for receiving buffers of ssh_scp" ); - cleanup_sessions( &session, NULL, &scp, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } memset( buf, 0, ( nof_sessions + 1 ) * sizeof( char * ) ); @@ -838,18 +871,19 @@ int main( int argc, char *argv[] ) buf[i] = (char *)malloc( BUFSIZE ); if( buf[i] == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for receiving buffers of ssh_scp" ); - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, NULL, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } bool all_eof = false; - bool *is_eof = (bool *)malloc( ( nof_sessions + 1 ) * sizeof( bool ) ); - if( is_eof == NULL ) { + scp_read_state_e *read_state = (scp_read_state_e *)malloc( ( nof_sessions + 1 ) * sizeof( scp_read_state_e ) ); + if( read_state == NULL ) { fprintf( stderr, "ERROR: Memory allocation failed for 'is_eof'" ); - return -1; + cleanup_sessions( &session, NULL, &scp, NULL, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + exit( EXIT_FAILURE ); } - memset( is_eof, false, ( nof_sessions + 1 ) * sizeof( bool ) ); + memset( read_state, CSSH_SCP_READ_STATE_IDLE, ( nof_sessions + 1 ) * sizeof( scp_read_state_e ) ); while( !all_eof ) { @@ -876,7 +910,7 @@ int main( int argc, char *argv[] ) if( rc != SSH_OK ) { fprintf( stderr, "ERROR: accepting request for directory '%s' failed: %s\n", filename, ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } } break; @@ -897,7 +931,7 @@ int main( int argc, char *argv[] ) if( rc != SSH_OK ) { fprintf( stderr, "ERROR: accepting request for file '%s' failed: %s\n", filename, ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } // TODO: we receive a buffer of data < 65k, so we must introduce a @@ -913,7 +947,7 @@ int main( int argc, char *argv[] ) if( rc == SSH_ERROR ) { fprintf( stderr, "ERROR: reading data for file '%s' failed: %s\n", filename, ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); } bytesReceived += rc; @@ -921,10 +955,10 @@ int main( int argc, char *argv[] ) } break; case SSH_SCP_REQUEST_EOF: - is_eof[i] = true; + read_state[i] = CSSH_SCP_READ_STATE_EOF; all_eof = true; for( unsigned int i = 0; i < nof_sessions; i++ ) { - if( !is_eof[i] ) { + if( read_state[i] != CSSH_SCP_READ_STATE_EOF ) { all_eof = false; break; } @@ -934,14 +968,14 @@ int main( int argc, char *argv[] ) case SSH_ERROR: fprintf( stderr, "ERROR: error from remote host '%s': %s\n", host[i], ssh_get_error( session[i] ) ); - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); break; case SSH_SCP_REQUEST_WARNING: fprintf( stderr, "WARNING: remote host '%s': %s\n", host[i], ssh_scp_request_get_warning( scp[i] ) ); - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); exit( EXIT_FAILURE ); break; } @@ -950,7 +984,7 @@ int main( int argc, char *argv[] ) } } - cleanup_sessions( &session, NULL, &scp, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); + cleanup_sessions( &session, NULL, &scp, &read_state, &buf, host, port, nof_sessions, args_info.verbose_given > 0 ); } break; |