mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-01-06 14:21:55 +03: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;
|
||||
ssh_buffer buffer = NULL;
|
||||
uint32_t id;
|
||||
const char *extension_name = "posix-rename@openssh.com";
|
||||
int request_type;
|
||||
int rc;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
/*
|
||||
* posix-rename@openssh.com extension will be used
|
||||
* if it is supported by sftp
|
||||
*/
|
||||
if (sftp_extension_supported(sftp,
|
||||
extension_name,
|
||||
"1")) {
|
||||
rc = ssh_buffer_pack(buffer,
|
||||
"dsss",
|
||||
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) {
|
||||
/*
|
||||
* 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);
|
||||
rc = sftp_packet_write(sftp, request_type, buffer);
|
||||
SSH_BUFFER_FREE(buffer);
|
||||
if (rc < 0) {
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user