xref: /openbsd-src/usr.bin/ssh/sshd-debug.sh (revision 3bb7d5b07cbbc4be7d8d558ecad5337362957cc0)
1#!/bin/sh
2
3# ssh-debug
4
5# A wrapper script around sshd to invoke when debugging to debug the
6#  work-in-progress versions of sshd-auth and sshd-session, instead
7# of debugging the installed ones that probably don't have the change
8# you are working on.
9#
10#	Placed in the Public Domain.
11
12unset DIR SSHD SSHD_AUTH SSHD_SESSION
13
14fatal() {
15	echo >&2 $@
16	exit 1
17}
18
19case "$0" in
20/*)			DIR="`dirname $0`"	;;
21./sshd-debug.sh)	DIR="`pwd`"		;;
22*)			echo "Need full path or working directory."; exit 1 ;;
23esac
24
25for i in sshd/obj/sshd sshd/sshd sshd; do
26	if [ -f "${DIR}/$i" ] && [ -x "${DIR}/$i" ]; then
27		SSHD="${DIR}/$i"
28	fi
29done
30[ -z "${SSHD}" ] && fatal "Could not find sshd"
31
32for i in sshd-auth/obj/sshd-auth sshd-auth/sshd-auth sshd-auth; do
33	if [ -f "${DIR}/$i" ] && [ -x "${DIR}/$i" ]; then
34		SSHD_AUTH="${DIR}/$i"
35	fi
36done
37[ -z "${SSHD_AUTH}" ] && fatal "Could not find sshd-auth"
38
39for i in sshd-session/obj/sshd-session sshd-session/sshd-session sshd-session; do
40	if [ -f "${DIR}/$i" ] && [ -x "${DIR}/$i" ]; then
41		SSHD_SESSION="${DIR}/$i"
42	fi
43done
44[ -z "${SSHD_SESSION}" ] && fatal "Could not find sshd-session"
45
46echo >&2 Debugging ${SSHD} auth ${SSHD_AUTH} session ${SSHD_SESSION}
47
48# Append SshdSessionPath and SshdAuthPath pointing to the build directory.
49# If you explicitly specify these in the command line, the first-match
50# keyword semantics will override these.
51exec "${SSHD}" $@ \
52    -oSshdAuthPath="${SSHD_AUTH}" -oSshdSessionPath="${SSHD_SESSION}"
53