From 625f6bc39840167dafb3bf5b6a3e18503ac986e8 Mon Sep 17 00:00:00 2001
From: "dtucker@openbsd.org" <dtucker@openbsd.org>
Date: Fri, 13 Jan 2023 04:47:34 +0000
Subject: [PATCH] upstream: Move scp path setting to a helper function.
The
 previous

commit to add scp to the test sshd's path causes the t-envpass test to
fail
when the test scp is given using a fully qualified path.  Put this in a
helper function and only call it from the scp tests.

OpenBSD-Regress-ID: 7533dc1c4265c1de716abb062957994195b36df4
Conflict:NA
Reference:https://anongit.mindrot.org/openssh.git/commit?id=625f6bc39840167dafb3bf5b6a3e18503ac986e8
---
 regress/multiplex.sh |  3 ++-
 regress/scp-uri.sh   |  4 +++-
 regress/scp.sh       |  4 +++-
 regress/scp3.sh      |  6 ++++--
 regress/test-exec.sh | 21 +++++++++++++--------
 5 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/regress/multiplex.sh b/regress/multiplex.sh
index 6317099..046194c 100644
--- a/regress/multiplex.sh
+++ b/regress/multiplex.sh
@@ -1,4 +1,4 @@
-#	$OpenBSD: multiplex.sh,v 1.34 2022/06/03 04:31:54 djm Exp $
+#	$OpenBSD: multiplex.sh,v 1.35 2023/01/13 04:47:34 dtucker Exp $
 #	Placed in the Public Domain.
 
 make_tmpdir
@@ -24,6 +24,7 @@ wait_for_mux_master_ready()
 	fatal "mux master never becomes ready"
 }
 
+maybe_add_scp_path_to_sshd
 start_sshd
 
 start_mux_master()
diff --git a/regress/scp-uri.sh b/regress/scp-uri.sh
index 20ac3c8..eacbd45 100644
--- a/regress/scp-uri.sh
+++ b/regress/scp-uri.sh
@@ -1,4 +1,4 @@
-#	$OpenBSD: scp-uri.sh,v 1.4 2021/08/10 03:35:45 djm Exp $
+#	$OpenBSD: scp-uri.sh,v 1.5 2023/01/13 04:47:34 dtucker Exp $
 #	Placed in the Public Domain.
 
 tid="scp-uri"
@@ -9,6 +9,8 @@ COPY2=${OBJ}/copy2
 DIR=${COPY}.dd
 DIR2=${COPY}.dd2
 
+maybe_add_scp_path_to_sshd
+
 SRC=`dirname ${SCRIPT}`
 cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
 chmod 755 ${OBJ}/scp-ssh-wrapper.scp
diff --git a/regress/scp.sh b/regress/scp.sh
index f47c594..ef4399e 100644
--- a/regress/scp.sh
+++ b/regress/scp.sh
@@ -1,4 +1,4 @@
-#	$OpenBSD: scp.sh,v 1.14 2022/05/15 23:48:07 djm Exp $
+#   $OpenBSD: scp.sh,v 1.18 2023/01/13 04:47:34 dtucker Exp $
 #	Placed in the Public Domain.
 
 tid="scp"
@@ -16,6 +16,8 @@ COPY2=${OBJ}/copy2
 DIR=${COPY}.dd
 DIR2=${COPY}.dd2
 
+maybe_add_scp_path_to_sshd
+
 SRC=`dirname ${SCRIPT}`
 cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
 chmod 755 ${OBJ}/scp-ssh-wrapper.scp
diff --git a/regress/scp3.sh b/regress/scp3.sh
index 47db47c..dfb2d2f 100644
--- a/regress/scp3.sh
+++ b/regress/scp3.sh
@@ -1,9 +1,9 @@
-#	$OpenBSD: scp3.sh,v 1.3 2021/08/10 03:35:45 djm Exp $
+#	$OpenBSD: scp3.sh,v 1.4 2023/01/13 04:47:34 dtucker Exp $
 #	Placed in the Public Domain.
 
 tid="scp3"
 
-#set -x
+set -x
 
 COPY2=${OBJ}/copy2
 DIR=${COPY}.dd
@@ -15,6 +15,8 @@ if [ $? -eq 1 ]; then
 	skip "No scp on remote path."
 fi
 
+maybe_add_scp_path_to_sshd
+
 SRC=`dirname ${SCRIPT}`
 cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
 chmod 755 ${OBJ}/scp-ssh-wrapper.scp
diff --git a/regress/test-exec.sh b/regress/test-exec.sh
index 7e311e8..df43f02 100644
--- a/regress/test-exec.sh
+++ b/regress/test-exec.sh
@@ -1,4 +1,4 @@
-#	$OpenBSD: test-exec.sh,v 1.92 2022/07/25 07:12:45 dtucker Exp $
+#	$OpenBSD: test-exec.sh,v 1.94 2023/01/13 04:47:34 dtucker Exp $
 #	Placed in the Public Domain.
 
 #SUDO=sudo
@@ -509,6 +509,18 @@ skip ()
 	exit $RESULT
 }
 
+maybe_add_scp_path_to_sshd ()
+{
+	# If we're testing a non-installed scp, add its directory to sshd's
+	# PATH so we can test it.  We don't do this for all tests as it
+	# breaks the SetEnv tests.
+	case "$SCP" in
+	/*)	PATH_WITH_SCP="`dirname $SCP`:$PATH"
+		echo "	SetEnv PATH='$PATH_WITH_SCP'" >>$OBJ/sshd_config
+		echo "	SetEnv PATH='$PATH_WITH_SCP'" >>$OBJ/sshd_proxy ;;
+	esac
+}
+
 RESULT=0
 PIDFILE=$OBJ/pidfile
 
@@ -529,13 +541,6 @@ cat << EOF > $OBJ/sshd_config
 	Subsystem	sftp	$SFTPSERVER
 EOF
 
-# If we're testing a non-installed scp, add its directory to sshd's PATH
-# so we can test it.
-case "$SCP" in
-/*)	PATH_WITH_SCP="`dirname $SCP`:$PATH"
-	echo "	SetEnv PATH='$PATH_WITH_SCP'" >>$OBJ/sshd_config ;;
-esac
-
 # This may be necessary if /usr/src and/or /usr/obj are group-writable,
 # but if you aren't careful with permissions then the unit tests could
 # be abused to locally escalate privileges.
-- 
2.23.0

