164c2a712SDag-Erling Smørgrav# 264c2a712SDag-Erling Smørgrav# Copyright (c) 2023 Klara, Inc. 364c2a712SDag-Erling Smørgrav# 464c2a712SDag-Erling Smørgrav# SPDX-License-Identifier: BSD-2-Clause 564c2a712SDag-Erling Smørgrav# 664c2a712SDag-Erling Smørgrav 764c2a712SDag-Erling Smørgravtftp_dir="${TMPDIR:-/tmp}/tftp.dir" 864c2a712SDag-Erling Smørgravinetd_conf="${TMPDIR:-/tmp}/inetd.conf" 964c2a712SDag-Erling Smørgravinetd_pid="${TMPDIR:-/tmp}/inetd.pid" 1064c2a712SDag-Erling Smørgrav 1164c2a712SDag-Erling Smørgravstart_tftpd() { 1264c2a712SDag-Erling Smørgrav if ! [ -z "$(sockstat -PUDP -p69 -q)" ] ; then 1364c2a712SDag-Erling Smørgrav atf_skip "the tftp port is in use" 1464c2a712SDag-Erling Smørgrav fi 1564c2a712SDag-Erling Smørgrav echo "starting inetd for $(atf_get ident)" >&2 1664c2a712SDag-Erling Smørgrav rm -rf "${tftp_dir}" 1764c2a712SDag-Erling Smørgrav mkdir "${tftp_dir}" 1864c2a712SDag-Erling Smørgrav cat >"${inetd_conf}" <<EOF 1964c2a712SDag-Erling Smørgravtftp dgram udp wait root /usr/libexec/tftpd tftpd -d15 -l ${tftp_dir} 2064c2a712SDag-Erling Smørgravtftp dgram udp6 wait root /usr/libexec/tftpd tftpd -d15 -l ${tftp_dir} 2164c2a712SDag-Erling SmørgravEOF 2264c2a712SDag-Erling Smørgrav /usr/sbin/inetd -a localhost -p "${inetd_pid}" "${inetd_conf}" 2364c2a712SDag-Erling Smørgrav} 2464c2a712SDag-Erling Smørgrav 2564c2a712SDag-Erling Smørgravstop_tftpd() { 2664c2a712SDag-Erling Smørgrav echo "stopping inetd for $(atf_get ident)" >&2 2764c2a712SDag-Erling Smørgrav # Send SIGTERM to inetd, then SIGKILL until it's gone 2864c2a712SDag-Erling Smørgrav local sig=TERM 2964c2a712SDag-Erling Smørgrav while pkill -$sig -LF "${inetd_pid}" inetd ; do 3064c2a712SDag-Erling Smørgrav echo "waiting for inetd to stop" >&2 3164c2a712SDag-Erling Smørgrav sleep 1 3264c2a712SDag-Erling Smørgrav sig=KILL 3364c2a712SDag-Erling Smørgrav done 3464c2a712SDag-Erling Smørgrav rm -rf "${tftp_dir}" "${inetd_conf}" "${inetd_pid}" 3564c2a712SDag-Erling Smørgrav} 3664c2a712SDag-Erling Smørgrav 3764c2a712SDag-Erling Smørgravatf_test_case tftp_get_big cleanup 3864c2a712SDag-Erling Smørgravtftp_get_big_head() { 3964c2a712SDag-Erling Smørgrav atf_set "descr" "get command with big file" 4064c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 4164c2a712SDag-Erling Smørgrav} 4264c2a712SDag-Erling Smørgravtftp_get_big_body() { 4364c2a712SDag-Erling Smørgrav start_tftpd 4464c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/remote.bin" 4564c2a712SDag-Erling Smørgrav dd if=/dev/urandom of="${remote_file}" bs=1m count=16 status=none 4664c2a712SDag-Erling Smørgrav local local_file="local.bin" 4764c2a712SDag-Erling Smørgrav echo "get ${remote_file##*/} ${local_file}" >client-script 4864c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 4964c2a712SDag-Erling Smørgrav tftp localhost <client-script 5064c2a712SDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 5164c2a712SDag-Erling Smørgrav} 5264c2a712SDag-Erling Smørgravtftp_get_big_cleanup() { 5364c2a712SDag-Erling Smørgrav stop_tftpd 5464c2a712SDag-Erling Smørgrav} 5564c2a712SDag-Erling Smørgrav 5664c2a712SDag-Erling Smørgravatf_test_case tftp_get_host cleanup 5764c2a712SDag-Erling Smørgravtftp_get_host_head() { 5864c2a712SDag-Erling Smørgrav atf_set "descr" "get command with host name" 5964c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 6064c2a712SDag-Erling Smørgrav} 6164c2a712SDag-Erling Smørgravtftp_get_host_body() { 6264c2a712SDag-Erling Smørgrav start_tftpd 6364c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 6464c2a712SDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 6564c2a712SDag-Erling Smørgrav local local_file="${remote_file##*/}" 6664c2a712SDag-Erling Smørgrav echo "get localhost:${remote_file##*/}" >client-script 6764c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 6864c2a712SDag-Erling Smørgrav tftp <client-script 6964c2a712SDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 7064c2a712SDag-Erling Smørgrav} 7164c2a712SDag-Erling Smørgravtftp_get_host_cleanup() { 7264c2a712SDag-Erling Smørgrav stop_tftpd 7364c2a712SDag-Erling Smørgrav} 7464c2a712SDag-Erling Smørgrav 7564c2a712SDag-Erling Smørgravatf_test_case tftp_get_ipv4 cleanup 7664c2a712SDag-Erling Smørgravtftp_get_ipv4_head() { 7764c2a712SDag-Erling Smørgrav atf_set "descr" "get command with ipv4 address" 7864c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 7964c2a712SDag-Erling Smørgrav} 8064c2a712SDag-Erling Smørgravtftp_get_ipv4_body() { 8164c2a712SDag-Erling Smørgrav start_tftpd 8264c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 8364c2a712SDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 8464c2a712SDag-Erling Smørgrav local local_file="${remote_file##*/}" 8564c2a712SDag-Erling Smørgrav echo "get 127.0.0.1:${remote_file##*/}" >client-script 8664c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 8764c2a712SDag-Erling Smørgrav tftp <client-script 8864c2a712SDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 8964c2a712SDag-Erling Smørgrav} 9064c2a712SDag-Erling Smørgravtftp_get_ipv4_cleanup() { 9164c2a712SDag-Erling Smørgrav stop_tftpd 9264c2a712SDag-Erling Smørgrav} 9364c2a712SDag-Erling Smørgrav 9464c2a712SDag-Erling Smørgravatf_test_case tftp_get_ipv6 cleanup 9564c2a712SDag-Erling Smørgravtftp_get_ipv6_head() { 9664c2a712SDag-Erling Smørgrav atf_set "descr" "get command with ipv6 address" 9764c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 9864c2a712SDag-Erling Smørgrav} 9964c2a712SDag-Erling Smørgravtftp_get_ipv6_body() { 10064c2a712SDag-Erling Smørgrav sysctl -q kern.features.inet6 || atf_skip "This test requires IPv6 support" 10164c2a712SDag-Erling Smørgrav start_tftpd 10264c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 10364c2a712SDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 10464c2a712SDag-Erling Smørgrav local local_file="${remote_file##*/}" 10564c2a712SDag-Erling Smørgrav echo "get [::1]:${remote_file##*/}" >client-script 10664c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 10764c2a712SDag-Erling Smørgrav tftp <client-script 10864c2a712SDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 10964c2a712SDag-Erling Smørgrav} 11064c2a712SDag-Erling Smørgravtftp_get_ipv6_cleanup() { 11164c2a712SDag-Erling Smørgrav stop_tftpd 11264c2a712SDag-Erling Smørgrav} 11364c2a712SDag-Erling Smørgrav 11464c2a712SDag-Erling Smørgravatf_test_case tftp_get_one cleanup 11564c2a712SDag-Erling Smørgravtftp_get_one_head() { 11664c2a712SDag-Erling Smørgrav atf_set "descr" "get command with one argument" 11764c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 11864c2a712SDag-Erling Smørgrav} 11964c2a712SDag-Erling Smørgravtftp_get_one_body() { 12064c2a712SDag-Erling Smørgrav start_tftpd 12164c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 12264c2a712SDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 12364c2a712SDag-Erling Smørgrav local local_file="${remote_file##*/}" 12464c2a712SDag-Erling Smørgrav echo "get ${remote_file##*/}" >client-script 12564c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 12664c2a712SDag-Erling Smørgrav tftp localhost <client-script 12764c2a712SDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 12864c2a712SDag-Erling Smørgrav} 12964c2a712SDag-Erling Smørgravtftp_get_one_cleanup() { 13064c2a712SDag-Erling Smørgrav stop_tftpd 13164c2a712SDag-Erling Smørgrav} 13264c2a712SDag-Erling Smørgrav 13364c2a712SDag-Erling Smørgravatf_test_case tftp_get_two cleanup 13464c2a712SDag-Erling Smørgravtftp_get_two_head() { 13564c2a712SDag-Erling Smørgrav atf_set "descr" "get command with two arguments" 13664c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 13764c2a712SDag-Erling Smørgrav} 13864c2a712SDag-Erling Smørgravtftp_get_two_body() { 13964c2a712SDag-Erling Smørgrav start_tftpd 14064c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 14164c2a712SDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 14264c2a712SDag-Erling Smørgrav local local_file="world.txt" 14364c2a712SDag-Erling Smørgrav echo "get ${remote_file##*/} ${local_file}" >client-script 14464c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 14564c2a712SDag-Erling Smørgrav tftp localhost <client-script 14664c2a712SDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 14764c2a712SDag-Erling Smørgrav} 14864c2a712SDag-Erling Smørgravtftp_get_two_cleanup() { 14964c2a712SDag-Erling Smørgrav stop_tftpd 15064c2a712SDag-Erling Smørgrav} 15164c2a712SDag-Erling Smørgrav 15264c2a712SDag-Erling Smørgravatf_test_case tftp_get_more cleanup 15364c2a712SDag-Erling Smørgravtftp_get_more_head() { 15464c2a712SDag-Erling Smørgrav atf_set "descr" "get command with three or more arguments" 15564c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 15664c2a712SDag-Erling Smørgrav} 15764c2a712SDag-Erling Smørgravtftp_get_more_body() { 15864c2a712SDag-Erling Smørgrav start_tftpd 15964c2a712SDag-Erling Smørgrav for n in 3 4 5 6 7 ; do 16064c2a712SDag-Erling Smørgrav echo -n "get" >client-script 16164c2a712SDag-Erling Smørgrav for f in $(jot -c $n 97) ; do 16264c2a712SDag-Erling Smørgrav echo "test file $$/$f/$n" >"${tftp_dir}/${f}.txt" 16364c2a712SDag-Erling Smørgrav echo -n " ${f}.txt" >>client-script 16464c2a712SDag-Erling Smørgrav rm -f "${f}.txt" 16564c2a712SDag-Erling Smørgrav done 16664c2a712SDag-Erling Smørgrav echo >>client-script 16764c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 16864c2a712SDag-Erling Smørgrav tftp localhost <client-script 16964c2a712SDag-Erling Smørgrav for f in $(jot -c $n 97) ; do 17064c2a712SDag-Erling Smørgrav atf_check cmp -s "${f}.txt" "${tftp_dir}/${f}.txt" 17164c2a712SDag-Erling Smørgrav done 17264c2a712SDag-Erling Smørgrav done 17364c2a712SDag-Erling Smørgrav} 17464c2a712SDag-Erling Smørgravtftp_get_more_cleanup() { 17564c2a712SDag-Erling Smørgrav stop_tftpd 17664c2a712SDag-Erling Smørgrav} 17764c2a712SDag-Erling Smørgrav 17864c2a712SDag-Erling Smørgravatf_test_case tftp_get_multi_host cleanup 17964c2a712SDag-Erling Smørgravtftp_get_multi_host_head() { 18064c2a712SDag-Erling Smørgrav atf_set "descr" "get command with multiple files and host name" 18164c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 18264c2a712SDag-Erling Smørgrav} 18364c2a712SDag-Erling Smørgravtftp_get_multi_host_body() { 18464c2a712SDag-Erling Smørgrav start_tftpd 18564c2a712SDag-Erling Smørgrav for f in a b c ; do 18664c2a712SDag-Erling Smørgrav echo "test file $$/$f/$n" >"${tftp_dir}/${f}.txt" 18764c2a712SDag-Erling Smørgrav rm -f "${f}.txt" 18864c2a712SDag-Erling Smørgrav done 18964c2a712SDag-Erling Smørgrav echo "get localhost:a.txt b.txt c.txt" >client-script 19064c2a712SDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 19164c2a712SDag-Erling Smørgrav tftp localhost <client-script 19264c2a712SDag-Erling Smørgrav for f in a b c ; do 19364c2a712SDag-Erling Smørgrav atf_check cmp -s "${f}.txt" "${tftp_dir}/${f}.txt" 19464c2a712SDag-Erling Smørgrav done 19564c2a712SDag-Erling Smørgrav} 19664c2a712SDag-Erling Smørgravtftp_get_multi_host_cleanup() { 19764c2a712SDag-Erling Smørgrav stop_tftpd 19864c2a712SDag-Erling Smørgrav} 19964c2a712SDag-Erling Smørgrav 20064c2a712SDag-Erling Smørgravatf_test_case tftp_put_big cleanup 20164c2a712SDag-Erling Smørgravtftp_put_big_head() { 20264c2a712SDag-Erling Smørgrav atf_set "descr" "put command with big file" 20364c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 20464c2a712SDag-Erling Smørgrav} 20564c2a712SDag-Erling Smørgravtftp_put_big_body() { 20664c2a712SDag-Erling Smørgrav start_tftpd 20764c2a712SDag-Erling Smørgrav local local_file="local.bin" 20864c2a712SDag-Erling Smørgrav dd if=/dev/urandom of="${local_file}" bs=1m count=16 status=none 20964c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/random.bin" 21064c2a712SDag-Erling Smørgrav truncate -s 0 "${remote_file}" 21164c2a712SDag-Erling Smørgrav chown nobody:nogroup "${remote_file}" 21264c2a712SDag-Erling Smørgrav chmod 0666 "${remote_file}" 21364c2a712SDag-Erling Smørgrav echo "put ${local_file} ${remote_file##*/}" >client-script 21464c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 21564c2a712SDag-Erling Smørgrav tftp localhost <client-script 21664c2a712SDag-Erling Smørgrav atf_check cmp -s "${remote_file}" "${local_file}" 21764c2a712SDag-Erling Smørgrav} 21864c2a712SDag-Erling Smørgravtftp_put_big_cleanup() { 21964c2a712SDag-Erling Smørgrav stop_tftpd 22064c2a712SDag-Erling Smørgrav} 22164c2a712SDag-Erling Smørgrav 22264c2a712SDag-Erling Smørgravatf_test_case tftp_put_host cleanup 22364c2a712SDag-Erling Smørgravtftp_put_host_head() { 22464c2a712SDag-Erling Smørgrav atf_set "descr" "put command with host name" 22564c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 22664c2a712SDag-Erling Smørgrav} 22764c2a712SDag-Erling Smørgravtftp_put_host_body() { 22864c2a712SDag-Erling Smørgrav start_tftpd 22964c2a712SDag-Erling Smørgrav local local_file="local.txt" 23064c2a712SDag-Erling Smørgrav echo "test file $$" >"${local_file}" 23164c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/remote.txt" 23264c2a712SDag-Erling Smørgrav truncate -s 0 "${remote_file}" 23364c2a712SDag-Erling Smørgrav chown nobody:nogroup "${remote_file}" 23464c2a712SDag-Erling Smørgrav chmod 0666 "${remote_file}" 23564c2a712SDag-Erling Smørgrav echo "put ${local_file} localhost:${remote_file##*/}" >client-script 23664c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 23764c2a712SDag-Erling Smørgrav tftp <client-script 23864c2a712SDag-Erling Smørgrav atf_check cmp -s "${remote_file}" "${local_file}" 23964c2a712SDag-Erling Smørgrav} 24064c2a712SDag-Erling Smørgravtftp_put_host_cleanup() { 24164c2a712SDag-Erling Smørgrav stop_tftpd 24264c2a712SDag-Erling Smørgrav} 24364c2a712SDag-Erling Smørgrav 24464c2a712SDag-Erling Smørgravatf_test_case tftp_put_ipv4 cleanup 24564c2a712SDag-Erling Smørgravtftp_put_ipv4_head() { 24664c2a712SDag-Erling Smørgrav atf_set "descr" "put command with ipv4 address" 24764c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 24864c2a712SDag-Erling Smørgrav} 24964c2a712SDag-Erling Smørgravtftp_put_ipv4_body() { 25064c2a712SDag-Erling Smørgrav start_tftpd 25164c2a712SDag-Erling Smørgrav local local_file="local.txt" 25264c2a712SDag-Erling Smørgrav echo "test file $$" >"${local_file}" 25364c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/remote.txt" 25464c2a712SDag-Erling Smørgrav truncate -s 0 "${remote_file}" 25564c2a712SDag-Erling Smørgrav chown nobody:nogroup "${remote_file}" 25664c2a712SDag-Erling Smørgrav chmod 0666 "${remote_file}" 25764c2a712SDag-Erling Smørgrav echo "put ${local_file} 127.0.0.1:${remote_file##*/}" >client-script 25864c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 25964c2a712SDag-Erling Smørgrav tftp <client-script 26064c2a712SDag-Erling Smørgrav atf_check cmp -s "${remote_file}" "${local_file}" 26164c2a712SDag-Erling Smørgrav} 26264c2a712SDag-Erling Smørgravtftp_put_ipv4_cleanup() { 26364c2a712SDag-Erling Smørgrav stop_tftpd 26464c2a712SDag-Erling Smørgrav} 26564c2a712SDag-Erling Smørgrav 26664c2a712SDag-Erling Smørgravatf_test_case tftp_put_ipv6 cleanup 26764c2a712SDag-Erling Smørgravtftp_put_ipv6_head() { 26864c2a712SDag-Erling Smørgrav atf_set "descr" "put command with ipv6 address" 26964c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 27064c2a712SDag-Erling Smørgrav} 27164c2a712SDag-Erling Smørgravtftp_put_ipv6_body() { 27264c2a712SDag-Erling Smørgrav sysctl -q kern.features.inet6 || atf_skip "This test requires IPv6 support" 27364c2a712SDag-Erling Smørgrav start_tftpd 27464c2a712SDag-Erling Smørgrav local local_file="local.txt" 27564c2a712SDag-Erling Smørgrav echo "test file $$" >"${local_file}" 27664c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/remote.txt" 27764c2a712SDag-Erling Smørgrav truncate -s 0 "${remote_file}" 27864c2a712SDag-Erling Smørgrav chown nobody:nogroup "${remote_file}" 27964c2a712SDag-Erling Smørgrav chmod 0666 "${remote_file}" 28064c2a712SDag-Erling Smørgrav echo "put ${local_file} [::1]:${remote_file##*/}" >client-script 28164c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 28264c2a712SDag-Erling Smørgrav tftp <client-script 28364c2a712SDag-Erling Smørgrav atf_check cmp -s "${remote_file}" "${local_file}" 28464c2a712SDag-Erling Smørgrav} 28564c2a712SDag-Erling Smørgravtftp_put_ipv6_cleanup() { 28664c2a712SDag-Erling Smørgrav stop_tftpd 28764c2a712SDag-Erling Smørgrav} 28864c2a712SDag-Erling Smørgrav 28964c2a712SDag-Erling Smørgravatf_test_case tftp_put_one cleanup 29064c2a712SDag-Erling Smørgravtftp_put_one_head() { 29164c2a712SDag-Erling Smørgrav atf_set "descr" "put command with one argument" 29264c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 29364c2a712SDag-Erling Smørgrav} 29464c2a712SDag-Erling Smørgravtftp_put_one_body() { 29564c2a712SDag-Erling Smørgrav start_tftpd 29664c2a712SDag-Erling Smørgrav local local_file="file.txt" 29764c2a712SDag-Erling Smørgrav echo "test file $$" >"${local_file}" 29864c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/${local_file}" 29964c2a712SDag-Erling Smørgrav truncate -s 0 "${remote_file}" 30064c2a712SDag-Erling Smørgrav chown nobody:nogroup "${remote_file}" 30164c2a712SDag-Erling Smørgrav chmod 0666 "${remote_file}" 30264c2a712SDag-Erling Smørgrav echo "put ${local_file}" >client-script 30364c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 30464c2a712SDag-Erling Smørgrav tftp localhost <client-script 30564c2a712SDag-Erling Smørgrav atf_check cmp -s "${remote_file}" "${local_file}" 30664c2a712SDag-Erling Smørgrav} 30764c2a712SDag-Erling Smørgravtftp_put_one_cleanup() { 30864c2a712SDag-Erling Smørgrav stop_tftpd 30964c2a712SDag-Erling Smørgrav} 31064c2a712SDag-Erling Smørgrav 31164c2a712SDag-Erling Smørgravatf_test_case tftp_put_two cleanup 31264c2a712SDag-Erling Smørgravtftp_put_two_head() { 31364c2a712SDag-Erling Smørgrav atf_set "descr" "put command with two arguments" 31464c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 31564c2a712SDag-Erling Smørgrav} 31664c2a712SDag-Erling Smørgravtftp_put_two_body() { 31764c2a712SDag-Erling Smørgrav start_tftpd 31864c2a712SDag-Erling Smørgrav local local_file="local.txt" 31964c2a712SDag-Erling Smørgrav echo "test file $$" >"${local_file}" 32064c2a712SDag-Erling Smørgrav local remote_file="${tftp_dir}/remote.txt" 32164c2a712SDag-Erling Smørgrav truncate -s 0 "${remote_file}" 32264c2a712SDag-Erling Smørgrav chown nobody:nogroup "${remote_file}" 32364c2a712SDag-Erling Smørgrav chmod 0666 "${remote_file}" 32464c2a712SDag-Erling Smørgrav echo "put ${local_file} ${remote_file##*/}" >client-script 32564c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 32664c2a712SDag-Erling Smørgrav tftp localhost <client-script 32764c2a712SDag-Erling Smørgrav atf_check cmp -s "${remote_file}" "${local_file}" 32864c2a712SDag-Erling Smørgrav} 32964c2a712SDag-Erling Smørgravtftp_put_two_cleanup() { 33064c2a712SDag-Erling Smørgrav stop_tftpd 33164c2a712SDag-Erling Smørgrav} 33264c2a712SDag-Erling Smørgrav 33364c2a712SDag-Erling Smørgravatf_test_case tftp_put_more cleanup 33464c2a712SDag-Erling Smørgravtftp_put_more_head() { 33564c2a712SDag-Erling Smørgrav atf_set "descr" "put command with three or more arguments" 33664c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 33764c2a712SDag-Erling Smørgrav} 33864c2a712SDag-Erling Smørgravtftp_put_more_body() { 33964c2a712SDag-Erling Smørgrav start_tftpd 34064c2a712SDag-Erling Smørgrav mkdir "${tftp_dir}/subdir" 34164c2a712SDag-Erling Smørgrav for n in 2 3 4 5 6 ; do 34264c2a712SDag-Erling Smørgrav echo -n "put" >client-script 34364c2a712SDag-Erling Smørgrav for f in $(jot -c $n 97) ; do 34464c2a712SDag-Erling Smørgrav echo "test file $$/$f/$n" >"${f}.txt" 34564c2a712SDag-Erling Smørgrav truncate -s 0 "${tftp_dir}/subdir/${f}.txt" 34664c2a712SDag-Erling Smørgrav chown nobody:nogroup "${tftp_dir}/subdir/${f}.txt" 34764c2a712SDag-Erling Smørgrav chmod 0666 "${tftp_dir}/subdir/${f}.txt" 34864c2a712SDag-Erling Smørgrav echo -n " ${f}.txt" >>client-script 34964c2a712SDag-Erling Smørgrav done 35064c2a712SDag-Erling Smørgrav echo " subdir" >>client-script 35164c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 35264c2a712SDag-Erling Smørgrav tftp localhost <client-script 35364c2a712SDag-Erling Smørgrav for f in $(jot -c $n 97) ; do 35464c2a712SDag-Erling Smørgrav atf_check cmp -s "${tftp_dir}/subdir/${f}.txt" "${f}.txt" 35564c2a712SDag-Erling Smørgrav done 35664c2a712SDag-Erling Smørgrav done 35764c2a712SDag-Erling Smørgrav} 35864c2a712SDag-Erling Smørgravtftp_put_more_cleanup() { 35964c2a712SDag-Erling Smørgrav stop_tftpd 36064c2a712SDag-Erling Smørgrav} 36164c2a712SDag-Erling Smørgrav 36264c2a712SDag-Erling Smørgravatf_test_case tftp_put_multi_host cleanup 36364c2a712SDag-Erling Smørgravtftp_put_multi_host_head() { 36464c2a712SDag-Erling Smørgrav atf_set "descr" "put command with multiple files and host name" 36564c2a712SDag-Erling Smørgrav atf_set "require.user" "root" 36664c2a712SDag-Erling Smørgrav} 36764c2a712SDag-Erling Smørgravtftp_put_multi_host_body() { 36864c2a712SDag-Erling Smørgrav start_tftpd 36964c2a712SDag-Erling Smørgrav mkdir "${tftp_dir}/subdir" 37064c2a712SDag-Erling Smørgrav echo -n "put" >client-script 37164c2a712SDag-Erling Smørgrav for f in a b c ; do 37264c2a712SDag-Erling Smørgrav echo "test file $$/$f" >"${f}.txt" 37364c2a712SDag-Erling Smørgrav truncate -s 0 "${tftp_dir}/subdir/${f}.txt" 37464c2a712SDag-Erling Smørgrav chown nobody:nogroup "${tftp_dir}/subdir/${f}.txt" 37564c2a712SDag-Erling Smørgrav chmod 0666 "${tftp_dir}/subdir/${f}.txt" 37664c2a712SDag-Erling Smørgrav echo -n " ${f}.txt" >>client-script 37764c2a712SDag-Erling Smørgrav done 37864c2a712SDag-Erling Smørgrav echo " localhost:subdir" >>client-script 37964c2a712SDag-Erling Smørgrav atf_check -o match:"Sent [0-9]+ bytes" \ 38064c2a712SDag-Erling Smørgrav tftp <client-script 38164c2a712SDag-Erling Smørgrav for f in a b c ; do 38264c2a712SDag-Erling Smørgrav atf_check cmp -s "${tftp_dir}/subdir/${f}.txt" "${f}.txt" 38364c2a712SDag-Erling Smørgrav done 38464c2a712SDag-Erling Smørgrav} 38564c2a712SDag-Erling Smørgravtftp_put_multi_host_cleanup() { 38664c2a712SDag-Erling Smørgrav stop_tftpd 38764c2a712SDag-Erling Smørgrav} 38864c2a712SDag-Erling Smørgrav 389*fc76ddeeSDag-Erling Smørgravatf_test_case tftp_url_host cleanup 390*fc76ddeeSDag-Erling Smørgravtftp_url_host_head() { 391*fc76ddeeSDag-Erling Smørgrav atf_set "descr" "URL with hostname" 392*fc76ddeeSDag-Erling Smørgrav atf_set "require.user" "root" 393*fc76ddeeSDag-Erling Smørgrav} 394*fc76ddeeSDag-Erling Smørgravtftp_url_host_body() { 395*fc76ddeeSDag-Erling Smørgrav start_tftpd 396*fc76ddeeSDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 397*fc76ddeeSDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 398*fc76ddeeSDag-Erling Smørgrav local local_file="${remote_file##*/}" 399*fc76ddeeSDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 400*fc76ddeeSDag-Erling Smørgrav tftp tftp://localhost/"${remote_file##*/}" 401*fc76ddeeSDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 402*fc76ddeeSDag-Erling Smørgrav} 403*fc76ddeeSDag-Erling Smørgravtftp_url_host_cleanup() { 404*fc76ddeeSDag-Erling Smørgrav stop_tftpd 405*fc76ddeeSDag-Erling Smørgrav} 406*fc76ddeeSDag-Erling Smørgrav 407*fc76ddeeSDag-Erling Smørgravatf_test_case tftp_url_ipv4 cleanup 408*fc76ddeeSDag-Erling Smørgravtftp_url_ipv4_head() { 409*fc76ddeeSDag-Erling Smørgrav atf_set "descr" "URL with IPv4 address" 410*fc76ddeeSDag-Erling Smørgrav atf_set "require.user" "root" 411*fc76ddeeSDag-Erling Smørgrav} 412*fc76ddeeSDag-Erling Smørgravtftp_url_ipv4_body() { 413*fc76ddeeSDag-Erling Smørgrav start_tftpd 414*fc76ddeeSDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 415*fc76ddeeSDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 416*fc76ddeeSDag-Erling Smørgrav local local_file="${remote_file##*/}" 417*fc76ddeeSDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 418*fc76ddeeSDag-Erling Smørgrav tftp tftp://127.0.0.1/"${remote_file##*/}" 419*fc76ddeeSDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 420*fc76ddeeSDag-Erling Smørgrav} 421*fc76ddeeSDag-Erling Smørgravtftp_url_ipv4_cleanup() { 422*fc76ddeeSDag-Erling Smørgrav stop_tftpd 423*fc76ddeeSDag-Erling Smørgrav} 424*fc76ddeeSDag-Erling Smørgrav 425*fc76ddeeSDag-Erling Smørgravatf_test_case tftp_url_ipv6 cleanup 426*fc76ddeeSDag-Erling Smørgravtftp_url_ipv6_head() { 427*fc76ddeeSDag-Erling Smørgrav atf_set "descr" "URL with IPv6 address" 428*fc76ddeeSDag-Erling Smørgrav atf_set "require.user" "root" 429*fc76ddeeSDag-Erling Smørgrav} 430*fc76ddeeSDag-Erling Smørgravtftp_url_ipv6_body() { 431*fc76ddeeSDag-Erling Smørgrav sysctl -q kern.features.inet6 || atf_skip "This test requires IPv6 support" 432*fc76ddeeSDag-Erling Smørgrav atf_expect_fail "tftp does not support bracketed IPv6 literals in URLs" 433*fc76ddeeSDag-Erling Smørgrav start_tftpd 434*fc76ddeeSDag-Erling Smørgrav local remote_file="${tftp_dir}/hello.txt" 435*fc76ddeeSDag-Erling Smørgrav echo "Hello, $$!" >"${remote_file}" 436*fc76ddeeSDag-Erling Smørgrav local local_file="${remote_file##*/}" 437*fc76ddeeSDag-Erling Smørgrav atf_check -o match:"Received [0-9]+ bytes" \ 438*fc76ddeeSDag-Erling Smørgrav tftp tftp://"[::1]"/"${remote_file##*/}" 439*fc76ddeeSDag-Erling Smørgrav atf_check cmp -s "${local_file}" "${remote_file}" 440*fc76ddeeSDag-Erling Smørgrav} 441*fc76ddeeSDag-Erling Smørgravtftp_url_ipv6_cleanup() { 442*fc76ddeeSDag-Erling Smørgrav stop_tftpd 443*fc76ddeeSDag-Erling Smørgrav} 444*fc76ddeeSDag-Erling Smørgrav 44564c2a712SDag-Erling Smørgravatf_init_test_cases() { 44664c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_big 44764c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_host 44864c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_ipv4 44964c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_ipv6 45064c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_one 45164c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_two 45264c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_more 45364c2a712SDag-Erling Smørgrav atf_add_test_case tftp_get_multi_host 45464c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_big 45564c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_host 45664c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_ipv4 45764c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_ipv6 45864c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_one 45964c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_two 46064c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_more 46164c2a712SDag-Erling Smørgrav atf_add_test_case tftp_put_multi_host 462*fc76ddeeSDag-Erling Smørgrav atf_add_test_case tftp_url_host 463*fc76ddeeSDag-Erling Smørgrav atf_add_test_case tftp_url_ipv4 464*fc76ddeeSDag-Erling Smørgrav atf_add_test_case tftp_url_ipv6 46564c2a712SDag-Erling Smørgrav} 466