1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

sftp: Keep a ssh_packet for reading in the sftp handle

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Andreas Schneider
2018-09-03 14:24:40 +02:00
parent 945afaa6b4
commit 79a3fcac72
2 changed files with 30 additions and 15 deletions

View File

@@ -84,6 +84,7 @@ struct sftp_session_struct {
int errnum; int errnum;
void **handles; void **handles;
sftp_ext ext; sftp_ext ext;
sftp_packet read_packet;
}; };
struct sftp_packet_struct { struct sftp_packet_struct {

View File

@@ -109,36 +109,48 @@ sftp_session sftp_new(ssh_session session)
sftp->ext = sftp_ext_new(); sftp->ext = sftp_ext_new();
if (sftp->ext == NULL) { if (sftp->ext == NULL) {
ssh_set_error_oom(session); goto error;
SAFE_FREE(sftp); }
return NULL; sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
if (sftp->read_packet == NULL) {
goto error;
}
sftp->read_packet->payload = ssh_buffer_new();
if (sftp->read_packet->payload == NULL) {
goto error;
} }
sftp->session = session; sftp->session = session;
sftp->channel = ssh_channel_new(session); sftp->channel = ssh_channel_new(session);
if (sftp->channel == NULL) { if (sftp->channel == NULL) {
sftp_ext_free(sftp->ext); goto error;
SAFE_FREE(sftp);
return NULL;
} }
if (ssh_channel_open_session(sftp->channel)) { if (ssh_channel_open_session(sftp->channel)) {
ssh_channel_free(sftp->channel); goto error;
sftp_ext_free(sftp->ext);
SAFE_FREE(sftp);
return NULL;
} }
if (ssh_channel_request_sftp(sftp->channel)) { if (ssh_channel_request_sftp(sftp->channel)) {
sftp_free(sftp); goto error;
return NULL;
} }
return sftp; return sftp;
error:
ssh_set_error_oom(session);
if (sftp->ext != NULL) {
sftp_ext_free(sftp->ext);
}
if (sftp->channel != NULL) {
ssh_channel_free(sftp->channel);
}
if (sftp->read_packet->payload != NULL) {
ssh_buffer_free(sftp->read_packet->payload);
}
SAFE_FREE(sftp->read_packet);
SAFE_FREE(sftp);
return NULL;
} }
sftp_session sftp_new_channel(ssh_session session, ssh_channel channel){ sftp_session sftp_new_channel(ssh_session session, ssh_channel channel){
@@ -265,6 +277,8 @@ void sftp_free(sftp_session sftp)
ssh_channel_free(sftp->channel); ssh_channel_free(sftp->channel);
SAFE_FREE(sftp->handles); SAFE_FREE(sftp->handles);
SSH_BUFFER_FREE(sftp->read_packet->payload);
SAFE_FREE(sftp->read_packet);
sftp_ext_free(sftp->ext); sftp_ext_free(sftp->ext);