xref: /freebsd/crypto/openssh/regress/agent-ptrace.sh (revision 5f4c09dd85bff675e0ca63c55ea3c517e0fddfcc)
1#	$OpenBSD: agent-ptrace.sh,v 1.5 2022/04/22 05:08:43 anton 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}
41	trap "$SUDO chown ${USER} ${SSHAGENT}; $SUDO chmod 755 ${SSHAGENT}" 0
42fi
43
44trace "start agent"
45eval `${SSHAGENT} ${EXTRA_AGENT_ARGS} -s` > /dev/null
46r=$?
47if [ $r -ne 0 ]; then
48	fail "could not start ssh-agent: exit code $r"
49else
50	# ls -l ${SSH_AUTH_SOCK}
51	gdb ${SSHAGENT} ${SSH_AGENT_PID} > ${OBJ}/gdb.out 2>&1 << EOF
52		quit
53EOF
54	r=$?
55	if [ $r -ne 0 ]; then
56		fail "gdb failed: exit code $r"
57	fi
58	egrep 'Operation not permitted.|Permission denied.|Invalid argument.|Unable to access task|Inappropriate ioctl for device.' >/dev/null ${OBJ}/gdb.out
59	r=$?
60	rm -f ${OBJ}/gdb.out
61	if [ $r -ne 0 ]; then
62		fail "ptrace succeeded?: exit code $r"
63	fi
64
65	trace "kill agent"
66	${SSHAGENT} -k > /dev/null
67fi
68