mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
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>
This commit is contained in:
committed by
Andreas Schneider
parent
e4711c469f
commit
6c56c1e0d7
@@ -135,6 +135,7 @@ struct sftp_client_message_struct {
|
|||||||
ssh_string data; /* can be newpath of rename() */
|
ssh_string data; /* can be newpath of rename() */
|
||||||
ssh_buffer complete_message; /* complete message in case of retransmission*/
|
ssh_buffer complete_message; /* complete message in case of retransmission*/
|
||||||
char *str_data; /* cstring version of data */
|
char *str_data; /* cstring version of data */
|
||||||
|
char *submessage; /* for extended messages */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sftp_request_queue_struct {
|
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 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 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 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_send_client_message(sftp_session sftp, sftp_client_message msg);
|
||||||
LIBSSH_API int sftp_reply_name(sftp_client_message msg, const char *name,
|
LIBSSH_API int sftp_reply_name(sftp_client_message msg, const char *name,
|
||||||
sftp_attributes attr);
|
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_RENAME SSH_FXP_RENAME
|
||||||
#define SFTP_READLINK SSH_FXP_READLINK
|
#define SFTP_READLINK SSH_FXP_READLINK
|
||||||
#define SFTP_SYMLINK SSH_FXP_SYMLINK
|
#define SFTP_SYMLINK SSH_FXP_SYMLINK
|
||||||
|
#define SFTP_EXTENDED SSH_FXP_EXTENDED
|
||||||
|
|
||||||
/* openssh flags */
|
/* openssh flags */
|
||||||
#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
|
#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ int sftp_server_init(sftp_session sftp){
|
|||||||
sftp_packet packet = NULL;
|
sftp_packet packet = NULL;
|
||||||
ssh_buffer reply = NULL;
|
ssh_buffer reply = NULL;
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
|
int rc;
|
||||||
|
|
||||||
packet = sftp_packet_read(sftp);
|
packet = sftp_packet_read(sftp);
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
@@ -249,7 +250,13 @@ int sftp_server_init(sftp_session sftp){
|
|||||||
return -1;
|
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_set_error_oom(session);
|
||||||
ssh_buffer_free(reply);
|
ssh_buffer_free(reply);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -202,6 +202,29 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
ssh_set_error(sftp->session, SSH_FATAL,
|
ssh_set_error(sftp->session, SSH_FATAL,
|
||||||
"Received unhandled sftp message %d", msg->type);
|
"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;
|
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) {
|
void sftp_client_message_free(sftp_client_message msg) {
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SAFE_FREE(msg->filename);
|
SAFE_FREE(msg->filename);
|
||||||
|
SAFE_FREE(msg->submessage);
|
||||||
ssh_string_free(msg->data);
|
ssh_string_free(msg->data);
|
||||||
ssh_string_free(msg->handle);
|
ssh_string_free(msg->handle);
|
||||||
sftp_attributes_free(msg->attr);
|
sftp_attributes_free(msg->attr);
|
||||||
|
|||||||
Reference in New Issue
Block a user