summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-08-21 02:41:15 +1000
committerDamien Miller <djm@mindrot.org>2013-08-21 02:41:15 +1000
commitc7dba12bf95eb1d69711881a153cc286c1987663 (patch)
treea91e31b8edac374ff5e1b9e671b8f411ae313ad0
parent034f27a0c09e69fe3589045b41f03f6e345b63f5 (diff)
- djm@cvs.openbsd.org 2013/08/08 05:04:03
[sftp-client.c sftp-client.h sftp.c] add a "-l" flag for the rename command to force it to use the silly standard SSH_FXP_RENAME command instead of the POSIX-rename- like posix-rename@openssh.com extension. intended for use in regress tests, so no documentation.
-rw-r--r--ChangeLog6
-rw-r--r--sftp-client.c12
-rw-r--r--sftp-client.h4
-rw-r--r--sftp.c35
4 files changed, 47 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 16bb10b4f..cd46b83aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,7 +19,13 @@
19 [sftp.c] 19 [sftp.c]
20 fix two year old regression: symlinking a file would incorrectly 20 fix two year old regression: symlinking a file would incorrectly
21 canonicalise the target path. bz#2129 report from delphij AT freebsd.org 21 canonicalise the target path. bz#2129 report from delphij AT freebsd.org
22 - djm@cvs.openbsd.org 2013/08/08 05:04:03
23 [sftp-client.c sftp-client.h sftp.c]
24 add a "-l" flag for the rename command to force it to use the silly
25 standard SSH_FXP_RENAME command instead of the POSIX-rename- like
26 posix-rename@openssh.com extension.
22 27
28 intended for use in regress tests, so no documentation.
2320130808 2920130808
24 - (dtucker) [regress/Makefile regress/test-exec.sh] Don't try to use test -nt 30 - (dtucker) [regress/Makefile regress/test-exec.sh] Don't try to use test -nt
25 since some platforms (eg really old FreeBSD) don't have it. Instead, 31 since some platforms (eg really old FreeBSD) don't have it. Instead,
diff --git a/sftp-client.c b/sftp-client.c
index f4f1970b6..0eeb73c8b 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.101 2013/07/25 00:56:51 djm Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.102 2013/08/08 05:04:03 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 *
@@ -768,16 +768,18 @@ do_realpath(struct sftp_conn *conn, char *path)
768} 768}
769 769
770int 770int
771do_rename(struct sftp_conn *conn, char *oldpath, char *newpath) 771do_rename(struct sftp_conn *conn, char *oldpath, char *newpath,
772 int force_legacy)
772{ 773{
773 Buffer msg; 774 Buffer msg;
774 u_int status, id; 775 u_int status, id;
776 int use_ext = (conn->exts & SFTP_EXT_POSIX_RENAME) && !force_legacy;
775 777
776 buffer_init(&msg); 778 buffer_init(&msg);
777 779
778 /* Send rename request */ 780 /* Send rename request */
779 id = conn->msg_id++; 781 id = conn->msg_id++;
780 if ((conn->exts & SFTP_EXT_POSIX_RENAME)) { 782 if (use_ext) {
781 buffer_put_char(&msg, SSH2_FXP_EXTENDED); 783 buffer_put_char(&msg, SSH2_FXP_EXTENDED);
782 buffer_put_int(&msg, id); 784 buffer_put_int(&msg, id);
783 buffer_put_cstring(&msg, "posix-rename@openssh.com"); 785 buffer_put_cstring(&msg, "posix-rename@openssh.com");
@@ -789,8 +791,8 @@ do_rename(struct sftp_conn *conn, char *oldpath, char *newpath)
789 buffer_put_cstring(&msg, newpath); 791 buffer_put_cstring(&msg, newpath);
790 send_msg(conn, &msg); 792 send_msg(conn, &msg);
791 debug3("Sent message %s \"%s\" -> \"%s\"", 793 debug3("Sent message %s \"%s\" -> \"%s\"",
792 (conn->exts & SFTP_EXT_POSIX_RENAME) ? "posix-rename@openssh.com" : 794 use_ext ? "posix-rename@openssh.com" : "SSH2_FXP_RENAME",
793 "SSH2_FXP_RENAME", oldpath, newpath); 795 oldpath, newpath);
794 buffer_free(&msg); 796 buffer_free(&msg);
795 797
796 status = get_status(conn, id); 798 status = get_status(conn, id);
diff --git a/sftp-client.h b/sftp-client.h
index 111a998c8..dc54cfe3b 100644
--- a/sftp-client.h
+++ b/sftp-client.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.h,v 1.21 2013/07/25 00:56:51 djm Exp $ */ 1/* $OpenBSD: sftp-client.h,v 1.22 2013/08/08 05:04:03 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 4 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
@@ -92,7 +92,7 @@ char *do_realpath(struct sftp_conn *, char *);
92int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int); 92int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
93 93
94/* Rename 'oldpath' to 'newpath' */ 94/* Rename 'oldpath' to 'newpath' */
95int do_rename(struct sftp_conn *, char *, char *); 95int do_rename(struct sftp_conn *, char *, char *m, int force_legacy);
96 96
97/* Link 'oldpath' to 'newpath' */ 97/* Link 'oldpath' to 'newpath' */
98int do_hardlink(struct sftp_conn *, char *, char *); 98int do_hardlink(struct sftp_conn *, char *, char *);
diff --git a/sftp.c b/sftp.c
index 6f16f7cc6..66ab2b0d4 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.151 2013/08/08 04:52:04 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.152 2013/08/08 05:04:03 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 *
@@ -415,6 +415,30 @@ parse_link_flags(const char *cmd, char **argv, int argc, int *sflag)
415} 415}
416 416
417static int 417static int
418parse_rename_flags(const char *cmd, char **argv, int argc, int *lflag)
419{
420 extern int opterr, optind, optopt, optreset;
421 int ch;
422
423 optind = optreset = 1;
424 opterr = 0;
425
426 *lflag = 0;
427 while ((ch = getopt(argc, argv, "l")) != -1) {
428 switch (ch) {
429 case 'l':
430 *lflag = 1;
431 break;
432 default:
433 error("%s: Invalid flag -%c", cmd, optopt);
434 return -1;
435 }
436 }
437
438 return optind;
439}
440
441static int
418parse_ls_flags(char **argv, int argc, int *lflag) 442parse_ls_flags(char **argv, int argc, int *lflag)
419{ 443{
420 extern int opterr, optind, optopt, optreset; 444 extern int opterr, optind, optopt, optreset;
@@ -1210,8 +1234,13 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
1210 case I_LINK: 1234 case I_LINK:
1211 if ((optidx = parse_link_flags(cmd, argv, argc, sflag)) == -1) 1235 if ((optidx = parse_link_flags(cmd, argv, argc, sflag)) == -1)
1212 return -1; 1236 return -1;
1213 case I_SYMLINK: 1237 goto parse_two_paths;
1214 case I_RENAME: 1238 case I_RENAME:
1239 if ((optidx = parse_rename_flags(cmd, argv, argc, lflag)) == -1)
1240 return -1;
1241 goto parse_two_paths;
1242 case I_SYMLINK:
1243 parse_two_paths:
1215 if (argc - optidx < 2) { 1244 if (argc - optidx < 2) {
1216 error("You must specify two paths after a %s " 1245 error("You must specify two paths after a %s "
1217 "command.", cmd); 1246 "command.", cmd);
@@ -1353,7 +1382,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
1353 case I_RENAME: 1382 case I_RENAME:
1354 path1 = make_absolute(path1, *pwd); 1383 path1 = make_absolute(path1, *pwd);
1355 path2 = make_absolute(path2, *pwd); 1384 path2 = make_absolute(path2, *pwd);
1356 err = do_rename(conn, path1, path2); 1385 err = do_rename(conn, path1, path2, lflag);
1357 break; 1386 break;
1358 case I_SYMLINK: 1387 case I_SYMLINK:
1359 sflag = 1; 1388 sflag = 1;