Skip to content

Commit

Permalink
add test for connecting to a unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Dec 30, 2023
1 parent 5c7407f commit 8ce8cde
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions regress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ clean:
distclean: clean

LTESTS= connect \
connect-unix \
proxy-connect \
sshfp-connect \
connect-privsep \
Expand Down
43 changes: 43 additions & 0 deletions regress/connect-unix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
tid="simple connect"

SCRIPT_DIR=`dirname $0`

start_sshd_unix()
{
${SUDO} env NC=${NC} SSHD=${SSHD} OBJ=${OBJ} ${SCRIPT_DIR}/sshd-unix.sh&

trace "wait for sshd-unix"
i=0;
while [ ! -f ${OBJ}/sshd-unix.pid -a $i -lt 10 ]; do
i=`expr $i + 1`
sleep $i
done

i=0;
while [ ! -S ${OBJ}/sshd.socket -a $i -lt 10 ]; do
i=`expr $i + 1`
sleep $i
done

test -S ${OBJ}/sshd.socket || fatal "no sshd.socket created"
chmod 0666 ${OBJ}/sshd.socket
}

stop_sshd_unix()
{
kill `cat ${OBJ}/sshd-unix.pid`
}


# create client config
sed -e /Hostname/d -e /HostKeyAlias/d -e /Port/d -e /StrictHostKeyChecking/d < $OBJ/ssh_config > $OBJ/ssh_unix_config
echo StrictHostKeyChecking=no >> $OBJ/ssh_unix_config

start_sshd_unix

trace "direct unix socket connect"
${SSH} -F ${OBJ}/ssh_unix_config ${OBJ}/sshd.socket true
if [ $? -ne 0 ]; then
fail "ssh direct connect unix failed"
fi

13 changes: 13 additions & 0 deletions regress/sshd-unix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# create an ssh server listening on a Unix socket, using netcat

run_sshd_unix() {
# see example in netcat man page, modified here for a unix socket
rm -f ${OBJ}/sshd.fifo && mkfifo ${OBJ}/sshd.fifo
rm -f ${OBJ}/sshd.socket
touch ${OBJ}/sshd-unix.log ; chmod 0644 ${OBJ}/sshd-unix.log
cat ${OBJ}/sshd.fifo | ${SSHD} -i -f ${OBJ}/sshd_config "$@" -E ${OBJ}/sshd-unix.log | ${NC} -l -U ${OBJ}/sshd.socket > ${OBJ}/sshd.fifo
}

run_sshd_unix

0 comments on commit 8ce8cde

Please sign in to comment.