summaryrefslogtreecommitdiff
path: root/regress/usr.bin/ssh/agent-ptrace.sh
blob: 6695fd094dd8e3dc1fad41ab76de98e894bdd09f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#	$OpenBSD: agent-ptrace.sh,v 1.5 2022/04/22 05:08:43 anton Exp $
#	Placed in the Public Domain.

tid="disallow agent ptrace attach"

if [ "x$USER" = "xroot" ]; then
	skip "running as root"
fi

if ! which gdb >/dev/null 2>&1; then
	skip "gdb not found"
fi

trace "start agent"
eval `${SSHAGENT} ${EXTRA_AGENT_ARGS} -s` > /dev/null
r=$?
if [ $r -ne 0 ]; then
	fail "could not start ssh-agent: exit code $r"
else
	# ls -l ${SSH_AUTH_SOCK}
	gdb ${SSHAGENT} ${SSH_AGENT_PID} > ${OBJ}/gdb.out 2>&1 << EOF
		quit
EOF
	r=$?
	if [ $r -ne 0 ]; then
		fail "gdb failed: exit code $r"
	fi
	grep -q 'ptrace: Operation not permitted.' ${OBJ}/gdb.out
	r=$?
	rm -f ${OBJ}/gdb.out
	if [ $r -ne 0 ]; then
		fail "ptrace succeeded?: exit code $r"
	fi

	trace "kill agent"
	${SSHAGENT} -k > /dev/null
fi