diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2001-03-07 10:11:24 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2001-03-07 10:11:24 +0000 |
commit | d3a6611d24ba76cf0d9a61c20b0b441946faf24a (patch) | |
tree | b6738e88f9e37ec29aee73922fbac8666f69b3be /usr.bin/ssh/sftp-client.c | |
parent | eb4a749e1d1cec4f3abb59abbe1905c6cab0fc3f (diff) |
Support for new draft (draft-ietf-secsh-filexfer-01). New symlink handling
functions and small protocol change.
Diffstat (limited to 'usr.bin/ssh/sftp-client.c')
-rw-r--r-- | usr.bin/ssh/sftp-client.c | 81 |
1 files changed, 77 insertions, 4 deletions
diff --git a/usr.bin/ssh/sftp-client.c b/usr.bin/ssh/sftp-client.c index 760a224e26d..a4b9fcf6464 100644 --- a/usr.bin/ssh/sftp-client.c +++ b/usr.bin/ssh/sftp-client.c @@ -29,7 +29,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.10 2001/02/14 09:46:03 djm Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.11 2001/03/07 10:11:22 djm Exp $"); #include "ssh.h" #include "buffer.h" @@ -247,7 +247,8 @@ do_init(int fd_in, int fd_out) } buffer_free(&msg); - return(0); + + return(version); } int @@ -483,8 +484,7 @@ do_realpath(int fd_in, int fd_out, char *path) Attrib *a; expected_id = id = msg_id++; - send_string_request(fd_out, id, SSH2_FXP_REALPATH, path, - strlen(path)); + send_string_request(fd_out, id, SSH2_FXP_REALPATH, path, strlen(path)); buffer_init(&msg); @@ -549,6 +549,79 @@ do_rename(int fd_in, int fd_out, char *oldpath, char *newpath) } int +do_symlink(int fd_in, int fd_out, char *oldpath, char *newpath) +{ + Buffer msg; + u_int status, id; + + buffer_init(&msg); + + /* Send rename request */ + id = msg_id++; + buffer_put_char(&msg, SSH2_FXP_SYMLINK); + buffer_put_int(&msg, id); + buffer_put_cstring(&msg, oldpath); + buffer_put_cstring(&msg, newpath); + send_msg(fd_out, &msg); + debug3("Sent message SSH2_FXP_SYMLINK \"%s\" -> \"%s\"", oldpath, + newpath); + buffer_free(&msg); + + status = get_status(fd_in, id); + if (status != SSH2_FX_OK) + error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, newpath, + fx2txt(status)); + + return(status); +} + +char * +do_readlink(int fd_in, int fd_out, char *path) +{ + Buffer msg; + u_int type, expected_id, count, id; + char *filename, *longname; + Attrib *a; + + expected_id = id = msg_id++; + send_string_request(fd_out, id, SSH2_FXP_READLINK, path, strlen(path)); + + buffer_init(&msg); + + get_msg(fd_in, &msg); + type = buffer_get_char(&msg); + id = buffer_get_int(&msg); + + if (id != expected_id) + fatal("ID mismatch (%d != %d)", id, expected_id); + + if (type == SSH2_FXP_STATUS) { + u_int status = buffer_get_int(&msg); + + error("Couldn't readlink: %s", fx2txt(status)); + return(NULL); + } else if (type != SSH2_FXP_NAME) + fatal("Expected SSH2_FXP_NAME(%d) packet, got %d", + SSH2_FXP_NAME, type); + + count = buffer_get_int(&msg); + if (count != 1) + fatal("Got multiple names (%d) from SSH_FXP_READLINK", count); + + filename = buffer_get_string(&msg, NULL); + longname = buffer_get_string(&msg, NULL); + a = decode_attrib(&msg); + + debug3("SSH_FXP_READLINK %s -> %s", path, filename); + + xfree(longname); + + buffer_free(&msg); + + return(filename); +} + +int do_download(int fd_in, int fd_out, char *remote_path, char *local_path, int pflag) { |