Damien Miller | 7b1877c | 2006-07-24 15:31:41 +1000 | [diff] [blame] | 1 | # $OpenBSD: agent-getpeereid.sh,v 1.3 2006/07/06 12:01:53 grunk Exp $ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="disallow agent attach from other uid" |
| 5 | |
| 6 | UNPRIV=nobody |
| 7 | ASOCK=${OBJ}/agent |
| 8 | SSH_AUTH_SOCK=/nonexistant |
| 9 | |
Darren Tucker | 9869ab3 | 2007-03-21 21:45:48 +1100 | [diff] [blame] | 10 | if 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 Tucker | 2297ac4 | 2003-09-04 13:49:30 +1000 | [diff] [blame] | 13 | then |
| 14 | echo "skipped (not supported on this platform)" |
| 15 | exit 0 |
| 16 | fi |
Damien Miller | 7b1877c | 2006-07-24 15:31:41 +1000 | [diff] [blame] | 17 | if [ -z "$SUDO" ]; then |
| 18 | echo "skipped: need SUDO to switch to uid $UNPRIV" |
| 19 | exit 0 |
| 20 | fi |
| 21 | |
Darren Tucker | 2297ac4 | 2003-09-04 13:49:30 +1000 | [diff] [blame] | 22 | |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 23 | trace "start agent" |
| 24 | eval `${SSHAGENT} -s -a ${ASOCK}` > /dev/null |
| 25 | r=$? |
| 26 | if [ $r -ne 0 ]; then |
| 27 | fail "could not start ssh-agent: exit code $r" |
| 28 | else |
| 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 Miller | 27a0dfa | 2006-01-31 22:02:16 +1100 | [diff] [blame] | 37 | < /dev/null ${SUDO} -S -u ${UNPRIV} ssh-add -l > /dev/null 2>&1 |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 38 | 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 |
| 45 | fi |
| 46 | |
| 47 | rm -f ${OBJ}/agent |