blob: bb676d631574a8957b6e00bc3f82894b73915fe6 [file] [log] [blame]
Damien Miller834aeac2014-02-28 10:25:16 +11001# $OpenBSD: agent-ptrace.sh,v 1.2 2014/02/27 21:21:25 djm Exp $
Damien Miller8b9cde72003-01-22 17:53:16 +11002# Placed in the Public Domain.
3
4tid="disallow agent ptrace attach"
5
Tim Rice23ee3592003-09-11 22:32:17 -07006if have_prog uname ; then
Darren Tucker55697592003-09-04 13:55:25 +10007 case `uname` in
Darren Tuckerb17035f2004-08-29 20:33:07 +10008 AIX|CYGWIN*|OSF1)
Darren Tucker77d07e92003-09-04 22:06:16 +10009 echo "skipped (not supported on this platform)"
Darren Tucker55697592003-09-04 13:55:25 +100010 exit 0
11 ;;
12 esac
13fi
14
djm@openbsd.org00972482015-09-11 04:55:01 +000015if [ "x$USER" = "xroot" ]; then
16 echo "Skipped: running as root"
17 exit 0
18fi
19
Tim Riceb7efb632003-09-12 11:20:32 -070020if have_prog gdb ; then
21 : ok
22else
Darren Tucker55697592003-09-04 13:55:25 +100023 echo "skipped (gdb not found)"
24 exit 0
25fi
26
Damien Miller6d6fcd12013-12-08 15:53:28 +110027if $OBJ/setuid-allowed ${SSHAGENT} ; then
28 : ok
29else
30 echo "skipped (${SSHAGENT} is mounted on a no-setuid filesystem)"
31 exit 0
32fi
33
Darren Tuckerea4c6702003-10-21 22:27:08 +100034if test -z "$SUDO" ; then
35 echo "skipped (SUDO not set)"
36 exit 0
37else
Darren Tuckerbe8a7712003-11-03 22:52:52 +110038 $SUDO chown 0 ${SSHAGENT}
39 $SUDO chgrp 0 ${SSHAGENT}
Darren Tucker2bdacad2003-10-21 23:12:37 +100040 $SUDO chmod 2755 ${SSHAGENT}
Darren Tuckerea4c6702003-10-21 22:27:08 +100041fi
42
Damien Miller8b9cde72003-01-22 17:53:16 +110043trace "start agent"
44eval `${SSHAGENT} -s` > /dev/null
45r=$?
46if [ $r -ne 0 ]; then
47 fail "could not start ssh-agent: exit code $r"
48else
49 # ls -l ${SSH_AUTH_SOCK}
50 gdb ${SSHAGENT} ${SSH_AGENT_PID} > ${OBJ}/gdb.out 2>&1 << EOF
51 quit
52EOF
Tim Rice6f917ad2014-01-28 10:26:25 -080053 r=$?
54 if [ $r -ne 0 ]; then
55 fail "gdb failed: exit code $r"
Damien Miller8b9cde72003-01-22 17:53:16 +110056 fi
Damien Millerfd3669e2011-01-17 11:20:18 +110057 egrep 'ptrace: Operation not permitted.|procfs:.*Permission denied.|ttrace.*Permission denied.|procfs:.*: Invalid argument.|Unable to access task ' >/dev/null ${OBJ}/gdb.out
Damien Miller8b9cde72003-01-22 17:53:16 +110058 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
66fi