fix GNS2DNS records for LSD001 UTF-8 change
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 30 Nov 2019 11:21:01 +0000 (12:21 +0100)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 30 Nov 2019 11:21:01 +0000 (12:21 +0100)
src/gns/gnunet-service-gns_resolver.c
src/gns/nss/nss_gns_query.c
src/gns/plugin_gnsrecord_gns.c

index 01af17fdc1d8335a09d700a9276e3d10ef4c7833..fda2e69e0eadbfc355b323bf23b9cfe48b831fab 100644 (file)
@@ -1697,9 +1697,15 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh,
     n = GNUNET_DNSPARSER_parse_name (rd[i].data,
                                      rd[i].data_size,
                                      &off);
+#ifndef LSD001
+    ip = GNUNET_strdup (&rd[i].data[off]);
+    off += strlen (ip) + 1;
+#else
     ip = GNUNET_DNSPARSER_parse_name (rd[i].data,
                                       rd[i].data_size,
                                       &off);
+#endif
+
     if ((NULL == n) ||
         (NULL == ip) ||
         (off != rd[i].data_size))
index c79ae61f74f6ab33067c05d89fe9690df082dd1f..4f5f06cfac26bad23557e376ae1b8f9106810b85 100644 (file)
@@ -72,7 +72,9 @@ gns_resolve_name (int af, const char *name, struct userdata *u)
   {
     char *argv[] = { "gnunet-gns",
                      "-r", //Raw output for easier parsing
+#ifdef LSD001
                      "-d", //DNS compatibility (allow IDNA names, no UTF-8)
+#endif
                      "-t",
                      (AF_INET6 == af) ? "AAAA" : "A",
                      "-u",
index cffd5a9654a939a16d85e9b49d8d06a0da228b14..52c35ce100736312f5560b050d61e1c694636a7e 100644 (file)
@@ -72,14 +72,25 @@ gns_value_to_string (void *cls,
 
       off = 0;
       ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
+      if (NULL == ns)
+      {
+        GNUNET_break_op (0);
+        GNUNET_free_non_null (ns);
+        return NULL;
+      }
+#ifndef LSD001 //DNS server IP/name must be UTF-8
+      ip = GNUNET_strdup((char*) &data[off]);
+#else
+      // Must be IP or DNS name
       ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
-      if ((NULL == ns) || (NULL == ip) || (off != data_size))
+      if ((NULL == ip) || (off != data_size))
       {
         GNUNET_break_op (0);
         GNUNET_free_non_null (ns);
         GNUNET_free_non_null (ip);
         return NULL;
       }
+#endif
       GNUNET_asprintf (&nstr, "%s@%s", ns, ip);
       GNUNET_free_non_null (ns);
       GNUNET_free_non_null (ip);
@@ -203,19 +214,33 @@ gns_string_to_value (void *cls,
       at++;
 
       off = 0;
-      if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf,
+      if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf,
                                                            sizeof(nsbuf),
                                                            &off,
-                                                           cpy)) ||
-          (GNUNET_OK !=
-           GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, at)))
+                                                           cpy))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    _ (
+                      "Failed to serialize GNS2DNS record with value `%s': Not a DNS name.\n"),
+                    s);
+        GNUNET_free (cpy);
+        return GNUNET_SYSERR;
+      }
+#ifndef LSD001 //The DNS server location/name is in UTF-8
+      GNUNET_memcpy (&nsbuf[off], at, strlen (at) + 1);
+      off += strlen (at) + 1;
+#else
+      if (GNUNET_OK !=
+          GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, at))
       {
         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    _ ("Failed to serialize GNS2DNS record with value `%s'\n"),
+                    _ (
+                      "Failed to serialize GNS2DNS record with value `%s': Not a DNS name\n"),
                     s);
         GNUNET_free (cpy);
         return GNUNET_SYSERR;
       }
+#endif
       GNUNET_free (cpy);
       *data_size = off;
       *data = GNUNET_malloc (off);