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