rcolebaugh / rpms / openssh

Forked from rpms/openssh 2 years ago
Clone

Blame SOURCES/openssh-8.7p1-recursive-scp.patch

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