aboutsummaryrefslogtreecommitdiff
path: root/libssh/sftp.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-07-29 16:05:45 +0200
committerAndreas Schneider <mail@cynapses.org>2009-07-29 16:05:45 +0200
commited660c29c348eb2f7f2af21fa562589561cb35f1 (patch)
treec6dc7795a4026be7aa08110b4775791a75a490fc /libssh/sftp.c
parent6f47401173340665e25872bef0b87cedd9812602 (diff)
downloadlibssh-ed660c29c348eb2f7f2af21fa562589561cb35f1.tar.gz
libssh-ed660c29c348eb2f7f2af21fa562589561cb35f1.tar.xz
libssh-ed660c29c348eb2f7f2af21fa562589561cb35f1.zip
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.
Diffstat (limited to 'libssh/sftp.c')
-rw-r--r--libssh/sftp.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/libssh/sftp.c b/libssh/sftp.c
index e86a262b..f720aa58 100644
--- a/libssh/sftp.c
+++ b/libssh/sftp.c
@@ -2243,10 +2243,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);