xref: /freebsd/crypto/openssh/regress/agent-getpeereid.sh (revision ce3adf4362fcca6a43e500b2531f0038adbfbd21)
1*ce3adf43SDag-Erling Smørgrav#	$OpenBSD: agent-getpeereid.sh,v 1.5 2013/05/17 10:33:09 dtucker Exp $
2*ce3adf43SDag-Erling Smørgrav#	Placed in the Public Domain.
3*ce3adf43SDag-Erling Smørgrav
4*ce3adf43SDag-Erling Smørgravtid="disallow agent attach from other uid"
5*ce3adf43SDag-Erling Smørgrav
6*ce3adf43SDag-Erling SmørgravUNPRIV=nobody
7*ce3adf43SDag-Erling SmørgravASOCK=${OBJ}/agent
8*ce3adf43SDag-Erling SmørgravSSH_AUTH_SOCK=/nonexistent
9*ce3adf43SDag-Erling Smørgrav
10*ce3adf43SDag-Erling Smørgravif config_defined HAVE_GETPEEREID HAVE_GETPEERUCRED HAVE_SO_PEERCRED ; then
11*ce3adf43SDag-Erling Smørgrav	:
12*ce3adf43SDag-Erling Smørgravelse
13*ce3adf43SDag-Erling Smørgrav	echo "skipped (not supported on this platform)"
14*ce3adf43SDag-Erling Smørgrav	exit 0
15*ce3adf43SDag-Erling Smørgravfi
16*ce3adf43SDag-Erling Smørgravif [ -z "$SUDO" ]; then
17*ce3adf43SDag-Erling Smørgrav	echo "skipped: need SUDO to switch to uid $UNPRIV"
18*ce3adf43SDag-Erling Smørgrav	exit 0
19*ce3adf43SDag-Erling Smørgravfi
20*ce3adf43SDag-Erling Smørgrav
21*ce3adf43SDag-Erling Smørgravtrace "start agent"
22*ce3adf43SDag-Erling Smørgraveval `${SSHAGENT} -s -a ${ASOCK}` > /dev/null
23*ce3adf43SDag-Erling Smørgravr=$?
24*ce3adf43SDag-Erling Smørgravif [ $r -ne 0 ]; then
25*ce3adf43SDag-Erling Smørgrav	fail "could not start ssh-agent: exit code $r"
26*ce3adf43SDag-Erling Smørgravelse
27*ce3adf43SDag-Erling Smørgrav	chmod 644 ${SSH_AUTH_SOCK}
28*ce3adf43SDag-Erling Smørgrav
29*ce3adf43SDag-Erling Smørgrav	ssh-add -l > /dev/null 2>&1
30*ce3adf43SDag-Erling Smørgrav	r=$?
31*ce3adf43SDag-Erling Smørgrav	if [ $r -ne 1 ]; then
32*ce3adf43SDag-Erling Smørgrav		fail "ssh-add failed with $r != 1"
33*ce3adf43SDag-Erling Smørgrav	fi
34*ce3adf43SDag-Erling Smørgrav
35*ce3adf43SDag-Erling Smørgrav	< /dev/null ${SUDO} -S -u ${UNPRIV} ssh-add -l 2>/dev/null
36*ce3adf43SDag-Erling Smørgrav	r=$?
37*ce3adf43SDag-Erling Smørgrav	if [ $r -lt 2 ]; then
38*ce3adf43SDag-Erling Smørgrav		fail "ssh-add did not fail for ${UNPRIV}: $r < 2"
39*ce3adf43SDag-Erling Smørgrav	fi
40*ce3adf43SDag-Erling Smørgrav
41*ce3adf43SDag-Erling Smørgrav	trace "kill agent"
42*ce3adf43SDag-Erling Smørgrav	${SSHAGENT} -k > /dev/null
43*ce3adf43SDag-Erling Smørgravfi
44*ce3adf43SDag-Erling Smørgrav
45*ce3adf43SDag-Erling Smørgravrm -f ${OBJ}/agent
46