2023-11-01 02:08:38 +00:00
|
|
|
# $OpenBSD: forcecommand.sh,v 1.7 2023/11/01 02:08:38 dtucker Exp $
|
2006-07-24 05:31:41 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="forced command"
|
|
|
|
|
|
|
|
cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
|
|
|
|
|
2023-11-01 00:29:46 +00:00
|
|
|
authorized_keys() {
|
|
|
|
cmd=$1
|
|
|
|
cp /dev/null $OBJ/authorized_keys_$USER
|
|
|
|
for t in ${SSH_KEYTYPES}; do
|
|
|
|
test -z "$cmd" || \
|
|
|
|
printf "command=\"$cmd\" " >>$OBJ/authorized_keys_$USER
|
|
|
|
cat $OBJ/$t.pub >> $OBJ/authorized_keys_$USER
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
trace "test config with sftp"
|
|
|
|
authorized_keys
|
|
|
|
rm -f $OBJ/ssh_proxy.tmp
|
|
|
|
echo "@get $OBJ/ssh_proxy $OBJ/ssh_proxy.tmp" | \
|
2023-11-01 02:08:38 +00:00
|
|
|
${SFTP} -S ${SSH} -b - -qF $OBJ/ssh_proxy somehost 2>/dev/null || \
|
2023-11-01 00:29:46 +00:00
|
|
|
fail "sftp failed"
|
|
|
|
test -f "$OBJ/ssh_proxy.tmp" || fail "sftp did not download file"
|
|
|
|
rm -f $OBJ/ssh_proxy.tmp
|
2006-07-24 05:31:41 +00:00
|
|
|
|
2017-04-30 23:34:55 +00:00
|
|
|
trace "forced command in key option"
|
2023-11-01 00:29:46 +00:00
|
|
|
authorized_keys true
|
2023-05-12 06:36:27 +00:00
|
|
|
${SSH} -F $OBJ/ssh_proxy somehost false || fail "forced command in key option"
|
2006-07-24 05:31:41 +00:00
|
|
|
|
2023-11-01 00:29:46 +00:00
|
|
|
authorized_keys false
|
2006-07-24 05:31:41 +00:00
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
|
|
|
echo "ForceCommand true" >> $OBJ/sshd_proxy
|
|
|
|
|
2017-04-30 23:34:55 +00:00
|
|
|
trace "forced command in sshd_config overrides key option"
|
2023-05-12 06:36:27 +00:00
|
|
|
${SSH} -F $OBJ/ssh_proxy somehost false || fail "forced command config"
|
2006-07-24 05:31:41 +00:00
|
|
|
|
2023-11-01 00:29:46 +00:00
|
|
|
authorized_keys
|
2006-07-24 05:31:41 +00:00
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
|
|
|
echo "ForceCommand false" >> $OBJ/sshd_proxy
|
2023-11-01 00:29:46 +00:00
|
|
|
|
|
|
|
trace "force command overriding subsystem"
|
|
|
|
echo "@get $OBJ/ssh_proxy $OBJ/ssh_proxy.tmp" | \
|
2023-11-01 02:08:38 +00:00
|
|
|
${SFTP} -S ${SSH} -F $OBJ/ssh_proxy -oLoglevel=quiet somehost && \
|
2023-11-01 00:29:46 +00:00
|
|
|
fail "sftp succeeded"
|
|
|
|
|
2006-07-24 05:31:41 +00:00
|
|
|
echo "Match User $USER" >> $OBJ/sshd_proxy
|
|
|
|
echo " ForceCommand true" >> $OBJ/sshd_proxy
|
|
|
|
|
2017-04-30 23:34:55 +00:00
|
|
|
trace "forced command with match"
|
2023-05-12 06:36:27 +00:00
|
|
|
${SSH} -F $OBJ/ssh_proxy somehost false || fail "forced command match"
|
2023-11-01 00:29:46 +00:00
|
|
|
|
|
|
|
trace "force command in match overriding subsystem"
|
|
|
|
echo "@get $OBJ/ssh_proxy $OBJ/ssh_proxy.tmp" | \
|
2023-11-01 02:08:38 +00:00
|
|
|
${SFTP} -S ${SSH} -F $OBJ/ssh_proxy -oLoglevel=quiet somehost && \
|
2023-11-01 00:29:46 +00:00
|
|
|
fail "sftp succeeded"
|
|
|
|
|
|
|
|
trace "force command to sftpserver"
|
|
|
|
grep -vi subsystem $OBJ/sshd_proxy_bak > $OBJ/sshd_proxy
|
|
|
|
echo "Subsystem sftp /bin/false" >> $OBJ/sshd_proxy
|
|
|
|
echo "ForceCommand ${SFTPSERVER}" >> $OBJ/sshd_proxy
|
|
|
|
rm -f $OBJ/ssh_proxy.tmp
|
|
|
|
echo "@get $OBJ/ssh_proxy $OBJ/ssh_proxy.tmp" | \
|
2023-11-01 02:08:38 +00:00
|
|
|
${SFTP} -S ${SSH} -b - -qF $OBJ/ssh_proxy somehost 2>/dev/null || \
|
2023-11-01 00:29:46 +00:00
|
|
|
fail "sftp failed"
|
|
|
|
test -f "$OBJ/ssh_proxy.tmp" || fail "sftp did not download file"
|
|
|
|
rm -f $OBJ/ssh_proxy.tmp
|