diff options
author | Darren Tucker <dtucker@zip.com.au> | 2010-12-05 09:02:47 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2010-12-05 09:02:47 +1100 |
commit | af1f90925494deba97a4b877798cf250f7dc75cf (patch) | |
tree | c6e44e388c2bd4ca0caad6ce9f422576fe650b57 /sftp-client.c | |
parent | adab6f12992c522e1208fa2bdf89ce572840ccf8 (diff) |
- djm@cvs.openbsd.org 2010/12/04 00:18:01
[sftp-server.c sftp.1 sftp-client.h sftp.c PROTOCOL sftp-client.c]
add a protocol extension to support a hard link operation. It is
available through the "ln" command in the client. The old "ln"
behaviour of creating a symlink is available using its "-s" option
or through the preexisting "symlink" command; based on a patch from
miklos AT szeredi.hu in bz#1555; ok markus@
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/sftp-client.c b/sftp-client.c index 4e009ef25..caa384b4e 100644 --- a/sftp-client.c +++ b/sftp-client.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp-client.c,v 1.93 2010/09/22 22:58:51 djm Exp $ */ | 1 | /* $OpenBSD: sftp-client.c,v 1.94 2010/12/04 00:18:01 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> | 3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
4 | * | 4 | * |
@@ -75,6 +75,7 @@ struct sftp_conn { | |||
75 | #define SFTP_EXT_POSIX_RENAME 0x00000001 | 75 | #define SFTP_EXT_POSIX_RENAME 0x00000001 |
76 | #define SFTP_EXT_STATVFS 0x00000002 | 76 | #define SFTP_EXT_STATVFS 0x00000002 |
77 | #define SFTP_EXT_FSTATVFS 0x00000004 | 77 | #define SFTP_EXT_FSTATVFS 0x00000004 |
78 | #define SFTP_EXT_HARDLINK 0x00000008 | ||
78 | u_int exts; | 79 | u_int exts; |
79 | u_int64_t limit_kbps; | 80 | u_int64_t limit_kbps; |
80 | struct bwlimit bwlimit_in, bwlimit_out; | 81 | struct bwlimit bwlimit_in, bwlimit_out; |
@@ -378,10 +379,14 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests, | |||
378 | strcmp(value, "2") == 0) { | 379 | strcmp(value, "2") == 0) { |
379 | ret->exts |= SFTP_EXT_STATVFS; | 380 | ret->exts |= SFTP_EXT_STATVFS; |
380 | known = 1; | 381 | known = 1; |
381 | } if (strcmp(name, "fstatvfs@openssh.com") == 0 && | 382 | } else if (strcmp(name, "fstatvfs@openssh.com") == 0 && |
382 | strcmp(value, "2") == 0) { | 383 | strcmp(value, "2") == 0) { |
383 | ret->exts |= SFTP_EXT_FSTATVFS; | 384 | ret->exts |= SFTP_EXT_FSTATVFS; |
384 | known = 1; | 385 | known = 1; |
386 | } else if (strcmp(name, "hardlink@openssh.com") == 0 && | ||
387 | strcmp(value, "1") == 0) { | ||
388 | ret->exts |= SFTP_EXT_HARDLINK; | ||
389 | known = 1; | ||
385 | } | 390 | } |
386 | if (known) { | 391 | if (known) { |
387 | debug2("Server supports extension \"%s\" revision %s", | 392 | debug2("Server supports extension \"%s\" revision %s", |
@@ -795,6 +800,39 @@ do_rename(struct sftp_conn *conn, char *oldpath, char *newpath) | |||
795 | } | 800 | } |
796 | 801 | ||
797 | int | 802 | int |
803 | do_hardlink(struct sftp_conn *conn, char *oldpath, char *newpath) | ||
804 | { | ||
805 | Buffer msg; | ||
806 | u_int status, id; | ||
807 | |||
808 | buffer_init(&msg); | ||
809 | |||
810 | /* Send link request */ | ||
811 | id = conn->msg_id++; | ||
812 | if ((conn->exts & SFTP_EXT_HARDLINK) == 0) { | ||
813 | error("Server does not support hardlink@openssh.com extension"); | ||
814 | return -1; | ||
815 | } | ||
816 | |||
817 | buffer_put_char(&msg, SSH2_FXP_EXTENDED); | ||
818 | buffer_put_int(&msg, id); | ||
819 | buffer_put_cstring(&msg, "hardlink@openssh.com"); | ||
820 | buffer_put_cstring(&msg, oldpath); | ||
821 | buffer_put_cstring(&msg, newpath); | ||
822 | send_msg(conn, &msg); | ||
823 | debug3("Sent message hardlink@openssh.com \"%s\" -> \"%s\"", | ||
824 | oldpath, newpath); | ||
825 | buffer_free(&msg); | ||
826 | |||
827 | status = get_status(conn, id); | ||
828 | if (status != SSH2_FX_OK) | ||
829 | error("Couldn't link file \"%s\" to \"%s\": %s", oldpath, | ||
830 | newpath, fx2txt(status)); | ||
831 | |||
832 | return(status); | ||
833 | } | ||
834 | |||
835 | int | ||
798 | do_symlink(struct sftp_conn *conn, char *oldpath, char *newpath) | 836 | do_symlink(struct sftp_conn *conn, char *oldpath, char *newpath) |
799 | { | 837 | { |
800 | Buffer msg; | 838 | Buffer msg; |