Damien Miller | 834aeac | 2014-02-28 10:25:16 +1100 | [diff] [blame] | 1 | # $OpenBSD: agent-ptrace.sh,v 1.2 2014/02/27 21:21:25 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 ptrace attach" |
| 5 | |
Tim Rice | 23ee359 | 2003-09-11 22:32:17 -0700 | [diff] [blame] | 6 | if have_prog uname ; then |
Darren Tucker | 5569759 | 2003-09-04 13:55:25 +1000 | [diff] [blame] | 7 | case `uname` in |
Darren Tucker | b17035f | 2004-08-29 20:33:07 +1000 | [diff] [blame] | 8 | AIX|CYGWIN*|OSF1) |
Darren Tucker | 77d07e9 | 2003-09-04 22:06:16 +1000 | [diff] [blame] | 9 | echo "skipped (not supported on this platform)" |
Darren Tucker | 5569759 | 2003-09-04 13:55:25 +1000 | [diff] [blame] | 10 | exit 0 |
| 11 | ;; |
| 12 | esac |
| 13 | fi |
| 14 | |
djm@openbsd.org | 0097248 | 2015-09-11 04:55:01 +0000 | [diff] [blame] | 15 | if [ "x$USER" = "xroot" ]; then |
| 16 | echo "Skipped: running as root" |
| 17 | exit 0 |
| 18 | fi |
| 19 | |
Tim Rice | b7efb63 | 2003-09-12 11:20:32 -0700 | [diff] [blame] | 20 | if have_prog gdb ; then |
| 21 | : ok |
| 22 | else |
Darren Tucker | 5569759 | 2003-09-04 13:55:25 +1000 | [diff] [blame] | 23 | echo "skipped (gdb not found)" |
| 24 | exit 0 |
| 25 | fi |
| 26 | |
Damien Miller | 6d6fcd1 | 2013-12-08 15:53:28 +1100 | [diff] [blame] | 27 | if $OBJ/setuid-allowed ${SSHAGENT} ; then |
| 28 | : ok |
| 29 | else |
| 30 | echo "skipped (${SSHAGENT} is mounted on a no-setuid filesystem)" |
| 31 | exit 0 |
| 32 | fi |
| 33 | |
Darren Tucker | ea4c670 | 2003-10-21 22:27:08 +1000 | [diff] [blame] | 34 | if test -z "$SUDO" ; then |
| 35 | echo "skipped (SUDO not set)" |
| 36 | exit 0 |
| 37 | else |
Darren Tucker | be8a771 | 2003-11-03 22:52:52 +1100 | [diff] [blame] | 38 | $SUDO chown 0 ${SSHAGENT} |
| 39 | $SUDO chgrp 0 ${SSHAGENT} |
Darren Tucker | 2bdacad | 2003-10-21 23:12:37 +1000 | [diff] [blame] | 40 | $SUDO chmod 2755 ${SSHAGENT} |
Darren Tucker | ea4c670 | 2003-10-21 22:27:08 +1000 | [diff] [blame] | 41 | fi |
| 42 | |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 43 | trace "start agent" |
| 44 | eval `${SSHAGENT} -s` > /dev/null |
| 45 | r=$? |
| 46 | if [ $r -ne 0 ]; then |
| 47 | fail "could not start ssh-agent: exit code $r" |
| 48 | else |
| 49 | # ls -l ${SSH_AUTH_SOCK} |
| 50 | gdb ${SSHAGENT} ${SSH_AGENT_PID} > ${OBJ}/gdb.out 2>&1 << EOF |
| 51 | quit |
| 52 | EOF |
Tim Rice | 6f917ad | 2014-01-28 10:26:25 -0800 | [diff] [blame] | 53 | r=$? |
| 54 | if [ $r -ne 0 ]; then |
| 55 | fail "gdb failed: exit code $r" |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 56 | fi |
Damien Miller | fd3669e | 2011-01-17 11:20:18 +1100 | [diff] [blame] | 57 | egrep 'ptrace: Operation not permitted.|procfs:.*Permission denied.|ttrace.*Permission denied.|procfs:.*: Invalid argument.|Unable to access task ' >/dev/null ${OBJ}/gdb.out |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 58 | r=$? |
| 59 | rm -f ${OBJ}/gdb.out |
| 60 | if [ $r -ne 0 ]; then |
| 61 | fail "ptrace succeeded?: exit code $r" |
| 62 | fi |
| 63 | |
| 64 | trace "kill agent" |
| 65 | ${SSHAGENT} -k > /dev/null |
| 66 | fi |