@@ -12,7 +12,9 @@ if [ -z "$1" ] || [ -z "$2" ]; then
1212 exit 1
1313fi
1414
15- PWD=` pwd`
15+ # Not PWD: that is bash's own variable and the shell rewrites it on every cd,
16+ # so a saved copy is gone by the time it is read.
17+ TESTDIR=` pwd`
1618USER=` whoami`
1719TEST_HOST=" $1 "
1820
@@ -46,15 +48,24 @@ if [ -f ./log.txt ]; then
4648fi
4749touch log.txt
4850
49- TEST_CLIENT=" ../../../examples/client/client"
50- SFTP_CLIENT=" ../../../examples/sftpclient/wolfsftp"
51- SCP_CLIENT=" ../../../examples/scpclient/wolfscp"
52- PRIVATE_KEY=" ../../../keys/hansel-key-ecc.der"
53- PUBLIC_KEY=" ../../../keys/hansel-key-ecc.pub"
51+ ROOT=" $TESTDIR /../../.."
52+ TEST_CLIENT=" $ROOT /examples/client/client"
53+ SFTP_CLIENT=" $ROOT /examples/sftpclient/wolfsftp"
54+ SCP_CLIENT=" $ROOT /examples/scpclient/wolfscp"
55+
56+ # Absolute, and that matters. Unlike the other sshd tests this one runs from
57+ # its own directory rather than the repository root, and the example clients
58+ # call ChangeToWolfSshRoot() before parsing anything, so every path they are
59+ # handed is resolved from the repository root instead of here. Relative paths
60+ # were read as <root>/../../../keys/... and the clients died at "Error setting
61+ # private key" without ever opening a socket.
62+ PRIVATE_KEY=" $ROOT /keys/hansel-key-ecc.der"
63+ PUBLIC_KEY=" $ROOT /keys/hansel-key-ecc.pub"
5464
5565# Small payload for the sftp/scp transfers. The connection dies at the failed
56- # drop long before any data moves, so the contents do not matter.
57- PAYLOAD=" privdrop_payload.txt"
66+ # drop long before any data moves, so the contents do not matter. Absolute for
67+ # the same reason: the sftp client reads it after the chdir above.
68+ PAYLOAD=" $TESTDIR /privdrop_payload.txt"
5869echo " privdrop" > " $PAYLOAD "
5970
6071source ./start_sshd.sh
@@ -68,16 +79,17 @@ PasswordAuthentication yes
6879PermitEmptyPasswords no
6980UsePrivilegeSeparation no
7081UseDNS no
71- HostKey $PWD /../../.. /keys/server-key.pem
72- AuthorizedKeysFile $PWD /authorized_keys_test
82+ HostKey $ROOT /keys/server-key.pem
83+ AuthorizedKeysFile $TESTDIR /authorized_keys_test
7384EOF
7485
7586# Preload and arm the interposer via SSHD_ENV (start_sshd.sh passes it through
7687# "sudo env"). "UsePrivilegeSeparation no" is the worst case: old fallback = noop.
7788SSHD_ENV=" LD_PRELOAD=$PRELOAD_LIB WOLFSSHD_FAULT_PRIVDROP=1"
7889export SSHD_BIN SSHD_ENV
7990
80- # Teardown on every exit path; log.txt is kept for debugging like the other tests.
91+ # Teardown on every exit path; log.txt and the client logs are kept for
92+ # debugging like the other tests, and removed on the success path below.
8193cleanup () {
8294 stop_wolfsshd
8395 rm -f sshd_config_test_privdrop " $PAYLOAD " " $PRELOAD_LIB "
94106
95107DEADLINE=30
96108
109+ # Every failure below is ambiguous without the client's own output.
110+ client_said () {
111+ echo " client said: ` tail -n 3 " $CLIENT_LOG " | tr ' \n' ' |' ` "
112+ echo " full client output in $CLIENT_LOG "
113+ }
114+
97115# Drives one client; the connection dies, so its exit status is not checked.
98116# Counts are per-call deltas since all three subsystems share the one log.
99117check_subsystem () {
@@ -104,7 +122,11 @@ check_subsystem() {
104122 BEFORE_CLOSE=` grep -c " Attempting to close down connection" log.txt`
105123 BEFORE_SPAWN=` grep -c " Spawned new process" log.txt`
106124
107- " $@ " > /dev/null 2>&1 &
125+ # Keep the client's output. Its exit status is meaningless here (the
126+ # connection is killed under it), but if it dies before opening a socket
127+ # the daemon-side counters below stay flat and look like a daemon fault.
128+ CLIENT_LOG=" $TESTDIR /privdrop_client_$LABEL .log"
129+ " $@ " > " $CLIENT_LOG " 2>&1 &
108130 CLIENT_PID=$!
109131
110132 # Wait for the connection child to fork and hit the failed drop, then take
@@ -128,7 +150,12 @@ check_subsystem() {
128150 wait $CLIENT_PID > /dev/null 2>&1
129151
130152 if [ -z " $CHILD " ]; then
131- echo " FAIL: $LABEL never reached the privilege drop"
153+ if [ " $AFTER_SPAWN " -eq " $BEFORE_SPAWN " ]; then
154+ echo " FAIL: $LABEL daemon never forked a connection process"
155+ else
156+ echo " FAIL: $LABEL never reached the privilege drop"
157+ fi
158+ client_said
132159 exit 1
133160 fi
134161
@@ -141,6 +168,7 @@ check_subsystem() {
141168 done
142169 if ps -p " $CHILD " > /dev/null 2>&1 ; then
143170 echo " FAIL: $LABEL connection process still running after ${DEADLINE} s"
171+ client_said
144172 exit 1
145173 fi
146174
@@ -149,6 +177,7 @@ check_subsystem() {
149177 AFTER_CLOSE=` grep -c " Attempting to close down connection" log.txt`
150178 if [ " $AFTER_CLOSE " -gt " $BEFORE_CLOSE " ]; then
151179 echo " FAIL: $LABEL handler continued after a failed privilege drop"
180+ client_said
152181 exit 1
153182 fi
154183
@@ -170,7 +199,9 @@ check_subsystem "sftp" \
170199# SCP_Subsystem.
171200check_subsystem " scp" \
172201 " $SCP_CLIENT " -u " $USER " -i " $PRIVATE_KEY " -j " $PUBLIC_KEY " \
173- -S" $PWD /$PAYLOAD :." -H " $TEST_HOST " -p " $TEST_PORT "
202+ -S" $PAYLOAD :." -H " $TEST_HOST " -p " $TEST_PORT "
203+
204+ rm -f " $TESTDIR " /privdrop_client_* .log
174205
175206echo " PASS: all subsystems terminate on privilege-drop failure"
176207exit 0
0 commit comments