1 diff -up bind-9.7.0b1/bin/dig/dighost.c.libidn bind-9.7.0b1/bin/dig/dighost.c
2 --- bind-9.7.0b1/bin/dig/dighost.c.libidn 2009-09-16 01:48:09.000000000 +0200
3 +++ bind-9.7.0b1/bin/dig/dighost.c 2009-10-20 10:49:26.719056220 +0200
9 +#include <stringprep.h>
13 #include <dns/byaddr.h>
15 #include <dns/dnssec.h>
16 @@ -153,6 +158,14 @@ static void idn_check_result(idn_result
21 +static isc_result_t libidn_locale_to_utf8 (const char* from, char **to);
22 +static isc_result_t libidn_utf8_to_ascii (const char* from, char *to);
23 +static isc_result_t output_filter (isc_buffer_t *buffer,
24 + unsigned int used_org,
25 + isc_boolean_t absolute);
31 @@ -1184,6 +1197,9 @@ setup_system(void) {
32 dig_searchlist_t *domain = NULL;
33 lwres_result_t lwresult;
34 unsigned int lwresflags;
36 + isc_result_t result;
39 debug("setup_system()");
41 @@ -1242,8 +1258,15 @@ setup_system(void) {
48 + result = dns_name_settotextfilter(output_filter);
49 + check_result(result, "dns_name_settotextfilter");
50 +#ifdef HAVE_SETLOCALE
51 + setlocale (LC_ALL, "");
57 else if (keysecret[0] != 0)
58 @@ -1957,12 +1980,18 @@ setup_lookup(dig_lookup_t *lookup) {
60 char utf8_textname[MXNAME], utf8_origin[MXNAME], idn_textname[MXNAME];
63 + char *utf8_str = NULL, utf8_name[MXNAME], ascii_name[MXNAME];
67 result = dns_name_settotextfilter(output_filter);
68 check_result(result, "dns_name_settotextfilter");
72 + result = dns_name_settotextfilter (output_filter);
73 + check_result(result, "dns_name_settotextfilter");
75 REQUIRE(lookup != NULL);
78 @@ -1999,6 +2028,16 @@ setup_lookup(dig_lookup_t *lookup) {
79 mr = idn_encodename(IDN_LOCALCONV | IDN_DELIMMAP, lookup->textname,
80 utf8_textname, sizeof(utf8_textname));
81 idn_check_result(mr, "convert textname to UTF-8");
82 +#elif defined (WITH_LIBIDN)
83 + result = libidn_locale_to_utf8 (lookup->textname, &utf8_str);
84 + check_result (result, "converting textname to UTF-8");
85 + len = strlen (utf8_str);
87 + (void) strcpy (utf8_name, utf8_str);
89 + fatal ("Too long name");
91 + isc_mem_free (mctx, utf8_str);
95 @@ -2018,6 +2057,15 @@ setup_lookup(dig_lookup_t *lookup) {
96 lookup->origin = ISC_LIST_HEAD(search_list);
97 lookup->need_search = ISC_FALSE;
99 +#elif defined (WITH_LIBIDN)
100 + if ((count_dots(utf8_name) >= ndots) || !usesearch) {
101 + lookup->origin = NULL; /* Force abs lookup */
102 + lookup->done_as_is = ISC_TRUE;
103 + lookup->need_search = usesearch;
104 + } else if (lookup->origin == NULL && usesearch) {
105 + lookup->origin = ISC_LIST_HEAD(search_list);
106 + lookup->need_search = ISC_FALSE;
109 if ((count_dots(lookup->textname) >= ndots) || !usesearch) {
110 lookup->origin = NULL; /* Force abs lookup */
111 @@ -2044,6 +2092,20 @@ setup_lookup(dig_lookup_t *lookup) {
112 IDN_IDNCONV | IDN_LENCHECK, utf8_textname,
113 idn_textname, sizeof(idn_textname));
114 idn_check_result(mr, "convert UTF-8 textname to IDN encoding");
115 +#elif defined (WITH_LIBIDN)
116 + if (lookup->origin != NULL) {
117 + result = libidn_locale_to_utf8 (lookup->origin->origin, &utf8_str);
118 + check_result (result, "convert origin to UTF-8");
119 + if (len + strlen (utf8_str) + 1 < MXNAME) {
120 + utf8_name[len++] = '.';
121 + (void) strcpy (utf8_name + len, utf8_str);
123 + fatal ("Too long name + origin");
125 + isc_mem_free (mctx, utf8_str);
128 + result = libidn_utf8_to_ascii (utf8_name, ascii_name);
130 if (lookup->origin != NULL) {
131 debug("trying origin %s", lookup->origin->origin);
132 @@ -2099,6 +2161,13 @@ setup_lookup(dig_lookup_t *lookup) {
133 result = dns_name_fromtext(lookup->name, &b,
136 +#elif defined (WITH_LIBIDN)
137 + len = strlen (ascii_name);
138 + isc_buffer_init(&b, ascii_name, len);
139 + isc_buffer_add(&b, len);
140 + result = dns_name_fromtext(lookup->name, &b,
144 len = strlen(lookup->textname);
145 isc_buffer_init(&b, lookup->textname, len);
146 @@ -3617,7 +3686,7 @@ destroy_libs(void) {
148 dig_message_t *chase_msg;
151 +#if defined (WITH_IDN) || defined (WITH_LIBIDN)
155 @@ -3656,6 +3725,10 @@ destroy_libs(void) {
156 result = dns_name_settotextfilter(NULL);
157 check_result(result, "dns_name_settotextfilter");
160 + result = dns_name_settotextfilter (NULL);
161 + check_result(result, "clearing dns_name_settotextfilter");
165 if (commctx != NULL) {
166 @@ -3834,6 +3907,79 @@ idn_check_result(idn_result_t r, const c
169 #endif /* WITH_IDN */
171 +/* If stringprep_locale_to_utf8 fails simple copy string */
173 +libidn_locale_to_utf8 (const char *from, char **to) {
176 + utf8_str = stringprep_locale_to_utf8 (from);
177 + if (utf8_str == NULL) {
178 + *to = isc_mem_allocate (mctx, strlen (from) + 1);
180 + return (ISC_R_NOMEMORY);
181 + (void) strcpy (*to, from);
183 + *to = isc_mem_allocate (mctx, strlen (utf8_str) + 1);
185 + return (ISC_R_NOMEMORY);
186 + (void) strcpy (*to, utf8_str);
189 + return (ISC_R_SUCCESS);
192 +libidn_utf8_to_ascii (const char *from, char *to) {
195 + if (idna_to_ascii_8z (from, &ascii, 0) != IDNA_SUCCESS)
196 + return (ISC_R_FAILURE);
198 + (void) strcpy (to, ascii);
200 + return (ISC_R_SUCCESS);
202 +/* based on idnkit's code*/
204 +output_filter (isc_buffer_t *buffer, unsigned int used_org,
205 + isc_boolean_t absolute) {
206 + char tmp1[MXNAME], *tmp2;
207 + size_t fromlen, tolen;
208 + isc_boolean_t end_with_dot;
210 + fromlen = isc_buffer_usedlength(buffer) - used_org;
211 + if (fromlen >= MXNAME)
212 + return (ISC_R_SUCCESS);
213 + memcpy(tmp1, (char *)isc_buffer_base(buffer) + used_org, fromlen);
214 + end_with_dot = (tmp1[fromlen - 1] == '.') ? ISC_TRUE : ISC_FALSE;
215 + if (absolute && !end_with_dot) {
217 + if (fromlen >= MXNAME)
218 + return (ISC_R_SUCCESS);
219 + tmp1[fromlen - 1] = '.';
221 + tmp1[fromlen] = '\0';
223 + if (idna_to_unicode_lzlz (tmp1, &tmp2, 0) != IDNA_SUCCESS)
224 + return (ISC_R_SUCCESS);
226 + (void) strcpy (tmp1, tmp2);
229 + tolen = strlen(tmp1);
230 + if (absolute && !end_with_dot && tmp1[tolen - 1] == '.')
233 + if (isc_buffer_length(buffer) < used_org + tolen)
234 + return (ISC_R_NOSPACE);
236 + isc_buffer_subtract(buffer, isc_buffer_usedlength(buffer) - used_org);
237 + memcpy(isc_buffer_used(buffer), tmp1, tolen);
238 + isc_buffer_add(buffer, tolen);
240 + return (ISC_R_SUCCESS);
242 +#endif /* WITH_LIBIDN*/
246 diff -up bind-9.7.0b1/bin/dig/Makefile.in.libidn bind-9.7.0b1/bin/dig/Makefile.in
247 --- bind-9.7.0b1/bin/dig/Makefile.in.libidn 2009-09-22 10:47:55.000000000 +0200
248 +++ bind-9.7.0b1/bin/dig/Makefile.in 2009-10-20 10:50:06.201543709 +0200
249 @@ -46,10 +46,10 @@ DEPLIBS = ${DNSDEPLIBS} ${BIND9DEPLIBS}
252 LIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} ${ISCCFGLIBS} \
253 - ${ISCLIBS} @IDNLIBS@ @LIBS@
254 + ${ISCLIBS} @IDNLIBS@ @LIBS@ -lidn
256 NOSYMLIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} ${ISCCFGLIBS} \
257 - ${ISCNOSYMLIBS} @IDNLIBS@ @LIBS@
258 + ${ISCNOSYMLIBS} @IDNLIBS@ @LIBS@ -lidn
262 @@ -67,6 +67,8 @@ HTMLPAGES = dig.html host.html nslookup.
264 MANOBJS = ${MANPAGES} ${HTMLPAGES}
266 +EXT_CFLAGS = -DWITH_LIBIDN
270 dig@EXEEXT@: dig.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}