From: djm@openbsd.org Date: Wed, 18 Feb 2026 03:04:12 +0000 (+0000) Subject: upstream: same treatment for remote/remote copies (i.e. scp -3): X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84206bde8adbef2dfe4f5b97dd23399827015333;p=thirdparty%2Fopenssh-portable.git upstream: same treatment for remote/remote copies (i.e. scp -3): adjust permissions on destination directory only if we created it or -p was requested. bz3925 OpenBSD-Commit-ID: d977006df7b8330e06ceaa319383b347f1aca3ef --- diff --git a/sftp-client.c b/sftp-client.c index ab33bdb8a..7cc20f34d 100644 --- a/sftp-client.c +++ b/sftp-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sftp-client.c,v 1.183 2026/02/18 02:59:27 djm Exp $ */ +/* $OpenBSD: sftp-client.c,v 1.184 2026/02/18 03:04:12 djm Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller * @@ -2693,7 +2693,7 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, int depth, Attrib *dirattrib, int preserve_flag, int print_flag, int follow_link_flag) { - int i, ret = 0; + int i, ret = 0, created = 0; SFTP_DIRENT **dir_entries; char *filename, *new_from_path = NULL, *new_to_path = NULL; mode_t mode = 0777; @@ -2739,7 +2739,9 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, * the path already existed and is a directory. Ensure we can * write to the directory we create for the duration of the transfer. */ - if (sftp_mkdir(to, to_path, &curdir, 0) != 0) { + if (sftp_mkdir(to, to_path, &curdir, 0) == 0) + created = 1; + else { if (sftp_stat(to, to_path, 0, &newdir) != 0) return -1; if (!S_ISDIR(newdir.perm)) { @@ -2801,7 +2803,8 @@ crossload_dir_internal(struct sftp_conn *from, struct sftp_conn *to, free(new_to_path); free(new_from_path); - sftp_setstat(to, to_path, &curdir); + if (created || preserve_flag) + sftp_setstat(to, to_path, &curdir); sftp_free_dirents(dir_entries);