test_gnunet_dns.sh 1.4 KB

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