add changelog
[oweals/gnunet.git] / src / dns / test_gnunet_dns.sh
1 #!/bin/sh
2
3 ME=`whoami`
4 if [ "$ME" != "root" ]
5 then
6   echo "This test only works if run as root.  Skipping."
7   exit 77
8 fi
9 if ! which sudo > /dev/null
10 then
11   echo "This test requires sudo.  Skipping."
12   exit 77
13 fi
14 if [ ! -x `which sudo` ]
15 then
16   echo "This test requires sudo.  Skipping."
17   exit 77
18 fi
19 if ! which nslookup > /dev/null
20 then
21   echo "This test requires nslookup.  Skipping."
22   exit 77
23 fi
24 if [ ! -x `which nslookup` ]
25 then
26   echo "This test requires nslookup.  Skipping."
27   exit 77
28 fi
29 if [ ! -x `which iptables` ]
30 then
31     echo "This test requires iptables.  Skipping."
32     exit 77
33 fi
34 if ! iptables -t mangle --list > /dev/null 2>&1
35 then
36   echo "This test requires iptables with 'mangle' support. Skipping."
37   exit 77
38 fi
39 if grep % /etc/resolv.conf > /dev/null 2>&1
40 then
41   echo "This system seems to use a DNS server on an IPv6 link-local address, which is not supported. Skipping."
42   exit 77
43 fi
44
45 if test ! `id nobody`;
46 then
47     echo "This tests requires a user account 'nobody'. Skipping."
48     exit 77
49 fi
50
51 export PATH=".:$PATH"
52 gnunet-service-dns -c dns.conf &
53 gnunet-dns-redirector -c dns.conf -4 127.0.0.1 &
54 sleep 1
55 # need to run 'nslookup' as 'nobody', as gnunet-service-dns runs as root
56 # and thus 'root' is excepted from DNS interception!
57 LO=`sudo -u nobody nslookup -type=A gnunet.org | grep Address | tail -n1`
58 if [ "$LO" != "Address: 127.0.0.1" ]
59 then
60  echo "Fail: got address $LO, wanted 127.0.0.1"
61  ret=1
62 else
63  echo "Test run, with success."
64  ret=0
65 fi
66 # TODO: jobs is a possible bashism. Fix.
67 kill `jobs -p`
68 exit $ret