mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
Introduce the posix-rename@openssh.com extension handling
Changes done in sftp_rename such that it will use posix-rename@openssh.com extension if supported and send a SSH_FXP_EXTENDED request. If the extension is not supported a normal SSH_FXP_RENAME request will be sent. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
b067d7a123
commit
ef901829c1
65
src/sftp.c
65
src/sftp.c
@@ -2520,6 +2520,8 @@ int sftp_rename(sftp_session sftp, const char *original, const char *newname)
|
|||||||
sftp_message msg = NULL;
|
sftp_message msg = NULL;
|
||||||
ssh_buffer buffer = NULL;
|
ssh_buffer buffer = NULL;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
const char *extension_name = "posix-rename@openssh.com";
|
||||||
|
int request_type;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
buffer = ssh_buffer_new();
|
buffer = ssh_buffer_new();
|
||||||
@@ -2531,27 +2533,52 @@ int sftp_rename(sftp_session sftp, const char *original, const char *newname)
|
|||||||
|
|
||||||
id = sftp_get_new_id(sftp);
|
id = sftp_get_new_id(sftp);
|
||||||
|
|
||||||
rc = ssh_buffer_pack(buffer,
|
/*
|
||||||
"dss",
|
* posix-rename@openssh.com extension will be used
|
||||||
id,
|
* if it is supported by sftp
|
||||||
original,
|
*/
|
||||||
newname);
|
if (sftp_extension_supported(sftp,
|
||||||
if (rc != SSH_OK) {
|
extension_name,
|
||||||
ssh_set_error_oom(sftp->session);
|
"1")) {
|
||||||
SSH_BUFFER_FREE(buffer);
|
rc = ssh_buffer_pack(buffer,
|
||||||
sftp_set_error(sftp, SSH_FX_FAILURE);
|
"dsss",
|
||||||
return -1;
|
id,
|
||||||
|
extension_name,
|
||||||
|
original,
|
||||||
|
newname);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
SSH_BUFFER_FREE(buffer);
|
||||||
|
sftp_set_error(sftp, SSH_FX_FAILURE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
request_type = SSH_FXP_EXTENDED;
|
||||||
|
} else {
|
||||||
|
rc = ssh_buffer_pack(buffer,
|
||||||
|
"dss",
|
||||||
|
id,
|
||||||
|
original,
|
||||||
|
newname);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
SSH_BUFFER_FREE(buffer);
|
||||||
|
sftp_set_error(sftp, SSH_FX_FAILURE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sftp->version >= 4) {
|
||||||
|
/*
|
||||||
|
* POSIX rename atomically replaces newpath,
|
||||||
|
* we should do the same only available on >=v4
|
||||||
|
*/
|
||||||
|
ssh_buffer_add_u32(buffer, SSH_FXF_RENAME_OVERWRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
request_type = SSH_FXP_RENAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sftp->version >= 4) {
|
rc = sftp_packet_write(sftp, request_type, buffer);
|
||||||
/*
|
|
||||||
* POSIX rename atomically replaces newpath,
|
|
||||||
* we should do the same only available on >=v4
|
|
||||||
*/
|
|
||||||
ssh_buffer_add_u32(buffer, SSH_FXF_RENAME_OVERWRITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = sftp_packet_write(sftp, SSH_FXP_RENAME, buffer);
|
|
||||||
SSH_BUFFER_FREE(buffer);
|
SSH_BUFFER_FREE(buffer);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user