From 69ceaae9a9f69dba11ab01889da5b41cb1487896 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 28 Jul 2009 11:47:53 +0200 Subject: Check for OpenSSH and implement sftp_symlink correct. When OpenSSH's sftp-server was implemented, the order of the arguments to the SSH_FXP_SYMLINK method was inadvertently reversed. Unfortunately, the reversal was not noticed until the server was widely deployed. Since fixing this to follow the specification would cause incompatibility, the current order was retained. --- libssh/sftp.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'libssh/sftp.c') diff --git a/libssh/sftp.c b/libssh/sftp.c index f64aa302..41402810 100644 --- a/libssh/sftp.c +++ b/libssh/sftp.c @@ -2247,10 +2247,32 @@ int sftp_symlink(SFTP_SESSION *sftp, const char *target, const char *dest) { } id = sftp_get_new_id(sftp); - if (buffer_add_u32(buffer, id) < 0 || - buffer_add_ssh_string(buffer, target_s) < 0 || - buffer_add_ssh_string(buffer, dest_s) < 0 || - sftp_packet_write(sftp, SSH_FXP_SYMLINK, buffer) < 0) { + if (buffer_add_u32(buffer, id) < 0) { + buffer_free(buffer); + string_free(dest_s); + string_free(target_s); + return -1; + } + if (ssh_get_openssh_version(sftp->session)) { + /* TODO check for version number if they ever fix it. */ + if (buffer_add_ssh_string(buffer, target_s) < 0 || + buffer_add_ssh_string(buffer, dest_s) < 0) { + buffer_free(buffer); + string_free(dest_s); + string_free(target_s); + return -1; + } + } else { + if (buffer_add_ssh_string(buffer, dest_s) < 0 || + buffer_add_ssh_string(buffer, target_s) < 0) { + buffer_free(buffer); + string_free(dest_s); + string_free(target_s); + return -1; + } + } + + if (sftp_packet_write(sftp, SSH_FXP_SYMLINK, buffer) < 0) { buffer_free(buffer); string_free(dest_s); string_free(target_s); -- cgit v1.2.3