]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tools: use idna_to_ascii_8z() to convert internationalized hostnames
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 23 Aug 2014 03:06:43 +0000 (05:06 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 23 Aug 2014 03:09:42 +0000 (05:09 +0200)
src/Makefile.am
src/socket.c

index 78d8cb293b86ed6c544e2ffc6c587dff3ee223d9..efe470436b3aca8a65325ebe840c3d56220f2592 100644 (file)
@@ -96,7 +96,7 @@ if ENABLE_OCSP
 ocsptool_SOURCES = ocsptool.c ocsptool-common.h ocsptool-common.c \
        socket.c socket.h
 ocsptool_LDADD = ../lib/libgnutls.la libcmd-ocsp.la $(LIBOPTS) ../gl/libgnu.la 
-ocsptool_LDADD += $(LTLIBINTL) $(GETADDRINFO_LIB) gl/libgnu_gpl.la
+ocsptool_LDADD += $(LTLIBINTL) $(GETADDRINFO_LIB) gl/libgnu_gpl.la $(LIBIDN_LIBS)
 noinst_LTLIBRARIES += libcmd-ocsp.la
 libcmd_ocsp_la_SOURCES = ocsptool-args.def ocsptool-args.h ocsptool-args.c
 
@@ -109,7 +109,7 @@ gnutls_serv_SOURCES =               \
 gnutls_serv_LDADD = ../lib/libgnutls.la
 gnutls_serv_LDADD += libcmd-serv.la $(LIBOPTS) ../gl/libgnu.la
 gnutls_serv_LDADD += $(LTLIBINTL) gl/libgnu_gpl.la
-gnutls_serv_LDADD += $(LIBSOCKET) $(GETADDRINFO_LIB)
+gnutls_serv_LDADD += $(LIBSOCKET) $(GETADDRINFO_LIB) $(LIBIDN_LIBS)
 noinst_LTLIBRARIES += libcmd-serv.la
 libcmd_serv_la_SOURCES = serv-args.def serv-args.c serv-args.h
 
@@ -124,7 +124,7 @@ gnutls_cli_LDADD = ../lib/libgnutls.la
 if ENABLE_DANE
 gnutls_cli_LDADD += ../libdane/libgnutls-dane.la
 endif
-gnutls_cli_LDADD += libcmd-cli.la $(LIBOPTS) ../gl/libgnu.la $(LTLIBINTL)
+gnutls_cli_LDADD += libcmd-cli.la $(LIBOPTS) ../gl/libgnu.la $(LTLIBINTL) $(LIBIDN_LIBS)
 gnutls_cli_LDADD += $(LIBSOCKET) $(GETADDRINFO_LIB) $(LIB_CLOCK_GETTIME) \
         $(SERVENT_LIB) gl/libgnu_gpl.la
 noinst_LTLIBRARIES += libcmd-cli.la
@@ -136,7 +136,7 @@ gnutls_cli_debug_SOURCES = cli-debug.c tests.h tests.c \
                socket.c socket.h common.h common.c
 gnutls_cli_debug_LDADD = ../lib/libgnutls.la libcmd-cli-debug.la 
 gnutls_cli_debug_LDADD += $(LIBOPTS) ../gl/libgnu.la gl/libgnu_gpl.la
-gnutls_cli_debug_LDADD += $(LTLIBINTL)
+gnutls_cli_debug_LDADD += $(LTLIBINTL) $(LIBIDN_LIBS)
 gnutls_cli_debug_LDADD += $(LIBSOCKET) $(GETADDRINFO_LIB)
 noinst_LTLIBRARIES += libcmd-cli-debug.la
 libcmd_cli_debug_la_SOURCES = cli-debug-args.def cli-debug-args.c cli-debug-args.h
@@ -156,7 +156,7 @@ libcmd_certtool_la_LIBADD += $(LTLIBREADLINE) gl/libgnu_gpl.la
 libcmd_certtool_la_LIBADD += $(INET_PTON_LIB) $(LIB_CLOCK_GETTIME)
 
 danetool_SOURCES = danetool.c certtool-common.c certtool-extras.c common.c socket.c
-danetool_LDADD = ../lib/libgnutls.la 
+danetool_LDADD = ../lib/libgnutls.la  $(LIBIDN_LIBS)
 danetool_LDADD += libcmd-danetool.la ../gl/libgnu.la gl/libgnu_gpl.la
 if ENABLE_DANE
 danetool_LDADD += ../libdane/libgnutls-dane.la
index 3428888f48a552afab30572a5b13f970354ae319..135f9bf592f6e88c9296f60202b490fd039d80ed 100644 (file)
 #include <socket.h>
 #include "sockets.h"
 
+#ifdef HAVE_LIBIDN
+#include <idna.h>
+#include <idn-free.h>
+#endif
+
 #define MAX_BUF 4096
 
 /* Functions to manipulate sockets
@@ -220,14 +225,24 @@ socket_open(socket_st * hd, const char *hostname, const char *service,
        int sd, err;
        char buffer[MAX_BUF + 1];
        char portname[16] = { 0 };
+       char *a_hostname = (char*)hostname;
+
+#ifdef HAVE_LIBIDN
+       err = idna_to_ascii_8z(hostname, &a_hostname, IDNA_ALLOW_UNASSIGNED);
+       if (err != IDNA_SUCCESS) {
+               fprintf(stderr, "Cannot convert %s to IDNA: %s\n", hostname,
+                       idna_strerror(err));
+               exit(1);
+       }
+#endif
 
        if (msg != NULL)
-               printf("Resolving '%s'...\n", hostname);
+               printf("Resolving '%s'...\n", a_hostname);
 
        /* get server name */
        memset(&hints, 0, sizeof(hints));
        hints.ai_socktype = udp ? SOCK_DGRAM : SOCK_STREAM;
-       if ((err = getaddrinfo(hostname, service, &hints, &res))) {
+       if ((err = getaddrinfo(a_hostname, service, &hints, &res))) {
                fprintf(stderr, "Cannot resolve %s:%s: %s\n", hostname,
                        service, gai_strerror(err));
                exit(1);
@@ -294,7 +309,9 @@ socket_open(socket_st * hd, const char *hostname, const char *service,
        hd->service = strdup(portname);
        hd->ptr = ptr;
        hd->addr_info = res;
-
+#ifdef HAVE_LIBIDN
+       idn_free(a_hostname);
+#endif
        return;
 }