[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] sftpserver: Support some openssh extensions


On Tuesday, 4 September 2018 20:10:17 CEST Alberto Aguirre wrote:
> From: Chris Townsend <christopher.townsend@xxxxxxxxxxxxx>

I guess we need Chris his sign-off for this patch too.

Another comment inline ...

> Add support for "hardlink@xxxxxxxxxxx" and
> "posix-rename@xxxxxxxxxxx" extensions.
> 
> Signed-off-by: Alberto Aguirre <albaguirre@xxxxxxxxx>
> ---
>  include/libssh/sftp.h |  3 +++
>  src/sftp.c            |  7 ++++++-
>  src/sftpserver.c      | 28 ++++++++++++++++++++++++++++
>  3 files changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
> index b07f269f..b2d4dff5 100644
> --- a/include/libssh/sftp.h
> +++ b/include/libssh/sftp.h
> @@ -134,6 +134,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 {
> @@ -862,6 +863,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);
> @@ -1011,6 +1013,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 ae7d0721..80758272 100644
> --- a/src/sftp.c
> +++ b/src/sftp.c
> @@ -219,7 +219,12 @@ int sftp_server_init(sftp_session sftp){
>      return -1;
>    }

please use:

rc = ssh_buffer_pack();
if (rc != SSH_OK)

as done below :-)

> -  if (ssh_buffer_add_u32(reply, ntohl(LIBSFTP_VERSION)) < 0) {
> +  if (ssh_buffer_pack(reply, "dssss",
> +                      LIBSFTP_VERSION,
> +                      "posix-rename@xxxxxxxxxxx",
> +                      "1",
> +                      "hardlink@xxxxxxxxxxx",
> +                      "1") < 0) {
>      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@xxxxxxxxxxx") == 0 ||
> +          strcmp(msg->submessage, "posix-rename@xxxxxxxxxxx") == 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);


-- 
Andreas Schneider                 asn@xxxxxxxxxxxxxx
GPG-ID:     8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D



References:
[PATCH] sftpserver: Support some openssh extensionsAlberto Aguirre <albaguirre@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org