summaryrefslogtreecommitdiff
path: root/sftp-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2008-03-27 10:59:57 +1100
committerDamien Miller <djm@mindrot.org>2008-03-27 10:59:57 +1100
commit7a3e1d0bc9de3af87afcfa1159b4e906efde558b (patch)
tree3e328aaea4a623adc9088c6feeeafb7177b62349 /sftp-client.c
parentbe71e2d9725cf0833ee208222eb6860bb17316ef (diff)
- djm@cvs.openbsd.org 2008/03/23 12:54:01
[sftp-client.c] prefer POSIX-style file renaming over filexfer rename behaviour if the server supports the posix-rename@openssh.com extension. Note that the old (filexfer) behaviour would refuse to clobber an existing file. Users who depended on this should adjust their sftp(1) usage. ok deraadt@ markus@
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/sftp-client.c b/sftp-client.c
index b189422d4..69c637785 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.80 2008/01/21 19:20:17 djm Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.81 2008/03/23 12:54: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 *
@@ -65,6 +65,8 @@ struct sftp_conn {
65 u_int num_requests; 65 u_int num_requests;
66 u_int version; 66 u_int version;
67 u_int msg_id; 67 u_int msg_id;
68#define SFTP_EXT_POSIX_RENAME 1
69 u_int exts;
68}; 70};
69 71
70static void 72static void
@@ -239,7 +241,7 @@ get_decode_stat(int fd, u_int expected_id, int quiet)
239struct sftp_conn * 241struct sftp_conn *
240do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests) 242do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests)
241{ 243{
242 u_int type; 244 u_int type, exts = 0;
243 int version; 245 int version;
244 Buffer msg; 246 Buffer msg;
245 struct sftp_conn *ret; 247 struct sftp_conn *ret;
@@ -270,6 +272,8 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests)
270 char *value = buffer_get_string(&msg, NULL); 272 char *value = buffer_get_string(&msg, NULL);
271 273
272 debug2("Init extension: \"%s\"", name); 274 debug2("Init extension: \"%s\"", name);
275 if (strcmp(name, "posix-rename@openssh.com") == 0)
276 exts |= SFTP_EXT_POSIX_RENAME;
273 xfree(name); 277 xfree(name);
274 xfree(value); 278 xfree(value);
275 } 279 }
@@ -283,6 +287,7 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests)
283 ret->num_requests = num_requests; 287 ret->num_requests = num_requests;
284 ret->version = version; 288 ret->version = version;
285 ret->msg_id = 1; 289 ret->msg_id = 1;
290 ret->exts = exts;
286 291
287 /* Some filexfer v.0 servers don't support large packets */ 292 /* Some filexfer v.0 servers don't support large packets */
288 if (version == 0) 293 if (version == 0)
@@ -639,13 +644,20 @@ do_rename(struct sftp_conn *conn, char *oldpath, char *newpath)
639 644
640 /* Send rename request */ 645 /* Send rename request */
641 id = conn->msg_id++; 646 id = conn->msg_id++;
642 buffer_put_char(&msg, SSH2_FXP_RENAME); 647 if ((conn->exts & SFTP_EXT_POSIX_RENAME)) {
643 buffer_put_int(&msg, id); 648 buffer_put_char(&msg, SSH2_FXP_EXTENDED);
649 buffer_put_int(&msg, id);
650 buffer_put_cstring(&msg, "posix-rename@openssh.com");
651 } else {
652 buffer_put_char(&msg, SSH2_FXP_RENAME);
653 buffer_put_int(&msg, id);
654 }
644 buffer_put_cstring(&msg, oldpath); 655 buffer_put_cstring(&msg, oldpath);
645 buffer_put_cstring(&msg, newpath); 656 buffer_put_cstring(&msg, newpath);
646 send_msg(conn->fd_out, &msg); 657 send_msg(conn->fd_out, &msg);
647 debug3("Sent message SSH2_FXP_RENAME \"%s\" -> \"%s\"", oldpath, 658 debug3("Sent message %s \"%s\" -> \"%s\"",
648 newpath); 659 (conn->exts & SFTP_EXT_POSIX_RENAME) ? "posix-rename@openssh.com" :
660 "SSH2_FXP_RENAME", oldpath, newpath);
649 buffer_free(&msg); 661 buffer_free(&msg);
650 662
651 status = get_status(conn->fd_in, id); 663 status = get_status(conn->fd_in, id);