xref: /freebsd/crypto/openssh/regress/agent-getpeereid.sh (revision 19261079b74319502c6ffa1249920079f0f69a72)
1*19261079SEd Maste#	$OpenBSD: agent-getpeereid.sh,v 1.11 2019/11/26 23:43:10 djm Exp $
2ce3adf43SDag-Erling Smørgrav#	Placed in the Public Domain.
3ce3adf43SDag-Erling Smørgrav
4ce3adf43SDag-Erling Smørgravtid="disallow agent attach from other uid"
5ce3adf43SDag-Erling Smørgrav
6ce3adf43SDag-Erling SmørgravUNPRIV=nobody
7ce3adf43SDag-Erling SmørgravASOCK=${OBJ}/agent
8ce3adf43SDag-Erling SmørgravSSH_AUTH_SOCK=/nonexistent
9ce3adf43SDag-Erling Smørgrav
10ce3adf43SDag-Erling Smørgravif config_defined HAVE_GETPEEREID HAVE_GETPEERUCRED HAVE_SO_PEERCRED ; then
11ce3adf43SDag-Erling Smørgrav	:
12ce3adf43SDag-Erling Smørgravelse
13ce3adf43SDag-Erling Smørgrav	echo "skipped (not supported on this platform)"
14ce3adf43SDag-Erling Smørgrav	exit 0
15ce3adf43SDag-Erling Smørgravfi
16076ad2f8SDag-Erling Smørgravcase "x$SUDO" in
17076ad2f8SDag-Erling Smørgrav	xsudo) sudo=1;;
18*19261079SEd Maste	xdoas|xdoas\ *) ;;
19076ad2f8SDag-Erling Smørgrav	x)
20076ad2f8SDag-Erling Smørgrav		echo "need SUDO to switch to uid $UNPRIV"
2147dd1d1bSDag-Erling Smørgrav		echo SKIPPED
22076ad2f8SDag-Erling Smørgrav		exit 0 ;;
23076ad2f8SDag-Erling Smørgrav	*)
24076ad2f8SDag-Erling Smørgrav		echo "unsupported $SUDO - "doas" and "sudo" are allowed"
25076ad2f8SDag-Erling Smørgrav		exit 0 ;;
26076ad2f8SDag-Erling Smørgravesac
27ce3adf43SDag-Erling Smørgrav
28ce3adf43SDag-Erling Smørgravtrace "start agent"
29*19261079SEd Masteeval `${SSHAGENT} ${EXTRA_AGENT_ARGS} -s -a ${ASOCK}` > /dev/null
30ce3adf43SDag-Erling Smørgravr=$?
31ce3adf43SDag-Erling Smørgravif [ $r -ne 0 ]; then
32ce3adf43SDag-Erling Smørgrav	fail "could not start ssh-agent: exit code $r"
33ce3adf43SDag-Erling Smørgravelse
34ce3adf43SDag-Erling Smørgrav	chmod 644 ${SSH_AUTH_SOCK}
35ce3adf43SDag-Erling Smørgrav
36d93a896eSDag-Erling Smørgrav	${SSHADD} -l > /dev/null 2>&1
37ce3adf43SDag-Erling Smørgrav	r=$?
38ce3adf43SDag-Erling Smørgrav	if [ $r -ne 1 ]; then
39ce3adf43SDag-Erling Smørgrav		fail "ssh-add failed with $r != 1"
40ce3adf43SDag-Erling Smørgrav	fi
41076ad2f8SDag-Erling Smørgrav	if test -z "$sudo" ; then
42076ad2f8SDag-Erling Smørgrav		# doas
43d93a896eSDag-Erling Smørgrav		${SUDO} -n -u ${UNPRIV} ${SSHADD} -l 2>/dev/null
44076ad2f8SDag-Erling Smørgrav	else
45076ad2f8SDag-Erling Smørgrav		# sudo
46d93a896eSDag-Erling Smørgrav		< /dev/null ${SUDO} -S -u ${UNPRIV} ${SSHADD} -l 2>/dev/null
47076ad2f8SDag-Erling Smørgrav	fi
48ce3adf43SDag-Erling Smørgrav	r=$?
49ce3adf43SDag-Erling Smørgrav	if [ $r -lt 2 ]; then
50ce3adf43SDag-Erling Smørgrav		fail "ssh-add did not fail for ${UNPRIV}: $r < 2"
51ce3adf43SDag-Erling Smørgrav	fi
52ce3adf43SDag-Erling Smørgrav
53ce3adf43SDag-Erling Smørgrav	trace "kill agent"
54ce3adf43SDag-Erling Smørgrav	${SSHAGENT} -k > /dev/null
55ce3adf43SDag-Erling Smørgravfi
56ce3adf43SDag-Erling Smørgrav
57ce3adf43SDag-Erling Smørgravrm -f ${OBJ}/agent
58