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>
Этот коммит содержится в:
родитель
e4711c469f
Коммит
6c56c1e0d7
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user