|
|
9070b3 |
diff -up openssh-8.7p1/scp.c.scp-sftpdirs openssh-8.7p1/scp.c
|
|
|
9070b3 |
--- openssh-8.7p1/scp.c.scp-sftpdirs 2022-02-07 12:31:07.407740407 +0100
|
|
|
9070b3 |
+++ openssh-8.7p1/scp.c 2022-02-07 12:31:07.409740424 +0100
|
|
|
9070b3 |
@@ -1324,7 +1324,7 @@ source_sftp(int argc, char *src, char *t
|
|
|
9070b3 |
|
|
|
9070b3 |
if (src_is_dir && iamrecursive) {
|
|
|
9070b3 |
if (upload_dir(conn, src, abs_dst, pflag,
|
|
|
9070b3 |
- SFTP_PROGRESS_ONLY, 0, 0, 1) != 0) {
|
|
|
9070b3 |
+ SFTP_PROGRESS_ONLY, 0, 0, 1, 1) != 0) {
|
|
|
9070b3 |
error("failed to upload directory %s to %s",
|
|
|
9070b3 |
src, abs_dst);
|
|
|
9070b3 |
errs = 1;
|
|
|
9070b3 |
diff -up openssh-8.7p1/sftp-client.c.scp-sftpdirs openssh-8.7p1/sftp-client.c
|
|
|
9070b3 |
--- openssh-8.7p1/sftp-client.c.scp-sftpdirs 2021-08-20 06:03:49.000000000 +0200
|
|
|
9070b3 |
+++ openssh-8.7p1/sftp-client.c 2022-02-07 12:47:59.117516131 +0100
|
|
|
9070b3 |
@@ -971,7 +971,7 @@ do_fsetstat(struct sftp_conn *conn, cons
|
|
|
9070b3 |
|
|
|
9070b3 |
/* Implements both the realpath and expand-path operations */
|
|
|
9070b3 |
static char *
|
|
|
9070b3 |
-do_realpath_expand(struct sftp_conn *conn, const char *path, int expand)
|
|
|
9070b3 |
+do_realpath_expand(struct sftp_conn *conn, const char *path, int expand, int create_dir)
|
|
|
9070b3 |
{
|
|
|
9070b3 |
struct sshbuf *msg;
|
|
|
9070b3 |
u_int expected_id, count, id;
|
|
|
9070b3 |
@@ -1012,9 +1012,38 @@ do_realpath_expand(struct sftp_conn *con
|
|
|
9070b3 |
|
|
|
9070b3 |
if ((r = sshbuf_get_u32(msg, &status)) != 0)
|
|
|
9070b3 |
fatal_fr(r, "parse status");
|
|
|
9070b3 |
- error("Couldn't canonicalize: %s", fx2txt(status));
|
|
|
9070b3 |
- sshbuf_free(msg);
|
|
|
9070b3 |
- return NULL;
|
|
|
9070b3 |
+ if ((status == SSH2_FX_NO_SUCH_FILE) && create_dir) {
|
|
|
9070b3 |
+ memset(&a, '\0', sizeof(a));
|
|
|
9070b3 |
+ if ((r = do_mkdir(conn, path, &a, 0)) != 0) {
|
|
|
9070b3 |
+ sshbuf_free(msg);
|
|
|
9070b3 |
+ return NULL;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ send_string_request(conn, id, SSH2_FXP_REALPATH,
|
|
|
9070b3 |
+ path, strlen(path));
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ get_msg(conn, msg);
|
|
|
9070b3 |
+ if ((r = sshbuf_get_u8(msg, &type)) != 0 ||
|
|
|
9070b3 |
+ (r = sshbuf_get_u32(msg, &id)) != 0)
|
|
|
9070b3 |
+ fatal_fr(r, "parse");
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (id != expected_id)
|
|
|
9070b3 |
+ fatal("ID mismatch (%u != %u)", id, expected_id);
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (type == SSH2_FXP_STATUS) {
|
|
|
9070b3 |
+ u_int status;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if ((r = sshbuf_get_u32(msg, &status)) != 0)
|
|
|
9070b3 |
+ fatal_fr(r, "parse status");
|
|
|
9070b3 |
+ error("Couldn't canonicalize: %s", fx2txt(status));
|
|
|
9070b3 |
+ sshbuf_free(msg);
|
|
|
9070b3 |
+ return NULL;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+ } else {
|
|
|
9070b3 |
+ error("Couldn't canonicalize: %s", fx2txt(status));
|
|
|
9070b3 |
+ sshbuf_free(msg);
|
|
|
9070b3 |
+ return NULL;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
} else if (type != SSH2_FXP_NAME)
|
|
|
9070b3 |
fatal("Expected SSH2_FXP_NAME(%u) packet, got %u",
|
|
|
9070b3 |
SSH2_FXP_NAME, type);
|
|
|
9070b3 |
@@ -1039,9 +1067,9 @@ do_realpath_expand(struct sftp_conn *con
|
|
|
9070b3 |
}
|
|
|
9070b3 |
|
|
|
9070b3 |
char *
|
|
|
9070b3 |
-do_realpath(struct sftp_conn *conn, const char *path)
|
|
|
9070b3 |
+do_realpath(struct sftp_conn *conn, const char *path, int create_dir)
|
|
|
9070b3 |
{
|
|
|
9070b3 |
- return do_realpath_expand(conn, path, 0);
|
|
|
9070b3 |
+ return do_realpath_expand(conn, path, 0, create_dir);
|
|
|
9070b3 |
}
|
|
|
9070b3 |
|
|
|
9070b3 |
int
|
|
|
9070b3 |
@@ -1055,9 +1083,9 @@ do_expand_path(struct sftp_conn *conn, c
|
|
|
9070b3 |
{
|
|
|
9070b3 |
if (!can_expand_path(conn)) {
|
|
|
9070b3 |
debug3_f("no server support, fallback to realpath");
|
|
|
9070b3 |
- return do_realpath_expand(conn, path, 0);
|
|
|
9070b3 |
+ return do_realpath_expand(conn, path, 0, 0);
|
|
|
9070b3 |
}
|
|
|
9070b3 |
- return do_realpath_expand(conn, path, 1);
|
|
|
9070b3 |
+ return do_realpath_expand(conn, path, 1, 0);
|
|
|
9070b3 |
}
|
|
|
9070b3 |
|
|
|
9070b3 |
int
|
|
|
9070b3 |
@@ -1807,7 +1835,7 @@ download_dir(struct sftp_conn *conn, con
|
|
|
9070b3 |
char *src_canon;
|
|
|
9070b3 |
int ret;
|
|
|
9070b3 |
|
|
|
9070b3 |
- if ((src_canon = do_realpath(conn, src)) == NULL) {
|
|
|
9070b3 |
+ if ((src_canon = do_realpath(conn, src, 0)) == NULL) {
|
|
|
9070b3 |
error("Unable to canonicalize path \"%s\"", src);
|
|
|
9070b3 |
return -1;
|
|
|
9070b3 |
}
|
|
|
9070b3 |
@@ -2115,12 +2143,12 @@ upload_dir_internal(struct sftp_conn *co
|
|
|
9070b3 |
int
|
|
|
9070b3 |
upload_dir(struct sftp_conn *conn, const char *src, const char *dst,
|
|
|
9070b3 |
int preserve_flag, int print_flag, int resume, int fsync_flag,
|
|
|
9070b3 |
- int follow_link_flag)
|
|
|
9070b3 |
+ int follow_link_flag, int create_dir)
|
|
|
9070b3 |
{
|
|
|
9070b3 |
char *dst_canon;
|
|
|
9070b3 |
int ret;
|
|
|
9070b3 |
|
|
|
9070b3 |
- if ((dst_canon = do_realpath(conn, dst)) == NULL) {
|
|
|
9070b3 |
+ if ((dst_canon = do_realpath(conn, dst, create_dir)) == NULL) {
|
|
|
9070b3 |
error("Unable to canonicalize path \"%s\"", dst);
|
|
|
9070b3 |
return -1;
|
|
|
9070b3 |
}
|
|
|
9070b3 |
@@ -2557,7 +2585,7 @@ crossload_dir(struct sftp_conn *from, st
|
|
|
9070b3 |
char *from_path_canon;
|
|
|
9070b3 |
int ret;
|
|
|
9070b3 |
|
|
|
9070b3 |
- if ((from_path_canon = do_realpath(from, from_path)) == NULL) {
|
|
|
9070b3 |
+ if ((from_path_canon = do_realpath(from, from_path, 0)) == NULL) {
|
|
|
9070b3 |
error("Unable to canonicalize path \"%s\"", from_path);
|
|
|
9070b3 |
return -1;
|
|
|
9070b3 |
}
|
|
|
9070b3 |
diff -up openssh-8.7p1/sftp-client.h.scp-sftpdirs openssh-8.7p1/sftp-client.h
|
|
|
9070b3 |
--- openssh-8.7p1/sftp-client.h.scp-sftpdirs 2021-08-20 06:03:49.000000000 +0200
|
|
|
9070b3 |
+++ openssh-8.7p1/sftp-client.h 2022-02-07 12:31:07.410740433 +0100
|
|
|
9070b3 |
@@ -111,7 +111,7 @@ int do_fsetstat(struct sftp_conn *, cons
|
|
|
9070b3 |
int do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
|
|
|
9070b3 |
|
|
|
9070b3 |
/* Canonicalise 'path' - caller must free result */
|
|
|
9070b3 |
-char *do_realpath(struct sftp_conn *, const char *);
|
|
|
9070b3 |
+char *do_realpath(struct sftp_conn *, const char *, int);
|
|
|
9070b3 |
|
|
|
9070b3 |
/* Canonicalisation with tilde expansion (requires server extension) */
|
|
|
9070b3 |
char *do_expand_path(struct sftp_conn *, const char *);
|
|
|
9070b3 |
@@ -159,7 +159,7 @@ int do_upload(struct sftp_conn *, const
|
|
|
9070b3 |
* times if 'pflag' is set
|
|
|
9070b3 |
*/
|
|
|
9070b3 |
int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
|
|
|
9070b3 |
- int, int);
|
|
|
9070b3 |
+ int, int, int);
|
|
|
9070b3 |
|
|
|
9070b3 |
/*
|
|
|
9070b3 |
* Download a 'from_path' from the 'from' connection and upload it to
|
|
|
9070b3 |
diff -up openssh-8.7p1/sftp.c.scp-sftpdirs openssh-8.7p1/sftp.c
|
|
|
9070b3 |
--- openssh-8.7p1/sftp.c.scp-sftpdirs 2021-08-20 06:03:49.000000000 +0200
|
|
|
9070b3 |
+++ openssh-8.7p1/sftp.c 2022-02-07 12:31:07.411740442 +0100
|
|
|
9070b3 |
@@ -760,7 +760,7 @@ process_put(struct sftp_conn *conn, cons
|
|
|
9070b3 |
if (globpath_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) {
|
|
|
9070b3 |
if (upload_dir(conn, g.gl_pathv[i], abs_dst,
|
|
|
9070b3 |
pflag || global_pflag, 1, resume,
|
|
|
9070b3 |
- fflag || global_fflag, 0) == -1)
|
|
|
9070b3 |
+ fflag || global_fflag, 0, 0) == -1)
|
|
|
9070b3 |
err = -1;
|
|
|
9070b3 |
} else {
|
|
|
9070b3 |
if (do_upload(conn, g.gl_pathv[i], abs_dst,
|
|
|
9070b3 |
@@ -1577,7 +1577,7 @@ parse_dispatch_command(struct sftp_conn
|
|
|
9070b3 |
if (path1 == NULL || *path1 == '\0')
|
|
|
9070b3 |
path1 = xstrdup(startdir);
|
|
|
9070b3 |
path1 = make_absolute(path1, *pwd);
|
|
|
9070b3 |
- if ((tmp = do_realpath(conn, path1)) == NULL) {
|
|
|
9070b3 |
+ if ((tmp = do_realpath(conn, path1, 0)) == NULL) {
|
|
|
9070b3 |
err = 1;
|
|
|
9070b3 |
break;
|
|
|
9070b3 |
}
|
|
|
9070b3 |
@@ -2160,7 +2160,7 @@ interactive_loop(struct sftp_conn *conn,
|
|
|
9070b3 |
}
|
|
|
9070b3 |
#endif /* USE_LIBEDIT */
|
|
|
9070b3 |
|
|
|
9070b3 |
- remote_path = do_realpath(conn, ".");
|
|
|
9070b3 |
+ remote_path = do_realpath(conn, ".", 0);
|
|
|
9070b3 |
if (remote_path == NULL)
|
|
|
9070b3 |
fatal("Need cwd");
|
|
|
9070b3 |
startdir = xstrdup(remote_path);
|