libssh port: required modifications for sftp

This patch allows to replace sftp packet read and write with
completely asynchronous versions needed to properly hook in existing
ssh_terminal implementation.

Issue #4258
This commit is contained in:
Tomasz Gajewski 2021-05-27 00:45:18 +02:00 committed by Norman Feske
parent e34d1550a4
commit f327a40bbb
4 changed files with 80 additions and 2 deletions

View File

@ -130,6 +130,7 @@ ssh_buffer_pass_bytes_end T
ssh_buffer_prepend_data T
ssh_buffer_reinit T
ssh_buffer_set_secure T
ssh_buffer_swap T
ssh_buffer_unpack_va T
ssh_buffer_validate_length T
ssh_channel_accept_forward T

View File

@ -1 +1 @@
a475cccf96aa9126ed5fd135f108996c02f448e8
41048c9e30b72f70e68fad3806ce1a756178e713

View File

@ -9,5 +9,5 @@ DIR(libssh) := src/lib/libssh
DIRS := include
DIR_CONTENT(include) := src/lib/libssh/include/libssh
PATCHES := src/lib/libssh/event_bind.patch
PATCHES := src/lib/libssh/event_bind.patch src/lib/libssh/sftp_support.patch
PATCH_OPT := -p1 -d src/lib/libssh

View File

@ -0,0 +1,77 @@
--- a/include/libssh/buffer.h
+++ b/include/libssh/buffer.h
@@ -74,4 +74,8 @@
uint32_t ssh_buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
uint32_t ssh_buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
+/* ssh_buffer_swap replaces contents of two buffers */
+void ssh_buffer_swap(struct ssh_buffer_struct *buffer1,
+ struct ssh_buffer_struct *buffer2);
+
#endif /* BUFFER_H_ */
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -73,6 +73,10 @@
typedef struct sftp_status_message_struct* sftp_status_message;
typedef struct sftp_statvfs_struct* sftp_statvfs_t;
+typedef int (*sftp_packet_write_override)(sftp_session sftp, uint8_t type,
+ ssh_buffer payload, void *userdata);
+typedef sftp_packet (*sftp_packet_read_override)(sftp_session sftp, void *userdata);
+
struct sftp_session_struct {
ssh_session session;
ssh_channel channel;
@@ -85,6 +89,10 @@
void **handles;
sftp_ext ext;
sftp_packet read_packet;
+
+ void *userdata;
+ sftp_packet_write_override sftp_packet_write_function;
+ sftp_packet_read_override sftp_packet_read_function;
};
struct sftp_packet_struct {
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1332,4 +1332,14 @@
return rc;
}
+
+void ssh_buffer_swap(struct ssh_buffer_struct *buffer1,
+ struct ssh_buffer_struct *buffer2)
+{
+ struct ssh_buffer_struct tmp;
+ tmp = *buffer2;
+ *buffer2 = *buffer1;
+ *buffer1 = tmp;
+}
+
/** @} */
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -344,6 +344,11 @@
return -1;
}
+ /* override for packet write (payload already prepared) */
+ if (sftp->sftp_packet_write_function) {
+ return (*(sftp->sftp_packet_write_function))(sftp, type, payload, sftp->userdata);
+ }
+
size = ssh_channel_write(sftp->channel, ssh_buffer_get(payload),
ssh_buffer_get_len(payload));
if (size < 0) {
@@ -360,6 +365,10 @@
sftp_packet sftp_packet_read(sftp_session sftp)
{
+ if (sftp->sftp_packet_read_function) {
+ return (*(sftp->sftp_packet_read_function))(sftp, sftp->userdata);
+ }
+
uint8_t buffer[SFTP_BUFFER_SIZE_MAX];
sftp_packet packet = sftp->read_packet;
uint32_t size;