From 0c7a03ffdb1388ac0caf90a22f9b1e93b6befa8f Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 24 Feb 2012 17:00:42 +0000 Subject: [PATCH] -test and config --- src/gns/Makefile.am | 8 ++++---- src/gns/gns.conf.in | 13 +++++++++++++ src/gns/gnunet-service-gns.c | 21 ++++++++++++++------- src/gns/test_gnunet_gns.sh | 22 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 src/gns/gns.conf.in create mode 100755 src/gns/test_gnunet_gns.sh diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 09c7550ad..9f947b2c1 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am @@ -12,8 +12,8 @@ pkgcfgdir= $(pkgdatadir)/config.d/ plugindir = $(libdir)/gnunet -#pkgcfg_DATA = \ -# dns.conf +pkgcfg_DATA = \ + gns.conf lib_LTLIBRARIES = \ libgnunetgns.la libgnunetnamestore.la @@ -24,8 +24,8 @@ bin_PROGRAMS = \ #noinst_PROGRAMS = \ # gnunet-gns-lookup -#check_SCRIPTS = \ -# test_gnunet_dns.sh +check_SCRIPTS = \ + test_gnunet_gns.sh #gnunet_gns_lookup_SOURCES = \ # gnunet-gns-lookup.c diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in new file mode 100644 index 000000000..acf0a222a --- /dev/null +++ b/src/gns/gns.conf.in @@ -0,0 +1,13 @@ +[gns] +AUTOSTART = YES +HOSTNAME = localhost +HOME = $SERVICEHOME +CONFIG = $DEFAULTCONFIG +BINARY = gnunet-service-gns +UNIXPATH = /tmp/gnunet-service-gns.sock + +# Access to this service can compromise all DNS queries in this +# system. Thus access should be restricted to the same UID. +# (see https://gnunet.org/gnunet-access-control-model) +UNIX_MATCH_UID = YES +UNIX_MATCH_GID = YES diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 5454a4ec6..80f852768 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -521,10 +521,10 @@ process_authority_lookup(void* cls, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature) { - struct GNUNET_GNS_ResolverHandle *query; + struct GNUNET_GNS_ResolverHandle *rh; GNUNET_HashCode zone; - query = (struct GNUNET_GNS_ResolverHandle *)cls; + rh = (struct GNUNET_GNS_ResolverHandle *)cls; GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone); /** @@ -547,7 +547,7 @@ process_authority_lookup(void* cls, /** * Last hope */ - resolve_authority_dht(query, name); + resolve_authority_dht(rh, name); return; } @@ -560,9 +560,9 @@ process_authority_lookup(void* cls, GNUNET_assert(rd->record_type == GNUNET_GNS_RECORD_PKEY); GNUNET_HashCode *pkey_hash = GNUNET_malloc(sizeof(GNUNET_HashCode)); GNUNET_CRYPTO_hash(rd->data, GNUNET_CRYPTO_RSA_KEY_LENGTH, pkey_hash); - GNUNET_free_non_null(query->authority); - query->authority = pkey_hash; - resolve_name(query, query->authority); + GNUNET_free_non_null(rh->authority); + rh->authority = pkey_hash; + resolve_name(rh, rh->authority); } @@ -611,8 +611,12 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count, packet->num_additional_records = 0; packet->num_answers = rd_count; //answer->num_records; //packet.num_authority_records = 0;//answer->num_authority_records; + + if (NULL == rh->authority) + dnsflags.authoritative_answer = 1; + else + dnsflags.authoritative_answer = 0; - dnsflags.authoritative_answer = 1; dnsflags.message_truncated = 0; dnsflags.recursion_desired = 0; dnsflags.authenticated_data = 0; @@ -620,10 +624,12 @@ reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count, dnsflags.zero = 0; dnsflags.recursion_available = 0; dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY; + if (rd == NULL) dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NAME_ERROR; else dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; + dnsflags.query_or_response = 1; packet->flags = dnsflags; @@ -896,6 +902,7 @@ start_resolution(struct GNUNET_DNS_RequestHandle *request, rh = GNUNET_malloc(sizeof (struct GNUNET_GNS_ResolverHandle)); rh->packet = p; rh->query = q; + rh->authority = NULL; //FIXME do not forget to free!! rh->name = GNUNET_malloc(strlen(q->name) diff --git a/src/gns/test_gnunet_gns.sh b/src/gns/test_gnunet_gns.sh new file mode 100755 index 000000000..cd680276d --- /dev/null +++ b/src/gns/test_gnunet_gns.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +ME=`whoami` +if [ "$ME" != "root" ] +then + echo "This test only works if run as root. Skipping." + exit 0 +fi +export PATH=".:$PATH" +gnunet-service-gns -c gns.conf & +sleep 1 +LO=`nslookup alice.gnunet | grep Address | tail -n1` +if [ "$LO" != "Address: 1.2.3.4" ] +then + echo "Fail: $LO" +fi +LO=`nslookup www.bob.gnunet | grep Address | tail -n1` +if [ "$LO" != "Address: 4.5.6.7" ] +then + echo "Fail: $LO" +fi +kill `jobs -p` -- 2.25.1