From 38d8d634f7ea37fd182434ce8e4509a42254b838 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Wed, 28 Apr 2021 16:10:59 +0200 Subject: [PATCH] [lookup] idna --- src/config/cmdline.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/config/cmdline.c b/src/config/cmdline.c index 3a11d1616..99b6dbd8e 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -5,6 +5,7 @@ #endif #include +#include #include #include #ifdef HAVE_SYS_SOCKET_H @@ -15,6 +16,10 @@ #include #endif +#ifdef HAVE_IDNA_H +#include +#endif + /* We need to have it here. Stupid BSD. */ #ifdef HAVE_NETINET_IN_H #include @@ -153,17 +158,37 @@ lookup_cmd(struct option *o, char ***argv, int *argc) { struct sockaddr_storage *addrs = NULL; int addrno, i; + char *idname, *idname2; + int allocated = 0; if (!*argc) return gettext("Parameter expected"); if (*argc > 1) return gettext("Too many parameters"); (*argv)++; (*argc)--; - if (do_real_lookup(*(*argv - 1), &addrs, &addrno, 0) == DNS_ERROR) { + + idname = *(*argv - 1); + +#ifdef CONFIG_IDN + if (idname) { + int code = idna_to_ascii_lz(idname, &idname2, 0); + + /* FIXME: Return NULL if it coughed? --jonas */ + if (code == IDNA_SUCCESS) { + idname = idname2; + allocated = 1; + } + } +#endif + + if (do_real_lookup(idname, &addrs, &addrno, 0) == DNS_ERROR) { #ifdef HAVE_HERROR herror(gettext("error")); #else usrerror(gettext("Host not found")); #endif + if (allocated) { + free(idname2); + } return ""; } @@ -192,6 +217,10 @@ lookup_cmd(struct option *o, char ***argv, int *argc) fflush(stdout); + if (allocated) { + free(idname2); + } + return ""; }