etc/protocols - sync with NetBSD-8
[minix.git] / tests / lib / librumphijack / t_tcpip.sh
blob1ae73775e4b46be65aa90faf2e0afab1597c4f71
1 # $NetBSD: t_tcpip.sh,v 1.15 2015/08/26 09:19:20 martin Exp $
3 # Copyright (c) 2011 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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 rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet'
29 export RUMP_SERVER=unix://csock
31 atf_test_case http cleanup
32 http_head()
34 atf_set "descr" "Start hijacked httpd and get webpage from it"
37 http_body()
40 atf_check -s exit:0 ${rumpnetsrv} -lrumpnet_netinet6 ${RUMP_SERVER}
42 # start bozo in daemon mode
43 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
44 /usr/libexec/httpd -P ./httpd.pid -b -s $(atf_get_srcdir)
46 atf_check -s exit:0 -o file:"$(atf_get_srcdir)/netstat.expout" \
47 rump.netstat -a
49 # get the webpage
50 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
51 $(atf_get_srcdir)/h_netget 127.0.0.1 80 webfile
53 # check that we got what we wanted
54 atf_check -o match:'HTTP/1.0 200 OK' cat webfile
55 atf_check -o match:'Content-Length: 95' cat webfile
56 blank_line_re="$(printf '^\r$')" # matches a line with only <CR><LF>
57 atf_check -o file:"$(atf_get_srcdir)/index.html" \
58 sed -n "1,/${blank_line_re}/!p" webfile
61 http_cleanup()
63 if [ -f httpd.pid ]; then
64 kill -9 "$(cat httpd.pid)"
65 rm -f httpd.pid
68 rump.halt
72 # Starts a SSH server and sets up the client to access it.
73 # Authentication is allowed and done using an RSA key exclusively, which
74 # is generated on the fly as part of the test case.
75 # XXX: Ideally, all the tests in this test program should be able to share
76 # the generated key, because creating it can be a very slow process on some
77 # machines.
79 # XXX2: copypasted from jmmv's sshd thingamob in the psshfs test.
80 # ideally code (and keys, like jmmv notes above) could be shared
82 start_sshd() {
83 echo "Setting up SSH server configuration"
84 sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
85 $(atf_get_srcdir)/sshd_config.in >sshd_config || \
86 atf_fail "Failed to create sshd_config"
87 atf_check -s ignore -o empty -e ignore \
88 cp $(atf_get_srcdir)/ssh_host_key .
89 atf_check -s ignore -o empty -e ignore \
90 cp $(atf_get_srcdir)/ssh_host_key.pub .
91 atf_check -s eq:0 -o empty -e empty chmod 400 ssh_host_key
92 atf_check -s eq:0 -o empty -e empty chmod 444 ssh_host_key.pub
94 env LD_PRELOAD=/usr/lib/librumphijack.so \
95 /usr/sbin/sshd -e -f ./sshd_config
96 while [ ! -f sshd.pid ]; do
97 sleep 0.01
98 done
99 echo "SSH server started (pid $(cat sshd.pid))"
101 echo "Setting up SSH client configuration"
102 atf_check -s eq:0 -o empty -e empty \
103 ssh-keygen -f ssh_user_key -t rsa -b 1024 -N "" -q
104 atf_check -s eq:0 -o empty -e empty \
105 cp ssh_user_key.pub authorized_keys
106 echo "127.0.0.1,localhost,::1 " \
107 "$(cat $(atf_get_srcdir)/ssh_host_key.pub)" >known_hosts || \
108 atf_fail "Failed to create known_hosts"
109 atf_check -s eq:0 -o empty -e empty chmod 600 authorized_keys
110 sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
111 $(atf_get_srcdir)/ssh_config.in >ssh_config || \
112 atf_fail "Failed to create ssh_config"
114 echo "sshd running"
117 atf_test_case ssh cleanup
118 ssh_head()
120 atf_set "descr" "Test that hijacked ssh/sshd works"
123 ssh_body()
125 atf_expect_fail "PR lib/50174"
127 atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER}
128 # make sure clients die after we nuke the server
129 export RUMPHIJACK_RETRYCONNECT='die'
131 start_sshd
133 # create some sort of directory for us to "ls"
134 mkdir testdir
135 cd testdir
136 jot 11 | xargs touch
137 jot 11 12 | xargs mkdir
138 cd ..
140 atf_check -s exit:0 -o save:ssh.out \
141 env LD_PRELOAD=/usr/lib/librumphijack.so \
142 ssh -T -F ssh_config 127.0.0.1 env BLOCKSIZE=512 \
143 ls -li $(pwd)/testdir
144 atf_check -s exit:0 -o file:ssh.out env BLOCKSIZE=512 \
145 ls -li $(pwd)/testdir
148 ssh_cleanup()
150 rump.halt
151 # sshd dies due to RUMPHIJACK_RETRYCONNECT=1d6
154 test_nfs()
157 magicstr='wind in my hair'
158 # create ffs file system we'll be serving from
159 atf_check -s exit:0 -o ignore newfs -F -s 10000 ffs.img
161 # start nfs kernel server. this is a mouthful
162 export RUMP_SERVER=unix://serversock
163 atf_check -s exit:0 rump_server $* ${RUMP_SERVER}
165 atf_check -s exit:0 rump.ifconfig shmif0 create
166 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
167 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.1
169 export RUMPHIJACK_RETRYCONNECT=die
170 export LD_PRELOAD=/usr/lib/librumphijack.so
172 atf_check -s exit:0 mkdir -p /rump/var/run
173 atf_check -s exit:0 mkdir -p /rump/var/db
174 atf_check -s exit:0 touch /rump/var/db/mountdtab
175 atf_check -s exit:0 mkdir /rump/etc
176 atf_check -s exit:0 mkdir /rump/export
178 atf_check -s exit:0 -x \
179 'echo "/export -noresvport -noresvmnt 10.1.1.100" | \
180 dd of=/rump/etc/exports 2> /dev/null'
182 atf_check -s exit:0 -e ignore mount_ffs /dk /rump/export
183 atf_check -s exit:0 -x "echo ${magicstr} > /rump/export/im_alive"
185 # start rpcbind. we want /var/run/rpcbind.sock
186 export RUMPHIJACK='blanket=/var/run,socket=all'
187 atf_check -s exit:0 rpcbind
189 # ok, then we want mountd in the similar fashion
190 export RUMPHIJACK='blanket=/var/run:/var/db:/export,socket=all,path=/rump,vfs=all'
191 atf_check -s exit:0 mountd /rump/etc/exports
193 # finally, le nfschuck
194 export RUMPHIJACK='blanket=/var/run,socket=all,vfs=all'
195 atf_check -s exit:0 nfsd
198 # now, time for the client server and associated madness.
201 export RUMP_SERVER=unix://clientsock
202 unset RUMPHIJACK
203 unset LD_PRELOAD
205 # at least the kernel server is easier
206 atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet \
207 -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\
208 ${RUMP_SERVER}
210 atf_check -s exit:0 rump.ifconfig shmif0 create
211 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
212 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.100
214 export LD_PRELOAD=/usr/lib/librumphijack.so
216 atf_check -s exit:0 mkdir /rump/mnt
217 atf_check -s exit:0 mount_nfs 10.1.1.1:/export /rump/mnt
219 atf_check -s exit:0 -o inline:"${magicstr}\n" cat /rump/mnt/im_alive
220 atf_check -s exit:0 -o match:'.*im_alive$' ls -l /rump/mnt/im_alive
224 atf_test_case nfs cleanup
225 nfs_head()
227 atf_set "descr" "Test hijacked nfsd and mount_nfs"
230 nfs_body()
232 test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
233 -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif \
234 -lrumpdev_disk -lrumpfs_ffs -lrumpfs_nfs -lrumpfs_nfsserver \
235 -d key=/dk,hostpath=ffs.img,size=host
238 nfs_cleanup()
240 RUMP_SERVER=unix://serversock rump.halt 2> /dev/null
241 RUMP_SERVER=unix://clientsock rump.halt 2> /dev/null
245 atf_test_case nfs_autoload cleanup
246 nfs_autoload_head()
248 atf_set "descr" "Test hijacked nfsd with autoload from /stand"
251 nfs_autoload_body()
253 [ `uname -m` = "i386" ] || atf_skip "test currently valid only on i386"
254 test_nfs -lrumpvfs -lrumpdev -lrumpnet -lrumpnet_net \
255 -lrumpnet_netinet -lrumpnet_local -lrumpnet_shmif \
256 -lrumpdev_disk -d key=/dk,hostpath=ffs.img,size=host
259 nfs_autoload_cleanup()
261 nfs_cleanup
264 atf_init_test_cases()
266 atf_add_test_case http
267 atf_add_test_case ssh
268 atf_add_test_case nfs
269 atf_add_test_case nfs_autoload