summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-11-30 10:20:24 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-11-30 10:20:24 +0100
commite9ad4ee3550aeb0ff67fd98ddebafbd5f54dad3d (patch)
tree13f46c6cc728011e92b2cd30f6ce1f23e2d36473 /src
parent64c75b64f46f8437f940ce74017641e509cf4c54 (diff)
support compatibility mode for DNS names in gnunet-gns
Diffstat (limited to 'src')
-rw-r--r--src/gns/Makefile.am11
-rw-r--r--src/gns/gnunet-gns.c66
-rw-r--r--src/gns/nss/nss_gns_query.c3
3 files changed, 73 insertions, 7 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 846507b6f..bb319ce6e 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -10,7 +10,17 @@ SUBDIRS = . $(NSS_SUBDIR)
pkgdata_DATA = \
gnunet-gns-proxy-ca.template
+if HAVE_LIBIDN
+ LIBIDN= -lidn
+else
+ LIBIDN=
+endif
+if HAVE_LIBIDN2
+ LIBIDN2= -lidn2
+else
+ LIBIDN2=
+endif
EXTRA_DIST = \
test_gns_defaults.conf \
@@ -139,6 +149,7 @@ gnunet_gns_LDADD = \
libgnunetgns.la \
$(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(LIBIDN) $(LIBIDN2) \
$(GN_LIBINTL)
gnunet_gns_benchmark_SOURCES = \
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index c3ba0a1f8..fe51013ed 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -23,12 +23,26 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#if HAVE_LIBIDN2
+#if HAVE_IDN2_H
+#include <idn2.h>
+#elif HAVE_IDN2_IDN2_H
+#include <idn2/idn2.h>
+#endif
+#elif HAVE_LIBIDN
+#if HAVE_IDNA_H
+#include <idna.h>
+#elif HAVE_IDN_IDNA_H
+#include <idn/idna.h>
+#endif
+#endif
#include <gnunet_util_lib.h>
#include <gnunet_dnsparser_lib.h>
#include <gnunet_gnsrecord_lib.h>
#include <gnunet_namestore_service.h>
#include <gnunet_gns_service.h>
+
/**
* Configuration we are using.
*/
@@ -45,6 +59,16 @@ static struct GNUNET_GNS_Handle *gns;
static char *lookup_name;
/**
+ * DNS IDNA name to lookup. (set if -d option is set)
+ */
+char *idna_name;
+
+/**
+ * DNS compatibility (name is given as DNS name, possible IDNA).
+ */
+static int dns_compat;
+
+/**
* record type to look up (-t option)
*/
static char *lookup_type;
@@ -108,6 +132,11 @@ do_shutdown (void *cls)
GNUNET_GNS_disconnect (gns);
gns = NULL;
}
+ if (NULL != idna_name)
+ {
+ GNUNET_free (idna_name);
+ idna_name = NULL;
+ }
}
@@ -200,6 +229,7 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
+ Idna_rc rc;
cfg = c;
to_task = NULL;
@@ -209,13 +239,32 @@ run (void *cls,
if (NULL != (colon = strchr (lookup_name, ':')))
*colon = '\0';
}
- if (GNUNET_OK != GNUNET_DNSPARSER_check_name (lookup_name))
+ /**
+ * If DNS compatibility is requested, we first verify that the
+ * lookup_name is in a DNS format. If yes, we convert it to UTF-8.
+ */
+ if (GNUNET_YES == dns_compat)
{
- fprintf (stderr,
- _ ("`%s' is not a valid domain name\n"),
- lookup_name);
- global_ret = 3;
- return;
+ if (GNUNET_OK != GNUNET_DNSPARSER_check_name (lookup_name))
+ {
+ fprintf (stderr,
+ _ ("`%s' is not a valid DNS domain name\n"),
+ lookup_name);
+ global_ret = 3;
+ return;
+ }
+ if (IDNA_SUCCESS !=
+ (rc = idna_to_unicode_8z8z (lookup_name, &idna_name,
+ IDNA_ALLOW_UNASSIGNED)))
+ {
+ fprintf (stderr,
+ _ ("Failed to convert DNS IDNA name `%s' to UTF-8: %s\n"),
+ lookup_name,
+ idna_strerror (rc));
+ global_ret = 3;
+ return;
+ }
+ lookup_name = idna_name;
}
if (GNUNET_YES !=
GNUNET_CLIENT_test (cfg,
@@ -299,6 +348,11 @@ main (int argc, char *const *argv)
"raw",
gettext_noop ("No unneeded output"),
&raw),
+ GNUNET_GETOPT_option_flag ('d',
+ "dns",
+ gettext_noop (
+ "DNS Compatibility: Name is passed in IDNA instead of UTF-8"),
+ &dns_compat),
GNUNET_GETOPT_OPTION_END };
int ret;
diff --git a/src/gns/nss/nss_gns_query.c b/src/gns/nss/nss_gns_query.c
index 9ebdcb31f..c79ae61f7 100644
--- a/src/gns/nss/nss_gns_query.c
+++ b/src/gns/nss/nss_gns_query.c
@@ -71,7 +71,8 @@ gns_resolve_name (int af, const char *name, struct userdata *u)
if (0 == pid)
{
char *argv[] = { "gnunet-gns",
- "-r",
+ "-r", //Raw output for easier parsing
+ "-d", //DNS compatibility (allow IDNA names, no UTF-8)
"-t",
(AF_INET6 == af) ? "AAAA" : "A",
"-u",