djm@openbsd.org | 01cfaa2 | 2017-01-06 02:51:16 +0000 | [diff] [blame] | 1 | # $OpenBSD: agent-getpeereid.sh,v 1.8 2017/01/06 02:51:16 djm 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 |
Damien Miller | d666d8e | 2008-03-12 23:58:55 +1100 | [diff] [blame] | 8 | SSH_AUTH_SOCK=/nonexistent |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 9 | |
Tim Rice | 6dfcd34 | 2011-01-16 22:53:56 -0800 | [diff] [blame] | 10 | if config_defined HAVE_GETPEEREID HAVE_GETPEERUCRED HAVE_SO_PEERCRED ; then |
| 11 | : |
| 12 | else |
Darren Tucker | 2297ac4 | 2003-09-04 13:49:30 +1000 | [diff] [blame] | 13 | echo "skipped (not supported on this platform)" |
| 14 | exit 0 |
| 15 | fi |
djm@openbsd.org | 07d5608 | 2016-05-03 14:41:04 +0000 | [diff] [blame] | 16 | case "x$SUDO" in |
| 17 | xsudo) sudo=1;; |
| 18 | xdoas) ;; |
| 19 | x) |
| 20 | echo "need SUDO to switch to uid $UNPRIV" |
| 21 | exit 0 ;; |
| 22 | *) |
| 23 | echo "unsupported $SUDO - "doas" and "sudo" are allowed" |
| 24 | exit 0 ;; |
| 25 | esac |
Damien Miller | 7b1877c | 2006-07-24 15:31:41 +1000 | [diff] [blame] | 26 | |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 27 | trace "start agent" |
| 28 | eval `${SSHAGENT} -s -a ${ASOCK}` > /dev/null |
| 29 | r=$? |
| 30 | if [ $r -ne 0 ]; then |
| 31 | fail "could not start ssh-agent: exit code $r" |
| 32 | else |
| 33 | chmod 644 ${SSH_AUTH_SOCK} |
| 34 | |
djm@openbsd.org | 01cfaa2 | 2017-01-06 02:51:16 +0000 | [diff] [blame] | 35 | ${SSHADD} -l > /dev/null 2>&1 |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 36 | r=$? |
| 37 | if [ $r -ne 1 ]; then |
| 38 | fail "ssh-add failed with $r != 1" |
| 39 | fi |
djm@openbsd.org | 07d5608 | 2016-05-03 14:41:04 +0000 | [diff] [blame] | 40 | if test -z "$sudo" ; then |
| 41 | # doas |
djm@openbsd.org | 01cfaa2 | 2017-01-06 02:51:16 +0000 | [diff] [blame] | 42 | ${SUDO} -n -u ${UNPRIV} ${SSHADD} -l 2>/dev/null |
djm@openbsd.org | 07d5608 | 2016-05-03 14:41:04 +0000 | [diff] [blame] | 43 | else |
| 44 | # sudo |
djm@openbsd.org | 01cfaa2 | 2017-01-06 02:51:16 +0000 | [diff] [blame] | 45 | < /dev/null ${SUDO} -S -u ${UNPRIV} ${SSHADD} -l 2>/dev/null |
djm@openbsd.org | 07d5608 | 2016-05-03 14:41:04 +0000 | [diff] [blame] | 46 | fi |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 47 | r=$? |
| 48 | if [ $r -lt 2 ]; then |
| 49 | fail "ssh-add did not fail for ${UNPRIV}: $r < 2" |
| 50 | fi |
| 51 | |
| 52 | trace "kill agent" |
| 53 | ${SSHAGENT} -k > /dev/null |
| 54 | fi |
| 55 | |
| 56 | rm -f ${OBJ}/agent |