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