1 # $NetBSD: t_tcpip.sh,v 1.18 2016/08/13 11:22:11 christos Exp $
3 # Copyright (c) 2011 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 rumpnetlibs="-lrumpnet -lrumpnet_net -lrumpnet_netinet6 -lrumpnet_netinet"
29 rumpnetsrv="rump_server $rumpnetlibs -lrumpdev"
30 export RUMP_SERVER=unix://csock
32 atf_test_case http cleanup
35 atf_set "descr" "Start hijacked httpd and get webpage from it"
41 atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
43 # start bozo in daemon mode
44 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
45 /usr/libexec/httpd -P ./httpd.pid -b -s $(atf_get_srcdir)
47 atf_check -s exit:0 -o file:"$(atf_get_srcdir)/netstat.expout" \
51 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
52 $(atf_get_srcdir)/h_netget 127.0.0.1 80 webfile
54 # check that we got what we wanted
55 atf_check -o match:'HTTP/1.0 200 OK' cat webfile
56 atf_check -o match:'Content-Length: 95' cat webfile
57 blank_line_re="$(printf '^\r$')" # matches a line with only <CR><LF>
58 atf_check -o file:"$(atf_get_srcdir)/index.html" \
59 sed -n "1,/${blank_line_re}/!p" webfile
64 if [ -f httpd.pid ]; then
65 kill -9 "$(cat httpd.pid)"
73 # Starts a SSH server and sets up the client to access it.
74 # Authentication is allowed and done using an RSA key exclusively, which
75 # is generated on the fly as part of the test case.
76 # XXX: Ideally, all the tests in this test program should be able to share
77 # the generated key, because creating it can be a very slow process on some
80 # XXX2: copypasted from jmmv's sshd thingamob in the psshfs test.
81 # ideally code (and keys, like jmmv notes above) could be shared
84 echo "Setting up SSH server configuration"
85 sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
86 $(atf_get_srcdir)/sshd_config.in >sshd_config || \
87 atf_fail "Failed to create sshd_config"
88 atf_check -s ignore -o empty -e ignore \
89 cp $(atf_get_srcdir)/ssh_host_key .
90 atf_check -s ignore -o empty -e ignore \
91 cp $(atf_get_srcdir)/ssh_host_key.pub .
92 atf_check -s eq:0 -o empty -e empty chmod 400 ssh_host_key
93 atf_check -s eq:0 -o empty -e empty chmod 444 ssh_host_key.pub
95 env LD_PRELOAD=/usr/lib/librumphijack.so \
96 /usr/sbin/sshd -e -f ./sshd_config
97 while [ ! -f sshd.pid ]; do
100 echo "SSH server started (pid $(cat sshd.pid))"
102 echo "Setting up SSH client configuration"
103 atf_check -s eq:0 -o empty -e empty \
104 ssh-keygen -f ssh_user_key -t rsa -b 1024 -N "" -q
105 atf_check -s eq:0 -o empty -e empty \
106 cp ssh_user_key.pub authorized_keys
107 echo "127.0.0.1,localhost,::1 " \
108 "$(cat $(atf_get_srcdir)/ssh_host_key.pub)" >known_hosts || \
109 atf_fail "Failed to create known_hosts"
110 atf_check -s eq:0 -o empty -e empty chmod 600 authorized_keys
111 sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
112 $(atf_get_srcdir)/ssh_config.in >ssh_config || \
113 atf_fail "Failed to create ssh_config"
118 atf_test_case ssh cleanup
121 atf_set "descr" "Test that hijacked ssh/sshd works"
126 atf_expect_fail "PR lib/50174"
128 atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
129 # make sure clients die after we nuke the server
130 export RUMPHIJACK_RETRYCONNECT='die'
134 # create some sort of directory for us to "ls"
138 jot 11 12 | xargs mkdir
141 atf_check -s exit:0 -o save:ssh.out \
142 env LD_PRELOAD=/usr/lib/librumphijack.so \
143 ssh -T -F ssh_config 127.0.0.1 env BLOCKSIZE=512 \
144 ls -li $(pwd)/testdir
145 atf_check -s exit:0 -o file:ssh.out env BLOCKSIZE=512 \
146 ls -li $(pwd)/testdir
152 # sshd dies due to RUMPHIJACK_RETRYCONNECT=1d6
158 magicstr='wind in my hair'
159 # create ffs file system we'll be serving from
160 atf_check -s exit:0 -o ignore newfs -F -s 10000 ffs.img
162 # start nfs kernel server. this is a mouthful
163 export RUMP_SERVER=unix://serversock
164 atf_check -s exit:0 rump_server $* ${RUMP_SERVER}
166 atf_check -s exit:0 rump.ifconfig shmif0 create
167 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
168 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.1
170 export RUMPHIJACK_RETRYCONNECT=die
171 export LD_PRELOAD=/usr/lib/librumphijack.so
173 atf_check -s exit:0 mkdir -p /rump/var/run
174 atf_check -s exit:0 mkdir -p /rump/var/db
175 atf_check -s exit:0 touch /rump/var/db/mountdtab
176 atf_check -s exit:0 mkdir /rump/etc
177 atf_check -s exit:0 mkdir /rump/export
179 atf_check -s exit:0 -x \
180 'echo "/export -noresvport -noresvmnt 10.1.1.100" | \
181 dd of=/rump/etc/exports 2> /dev/null'
183 atf_check -s exit:0 rump.sysctl -q -w kern.module.autoload=1
185 atf_check -s exit:0 -e ignore mount_ffs /dk /rump/export
186 atf_check -s exit:0 -x "echo ${magicstr} > /rump/export/im_alive"
188 # start rpcbind. we want /var/run/rpcbind.sock
189 export RUMPHIJACK='blanket=/var/run,socket=all'
190 atf_check -s exit:0 rpcbind
192 # ok, then we want mountd in the similar fashion
193 export RUMPHIJACK='blanket=/var/run:/var/db:/export,socket=all,path=/rump,vfs=all'
194 atf_check -s exit:0 mountd /rump/etc/exports
196 # finally, le nfschuck
197 export RUMPHIJACK='blanket=/var/run,socket=all,vfs=all'
198 atf_check -s exit:0 nfsd
201 # now, time for the client server and associated madness.
204 export RUMP_SERVER=unix://clientsock
208 # at least the kernel server is easier
209 atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet -lrumpdev \
210 -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\
213 atf_check -s exit:0 rump.ifconfig shmif0 create
214 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
215 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.100
217 export LD_PRELOAD=/usr/lib/librumphijack.so
219 atf_check -s exit:0 mkdir /rump/mnt
220 atf_check -s exit:0 mount_nfs 10.1.1.1:/export /rump/mnt
222 atf_check -s exit:0 -o inline:"${magicstr}\n" cat /rump/mnt/im_alive
223 atf_check -s exit:0 -o match:'.*im_alive$' ls -l /rump/mnt/im_alive
227 atf_test_case nfs cleanup
230 atf_set "descr" "Test hijacked nfsd and mount_nfs"
235 test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
236 -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif -lrumpdev \
237 -lrumpdev_disk -lrumpfs_ffs -lrumpfs_nfs -lrumpfs_nfsserver \
238 -d key=/dk,hostpath=ffs.img,size=host
243 RUMP_SERVER=unix://serversock rump.halt 2> /dev/null
244 RUMP_SERVER=unix://clientsock rump.halt 2> /dev/null
248 atf_test_case nfs_autoload cleanup
251 atf_set "descr" "Test hijacked nfsd with autoload from /stand"
256 [ `uname -m` = "i386" ] || atf_skip "test currently valid only on i386"
257 test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
258 -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif -lrumpdev \
259 -lrumpdev_disk -d key=/dk,hostpath=ffs.img,size=host
262 nfs_autoload_cleanup()
267 atf_init_test_cases()
269 atf_add_test_case http
270 atf_add_test_case ssh
271 atf_add_test_case nfs
272 atf_add_test_case nfs_autoload