blob: 5d7f73291dc801a5415708c271bf53f9fde24f6d [file] [log] [blame]
Damien Millerd666d8e2008-03-12 23:58:55 +11001# $OpenBSD: agent-getpeereid.sh,v 1.4 2007/11/25 15:35:09 jmc Exp $
Damien Miller8b9cde72003-01-22 17:53:16 +11002# Placed in the Public Domain.
3
4tid="disallow agent attach from other uid"
5
6UNPRIV=nobody
7ASOCK=${OBJ}/agent
Damien Millerd666d8e2008-03-12 23:58:55 +11008SSH_AUTH_SOCK=/nonexistent
Damien Miller8b9cde72003-01-22 17:53:16 +11009
Darren Tucker9869ab32007-03-21 21:45:48 +110010if grep "#undef.*HAVE_GETPEEREID" ${BUILDDIR}/config.h >/dev/null 2>&1 && \
11 grep "#undef.*HAVE_GETPEERUCRED" ${BUILDDIR}/config.h >/dev/null && \
12 grep "#undef.*HAVE_SO_PEERCRED" ${BUILDDIR}/config.h >/dev/null
Darren Tucker2297ac42003-09-04 13:49:30 +100013then
14 echo "skipped (not supported on this platform)"
15 exit 0
16fi
Damien Miller7b1877c2006-07-24 15:31:41 +100017if [ -z "$SUDO" ]; then
18 echo "skipped: need SUDO to switch to uid $UNPRIV"
19 exit 0
20fi
21
Darren Tucker2297ac42003-09-04 13:49:30 +100022
Damien Miller8b9cde72003-01-22 17:53:16 +110023trace "start agent"
24eval `${SSHAGENT} -s -a ${ASOCK}` > /dev/null
25r=$?
26if [ $r -ne 0 ]; then
27 fail "could not start ssh-agent: exit code $r"
28else
29 chmod 644 ${SSH_AUTH_SOCK}
30
31 ssh-add -l > /dev/null 2>&1
32 r=$?
33 if [ $r -ne 1 ]; then
34 fail "ssh-add failed with $r != 1"
35 fi
36
Damien Miller27a0dfa2006-01-31 22:02:16 +110037 < /dev/null ${SUDO} -S -u ${UNPRIV} ssh-add -l > /dev/null 2>&1
Damien Miller8b9cde72003-01-22 17:53:16 +110038 r=$?
39 if [ $r -lt 2 ]; then
40 fail "ssh-add did not fail for ${UNPRIV}: $r < 2"
41 fi
42
43 trace "kill agent"
44 ${SSHAGENT} -k > /dev/null
45fi
46
47rm -f ${OBJ}/agent