1# $OpenBSD: agent-getpeereid.sh,v 1.5 2013/05/17 10:33:09 dtucker Exp $ 2# Placed in the Public Domain. 3 4tid="disallow agent attach from other uid" 5 6UNPRIV=nobody 7ASOCK=${OBJ}/agent 8SSH_AUTH_SOCK=/nonexistent 9 10if [ -z "$SUDO" ]; then 11 fatal "need SUDO to switch to uid $UNPRIV, test won't work without" 12fi 13 14trace "start agent" 15eval `${SSHAGENT} -s -a ${ASOCK}` > /dev/null 16r=$? 17if [ $r -ne 0 ]; then 18 fail "could not start ssh-agent: exit code $r" 19else 20 chmod 644 ${SSH_AUTH_SOCK} 21 22 ssh-add -l > /dev/null 2>&1 23 r=$? 24 if [ $r -ne 1 ]; then 25 fail "ssh-add failed with $r != 1" 26 fi 27 28 < /dev/null ${SUDO} -S -u ${UNPRIV} ssh-add -l 2>/dev/null 29 r=$? 30 if [ $r -lt 2 ]; then 31 fail "ssh-add did not fail for ${UNPRIV}: $r < 2" 32 fi 33 34 trace "kill agent" 35 ${SSHAGENT} -k > /dev/null 36fi 37 38rm -f ${OBJ}/agent 39