aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Townsend <christopher.townsend@canonical.com>2018-09-05 10:51:38 -0500
committerAndreas Schneider <asn@cryptomilk.org>2018-09-20 16:35:13 +0200
commit6c56c1e0d72670da274f3e77c51a7b4e078d59c6 (patch)
tree5b345b383fac177e07d5a383ca90fddd6c90ce43
parente4711c469f1247c26e069d9d25f1669cb051bd27 (diff)
downloadlibssh-6c56c1e0d72670da274f3e77c51a7b4e078d59c6.tar.gz
libssh-6c56c1e0d72670da274f3e77c51a7b4e078d59c6.tar.xz
libssh-6c56c1e0d72670da274f3e77c51a7b4e078d59c6.zip
sftpserver: Support some openssh extensions
Add support for "hardlink@openssh.com" and "posix-rename@openssh.com" extensions. Signed-off-by: Chris Townsend <christopher.townsend@canonical.com> Signed-off-by: Alberto Aguirre <albaguirre@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--include/libssh/sftp.h3
-rw-r--r--src/sftp.c9
-rw-r--r--src/sftpserver.c28
3 files changed, 39 insertions, 1 deletions
diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
index eeb4e615..b18bdc48 100644
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -135,6 +135,7 @@ struct sftp_client_message_struct {
ssh_string data; /* can be newpath of rename() */
ssh_buffer complete_message; /* complete message in case of retransmission*/
char *str_data; /* cstring version of data */
+ char *submessage; /* for extended messages */
};
struct sftp_request_queue_struct {
@@ -863,6 +864,7 @@ LIBSSH_API const char *sftp_client_message_get_filename(sftp_client_message msg)
LIBSSH_API void sftp_client_message_set_filename(sftp_client_message msg, const char *newname);
LIBSSH_API const char *sftp_client_message_get_data(sftp_client_message msg);
LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
+LIBSSH_API const char *sftp_client_message_get_submessage(sftp_client_message msg);
LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
LIBSSH_API int sftp_reply_name(sftp_client_message msg, const char *name,
sftp_attributes attr);
@@ -1012,6 +1014,7 @@ LIBSSH_API void sftp_handle_remove(sftp_session sftp, void *handle);
#define SFTP_RENAME SSH_FXP_RENAME
#define SFTP_READLINK SSH_FXP_READLINK
#define SFTP_SYMLINK SSH_FXP_SYMLINK
+#define SFTP_EXTENDED SSH_FXP_EXTENDED
/* openssh flags */
#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
diff --git a/src/sftp.c b/src/sftp.c
index 6fc08f61..9a98d444 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -222,6 +222,7 @@ int sftp_server_init(sftp_session sftp){
sftp_packet packet = NULL;
ssh_buffer reply = NULL;
uint32_t version;
+ int rc;
packet = sftp_packet_read(sftp);
if (packet == NULL) {
@@ -249,7 +250,13 @@ int sftp_server_init(sftp_session sftp){
return -1;
}
- if (ssh_buffer_add_u32(reply, ntohl(LIBSFTP_VERSION)) < 0) {
+ rc = ssh_buffer_pack(reply, "dssss",
+ LIBSFTP_VERSION,
+ "posix-rename@openssh.com",
+ "1",
+ "hardlink@openssh.com",
+ "1");
+ if (rc != SSH_OK) {
ssh_set_error_oom(session);
ssh_buffer_free(reply);
return -1;
diff --git a/src/sftpserver.c b/src/sftpserver.c
index 68fdb3d2..3cb30090 100644
--- a/src/sftpserver.c
+++ b/src/sftpserver.c
@@ -202,6 +202,29 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
return NULL;
}
break;
+ case SSH_FXP_EXTENDED:
+ rc = ssh_buffer_unpack(payload,
+ "s",
+ &msg->submessage);
+ if (rc != SSH_OK) {
+ ssh_set_error_oom(session);
+ sftp_client_message_free(msg);
+ return NULL;
+ }
+
+ if (strcmp(msg->submessage, "hardlink@openssh.com") == 0 ||
+ strcmp(msg->submessage, "posix-rename@openssh.com") == 0) {
+ rc = ssh_buffer_unpack(payload,
+ "sS",
+ &msg->filename,
+ &msg->data);
+ if (rc != SSH_OK) {
+ ssh_set_error_oom(session);
+ sftp_client_message_free(msg);
+ return NULL;
+ }
+ }
+ break;
default:
ssh_set_error(sftp->session, SSH_FATAL,
"Received unhandled sftp message %d", msg->type);
@@ -242,12 +265,17 @@ uint32_t sftp_client_message_get_flags(sftp_client_message msg){
return msg->flags;
}
+const char *sftp_client_message_get_submessage(sftp_client_message msg){
+ return msg->submessage;
+}
+
void sftp_client_message_free(sftp_client_message msg) {
if (msg == NULL) {
return;
}
SAFE_FREE(msg->filename);
+ SAFE_FREE(msg->submessage);
ssh_string_free(msg->data);
ssh_string_free(msg->handle);
sftp_attributes_free(msg->attr);