aboutsummaryrefslogtreecommitdiff
path: root/src/dns/test_gnunet_dns.sh
blob: 0fa338c9ba1e930cd5355dceb1ac3ece25a3398b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

ME=`whoami`
if [ "$ME" != "root" ]
then
  echo "This test only works if run as root.  Skipping."
  exit 77
fi
if ! which sudo > /dev/null
then
  echo "This test requires sudo.  Skipping."
  exit 77
fi
if [ ! -x `which sudo` ]
then
  echo "This test requires sudo.  Skipping."
  exit 77
fi
if ! which nslookup > /dev/null
then
  echo "This test requires nslookup.  Skipping."
  exit 77
fi
if [ ! -x `which nslookup` ]
then
  echo "This test requires nslookup.  Skipping."
  exit 77
fi
if [ ! -x `which iptables` ]
then
    echo "This test requires iptables.  Skipping."
    exit 77
fi
if ! iptables -t mangle --list > /dev/null 2>&1
then
  echo "This test requires iptables with 'mangle' support. Skipping."
  exit 77
fi
if grep % /etc/resolv.conf > /dev/null 2>&1
then
  echo "This system seems to use a DNS server on an IPv6 link-local address, which is not supported. Skipping."
  exit 77
fi

export PATH=".:$PATH"
gnunet-service-dns -c dns.conf &
gnunet-dns-redirector -c dns.conf -4 127.0.0.1 &
sleep 1
# need to run 'nslookup' as 'nobody', as gnunet-service-dns runs as root
# and thus 'root' is excepted from DNS interception!
LO=`sudo -u nobody nslookup -type=A gnunet.org | grep Address | tail -n1`
if [ "$LO" != "Address: 127.0.0.1" ]
then
 echo "Fail: got address $LO, wanted 127.0.0.1"
 ret=1
else
 echo "Test run, with success."
 ret=0
fi
# TODO: jobs is a possible bashism. Fix.
kill `jobs -p`
exit $ret