summaryrefslogtreecommitdiffstats
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 16bb10b4..cd46b83a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,7 +19,13 @@
[sftp.c]
fix two year old regression: symlinking a file would incorrectly
canonicalise the target path. bz#2129 report from delphij AT freebsd.org
+ - 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.
20130808
- (dtucker) [regress/Makefile regress/test-exec.sh] Don't try to use test -nt
since some platforms (eg really old FreeBSD) don't have it. Instead,
diff --git a/sftp-client.c b/sftp-client.c
index f4f1970b..0eeb73c8 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.c,v 1.101 2013/07/25 00:56:51 djm Exp $ */
+/* $OpenBSD: sftp-client.c,v 1.102 2013/08/08 05:04:03 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -768,16 +768,18 @@ do_realpath(struct sftp_conn *conn, char *path)
}
int
-do_rename(struct sftp_conn *conn, char *oldpath, char *newpath)
+do_rename(struct sftp_conn *conn, char *oldpath, char *newpath,
+ int force_legacy)
{
Buffer msg;
u_int status, id;
+ int use_ext = (conn->exts & SFTP_EXT_POSIX_RENAME) && !force_legacy;
buffer_init(&msg);
/* Send rename request */
id = conn->msg_id++;
- if ((conn->exts & SFTP_EXT_POSIX_RENAME)) {
+ if (use_ext) {
buffer_put_char(&msg, SSH2_FXP_EXTENDED);
buffer_put_int(&msg, id);
buffer_put_cstring(&msg, "posix-rename@openssh.com");
@@ -789,8 +791,8 @@ do_rename(struct sftp_conn *conn, char *oldpath, char *newpath)
buffer_put_cstring(&msg, newpath);
send_msg(conn, &msg);
debug3("Sent message %s \"%s\" -> \"%s\"",
- (conn->exts & SFTP_EXT_POSIX_RENAME) ? "posix-rename@openssh.com" :
- "SSH2_FXP_RENAME", oldpath, newpath);
+ use_ext ? "posix-rename@openssh.com" : "SSH2_FXP_RENAME",
+ oldpath, newpath);
buffer_free(&msg);
status = get_status(conn, id);
diff --git a/sftp-client.h b/sftp-client.h
index 111a998c..dc54cfe3 100644
--- a/sftp-client.h
+++ b/sftp-client.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-client.h,v 1.21 2013/07/25 00:56:51 djm Exp $ */
+/* $OpenBSD: sftp-client.h,v 1.22 2013/08/08 05:04:03 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
@@ -92,7 +92,7 @@ char *do_realpath(struct sftp_conn *, char *);
int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
/* Rename 'oldpath' to 'newpath' */
-int do_rename(struct sftp_conn *, char *, char *);
+int do_rename(struct sftp_conn *, char *, char *m, int force_legacy);
/* Link 'oldpath' to 'newpath' */
int do_hardlink(struct sftp_conn *, char *, char *);
diff --git a/sftp.c b/sftp.c
index 6f16f7cc..66ab2b0d 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.151 2013/08/08 04:52:04 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.152 2013/08/08 05:04:03 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -415,6 +415,30 @@ parse_link_flags(const char *cmd, char **argv, int argc, int *sflag)
}
static int
+parse_rename_flags(const char *cmd, char **argv, int argc, int *lflag)
+{
+ extern int opterr, optind, optopt, optreset;
+ int ch;
+
+ optind = optreset = 1;
+ opterr = 0;
+
+ *lflag = 0;
+ while ((ch = getopt(argc, argv, "l")) != -1) {
+ switch (ch) {
+ case 'l':
+ *lflag = 1;
+ break;
+ default:
+ error("%s: Invalid flag -%c", cmd, optopt);
+ return -1;
+ }
+ }
+
+ return optind;
+}
+
+static int
parse_ls_flags(char **argv, int argc, int *lflag)
{
extern int opterr, optind, optopt, optreset;
@@ -1210,8 +1234,13 @@ parse_args(const char **cpp, int *aflag, int *hflag, int *iflag, int *lflag,
case I_LINK:
if ((optidx = parse_link_flags(cmd, argv, argc, sflag)) == -1)
return -1;
- case I_SYMLINK:
+ goto parse_two_paths;
case I_RENAME:
+ if ((optidx = parse_rename_flags(cmd, argv, argc, lflag)) == -1)
+ return -1;
+ goto parse_two_paths;
+ case I_SYMLINK:
+ parse_two_paths:
if (argc - optidx < 2) {
error("You must specify two paths after a %s "
"command.", cmd);
@@ -1353,7 +1382,7 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
case I_RENAME:
path1 = make_absolute(path1, *pwd);
path2 = make_absolute(path2, *pwd);
- err = do_rename(conn, path1, path2);
+ err = do_rename(conn, path1, path2, lflag);
break;
case I_SYMLINK:
sflag = 1;