xref: /openbsd/regress/usr.bin/ssh/agent-ptrace.sh (revision 5dea098c)
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 [ "x$USER" = "xroot" ]; then
7	skip "running as root"
8fi
9
10if ! which gdb >/dev/null 2>&1; then
11	skip "gdb not found"
12fi
13
14trace "start agent"
15eval `${SSHAGENT} ${EXTRA_AGENT_ARGS} -s` > /dev/null
16r=$?
17if [ $r -ne 0 ]; then
18	fail "could not start ssh-agent: exit code $r"
19else
20	# ls -l ${SSH_AUTH_SOCK}
21	gdb ${SSHAGENT} ${SSH_AGENT_PID} > ${OBJ}/gdb.out 2>&1 << EOF
22		quit
23EOF
24	r=$?
25	if [ $r -ne 0 ]; then
26		fail "gdb failed: exit code $r"
27	fi
28	grep -q 'ptrace: Operation not permitted.' ${OBJ}/gdb.out
29	r=$?
30	rm -f ${OBJ}/gdb.out
31	if [ $r -ne 0 ]; then
32		fail "ptrace succeeded?: exit code $r"
33	fi
34
35	trace "kill agent"
36	${SSHAGENT} -k > /dev/null
37fi
38