1# $OpenBSD: agent-ptrace.sh,v 1.2 2014/02/27 21:21:25 djm Exp $ 2# Placed in the Public Domain. 3 4tid="disallow agent ptrace attach" 5 6if have_prog uname ; then 7 case `uname` in 8 AIX|CYGWIN*|OSF1) 9 echo "skipped (not supported on this platform)" 10 exit 0 11 ;; 12 esac 13fi 14 15if have_prog gdb ; then 16 : ok 17else 18 echo "skipped (gdb not found)" 19 exit 0 20fi 21 22if $OBJ/setuid-allowed ${SSHAGENT} ; then 23 : ok 24else 25 echo "skipped (${SSHAGENT} is mounted on a no-setuid filesystem)" 26 exit 0 27fi 28 29if test -z "$SUDO" ; then 30 echo "skipped (SUDO not set)" 31 exit 0 32else 33 $SUDO chown 0 ${SSHAGENT} 34 $SUDO chgrp 0 ${SSHAGENT} 35 $SUDO chmod 2755 ${SSHAGENT} 36fi 37 38trace "start agent" 39eval `${SSHAGENT} -s` > /dev/null 40r=$? 41if [ $r -ne 0 ]; then 42 fail "could not start ssh-agent: exit code $r" 43else 44 # ls -l ${SSH_AUTH_SOCK} 45 gdb ${SSHAGENT} ${SSH_AGENT_PID} > ${OBJ}/gdb.out 2>&1 << EOF 46 quit 47EOF 48 r=$? 49 if [ $r -ne 0 ]; then 50 fail "gdb failed: exit code $r" 51 fi 52 egrep 'ptrace: Operation not permitted.|procfs:.*Permission denied.|ttrace.*Permission denied.|procfs:.*: Invalid argument.|Unable to access task ' >/dev/null ${OBJ}/gdb.out 53 r=$? 54 rm -f ${OBJ}/gdb.out 55 if [ $r -ne 0 ]; then 56 fail "ptrace succeeded?: exit code $r" 57 fi 58 59 trace "kill agent" 60 ${SSHAGENT} -k > /dev/null 61fi 62