xref: /freebsd/crypto/openssh/regress/agent-ptrace.sh (revision 8ef24a0d4b28fe230e20637f56869cc4148cd2ca)
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 [ "x$USER" = "xroot" ]; then
16	echo "Skipped: running as root"
17	exit 0
18fi
19
20if have_prog gdb ; then
21	: ok
22else
23	echo "skipped (gdb not found)"
24	exit 0
25fi
26
27if $OBJ/setuid-allowed ${SSHAGENT} ; then
28	: ok
29else
30	echo "skipped (${SSHAGENT} is mounted on a no-setuid filesystem)"
31	exit 0
32fi
33
34if test -z "$SUDO" ; then
35	echo "skipped (SUDO not set)"
36	exit 0
37else
38	$SUDO chown 0 ${SSHAGENT}
39	$SUDO chgrp 0 ${SSHAGENT}
40	$SUDO chmod 2755 ${SSHAGENT}
41fi
42
43trace "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
53	r=$?
54	if [ $r -ne 0 ]; then
55		fail "gdb failed: exit code $r"
56	fi
57	egrep 'ptrace: Operation not permitted.|procfs:.*Permission denied.|ttrace.*Permission denied.|procfs:.*: Invalid argument.|Unable to access task ' >/dev/null ${OBJ}/gdb.out
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
66fi
67