aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am24
-rw-r--r--src/gns/gns.conf.in4
-rw-r--r--src/gns/gnunet-dns2gns.c60
-rw-r--r--src/gns/gnunet-gns-proxy-setup-ca.in322
-rw-r--r--src/gns/gnunet-gns-proxy.c59
-rw-r--r--src/gns/plugin_rest_gns.c478
-rwxr-xr-xsrc/gns/test_gns_at_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_cname_lookup.sh12
-rwxr-xr-xsrc/gns/test_gns_config_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_delegated_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_dht_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_gns2dns_cname_lookup.sh10
-rwxr-xr-xsrc/gns/test_gns_gns2dns_lookup.sh14
-rwxr-xr-xsrc/gns/test_gns_ipv6_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_mx_lookup.sh6
-rw-r--r--src/gns/test_gns_proxy.c16
-rwxr-xr-xsrc/gns/test_gns_quickupdate.sh6
-rwxr-xr-xsrc/gns/test_gns_rel_expiration.sh8
-rwxr-xr-xsrc/gns/test_gns_revocation.sh6
-rwxr-xr-xsrc/gns/test_gns_soa_lookup.sh8
-rwxr-xr-xsrc/gns/test_gns_txt_lookup.sh6
-rwxr-xr-xsrc/gns/test_gns_zkey_lookup.sh6
-rwxr-xr-xsrc/gns/test_gnunet_gns.sh25
-rwxr-xr-xsrc/gns/test_plugin_rest_gns.sh50
-rwxr-xr-xsrc/gns/test_proxy.sh4
26 files changed, 1011 insertions, 149 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 434d50f34..6ebbbcaff 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -89,9 +89,16 @@ bin_PROGRAMS += gnunet-bcd
89endif 89endif
90endif 90endif
91 91
92if HAVE_MHD
93if HAVE_JSON
94REST_PLUGIN = libgnunet_plugin_rest_gns.la
95endif
96endif
97
92plugin_LTLIBRARIES = \ 98plugin_LTLIBRARIES = \
93 libgnunet_plugin_block_gns.la \ 99 libgnunet_plugin_block_gns.la \
94 libgnunet_plugin_gnsrecord_gns.la 100 libgnunet_plugin_gnsrecord_gns.la \
101 $(REST_PLUGIN)
95 102
96 103
97bin_SCRIPTS = \ 104bin_SCRIPTS = \
@@ -104,6 +111,21 @@ gnunet-gns-proxy-setup-ca: gnunet-gns-proxy-setup-ca.in Makefile
104 $(do_subst) < $(srcdir)/gnunet-gns-proxy-setup-ca.in > gnunet-gns-proxy-setup-ca 111 $(do_subst) < $(srcdir)/gnunet-gns-proxy-setup-ca.in > gnunet-gns-proxy-setup-ca
105 chmod +x gnunet-gns-proxy-setup-ca 112 chmod +x gnunet-gns-proxy-setup-ca
106 113
114
115libgnunet_plugin_rest_gns_la_SOURCES = \
116 plugin_rest_gns.c
117libgnunet_plugin_rest_gns_la_LIBADD = \
118 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
119 libgnunetgns.la \
120 $(top_builddir)/src/rest/libgnunetrest.la \
121 $(top_builddir)/src/identity/libgnunetidentity.la \
122 $(top_builddir)/src/json/libgnunetjson.la \
123 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
124 $(LTLIBINTL) -ljansson -lmicrohttpd
125libgnunet_plugin_rest_gns_la_LDFLAGS = \
126 $(GN_PLUGIN_LDFLAGS)
127
128
107libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ 129libgnunet_plugin_gnsrecord_gns_la_SOURCES = \
108 plugin_gnsrecord_gns.c 130 plugin_gnsrecord_gns.c
109libgnunet_plugin_gnsrecord_gns_la_LIBADD = \ 131libgnunet_plugin_gnsrecord_gns_la_LIBADD = \
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index 2e6a02b07..3252e4888 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -32,6 +32,8 @@ INTERCEPT_DNS = NO
32BINARY = gnunet-gns-proxy 32BINARY = gnunet-gns-proxy
33START_ON_DEMAND = NO 33START_ON_DEMAND = NO
34RUN_PER_USER = YES 34RUN_PER_USER = YES
35BIND_TO=127.0.0.1
36BIND_TO6=::1
35 37
36# Where is the certificate for the GNS proxy stored? 38# Where is the certificate for the GNS proxy stored?
37PROXY_CACERT = $GNUNET_DATA_HOME/gns/gns_ca_cert.pem 39PROXY_CACERT = $GNUNET_DATA_HOME/gns/gns_ca_cert.pem
@@ -42,6 +44,8 @@ PROXY_UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gns-proxy.sock
42BINARY = gnunet-dns2gns 44BINARY = gnunet-dns2gns
43START_ON_DEMAND = NO 45START_ON_DEMAND = NO
44RUN_PER_USER = YES 46RUN_PER_USER = YES
47BIND_TO=127.0.0.1
48BIND_TO6=::1
45 49
46# -d: DNS resolver to use, -s: suffix to use, -f: fcfs suffix to use 50# -d: DNS resolver to use, -s: suffix to use, -f: fcfs suffix to use
47OPTIONS = -d 8.8.8.8 51OPTIONS = -d 8.8.8.8
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 68d090579..d2eabf02c 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -92,6 +92,17 @@ struct Request
92 uint16_t original_request_id; 92 uint16_t original_request_id;
93}; 93};
94 94
95/**
96 * The address to bind to
97 */
98static in_addr_t address;
99
100/**
101 * The IPv6 address to bind to
102 */
103static struct in6_addr address6;
104
105
95 106
96/** 107/**
97 * Handle to GNS resolver. 108 * Handle to GNS resolver.
@@ -578,6 +589,7 @@ run (void *cls,
578 const char *cfgfile, 589 const char *cfgfile,
579 const struct GNUNET_CONFIGURATION_Handle *c) 590 const struct GNUNET_CONFIGURATION_Handle *c)
580{ 591{
592 char *addr_str;
581 (void) cls; 593 (void) cls;
582 (void) args; 594 (void) args;
583 (void) cfgfile; 595 (void) cfgfile;
@@ -602,6 +614,52 @@ run (void *cls,
602 gns = NULL; 614 gns = NULL;
603 return; 615 return;
604 } 616 }
617
618 /* Get address to bind to */
619 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns",
620 "BIND_TO",
621 &addr_str))
622 {
623 //No address specified
624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
625 "Don't know what to bind to...\n");
626 GNUNET_free (addr_str);
627 GNUNET_SCHEDULER_shutdown ();
628 return;
629 }
630 if (1 != inet_pton (AF_INET, addr_str, &address))
631 {
632 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
633 "Unable to parse address %s\n",
634 addr_str);
635 GNUNET_free (addr_str);
636 GNUNET_SCHEDULER_shutdown ();
637 return;
638 }
639 GNUNET_free (addr_str);
640 /* Get address to bind to */
641 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (c, "dns2gns",
642 "BIND_TO6",
643 &addr_str))
644 {
645 //No address specified
646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
647 "Don't know what to bind6 to...\n");
648 GNUNET_free (addr_str);
649 GNUNET_SCHEDULER_shutdown ();
650 return;
651 }
652 if (1 != inet_pton (AF_INET6, addr_str, &address6))
653 {
654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
655 "Unable to parse IPv6 address %s\n",
656 addr_str);
657 GNUNET_free (addr_str);
658 GNUNET_SCHEDULER_shutdown ();
659 return;
660 }
661 GNUNET_free (addr_str);
662
605 listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET, 663 listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET,
606 SOCK_DGRAM, 664 SOCK_DGRAM,
607 IPPROTO_UDP); 665 IPPROTO_UDP);
@@ -611,6 +669,7 @@ run (void *cls,
611 669
612 memset (&v4, 0, sizeof (v4)); 670 memset (&v4, 0, sizeof (v4));
613 v4.sin_family = AF_INET; 671 v4.sin_family = AF_INET;
672 v4.sin_addr.s_addr = address;
614#if HAVE_SOCKADDR_IN_SIN_LEN 673#if HAVE_SOCKADDR_IN_SIN_LEN
615 v4.sin_len = sizeof (v4); 674 v4.sin_len = sizeof (v4);
616#endif 675#endif
@@ -634,6 +693,7 @@ run (void *cls,
634 693
635 memset (&v6, 0, sizeof (v6)); 694 memset (&v6, 0, sizeof (v6));
636 v6.sin6_family = AF_INET6; 695 v6.sin6_family = AF_INET6;
696 v6.sin6_addr = address6;
637#if HAVE_SOCKADDR_IN_SIN_LEN 697#if HAVE_SOCKADDR_IN_SIN_LEN
638 v6.sin6_len = sizeof (v6); 698 v6.sin6_len = sizeof (v6);
639#endif 699#endif
diff --git a/src/gns/gnunet-gns-proxy-setup-ca.in b/src/gns/gnunet-gns-proxy-setup-ca.in
index 0a6fab18a..184da4853 100644
--- a/src/gns/gnunet-gns-proxy-setup-ca.in
+++ b/src/gns/gnunet-gns-proxy-setup-ca.in
@@ -1,78 +1,252 @@
1#!/bin/sh 1#!/bin/sh
2# This shell script will generate an X509 certificate for your gnunet-gns-proxy
3# and install it (for both GNUnet and your browser).
4# 2#
3# This shell script will generate an X509 certificate for
4# your gnunet-gns-proxy and install it (for both GNUnet
5# and your browser).
6#
7# TODO: Implement support for more browsers
8# TODO: Debug and switch to the new version
9# TODO - The only remaining task is fixing the getopts
10# TODO: Error checks
11#
12# The current version partially reuses and recycles
13# code from build.sh by NetBSD (although not entirely
14# used because it needs debugging):
15#
16# Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
17# All rights reserved.
18#
19# This code is derived from software contributed to
20# The NetBSD Foundation by Todd Vierling and Luke Mewburn.
21
22# Redistribution and use in source and binary forms, with or
23# without modification, are permitted provided that the following
24# conditions are met:
25# 1. Redistributions of source code must retain the above
26# copyright notice, this list of conditions and the following
27# disclaimer.
28# 2. Redistributions in binary form must reproduce the above
29# copyright notice, this list of conditions and the following
30# disclaimer in the documentation and/or other materials
31# provided with the distribution.
5 32
6OPENSSLCFG=@pkgdatadir@/openssl.cnf 33# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
7if ! which openssl > /dev/null 34# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
8then 35# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
9 echo "'openssl' command not found. Please install it." 36# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
10 exit 1 37# DISCLAIMED.
11fi 38# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR
12 39# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
13echo "Generating CA" 40# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
14options='' 41# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15while getopts "c:" opt; do 42# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
16 case $opt in 43# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
17 c) 44# LIABILITY, OR TORT
18 options="$options -c $OPTARG" 45# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
19 ;; 46# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
20 \?) 47# OF SUCH DAMAGE.
21 echo "Invalid option: -$OPTARG" >&2 48
22 exit 1 49progname=${0##*/}
23 ;; 50
24 :) 51setdefaults()
25 echo "Option -$OPTARG requires an argument." >&2 52{
26 exit 1 53 verbosity=0
27 ;; 54 runcmd=
28 esac 55}
29done 56
30 57statusmsg()
31GNSCERT=`mktemp /tmp/gnscertXXXXXX.pem` 58{
32GNSCAKY=`mktemp /tmp/gnscakeyXXXXXX.pem` 59 ${runcmd} echo " $@"
33GNSCANO=`mktemp /tmp/gnscakeynoencXXXXXX.pem` 60}
34GNS_CA_CERT_PEM=`gnunet-config -s gns-proxy -o PROXY_CACERT -f $options` 61
35mkdir -p `dirname $GNS_CA_CERT_PEM` 62infomsg()
36 63{
37openssl req -config $OPENSSLCFG -new -x509 -days 3650 -extensions v3_ca -keyout $GNSCAKY -out $GNSCERT -subj "/C=ZZ/L=World/O=GNU/OU=GNUnet/CN=GNS Proxy CA/emailAddress=bounce@gnunet.org" -passout pass:"GNU Name System" 64 if [ $verbosity = 1 ]; then
38 65 statusmsg "INFO: $@"
39echo "Removing passphrase from key"
40openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
41
42echo "Making private key available to gnunet-gns-proxy"
43cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
44
45if ! which certutil > /dev/null
46then
47 echo "The 'certutil' command was not found. Not importing into browsers."
48 echo "For 'certutil' install nss."
49else
50 echo "Importing CA into browsers"
51 for f in ~/.mozilla/firefox/*.*/
52 do
53 if [ -d $f ]; then
54 echo "Importing CA info Firefox at $f"
55 # delete old certificate (if any)
56 certutil -D -n "GNS Proxy CA" -d "$f" >/dev/null 2>/dev/null
57 # add new certificate
58 certutil -A -n "GNS Proxy CA" -t CT,, -d "$f" < $GNSCERT
59 fi 66 fi
60 done 67}
61 68
62 if [ -d ~/.pki/nssdb/ ]; then 69warningmsg()
63 echo "Importing CA into Chrome at ~/.pki/nssdb/" 70{
64 # delete old certificate (if any) 71 statusmsg "WARNING: $@"
65 certutil -D -n "GNS Proxy CA" -d ~/.pki/nssdb/ >/dev/null 2>/dev/null 72}
66 # add new certificate 73
67 certutil -A -n "GNS Proxy CA" -t CT,, -d ~/.pki/nssdb/ < $GNSCERT 74errormsg()
68 fi 75{
69fi 76 statusmsg "ERROR: $@"
70 77}
71echo "Cleaning up." 78
72rm -f $GNSCAKY $GNSCANO $GNSCERT 79linemsg()
73 80{
74echo "===================================" 81 statusmsg "========================================="
75echo "You can now start gnunet-gns-proxy." 82}
76echo "Afterwards, configure your browser " 83
77echo " to use a SOCKS proxy on port 7777." 84
78echo "===================================" 85usage()
86{
87 if [ -n "$*" ]; then
88 echo ""
89 echo "${progname}: $*"
90 fi
91 cat <<_usage_
92
93Usage: ${progname} [-hv] [-c FILE] [...]
94
95Options:
96 -c FILE Use the configuration file FILE.
97 -h Print this help message.
98 -v Print the version and exit.
99 -V be verbose
100
101_usage_
102 exit 1
103}
104
105
106generate_ca()
107{
108 echo ""
109 infomsg "Generating CA"
110 TMPDIR=${TMPDIR:-/tmp}
111 if [ -e "$TMPDIR" ]; then
112 GNSCERT=`mktemp -t certXXXXXXXX.pem` || exit 1
113 GNSCAKY=`mktemp -t cakyXXXXXXXX.pem` || exit 1
114 GNSCANO=`mktemp -t canoXXXXXXXX.pem` || exit 1
115 else
116 # This warning is mostly pointless.
117 warning "You need to export the TMPDIR variable"
118 fi
119
120 # # ------------- gnutls
121 #
122 # if ! which certutil > /dev/null
123 # then
124 # warningmsg "The 'certutil' command was not found."
125 # warningmsg "Not importing into browsers."
126 # warningmsg "For 'certutil' install nss."
127 # else
128 # # Generate CA key
129 # # pkcs#8 password-protects key
130 # certtool --pkcs8 --generate-privkey --sec-param high --outfile ca-key.pem
131 # # self-sign the CA to create public certificate
132 # certtool --generate-self-signed --load-privkey ca-key.pem --template ca.cfg --outfile ca.pem
133
134 # ------------- openssl
135
136 OPENSSLCFG=@pkgdatadir@/openssl.cnf
137 if test -z "`openssl version`" > /dev/null
138 then
139 warningmsg "'openssl' command not found. Please install it."
140 infomsg "Cleaning up."
141 rm -f $GNSCAKY $GNSCANO $GNSCERT
142 exit 1
143 fi
144 if [ -n "${GNUNET_CONFIG_FILE}" ]; then
145 GNUNET_CONFIG="-c ${GNUNET_CONFIG_FILE}"
146 else
147 GNUNET_CONFIG=""
148 fi
149 GNS_CA_CERT_PEM=`gnunet-config ${GNUNET_CONFIG} -s gns-proxy -o PROXY_CACERT -f ${options}`
150 mkdir -p `dirname $GNS_CA_CERT_PEM`
151
152 openssl req -config $OPENSSLCFG -new -x509 -days 3650 -extensions v3_ca -keyout $GNSCAKY -out $GNSCERT -subj "/C=ZZ/L=World/O=GNU/OU=GNUnet/CN=GNS Proxy CA/emailAddress=bounce@gnunet.org" -passout pass:"GNU Name System"
153
154 infomsg "Removing passphrase from key"
155 openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
156
157 infomsg "Making private key available to gnunet-gns-proxy"
158 cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
159}
160
161importbrowsers()
162{
163 # Don't check with -H, -H defies any method to not
164 # print the output on screen! Let's hope that every
165 # certutil gets build with some kind of build flags
166 # which end up being printed here:
167 if test -z "`certutil --build-flags`" > /dev/null 2>&1
168 then
169 warningmsg "The 'certutil' command was not found."
170 warningmsg "Not importing into browsers."
171 warningmsg "For 'certutil' install nss."
172 else
173 infomsg "Importing CA into browsers"
174 # TODO: Error handling?
175 for f in ~/.mozilla/firefox/*.*/
176 do
177 if [ -d $f ]; then
178 infomsg "Importing CA into Firefox at $f"
179 # delete old certificate (if any)
180 certutil -D -n "GNS Proxy CA" -d "$f" >/dev/null 2>/dev/null
181 # add new certificate
182 certutil -A -n "GNS Proxy CA" -t CT,, -d "$f" < $GNSCERT
183 fi
184 done
185 # TODO: Error handling?
186 if [ -d ~/.pki/nssdb/ ]; then
187 infomsg "Importing CA into Chrome at ~/.pki/nssdb/"
188 # delete old certificate (if any)
189 certutil -D -n "GNS Proxy CA" -d ~/.pki/nssdb/ >/dev/null 2>/dev/null
190 # add new certificate
191 certutil -A -n "GNS Proxy CA" -t CT,, -d ~/.pki/nssdb/ < $GNSCERT
192 fi
193 fi
194}
195
196print_version()
197{
198 GNUNET_ARM_VERSION=`gnunet-arm -v`
199 echo $GNUNET_ARM_VERSION
200}
201
202clean_up()
203{
204 infomsg "Cleaning up."
205 rm -f $GNSCAKY $GNSCANO $GNSCERT
206 if [ -e $SETUP_TMPDIR ]; then
207 rm -rf $SETUP_TMPDIR
208 fi
209
210 linemsg
211 statusmsg "You can now start gnunet-gns-proxy."
212 statusmsg "Afterwards, configure your browser "
213 statusmsg "to use a SOCKS proxy on port 7777. "
214 linemsg
215}
216
217main()
218{
219 while getopts "vhVc:" opt; do
220 case $opt in
221 v)
222 print_version
223 exit 0
224 ;;
225 h)
226 usage
227 ;;
228 V)
229 verbosity=1
230 ;;
231 c)
232 options="$options -c $OPTARG"
233 infomsg "Using configuration file $OPTARG"
234 GNUNET_CONFIG_FILE=${OPTARG}
235 ;;
236 \?)
237 echo "Invalid option: -$OPTARG" >&2
238 usage
239 ;;
240 :)
241 echo "Option -$OPTARG requires an argument." >&2
242 usage
243 ;;
244 esac
245 done
246 setdefaults
247 generate_ca
248 importbrowsers
249 clean_up
250}
251
252main "$@"
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 65a7b6018..bae222499 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -661,6 +661,15 @@ struct Socks5Request
661 661
662/* *********************** Globals **************************** */ 662/* *********************** Globals **************************** */
663 663
664/**
665 * The address to bind to
666 */
667static in_addr_t address;
668
669/**
670 * The IPv6 address to bind to
671 */
672static struct in6_addr address6;
664 673
665/** 674/**
666 * The port the proxy is running on (default 7777) 675 * The port the proxy is running on (default 7777)
@@ -2182,7 +2191,7 @@ create_response (void *cls,
2182 } 2191 }
2183 MHD_get_connection_values (con, 2192 MHD_get_connection_values (con,
2184 MHD_HEADER_KIND, 2193 MHD_HEADER_KIND,
2185 &con_val_iter, 2194 (MHD_KeyValueIterator) &con_val_iter,
2186 s5r); 2195 s5r);
2187 curl_easy_setopt (s5r->curl, 2196 curl_easy_setopt (s5r->curl,
2188 CURLOPT_HTTPHEADER, 2197 CURLOPT_HTTPHEADER,
@@ -3516,6 +3525,7 @@ bind_v4 ()
3516 memset (&sa4, 0, sizeof (sa4)); 3525 memset (&sa4, 0, sizeof (sa4));
3517 sa4.sin_family = AF_INET; 3526 sa4.sin_family = AF_INET;
3518 sa4.sin_port = htons (port); 3527 sa4.sin_port = htons (port);
3528 sa4.sin_addr.s_addr = address;
3519#if HAVE_SOCKADDR_IN_SIN_LEN 3529#if HAVE_SOCKADDR_IN_SIN_LEN
3520 sa4.sin_len = sizeof (sa4); 3530 sa4.sin_len = sizeof (sa4);
3521#endif 3531#endif
@@ -3553,6 +3563,7 @@ bind_v6 ()
3553 memset (&sa6, 0, sizeof (sa6)); 3563 memset (&sa6, 0, sizeof (sa6));
3554 sa6.sin6_family = AF_INET6; 3564 sa6.sin6_family = AF_INET6;
3555 sa6.sin6_port = htons (port); 3565 sa6.sin6_port = htons (port);
3566 sa6.sin6_addr = address6;
3556#if HAVE_SOCKADDR_IN_SIN_LEN 3567#if HAVE_SOCKADDR_IN_SIN_LEN
3557 sa6.sin6_len = sizeof (sa6); 3568 sa6.sin6_len = sizeof (sa6);
3558#endif 3569#endif
@@ -3591,10 +3602,56 @@ run (void *cls,
3591{ 3602{
3592 char* cafile_cfg = NULL; 3603 char* cafile_cfg = NULL;
3593 char* cafile; 3604 char* cafile;
3605 char* addr_str;
3594 struct MhdHttpList *hd; 3606 struct MhdHttpList *hd;
3595 3607
3596 cfg = c; 3608 cfg = c;
3597 3609
3610 /* Get address to bind to */
3611 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy",
3612 "BIND_TO",
3613 &addr_str))
3614 {
3615 //No address specified
3616 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3617 "Don't know what to bind to...\n");
3618 GNUNET_free (addr_str);
3619 GNUNET_SCHEDULER_shutdown ();
3620 return;
3621 }
3622 if (1 != inet_pton (AF_INET, addr_str, &address))
3623 {
3624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3625 "Unable to parse address %s\n",
3626 addr_str);
3627 GNUNET_free (addr_str);
3628 GNUNET_SCHEDULER_shutdown ();
3629 return;
3630 }
3631 GNUNET_free (addr_str);
3632 /* Get address to bind to */
3633 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "gns-proxy",
3634 "BIND_TO6",
3635 &addr_str))
3636 {
3637 //No address specified
3638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3639 "Don't know what to bind6 to...\n");
3640 GNUNET_free (addr_str);
3641 GNUNET_SCHEDULER_shutdown ();
3642 return;
3643 }
3644 if (1 != inet_pton (AF_INET6, addr_str, &address6))
3645 {
3646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3647 "Unable to parse IPv6 address %s\n",
3648 addr_str);
3649 GNUNET_free (addr_str);
3650 GNUNET_SCHEDULER_shutdown ();
3651 return;
3652 }
3653 GNUNET_free (addr_str);
3654
3598 if (NULL == (curl_multi = curl_multi_init ())) 3655 if (NULL == (curl_multi = curl_multi_init ()))
3599 { 3656 {
3600 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
new file mode 100644
index 000000000..e41df4085
--- /dev/null
+++ b/src/gns/plugin_rest_gns.c
@@ -0,0 +1,478 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @author Philippe Buschmann
22 * @file gns/plugin_rest_gns.c
23 * @brief GNUnet Gns REST plugin
24 */
25
26#include "platform.h"
27#include "gnunet_rest_plugin.h"
28#include "gnunet_rest_lib.h"
29#include "gnunet_json_lib.h"
30#include "gnunet_gnsrecord_lib.h"
31#include "gnunet_gns_service.h"
32#include "microhttpd.h"
33#include <jansson.h>
34
35/**
36 * Rest API GNS Namespace
37 */
38#define GNUNET_REST_API_NS_GNS "/gns"
39
40/**
41 * Rest API GNS Parameter record_type
42 */
43#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
44
45/**
46 * Rest API GNS ERROR Unknown Error
47 */
48#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
49
50/**
51 * Rest API GNS ERROR Record not found
52 */
53#define GNUNET_REST_GNS_NOT_FOUND "Record not found"
54
55/**
56 * The configuration handle
57 */
58const struct GNUNET_CONFIGURATION_Handle *cfg;
59
60/**
61 * HTTP methods allows for this plugin
62 */
63static char* allow_methods;
64
65/**
66 * @brief struct returned by the initialization function of the plugin
67 */
68struct Plugin
69{
70 const struct GNUNET_CONFIGURATION_Handle *cfg;
71};
72
73/**
74 * The request handle
75 */
76struct RequestHandle
77{
78
79 /**
80 * Connection to GNS
81 */
82 struct GNUNET_GNS_Handle *gns;
83
84 /**
85 * Active GNS lookup
86 */
87 struct GNUNET_GNS_LookupWithTldRequest *gns_lookup;
88
89 /**
90 * Name to look up
91 */
92 char *name;
93
94 /**
95 * Record type to look up
96 */
97 int record_type;
98
99 /**
100 * Rest connection
101 */
102 struct GNUNET_REST_RequestHandle *rest_handle;
103
104 /**
105 * Desired timeout for the lookup (default is no timeout).
106 */
107 struct GNUNET_TIME_Relative timeout;
108
109 /**
110 * ID of a task associated with the resolution process.
111 */
112 struct GNUNET_SCHEDULER_Task *timeout_task;
113
114 /**
115 * The plugin result processor
116 */
117 GNUNET_REST_ResultProcessor proc;
118
119 /**
120 * The closure of the result processor
121 */
122 void *proc_cls;
123
124 /**
125 * The url
126 */
127 char *url;
128
129 /**
130 * Error response message
131 */
132 char *emsg;
133
134 /**
135 * Response code
136 */
137 int response_code;
138
139};
140
141
142/**
143 * Cleanup lookup handle
144 * @param handle Handle to clean up
145 */
146static void
147cleanup_handle (void *cls)
148{
149 struct RequestHandle *handle = cls;
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
151 "Cleaning up\n");
152
153 if (NULL != handle->gns_lookup)
154 {
155 GNUNET_GNS_lookup_with_tld_cancel (handle->gns_lookup);
156 handle->gns_lookup = NULL;
157 }
158 if (NULL != handle->gns)
159 {
160 GNUNET_GNS_disconnect (handle->gns);
161 handle->gns = NULL;
162 }
163
164 if (NULL != handle->timeout_task)
165 {
166 GNUNET_SCHEDULER_cancel (handle->timeout_task);
167 handle->timeout_task = NULL;
168 }
169 if (NULL != handle->url)
170 GNUNET_free (handle->url);
171 if (NULL != handle->name)
172 GNUNET_free (handle->name);
173 if (NULL != handle->emsg)
174 GNUNET_free (handle->emsg);
175
176 GNUNET_free (handle);
177}
178
179
180/**
181 * Task run on errors. Reports an error and cleans up everything.
182 *
183 * @param cls the `struct RequestHandle`
184 */
185static void
186do_error (void *cls)
187{
188 struct RequestHandle *handle = cls;
189 struct MHD_Response *resp;
190 json_t *json_error = json_object();
191 char *response;
192
193 if (NULL == handle->emsg)
194 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_ERROR_UNKNOWN);
195
196 json_object_set_new(json_error,"error", json_string(handle->emsg));
197
198 if (0 == handle->response_code)
199 handle->response_code = MHD_HTTP_OK;
200 response = json_dumps (json_error, 0);
201 resp = GNUNET_REST_create_response (response);
202 handle->proc (handle->proc_cls, resp, handle->response_code);
203 json_decref(json_error);
204 GNUNET_free(response);
205 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
206}
207
208
209/**
210 * Iterator called on obtained result for a GNS lookup.
211 *
212 * @param cls closure with the object
213 * @param was_gns #GNUNET_NO if name was not a GNS name
214 * @param rd_count number of records in @a rd
215 * @param rd the records in reply
216 */
217static void
218handle_gns_response (void *cls,
219 int was_gns,
220 uint32_t rd_count,
221 const struct GNUNET_GNSRECORD_Data *rd)
222{
223 struct RequestHandle *handle = cls;
224 struct MHD_Response *resp;
225 json_t *result_array;
226 json_t *record_obj;
227 char *result;
228
229 handle->gns_lookup = NULL;
230
231 if (GNUNET_NO == was_gns)
232 {
233 handle->response_code = MHD_HTTP_NOT_FOUND;
234 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
235 GNUNET_SCHEDULER_add_now (&do_error, handle);
236 return;
237 }
238
239 result_array = json_array();
240 for (uint32_t i=0;i<rd_count;i++)
241 {
242 if ((rd[i].record_type != handle->record_type) &&
243 (GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) )
244 {
245 continue;
246 }
247
248 record_obj = GNUNET_JSON_from_gns_record(NULL,&rd[i]);
249 json_array_append (result_array, record_obj);
250 json_decref (record_obj);
251 }
252
253 result = json_dumps(result_array, 0);
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
255 resp = GNUNET_REST_create_response (result);
256 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
257 GNUNET_free (result);
258 json_decref (result_array);
259 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
260}
261
262
263/**
264 * Handle gns GET request
265 *
266 * @param con_handle the connection handle
267 * @param url the url
268 * @param cls the RequestHandle
269 */
270void
271get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
272 const char* url,
273 void *cls)
274{
275 struct RequestHandle *handle = cls;
276 struct GNUNET_HashCode key;
277 char *record_type;
278 char *name;
279
280 name = NULL;
281 handle->name = NULL;
282 if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url))
283 {
284 name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1];
285 }
286
287 if (NULL == name)
288 {
289 handle->response_code = MHD_HTTP_NOT_FOUND;
290 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
291 GNUNET_SCHEDULER_add_now (&do_error, handle);
292 return;
293 }
294 if (0 >= strlen (name))
295 {
296 handle->response_code = MHD_HTTP_NOT_FOUND;
297 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
298 GNUNET_SCHEDULER_add_now (&do_error, handle);
299 return;
300 }
301 handle->name = GNUNET_strdup(name);
302
303 handle->record_type = UINT32_MAX;
304 GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_RECORD_TYPE,
305 strlen (GNUNET_REST_GNS_PARAM_RECORD_TYPE),
306 &key);
307 if ( GNUNET_YES
308 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map,
309 &key))
310 {
311 record_type = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
312 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
313 }
314
315 if(UINT32_MAX == handle->record_type)
316 {
317 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
318 }
319
320 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
321 handle->name,
322 handle->record_type,
323 GNUNET_NO,
324 &handle_gns_response,
325 handle);
326}
327
328
329
330/**
331 * Respond to OPTIONS request
332 *
333 * @param con_handle the connection handle
334 * @param url the url
335 * @param cls the RequestHandle
336 */
337static void
338options_cont (struct GNUNET_REST_RequestHandle *con_handle,
339 const char* url,
340 void *cls)
341{
342 struct MHD_Response *resp;
343 struct RequestHandle *handle = cls;
344
345 //independent of path return all options
346 resp = GNUNET_REST_create_response (NULL);
347 MHD_add_response_header (resp,
348 "Access-Control-Allow-Methods",
349 allow_methods);
350 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
351 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle);
352 return;
353}
354
355
356/**
357 * Handle rest request
358 *
359 * @param handle the request handle
360 */
361static void
362init_cont (struct RequestHandle *handle)
363{
364 struct GNUNET_REST_RequestHandlerError err;
365 static const struct GNUNET_REST_RequestHandler handlers[] = {
366 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
367 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
368 GNUNET_REST_HANDLER_END
369 };
370
371 if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle,
372 handlers,
373 &err,
374 handle))
375 {
376 handle->response_code = err.error_code;
377 GNUNET_SCHEDULER_add_now (&do_error, handle);
378 }
379}
380
381
382/**
383 * Function processing the REST call
384 *
385 * @param method HTTP method
386 * @param url URL of the HTTP request
387 * @param data body of the HTTP request (optional)
388 * @param data_size length of the body
389 * @param proc callback function for the result
390 * @param proc_cls closure for callback function
391 * @return GNUNET_OK if request accepted
392 */
393static void
394rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
395 GNUNET_REST_ResultProcessor proc,
396 void *proc_cls)
397{
398 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
399
400 handle->response_code = 0;
401 handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60);
402 handle->proc_cls = proc_cls;
403 handle->proc = proc;
404 handle->rest_handle = rest_handle;
405
406 handle->url = GNUNET_strdup (rest_handle->url);
407 if (handle->url[strlen (handle->url)-1] == '/')
408 handle->url[strlen (handle->url)-1] = '\0';
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
410 handle->gns = GNUNET_GNS_connect (cfg);
411 init_cont(handle);
412
413 handle->timeout_task =
414 GNUNET_SCHEDULER_add_delayed (handle->timeout,
415 &do_error,
416 handle);
417
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
419}
420
421
422/**
423 * Entry point for the plugin.
424 *
425 * @param cls Config info
426 * @return NULL on error, otherwise the plugin context
427 */
428void *
429libgnunet_plugin_rest_gns_init (void *cls)
430{
431 static struct Plugin plugin;
432 struct GNUNET_REST_Plugin *api;
433
434 cfg = cls;
435 if (NULL != plugin.cfg)
436 return NULL; /* can only initialize once! */
437 memset (&plugin, 0, sizeof (struct Plugin));
438 plugin.cfg = cfg;
439 api = GNUNET_new (struct GNUNET_REST_Plugin);
440 api->cls = &plugin;
441 api->name = GNUNET_REST_API_NS_GNS;
442 api->process_request = &rest_process_request;
443 GNUNET_asprintf (&allow_methods,
444 "%s, %s, %s, %s, %s",
445 MHD_HTTP_METHOD_GET,
446 MHD_HTTP_METHOD_POST,
447 MHD_HTTP_METHOD_PUT,
448 MHD_HTTP_METHOD_DELETE,
449 MHD_HTTP_METHOD_OPTIONS);
450
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
452 _("Gns REST API initialized\n"));
453 return api;
454}
455
456
457/**
458 * Exit point from the plugin.
459 *
460 * @param cls the plugin context (as returned by "init")
461 * @return always NULL
462 */
463void *
464libgnunet_plugin_rest_gns_done (void *cls)
465{
466 struct GNUNET_REST_Plugin *api = cls;
467 struct Plugin *plugin = api->cls;
468 plugin->cfg = NULL;
469
470 GNUNET_free_non_null (allow_methods);
471 GNUNET_free (api);
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "Gns REST plugin is finished\n");
474 return NULL;
475}
476
477/* end of plugin_rest_gns.c */
478
diff --git a/src/gns/test_gns_at_lookup.sh b/src/gns/test_gns_at_lookup.sh
index d900c070b..bacc63eb0 100755
--- a/src/gns/test_gns_at_lookup.sh
+++ b/src/gns/test_gns_at_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 17which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
18rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 18rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
19 19
20TEST_IP="127.0.0.1" 20TEST_IP="127.0.0.1"
@@ -31,7 +31,7 @@ gnunet-namestore -z delegatedego -d -n '@' -t A -V $TEST_IP -e never -c test_gn
31gnunet-arm -e -c test_gns_lookup.conf 31gnunet-arm -e -c test_gns_lookup.conf
32rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 32rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
33 33
34if [ "$RES_IP" == "$TEST_IP" ] 34if [ "$RES_IP" = "$TEST_IP" ]
35then 35then
36 exit 0 36 exit 0
37else 37else
diff --git a/src/gns/test_gns_cname_lookup.sh b/src/gns/test_gns_cname_lookup.sh
index de575c561..d97a4fe5e 100755
--- a/src/gns/test_gns_cname_lookup.sh
+++ b/src/gns/test_gns_cname_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -16,7 +16,7 @@ fi
16 16
17# permissive DNS resolver we will use for the test 17# permissive DNS resolver we will use for the test
18DNS_RESOLVER="8.8.8.8" 18DNS_RESOLVER="8.8.8.8"
19if ! nslookup gnunet.org $DNS_RESOLVER &> /dev/null 19if ! nslookup gnunet.org $DNS_RESOLVER > /dev/null 2>&1
20then 20then
21 echo "Cannot reach DNS, skipping test" 21 echo "Cannot reach DNS, skipping test"
22 exit 77 22 exit 77
@@ -36,7 +36,7 @@ TEST_RECORD_NAME_DNS="www3"
36MY_EGO="myego" 36MY_EGO="myego"
37TEST_DOMAIN_PLUS="www.$MY_EGO" 37TEST_DOMAIN_PLUS="www.$MY_EGO"
38TEST_DOMAIN_DNS="www3.$MY_EGO" 38TEST_DOMAIN_DNS="www3.$MY_EGO"
39which timeout &> /dev/null && DO_TIMEOUT="timeout 15" 39which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 15"
40 40
41gnunet-arm -s -c test_gns_lookup.conf 41gnunet-arm -s -c test_gns_lookup.conf
42gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 42gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
@@ -57,7 +57,7 @@ rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
57# make cmp case-insensitive by converting to lower case first 57# make cmp case-insensitive by converting to lower case first
58RES_CNAME_RAW=`echo $RES_CNAME_RAW | tr [A-Z] [a-z]` 58RES_CNAME_RAW=`echo $RES_CNAME_RAW | tr [A-Z] [a-z]`
59TESTEGOZONE=`echo $TESTEGOZONE | tr [A-Z] [a-z]` 59TESTEGOZONE=`echo $TESTEGOZONE | tr [A-Z] [a-z]`
60if [ "$RES_CNAME_RAW" == "server.$TESTEGOZONE" ] 60if [ "$RES_CNAME_RAW" = "server.$TESTEGOZONE" ]
61then 61then
62 echo "PASS: CNAME resolution from GNS" 62 echo "PASS: CNAME resolution from GNS"
63else 63else
@@ -65,7 +65,7 @@ else
65 exit 1 65 exit 1
66fi 66fi
67 67
68if [ "$RES_CNAME" == "$TEST_IP_PLUS" ] 68if [ "$RES_CNAME" = "$TEST_IP_PLUS" ]
69then 69then
70 echo "PASS: IP resolution from GNS" 70 echo "PASS: IP resolution from GNS"
71else 71else
@@ -73,7 +73,7 @@ else
73 exit 1 73 exit 1
74fi 74fi
75 75
76if [ "$RES_CNAME_DNS" == "$TEST_IP_DNS" ] 76if [ "$RES_CNAME_DNS" = "$TEST_IP_DNS" ]
77then 77then
78 echo "PASS: IP resolution from DNS" 78 echo "PASS: IP resolution from DNS"
79 exit 0 79 exit 0
diff --git a/src/gns/test_gns_config_lookup.sh b/src/gns/test_gns_config_lookup.sh
index 35d7c32d9..1c5a62b01 100755
--- a/src/gns/test_gns_config_lookup.sh
+++ b/src/gns/test_gns_config_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -18,7 +18,7 @@ MY_EGO="myego"
18rm -rf `gnunet-config -c test_gns_lookup.conf -s PATHS -o GNUNET_HOME -f` 18rm -rf `gnunet-config -c test_gns_lookup.conf -s PATHS -o GNUNET_HOME -f`
19CFG=`mktemp --tmpdir=$PWD` 19CFG=`mktemp --tmpdir=$PWD`
20cp test_gns_lookup.conf $CFG || exit 77 20cp test_gns_lookup.conf $CFG || exit 77
21which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 21which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
22TEST_IP="dead::beef" 22TEST_IP="dead::beef"
23gnunet-arm -s -c $CFG || exit 77 23gnunet-arm -s -c $CFG || exit 77
24gnunet-identity -C $MY_EGO -c $CFG 24gnunet-identity -C $MY_EGO -c $CFG
@@ -35,7 +35,7 @@ gnunet-arm -e -c $CFG
35rm -rf `gnunet-config -c $CFG -f -s paths -o GNUNET_TEST_HOME` 35rm -rf `gnunet-config -c $CFG -f -s paths -o GNUNET_TEST_HOME`
36rm $CFG 36rm $CFG
37 37
38if [ "$RES_IP" == "$TEST_IP" ] 38if [ "$RES_IP" = "$TEST_IP" ]
39then 39then
40 exit 0 40 exit 0
41else 41else
diff --git a/src/gns/test_gns_delegated_lookup.sh b/src/gns/test_gns_delegated_lookup.sh
index 21774ad8d..af9994b34 100755
--- a/src/gns/test_gns_delegated_lookup.sh
+++ b/src/gns/test_gns_delegated_lookup.sh
@@ -1,7 +1,7 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 4which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
5 5
6LOCATION=$(which gnunet-config) 6LOCATION=$(which gnunet-config)
7if [ -z $LOCATION ] 7if [ -z $LOCATION ]
@@ -35,7 +35,7 @@ gnunet-arm -e -c test_gns_lookup.conf
35 35
36rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 36rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
37 37
38if [ "$RES_IP" == "$TEST_IP" ] 38if [ "$RES_IP" = "$TEST_IP" ]
39then 39then
40 exit 0 40 exit 0
41else 41else
diff --git a/src/gns/test_gns_dht_lookup.sh b/src/gns/test_gns_dht_lookup.sh
index 07e559752..ac90d58a8 100755
--- a/src/gns/test_gns_dht_lookup.sh
+++ b/src/gns/test_gns_dht_lookup.sh
@@ -1,7 +1,7 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 4which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
5 5
6LOCATION=$(which gnunet-config) 6LOCATION=$(which gnunet-config)
7if [ -z $LOCATION ] 7if [ -z $LOCATION ]
@@ -55,7 +55,7 @@ then
55 echo "Failed to resolve to proper IP, got $RES_IP_REL. (relative expiration)" 55 echo "Failed to resolve to proper IP, got $RES_IP_REL. (relative expiration)"
56 #exit 1 56 #exit 1
57fi 57fi
58if [ "$RES_IP" == "$TEST_IP" ] 58if [ "$RES_IP" = "$TEST_IP" ]
59then 59then
60 exit 0 60 exit 0
61else 61else
diff --git a/src/gns/test_gns_gns2dns_cname_lookup.sh b/src/gns/test_gns_gns2dns_cname_lookup.sh
index c07905d83..fbc1dd7ee 100755
--- a/src/gns/test_gns_gns2dns_cname_lookup.sh
+++ b/src/gns/test_gns_gns2dns_cname_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -25,7 +25,7 @@ TEST_RECORD_NAME="homepage"
25 25
26XNS=ns.joker.com 26XNS=ns.joker.com
27 27
28if ! nslookup gnunet.org a.$XNS &> /dev/null 28if ! nslookup gnunet.org a.$XNS > /dev/null 2>&1
29then 29then
30 echo "Cannot reach DNS, skipping test" 30 echo "Cannot reach DNS, skipping test"
31 exit 77 31 exit 77
@@ -43,7 +43,7 @@ MY_EGO="myego"
43# various names we will use for resolution 43# various names we will use for resolution
44TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO" 44TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO"
45 45
46which timeout &> /dev/null && DO_TIMEOUT="timeout 15" 46which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 15"
47 47
48gnunet-arm -s -c test_gns_lookup.conf 48gnunet-arm -s -c test_gns_lookup.conf
49OUT=`$DO_TIMEOUT gnunet-resolver -c test_gns_lookup.conf gnunet.org` 49OUT=`$DO_TIMEOUT gnunet-resolver -c test_gns_lookup.conf gnunet.org`
@@ -77,7 +77,7 @@ gnunet-arm -e -c test_gns_lookup.conf
77rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 77rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
78 78
79ret=0 79ret=0
80if [ "$RES_IP" == "$TEST_IP" ] 80if [ "$RES_IP" = "$TEST_IP" ]
81then 81then
82 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP." 82 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP."
83else 83else
@@ -85,7 +85,7 @@ else
85 ret=1 85 ret=1
86fi 86fi
87 87
88if [ "$RES_IP6" == "$TEST_IP6" ] 88if [ "$RES_IP6" = "$TEST_IP6" ]
89then 89then
90 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6." 90 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6."
91else 91else
diff --git a/src/gns/test_gns_gns2dns_lookup.sh b/src/gns/test_gns_gns2dns_lookup.sh
index 24fb36b9d..22caa68ff 100755
--- a/src/gns/test_gns_gns2dns_lookup.sh
+++ b/src/gns/test_gns_gns2dns_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 2trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
3 3
4LOCATION=$(which gnunet-config) 4LOCATION=$(which gnunet-config)
@@ -26,7 +26,7 @@ TEST_IP_GNS2DNS="8.8.8.8"
26# main label used during resolution 26# main label used during resolution
27TEST_RECORD_NAME="homepage" 27TEST_RECORD_NAME="homepage"
28 28
29if ! nslookup gnunet.org $TEST_IP_GNS2DNS &> /dev/null 29if ! nslookup gnunet.org $TEST_IP_GNS2DNS > /dev/null 2>&1
30then 30then
31 echo "Cannot reach DNS, skipping test" 31 echo "Cannot reach DNS, skipping test"
32 exit 77 32 exit 77
@@ -44,7 +44,7 @@ TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO"
44TEST_DOMAIN_ALT="${TEST_RECORD_NAME}.$MY_EGO" 44TEST_DOMAIN_ALT="${TEST_RECORD_NAME}.$MY_EGO"
45TEST_DOMAIN_ALT2="docs.${TEST_RECORD_NAME}.$MY_EGO" 45TEST_DOMAIN_ALT2="docs.${TEST_RECORD_NAME}.$MY_EGO"
46 46
47which timeout &> /dev/null && DO_TIMEOUT="timeout 15" 47which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 15"
48 48
49 49
50gnunet-arm -s -c test_gns_lookup.conf 50gnunet-arm -s -c test_gns_lookup.conf
@@ -83,7 +83,7 @@ gnunet-arm -e -c test_gns_lookup.conf
83rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 83rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
84 84
85ret=0 85ret=0
86if [ "$RES_IP" == "$TEST_IP" ] 86if [ "$RES_IP" = "$TEST_IP" ]
87then 87then
88 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP." 88 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP."
89else 89else
@@ -91,7 +91,7 @@ else
91 ret=1 91 ret=1
92fi 92fi
93 93
94if [ "$RES_IP6" == "$TEST_IP6" ] 94if [ "$RES_IP6" = "$TEST_IP6" ]
95then 95then
96 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6." 96 echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6."
97else 97else
@@ -99,7 +99,7 @@ else
99 ret=1 99 ret=1
100fi 100fi
101 101
102if [ "$RES_IP_ALT" == "$TEST_IP" ] 102if [ "$RES_IP_ALT" = "$TEST_IP" ]
103then 103then
104 echo "PASS: Resolved $TEST_DOMAIN_ALT to $RES_IP_ALT." 104 echo "PASS: Resolved $TEST_DOMAIN_ALT to $RES_IP_ALT."
105else 105else
@@ -107,7 +107,7 @@ else
107 ret=1 107 ret=1
108fi 108fi
109 109
110if [ "$RES_IP_ALT2" == "$TEST_IP_ALT2" ] 110if [ "$RES_IP_ALT2" = "$TEST_IP_ALT2" ]
111then 111then
112 echo "PASS: Resolved $TEST_DOMAIN_ALT2 to $RES_IP_ALT2." 112 echo "PASS: Resolved $TEST_DOMAIN_ALT2 to $RES_IP_ALT2."
113else 113else
diff --git a/src/gns/test_gns_ipv6_lookup.sh b/src/gns/test_gns_ipv6_lookup.sh
index 72da5ee2c..5dbb34a2c 100755
--- a/src/gns/test_gns_ipv6_lookup.sh
+++ b/src/gns/test_gns_ipv6_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -16,7 +16,7 @@ fi
16MY_EGO="myego" 16MY_EGO="myego"
17 17
18rm -rf `gnunet-config -c test_gns_lookup.conf -s PATHS -o GNUNET_HOME -f` 18rm -rf `gnunet-config -c test_gns_lookup.conf -s PATHS -o GNUNET_HOME -f`
19which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 19which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
20TEST_IP="dead::beef" 20TEST_IP="dead::beef"
21gnunet-arm -s -c test_gns_lookup.conf 21gnunet-arm -s -c test_gns_lookup.conf
22gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 22gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
@@ -27,7 +27,7 @@ gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
27gnunet-arm -e -c test_gns_lookup.conf 27gnunet-arm -e -c test_gns_lookup.conf
28rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 28rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
29 29
30if [ "$RES_IP" == "$TEST_IP" ] 30if [ "$RES_IP" = "$TEST_IP" ]
31then 31then
32 exit 0 32 exit 0
33else 33else
diff --git a/src/gns/test_gns_lookup.sh b/src/gns/test_gns_lookup.sh
index 2dffa1251..4bd6ae879 100755
--- a/src/gns/test_gns_lookup.sh
+++ b/src/gns/test_gns_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -15,7 +15,7 @@ then
15fi 15fi
16 16
17rm -rf `gnunet-config -c test_gns_lookup.conf -s PATHS -o GNUNET_HOME -f` 17rm -rf `gnunet-config -c test_gns_lookup.conf -s PATHS -o GNUNET_HOME -f`
18which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 18which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
19TEST_IP="127.0.0.1" 19TEST_IP="127.0.0.1"
20MY_EGO="myego" 20MY_EGO="myego"
21LABEL="www" 21LABEL="www"
@@ -27,7 +27,7 @@ gnunet-namestore -z $MY_EGO -d -n $LABEL -t A -V $TEST_IP -e never -c test_gns_l
27gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 27gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
28gnunet-arm -e -c test_gns_lookup.conf 28gnunet-arm -e -c test_gns_lookup.conf
29 29
30if [ "$RES_IP" == "$TEST_IP" ] 30if [ "$RES_IP" = "$TEST_IP" ]
31then 31then
32 exit 0 32 exit 0
33else 33else
diff --git a/src/gns/test_gns_mx_lookup.sh b/src/gns/test_gns_mx_lookup.sh
index 79ac37b0a..4e9d98358 100755
--- a/src/gns/test_gns_mx_lookup.sh
+++ b/src/gns/test_gns_mx_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -15,7 +15,7 @@ then
15fi 15fi
16 16
17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 18which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
19 19
20MY_EGO="myego" 20MY_EGO="myego"
21TEST_MX="5,mail.+" 21TEST_MX="5,mail.+"
@@ -35,7 +35,7 @@ rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
35RES_MX=`echo $RES_MX | tr [A-Z] [a-z]` 35RES_MX=`echo $RES_MX | tr [A-Z] [a-z]`
36WANT_MX=`echo $WANT_MX | tr [A-Z] [a-z]` 36WANT_MX=`echo $WANT_MX | tr [A-Z] [a-z]`
37 37
38if [ "$RES_MX" == "$WANT_MX" ] 38if [ "$RES_MX" = "$WANT_MX" ]
39then 39then
40 exit 0 40 exit 0
41else 41else
diff --git a/src/gns/test_gns_proxy.c b/src/gns/test_gns_proxy.c
index 75fe95617..2a7f8104b 100644
--- a/src/gns/test_gns_proxy.c
+++ b/src/gns/test_gns_proxy.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -50,9 +50,9 @@ static int global_ret;
50 50
51static struct MHD_Daemon *mhd; 51static struct MHD_Daemon *mhd;
52 52
53static struct GNUNET_SCHEDULER_Task * mhd_task_id; 53static struct GNUNET_SCHEDULER_Task *mhd_task_id;
54 54
55static struct GNUNET_SCHEDULER_Task * curl_task_id; 55static struct GNUNET_SCHEDULER_Task *curl_task_id;
56 56
57static CURL *curl; 57static CURL *curl;
58 58
@@ -349,6 +349,7 @@ curl_main ()
349static void 349static void
350start_curl (void *cls) 350start_curl (void *cls)
351{ 351{
352 curl_task_id = NULL;
352 GNUNET_asprintf (&url, 353 GNUNET_asprintf (&url,
353 "https://%s:%d/hello_world", 354 "https://%s:%d/hello_world",
354 TEST_DOMAIN, port); 355 TEST_DOMAIN, port);
@@ -369,7 +370,9 @@ start_curl (void *cls)
369 multi = curl_multi_init (); 370 multi = curl_multi_init ();
370 GNUNET_assert (multi != NULL); 371 GNUNET_assert (multi != NULL);
371 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); 372 GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Beginning HTTP download from `%s'\n", url); 373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "Beginning HTTP download from `%s'\n",
375 url);
373 curl_main (); 376 curl_main ();
374} 377}
375 378
@@ -391,7 +394,8 @@ commence_testing (void *cls)
391{ 394{
392 curl_task_id = 395 curl_task_id =
393 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 396 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
394 &start_curl, NULL); 397 &start_curl,
398 NULL);
395} 399}
396 400
397 401
@@ -561,4 +565,4 @@ main (int argc, char *const *argv)
561 return global_ret; 565 return global_ret;
562} 566}
563 567
564/* end of test_gns_vpn.c */ 568/* end of test_gns_proxy.c */
diff --git a/src/gns/test_gns_quickupdate.sh b/src/gns/test_gns_quickupdate.sh
index d9807fe22..d2b4bf2cb 100755
--- a/src/gns/test_gns_quickupdate.sh
+++ b/src/gns/test_gns_quickupdate.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -19,7 +19,7 @@ OTHER_EGO="delegatedego"
19 19
20 20
21rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 21rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
22which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 22which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
23TEST_IP="127.0.0.1" 23TEST_IP="127.0.0.1"
24gnunet-arm -s -c test_gns_lookup.conf 24gnunet-arm -s -c test_gns_lookup.conf
25gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 25gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
@@ -56,7 +56,7 @@ gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
56gnunet-arm -e -c test_gns_lookup.conf 56gnunet-arm -e -c test_gns_lookup.conf
57rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 57rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
58 58
59if [ "$RES_IP" == "$TEST_IP" ] 59if [ "$RES_IP" = "$TEST_IP" ]
60then 60then
61 exit 0 61 exit 0
62else 62else
diff --git a/src/gns/test_gns_rel_expiration.sh b/src/gns/test_gns_rel_expiration.sh
index c7c66bc27..993c2131e 100755
--- a/src/gns/test_gns_rel_expiration.sh
+++ b/src/gns/test_gns_rel_expiration.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -25,7 +25,7 @@ MY_EGO="myego"
25OTHER_EGO="delegatedego" 25OTHER_EGO="delegatedego"
26 26
27rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 27rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
28which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 28which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
29TEST_IP="127.0.0.1" 29TEST_IP="127.0.0.1"
30gnunet-arm -s -c test_gns_lookup.conf 30gnunet-arm -s -c test_gns_lookup.conf
31gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 31gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
@@ -48,13 +48,13 @@ gnunet-identity -D $OTHER_EGO -c test_gns_lookup.conf
48gnunet-arm -e -c test_gns_lookup.conf 48gnunet-arm -e -c test_gns_lookup.conf
49rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 49rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
50 50
51if [ "$RES_IP_EXP" == "$TEST_IP" ] 51if [ "$RES_IP_EXP" = "$TEST_IP" ]
52then 52then
53 echo "Failed to properly expire IP, got $RES_IP_EXP." 53 echo "Failed to properly expire IP, got $RES_IP_EXP."
54 exit 1 54 exit 1
55fi 55fi
56 56
57if [ "$RES_IP" == "$TEST_IP" ] 57if [ "$RES_IP" = "$TEST_IP" ]
58then 58then
59 exit 0 59 exit 0
60else 60else
diff --git a/src/gns/test_gns_revocation.sh b/src/gns/test_gns_revocation.sh
index 08a0f8ac1..3c0cf02fb 100755
--- a/src/gns/test_gns_revocation.sh
+++ b/src/gns/test_gns_revocation.sh
@@ -1,7 +1,7 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 4which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
5 5
6LOCATION=$(which gnunet-config) 6LOCATION=$(which gnunet-config)
7if [ -z $LOCATION ] 7if [ -z $LOCATION ]
@@ -40,7 +40,7 @@ then
40 exit 1 40 exit 1
41fi 41fi
42 42
43if [ "x$RES_IP_REV" == "x" ] 43if [ "x$RES_IP_REV" = "x" ]
44then 44then
45 exit 0 45 exit 0
46else 46else
diff --git a/src/gns/test_gns_soa_lookup.sh b/src/gns/test_gns_soa_lookup.sh
index 6a09ac8c7..c5b049b72 100755
--- a/src/gns/test_gns_soa_lookup.sh
+++ b/src/gns/test_gns_soa_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -14,7 +14,7 @@ then
14 exit 77 14 exit 77
15fi 15fi
16 16
17which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 17which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
18 18
19rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 19rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
20MY_EGO="myego" 20MY_EGO="myego"
@@ -24,7 +24,7 @@ TEST_IP_GNS2DNS="184.172.157.218"
24TEST_RECORD_NAME="homepage" 24TEST_RECORD_NAME="homepage"
25TEST_RECORD_GNS2DNS="gnunet.org" 25TEST_RECORD_GNS2DNS="gnunet.org"
26 26
27if ! nslookup $TEST_RECORD_GNS2DNS $TEST_IP_GNS2DNS &> /dev/null 27if ! nslookup $TEST_RECORD_GNS2DNS $TEST_IP_GNS2DNS > /dev/null 2>&1
28then 28then
29 echo "Cannot reach DNS, skipping test" 29 echo "Cannot reach DNS, skipping test"
30 exit 77 30 exit 77
@@ -34,7 +34,7 @@ gnunet-arm -s -c test_gns_lookup.conf
34gnunet-identity -C $MY_EGO -c test_gns_lookup.conf 34gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
35gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf 35gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf
36RES_SOA=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t SOA -c test_gns_lookup.conf` 36RES_SOA=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t SOA -c test_gns_lookup.conf`
37gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf &> /dev/null 37gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf > /dev/null 2>&1
38gnunet-identity -D $MY_EGO -c test_gns_lookup.conf 38gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
39gnunet-arm -e -c test_gns_lookup.conf 39gnunet-arm -e -c test_gns_lookup.conf
40rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 40rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
diff --git a/src/gns/test_gns_txt_lookup.sh b/src/gns/test_gns_txt_lookup.sh
index 6c6b4b3f6..b0c9144c2 100755
--- a/src/gns/test_gns_txt_lookup.sh
+++ b/src/gns/test_gns_txt_lookup.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4 4
@@ -15,7 +15,7 @@ then
15fi 15fi
16 16
17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 17rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
18which timeout &> /dev/null && DO_TIMEOUT="timeout 30" 18which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
19TEST_TXT="GNS powered txt record data" 19TEST_TXT="GNS powered txt record data"
20MY_EGO="myego" 20MY_EGO="myego"
21LABEL="testtxt" 21LABEL="testtxt"
@@ -28,7 +28,7 @@ gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
28gnunet-arm -e -c test_gns_lookup.conf 28gnunet-arm -e -c test_gns_lookup.conf
29rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 29rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
30 30
31if [ "$RES_TXT" == "$TEST_TXT" ] 31if [ "$RES_TXT" = "$TEST_TXT" ]
32then 32then
33 exit 0 33 exit 0
34else 34else
diff --git a/src/gns/test_gns_zkey_lookup.sh b/src/gns/test_gns_zkey_lookup.sh
index b36a16fa2..03118d741 100755
--- a/src/gns/test_gns_zkey_lookup.sh
+++ b/src/gns/test_gns_zkey_lookup.sh
@@ -1,7 +1,7 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 3trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4which timeout &> /dev/null && DO_TIMEOUT="timeout 5" 4which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 5"
5 5
6LOCATION=$(which gnunet-config) 6LOCATION=$(which gnunet-config)
7if [ -z $LOCATION ] 7if [ -z $LOCATION ]
@@ -30,7 +30,7 @@ gnunet-namestore -z delegatedego -d -n www -t A -V $TEST_IP -e never -c test_gn
30gnunet-arm -e -c test_gns_lookup.conf 30gnunet-arm -e -c test_gns_lookup.conf
31rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` 31rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
32 32
33if [ "$RES_IP" == "$TEST_IP" ] 33if [ "$RES_IP" = "$TEST_IP" ]
34then 34then
35 exit 0 35 exit 0
36else 36else
diff --git a/src/gns/test_gnunet_gns.sh b/src/gns/test_gnunet_gns.sh
index f6b4e721a..74c49c537 100755
--- a/src/gns/test_gnunet_gns.sh
+++ b/src/gns/test_gnunet_gns.sh
@@ -1,15 +1,25 @@
1#!/bin/bash 1#!/bin/sh
2# This file is in the public domain. 2# This file is in the public domain.
3LOCATION=$(which gnunet-config) 3# test -z being correct was a false assumption here.
4if [ -z $LOCATION ] 4# I have no executable 'fooble', but this will
5then 5# return 1:
6 LOCATION="gnunet-config" 6# if test -z "`which fooble`"; then echo 1; fi
7# The command builtin might not work with busybox's ash
8# but this works for now.
9existence()
10{
11 command -v "$1" >/dev/null 2>&1
12}
13
14LOCATION=`existence gnunet-config`
15if test -z $LOCATION; then
16 LOCATION="gnunet-config"
7fi 17fi
8$LOCATION --version 18$LOCATION --version
9if test $? != 0 19if test $? != 0
10then 20then
11 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" 21 echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
12 exit 77 22 exit 77
13fi 23fi
14 24
15trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT 25trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
@@ -32,4 +42,5 @@ if [ "$LO" != "Address: 4.5.6.7" ]
32then 42then
33 echo "Fail: $LO" 43 echo "Fail: $LO"
34fi 44fi
45# XXX: jobs. a builtin by bash, netbsd sh, maybe leave it be for now.
35kill `jobs -p` 46kill `jobs -p`
diff --git a/src/gns/test_plugin_rest_gns.sh b/src/gns/test_plugin_rest_gns.sh
new file mode 100755
index 000000000..ec495a04b
--- /dev/null
+++ b/src/gns/test_plugin_rest_gns.sh
@@ -0,0 +1,50 @@
1#!/usr/bin/bash
2
3#First, start gnunet-arm and the rest-service.
4#Exit 0 means success, exit 1 means failed test
5
6gns_link="http://localhost:7776/gns"
7wrong_link="http://localhost:7776/gnsandmore"
8
9curl_get () {
10 #$1 is link
11 #$2 is grep
12 cache="$(curl -v "$1" 2>&1 | grep "$2")"
13 #echo $cache
14 if [ "" == "$cache" ]
15 then
16 exit 1
17 fi
18}
19
20gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
21
22curl_get "$gns_link/www.test_plugin_rest_gns" "error"
23
24gnunet-identity -C "test_plugin_rest_gns"
25
26curl_get "$gns_link/www.test_plugin_rest_gns" "\[\]"
27
28gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.1 -t A
29
30curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.1"
31
32gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1::1 -t AAAA
33
34curl_get "$gns_link/www.test_plugin_rest_gns" "1::1.*1.1.1.1"
35
36gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www -e 1d -V 1.1.1.2 -t A
37
38curl_get "$gns_link/www.test_plugin_rest_gns" "1.1.1.2.*1::1.*1.1.1.1"
39curl_get "$gns_link/www.test_plugin_rest_gns?record_type=A" "1.1.1.2.*1.1.1.1"
40curl_get "$gns_link/www.test_plugin_rest_gns?record_type=AAAA" "1::1"
41curl_get "$gns_link/www.test_plugin_rest_gns?record_type=WRONG_TYPE" "1.1.1.2.*1::1.*1.1.1.1"
42
43gnunet-namestore -z "test_plugin_rest_gns" -p -a -n www1 -e 1d -V 1.1.1.1 -t A
44curl_get "$gns_link/www1.test_plugin_rest_gns" "1.1.1.1"
45
46gnunet-identity -D "test_plugin_rest_gns" > /dev/null 2>&1
47
48curl_get "$gns_link/www1.test_plugin_rest_gns" "error"
49
50exit 0
diff --git a/src/gns/test_proxy.sh b/src/gns/test_proxy.sh
index c960d4df9..7c17cd4c5 100755
--- a/src/gns/test_proxy.sh
+++ b/src/gns/test_proxy.sh
@@ -1,7 +1,9 @@
1#!/bin/bash 1#!/bin/bash
2 2# This file is in the public domain.
3TEST_DOMAIN="www.test" 3TEST_DOMAIN="www.test"
4 4
5# Delete old files before starting test
6rm -rf /tmp/gnunet/test-gnunet-gns-testing/
5gnunet-arm -s -c test_gns_proxy.conf 7gnunet-arm -s -c test_gns_proxy.conf
6gnunet-gns-proxy-setup-ca -c test_gns_proxy.conf 8gnunet-gns-proxy-setup-ca -c test_gns_proxy.conf
7 9