summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2021-11-20 15:17:40 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2021-11-20 15:17:40 +0100
commit5de0e1ed05faeb26ae8044661ce721b7766fd4fd (patch)
tree0654028bfe7d677e304ceeb517085d4455ac90d4
parentc258810b81a9ef4d93530f5c26a5512954a86220 (diff)
downloadcssh-5de0e1ed05faeb26ae8044661ce721b7766fd4fd.tar.gz
cssh-5de0e1ed05faeb26ae8044661ce721b7766fd4fd.tar.bz2
some small fixes
-rw-r--r--src/cssh.c132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/cssh.c b/src/cssh.c
index 3fe7218..a5e29fb 100644
--- a/src/cssh.c
+++ b/src/cssh.c
@@ -220,11 +220,11 @@ ASK_AGAIN:
return true;
}
-static unsigned short get_default_ssh_port( )
+static unsigned int get_default_ssh_port( )
{
struct servent *ent = getservbyname( "ssh", "tcp" );
if( ent != NULL ) {
- return (unsigned short)ntohs( ent->s_port );
+ return (unsigned int)ntohs( ent->s_port );
} else {
return DEFAULT_SSH_PORT;
}
@@ -407,7 +407,7 @@ static int authenticate_password( ssh_session session, const char *host, const u
return -1;
}
-static int read_hosts_file( const char *hosts_file, unsigned short default_port, char ***host, unsigned short **port, unsigned int *nof_hosts )
+static int read_hosts_file( const char *hosts_file, unsigned int default_port, char ***host, unsigned int **port, unsigned int *nof_hosts )
{
FILE *f;
char buf[255];
@@ -421,8 +421,8 @@ static int read_hosts_file( const char *hosts_file, unsigned short default_port,
*nof_hosts = 0;
unsigned int size_hosts = 2;
- *host = (char **)malloc( size_hosts * sizeof( char * ) );
- *port = (unsigned short *)malloc( size_hosts * sizeof( unsigned short ) );
+ *host = (char **)calloc( size_hosts, sizeof( char * ) );
+ *port = (unsigned int *)calloc( size_hosts, sizeof( unsigned int ) );
if( *host == NULL || *port == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed in 'read_hosts_file'\n" );
return -1;
@@ -452,7 +452,7 @@ static int read_hosts_file( const char *hosts_file, unsigned short default_port,
if( *nof_hosts >= size_hosts ) {
size_hosts *= 2;
*host = (char **)realloc( *host, size_hosts * sizeof( char *) );
- *port = (unsigned short *)realloc( *port, size_hosts * sizeof( unsigned short ) );
+ *port = (unsigned int *)realloc( *port, size_hosts * sizeof( unsigned int ) );
if( *host == NULL || *port == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed in 'read_hosts_file'\n" );
return -1;
@@ -466,7 +466,7 @@ static int read_hosts_file( const char *hosts_file, unsigned short default_port,
}
// TODO: cleanup also progressbarpool
-static void cleanup_sessions( ssh_session **session, ssh_data_t **ssh_data, scp_data_t **scp_data, char **host, unsigned short *port, const int nof_sessions, bool verbose )
+static void finalize( ssh_session **session, ssh_data_t **ssh_data, scp_data_t **scp_data, char **host, unsigned int *port, const int nof_sessions, bool verbose )
{
for( unsigned int i = 0; i < nof_sessions; i++ ) {
if( ssh_is_connected( (*session)[i] ) ) {
@@ -533,6 +533,8 @@ static void cleanup_sessions( ssh_session **session, ssh_data_t **ssh_data, scp_
free( *session );
free( *host );
free( port );
+
+ ssh_finalize( );
}
static const char *buffer_contains_a_line( const char *buffer, size_t bufsize )
@@ -624,7 +626,7 @@ int main( int argc, char *argv[] )
unsigned int nof_sessions = 0;
char **host = NULL;
- unsigned short *port = NULL;
+ unsigned int *port = NULL;
char *cmd = NULL;
copy_direction_e copy_direction = CSSH_COPY_DIRECTION_DOWNLOAD;
char *local_directory = NULL;
@@ -646,7 +648,7 @@ int main( int argc, char *argv[] )
default_port = args_info.port_arg;
}
host = (char **)malloc( sizeof( char * ) );
- port = (unsigned short *)malloc( sizeof( unsigned short ) );
+ port = (unsigned int *)malloc( sizeof( unsigned int ) );
if( args_info.inputs_num >= 1 ) {
command_pos++;
nof_sessions = 1;
@@ -699,7 +701,7 @@ int main( int argc, char *argv[] )
unsigned short default_port = get_default_ssh_port( );
host = (char **)malloc( sizeof( char * ) );
- port = (unsigned short *)malloc( sizeof( unsigned short ) );
+ port = (unsigned int *)malloc( sizeof( unsigned int ) );
if( args_info.port_given ) {
default_port = args_info.port_arg;
}
@@ -774,7 +776,7 @@ int main( int argc, char *argv[] )
// for the hosts in the file containing hosts
unsigned nof_hosts;
- unsigned short default_port = get_default_ssh_port( );
+ unsigned int default_port = get_default_ssh_port( );
if( args_info.port_given ) {
default_port = args_info.port_arg;
}
@@ -787,7 +789,7 @@ int main( int argc, char *argv[] )
// initialize session with host, port and user parameters read
- session = (ssh_session *)malloc( nof_sessions * sizeof( ssh_session ) );
+ session = (ssh_session *)calloc( nof_sessions, sizeof( ssh_session ) );
if( session == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for ssh_sessions\n" );
exit( EXIT_SUCCESS );
@@ -825,7 +827,7 @@ int main( int argc, char *argv[] )
connection_state_e *connection_state = (connection_state_e *)calloc( nof_sessions, sizeof( connection_state_e ) );
if( connection_state == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for 'connection_state'\n" );
- cleanup_sessions( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_SUCCESS );
}
unsigned int nof_connected = 0;
@@ -849,7 +851,7 @@ int main( int argc, char *argv[] )
if( args_info.ignore_connect_errors_given ) {
connection_state[i] = CSSH_CONNECTION_STATE_ERROR;
} else {
- cleanup_sessions( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -870,7 +872,7 @@ int main( int argc, char *argv[] )
auth_state_e *auth_state = (auth_state_e *)calloc( nof_sessions, sizeof( auth_state_e ) );
if( auth_state == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for 'auth_state'\n" );
- cleanup_sessions( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
unsigned int nof_authenticated = 0;
@@ -884,7 +886,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, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
auth_state[i] = CSSH_AUTH_VERIFY_HOST_DONE;
@@ -905,7 +907,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, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
break;
@@ -930,7 +932,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, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
break;
@@ -949,8 +951,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, host, &port, nof_sessions, args_info.verbose_given > 0 );
- ssh_finalize( );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
} else {
@@ -977,8 +978,7 @@ int main( int argc, char *argv[] )
if( args_info.ignore_authentication_errors_given ) {
connection_state[i] = CSSH_CONNECTION_STATE_ERROR;
} else {
- cleanup_sessions( &session, NULL, NULL, host, &port, nof_sessions, args_info.verbose_given > 0 );
- ssh_finalize( );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1047,7 +1047,7 @@ CLI_NEXT_CMD:
ssh_data_t *ssh_data = (ssh_data_t *)calloc( nof_sessions, sizeof( ssh_data_t ) );
if( ssh_data == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for ssh_data array\n" );
- cleanup_sessions( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1056,7 +1056,7 @@ CLI_NEXT_CMD:
if( ssh_data[i].channel == NULL ) {
fprintf( stderr, "ERROR: Unable to open SSH channel for host '%s': %s\n",
host[i], ssh_get_error( session[i] ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1064,7 +1064,7 @@ CLI_NEXT_CMD:
for( unsigned int i = 0; i < nof_sessions; i++ ) {
rc = ssh_channel_open_session( ssh_data[i].channel );
if( rc != SSH_OK ) {
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1075,7 +1075,7 @@ CLI_NEXT_CMD:
if( rc != SSH_OK ) {
fprintf( stderr, "ERROR: Executing SSH command '%s' failed: %s\n",
cmd, ssh_get_error( session[i] ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1088,13 +1088,13 @@ CLI_NEXT_CMD:
ssh_data[i].stdout_buf = (char *)malloc( BUFSIZE );
if( ssh_data[i].stdout_buf == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for receiving buffers of ssh_channels\n" );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
ssh_data[i].stderr_buf = (char *)malloc( BUFSIZE );
if( ssh_data[i].stderr_buf == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for receiving buffers of ssh_channels\n" );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
ssh_data[i].stdout_bptr = ssh_data[i].stdout_buf;
@@ -1126,7 +1126,7 @@ CLI_NEXT_CMD:
if( rc == SSH_ERROR ) {
fprintf( stderr, "ERROR: ssh_channel_poll on stdout failed: %s\n",
ssh_get_error( session[i] ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1135,7 +1135,7 @@ CLI_NEXT_CMD:
if( nread == SSH_ERROR ) {
fprintf( stderr, "ERROR: ssh_channel_read_nonblocking on stdout failed: %s\n",
ssh_get_error( session[i] ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1148,7 +1148,7 @@ CLI_NEXT_CMD:
if( wrc < 0 ) {
fprintf( stderr, "ERROR: while writing to stdout: %s\n",
strerror( errno ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
assert( wrc <= nread + ( ssh_data[i].stdout_bptr - ssh_data[i].stdout_buf ) );
@@ -1162,7 +1162,7 @@ CLI_NEXT_CMD:
if( rc == SSH_ERROR ) {
fprintf( stderr, "ERROR: ssh_channel_poll on stderr failed: %s\n",
ssh_get_error( session[i] ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1171,7 +1171,7 @@ CLI_NEXT_CMD:
if( nread == SSH_ERROR ) {
fprintf( stderr, "ERROR: ssh_channel_read_nonblocking on stderr failed: %s\n",
ssh_get_error( session[i] ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1180,7 +1180,7 @@ CLI_NEXT_CMD:
if( wrc < 0 ) {
fprintf( stderr, "ERROR: while writting to stderr: %s\n",
strerror( errno ) );
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
assert( wrc <= nread + ( ssh_data[i].stderr_bptr - ssh_data[i].stderr_buf ) );
@@ -1203,7 +1203,7 @@ CLI_NEXT_CMD:
}
SHELL_EOF:
- cleanup_sessions( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, &ssh_data, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
} break;
@@ -1212,7 +1212,7 @@ SHELL_EOF:
scp_data_t *scp_data = (scp_data_t *)calloc( nof_sessions, sizeof( scp_data_t ) );
if( scp_data == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for scp_data array\n" );
- cleanup_sessions( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, NULL, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
for( unsigned int i = 0; i < nof_sessions; i++ ) {
@@ -1227,7 +1227,7 @@ SHELL_EOF:
if( scp_data[i].scp == NULL ) {
fprintf( stderr, "ERROR: Unable to open SCP channel: %s\n",
ssh_get_error( session[i] ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1237,7 +1237,7 @@ SHELL_EOF:
if( rc != SSH_OK ) {
fprintf( stderr, "ERROR: Unable to initialize SCP sessions: %s\n",
ssh_get_error( session[i] ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1246,7 +1246,7 @@ SHELL_EOF:
scp_data[i].buf = (char *)malloc( BUFSIZE );
if( scp_data[i].buf == NULL ) {
fprintf( stderr, "ERROR: Memory allocation failed for receiving buffers of ssh_scp\n" );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1255,7 +1255,7 @@ SHELL_EOF:
rc = create_progressbar_pool( &progressbars, nof_sessions );
if( rc < 0 ) {
fprintf( stderr, "ERROR: Creation of a pool of progress bars failed\n" );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1268,7 +1268,7 @@ SHELL_EOF:
if( pwd == NULL ) {
fprintf( stderr, "ERROR: failed to determine working directory for SCP for host '%s': %s\n",
host[i], strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1277,7 +1277,7 @@ SHELL_EOF:
fprintf( stderr, "ERROR: failed to push current directory to stack for host '%s'\n",
host[i] );
free( pwd );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1288,7 +1288,7 @@ SHELL_EOF:
fprintf( stderr, "ERROR: Memory allocation failed for full path of base directory for host '%s'\n",
host[i] );
free( pwd );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
snprintf( full_path, len, "%s/%s", pwd, host[i] );
@@ -1299,7 +1299,7 @@ SHELL_EOF:
fprintf( stderr, "ERROR: failed remember initial base directory '%s' in directory stack\n",
pwd );
free( pwd );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
free( pwd );
@@ -1309,7 +1309,7 @@ SHELL_EOF:
if( errno != EEXIST ) {
fprintf( stderr, "ERROR: failed to create base directory '%s' for host '%s': %s\n",
full_path, host[i], strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1323,7 +1323,7 @@ SHELL_EOF:
switch( copy_direction ) {
case CSSH_COPY_DIRECTION_UPLOAD: {
fprintf( stderr, "ERROR: SCP upload has not been implemented yet.\n" );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
} break;
@@ -1340,7 +1340,7 @@ SHELL_EOF:
if( rc < 0 ) {
fprintf( stderr, "ERROR: failed to change to directory '%s': %s\n",
dir, strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1354,7 +1354,7 @@ SHELL_EOF:
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_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1362,14 +1362,14 @@ SHELL_EOF:
if( rc < 0 ) {
fprintf( stderr, "ERROR: failed to create directory '%s': %s\n",
filename, strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
char *pwd = getcwd( NULL, 0 );
if( pwd == NULL ) {
fprintf( stderr, "ERROR: failed to determine working directory for SCP for host '%s': %s\n",
host[i], strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
size_t len = strlen( pwd ) + 2 + strlen( filename );
@@ -1378,7 +1378,7 @@ SHELL_EOF:
fprintf( stderr, "ERROR: Memory allocation failed for full path of directory '%s'\n",
filename );
free( pwd );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
snprintf( full_path, len, "%s/%s", pwd, filename );
@@ -1389,7 +1389,7 @@ SHELL_EOF:
fprintf( stderr, "ERROR: failed remember directory '%s' in directory stack\n",
full_path );
free( full_path );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
free( full_path );
@@ -1411,7 +1411,7 @@ SHELL_EOF:
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_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1420,7 +1420,7 @@ SHELL_EOF:
if( rc < 0 ) {
fprintf( stderr, "ERROR: failed to change to directory '%s': %s\n",
dir, strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1430,7 +1430,7 @@ SHELL_EOF:
fprintf( stderr, "ERROR: Memory allocation failed for full path of directory '%s'\n",
filename );
free( dir );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
snprintf( full_path, len, "%s/%s", dir, filename );
@@ -1439,7 +1439,7 @@ SHELL_EOF:
if( fd < 0 ) {
fprintf( stderr, "ERROR: Unable to open file '%s': %s\n",
full_path, strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
@@ -1454,7 +1454,7 @@ SHELL_EOF:
if( rc < 0 ) {
fprintf( stderr, "ERROR: Unable to create progress bar for host '%s' and file '%s'\n",
host[i], full_path );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
rc = append_progressbar_to_pool( &progressbars, &scp_data[i].progressbar );
@@ -1475,14 +1475,14 @@ SHELL_EOF:
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_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, 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_data[i].scp ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
break;
}
@@ -1494,7 +1494,7 @@ SHELL_EOF:
if( rc == SSH_ERROR ) {
fprintf( stderr, "ERROR: reading data for file '%s' failed: %s\n",
scp_data[i].filename, ssh_get_error( session[i] ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
scp_data[i].bytesReceived += rc;
@@ -1503,7 +1503,7 @@ SHELL_EOF:
if( r < 0 ) {
fprintf( stderr, "ERROR: writing data to file '%s' failed: %s\n",
scp_data[i].filename, strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
}
@@ -1515,7 +1515,7 @@ SHELL_EOF:
if( rc < 0 ) {
fprintf( stderr, "ERROR: Unable to close file '%s': %s\n",
scp_data[i].filename, strerror( errno ) );
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
exit( EXIT_FAILURE );
}
scp_data[i].read_state = CSSH_SCP_READ_STATE_IDLE;
@@ -1538,7 +1538,7 @@ SHELL_EOF:
}
}
- cleanup_sessions( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
+ finalize( &session, NULL, &scp_data, host, port, nof_sessions, args_info.verbose_given > 0 );
} break;
@@ -1548,10 +1548,10 @@ SHELL_EOF:
// the end
- free( connection_state );
free( auth_state );
-
- cmdline_parser_free( &args_info );
+ free( connection_state );
+ cmdline_parser_free( &args_info );
+
exit( EXIT_SUCCESS );
}