Check if we can copy sshd or need to use sudo to do so during reexec
authordtucker <dtucker@openbsd.org>
Thu, 19 Jan 2023 07:53:45 +0000 (07:53 +0000)
committerdtucker <dtucker@openbsd.org>
Thu, 19 Jan 2023 07:53:45 +0000 (07:53 +0000)
test. Skip test if neither can work.  Patch from anton@, tweaks from me.

regress/usr.bin/ssh/reexec.sh

index 52342fe..95c0dfd 100644 (file)
@@ -1,4 +1,4 @@
-#      $OpenBSD: reexec.sh,v 1.12 2017/08/07 03:52:55 dtucker Exp $
+#      $OpenBSD: reexec.sh,v 1.13 2023/01/19 07:53:45 dtucker Exp $
 #      Placed in the Public Domain.
 
 tid="reexec tests"
@@ -9,7 +9,11 @@ SSHD_COPY=$OBJ/sshd
 # Start a sshd and then delete it
 start_sshd_copy ()
 {
-       cp $SSHD_ORIG $SSHD_COPY
+       if [ -r "$SSHD_ORIG" ]; then
+               cp "$SSHD_ORIG" "$SSHD_COPY"
+       elif [ -z "$SUDO" ] || ! $SUDO cp "$SSHD_ORIG" "$SSHD_COPY"; then
+               skip "Cannot copy sshd."
+       fi
        SSHD=$SSHD_COPY
        start_sshd
        SSHD=$SSHD_ORIG
@@ -43,7 +47,7 @@ cp $OBJ/sshd_config.orig $OBJ/sshd_config
 verbose "test reexec fallback"
 
 start_sshd_copy
-rm -f $SSHD_COPY
+$SUDO rm -f $SSHD_COPY
 
 copy_tests