xref: /freebsd/crypto/openssh/regress/agent-getpeereid.sh (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1#	$OpenBSD: agent-getpeereid.sh,v 1.3 2006/07/06 12:01:53 grunk Exp $
2#	Placed in the Public Domain.
3
4tid="disallow agent attach from other uid"
5
6UNPRIV=nobody
7ASOCK=${OBJ}/agent
8SSH_AUTH_SOCK=/nonexistant
9
10if grep "#undef.*HAVE_GETPEEREID" ${BUILDDIR}/config.h >/dev/null 2>&1
11then
12	echo "skipped (not supported on this platform)"
13	exit 0
14fi
15if [ -z "$SUDO" ]; then
16	echo "skipped: need SUDO to switch to uid $UNPRIV"
17	exit 0
18fi
19
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 > /dev/null 2>&1
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