]> git.ipfire.org Git - ipfire-3.x.git/blame - bind/patches/bind-9.5-libidn.patch
bind: Rework package.
[ipfire-3.x.git] / bind / patches / bind-9.5-libidn.patch
CommitLineData
ac29baf9
SS
1diff -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
4@@ -44,6 +44,11 @@
5 #include <idn/api.h>
6 #endif
7
8+#ifdef WITH_LIBIDN
9+#include <stringprep.h>
10+#include <idna.h>
11+#endif
12+
13 #include <dns/byaddr.h>
14 #ifdef DIG_SIGCHASE
15 #include <dns/dnssec.h>
16@@ -153,6 +158,14 @@ static void idn_check_result(idn_result
17 int idnoptions = 0;
18 #endif
19
20+#ifdef WITH_LIBIDN
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);
26+#endif
27+
28 /*%
29 * Exit Codes:
30 *
31@@ -1184,6 +1197,9 @@ setup_system(void) {
32 dig_searchlist_t *domain = NULL;
33 lwres_result_t lwresult;
34 unsigned int lwresflags;
35+#ifdef WITH_LIBIDN
36+ isc_result_t result;
37+#endif
38
39 debug("setup_system()");
40
41@@ -1242,8 +1258,15 @@ setup_system(void) {
42
43 #ifdef WITH_IDN
44 initialize_idn();
45+
46+#endif
47+#ifdef WITH_LIBIDN
48+ result = dns_name_settotextfilter(output_filter);
49+ check_result(result, "dns_name_settotextfilter");
50+#ifdef HAVE_SETLOCALE
51+ setlocale (LC_ALL, "");
52+#endif
53 #endif
54-
55 if (keyfile[0] != 0)
56 setup_file_key();
57 else if (keysecret[0] != 0)
58@@ -1957,12 +1980,18 @@ setup_lookup(dig_lookup_t *lookup) {
59 idn_result_t mr;
60 char utf8_textname[MXNAME], utf8_origin[MXNAME], idn_textname[MXNAME];
61 #endif
62+#ifdef WITH_LIBIDN
63+ char *utf8_str = NULL, utf8_name[MXNAME], ascii_name[MXNAME];
64+#endif
65
66 #ifdef WITH_IDN
67 result = dns_name_settotextfilter(output_filter);
68 check_result(result, "dns_name_settotextfilter");
69 #endif
70-
71+#ifdef WITH_LIBIDN
72+ result = dns_name_settotextfilter (output_filter);
73+ check_result(result, "dns_name_settotextfilter");
74+#endif
75 REQUIRE(lookup != NULL);
76 INSIST(!free_now);
77
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);
86+ if (len < MXNAME) {
87+ (void) strcpy (utf8_name, utf8_str);
88+ } else {
89+ fatal ("Too long name");
90+ }
91+ isc_mem_free (mctx, utf8_str);
92 #endif
93
94 /*
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;
98 }
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;
107+ }
108 #else
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);
122+ } else {
123+ fatal ("Too long name + origin");
124+ }
125+ isc_mem_free (mctx, utf8_str);
126+ }
127+
128+ result = libidn_utf8_to_ascii (utf8_name, ascii_name);
129 #else
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,
134 dns_rootname, 0,
135 &lookup->namebuf);
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,
141+ dns_rootname, 0,
142+ &lookup->namebuf);
143 #else
144 len = strlen(lookup->textname);
145 isc_buffer_init(&b, lookup->textname, len);
146@@ -3617,7 +3686,7 @@ destroy_libs(void) {
147 void * ptr;
148 dig_message_t *chase_msg;
149 #endif
150-#ifdef WITH_IDN
151+#if defined (WITH_IDN) || defined (WITH_LIBIDN)
152 isc_result_t result;
153 #endif
154
155@@ -3656,6 +3725,10 @@ destroy_libs(void) {
156 result = dns_name_settotextfilter(NULL);
157 check_result(result, "dns_name_settotextfilter");
158 #endif
159+#ifdef WITH_LIBIDN
160+ result = dns_name_settotextfilter (NULL);
161+ check_result(result, "clearing dns_name_settotextfilter");
162+#endif
163 dns_name_destroy();
164
165 if (commctx != NULL) {
166@@ -3834,6 +3907,79 @@ idn_check_result(idn_result_t r, const c
167 }
168 }
169 #endif /* WITH_IDN */
170+#ifdef WITH_LIBIDN
171+/* If stringprep_locale_to_utf8 fails simple copy string */
172+static isc_result_t
173+libidn_locale_to_utf8 (const char *from, char **to) {
174+ char *utf8_str;
175+
176+ utf8_str = stringprep_locale_to_utf8 (from);
177+ if (utf8_str == NULL) {
178+ *to = isc_mem_allocate (mctx, strlen (from) + 1);
179+ if (*to == NULL)
180+ return (ISC_R_NOMEMORY);
181+ (void) strcpy (*to, from);
182+ } else {
183+ *to = isc_mem_allocate (mctx, strlen (utf8_str) + 1);
184+ if (*to == NULL)
185+ return (ISC_R_NOMEMORY);
186+ (void) strcpy (*to, utf8_str);
187+ free (utf8_str);
188+ }
189+ return (ISC_R_SUCCESS);
190+}
191+static isc_result_t
192+libidn_utf8_to_ascii (const char *from, char *to) {
193+ char *ascii;
194+
195+ if (idna_to_ascii_8z (from, &ascii, 0) != IDNA_SUCCESS)
196+ return (ISC_R_FAILURE);
197+
198+ (void) strcpy (to, ascii);
199+ free (ascii);
200+ return (ISC_R_SUCCESS);
201+}
202+/* based on idnkit's code*/
203+static isc_result_t
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;
209+
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) {
216+ fromlen++;
217+ if (fromlen >= MXNAME)
218+ return (ISC_R_SUCCESS);
219+ tmp1[fromlen - 1] = '.';
220+ }
221+ tmp1[fromlen] = '\0';
222+
223+ if (idna_to_unicode_lzlz (tmp1, &tmp2, 0) != IDNA_SUCCESS)
224+ return (ISC_R_SUCCESS);
225+
226+ (void) strcpy (tmp1, tmp2);
227+ free (tmp2);
228+
229+ tolen = strlen(tmp1);
230+ if (absolute && !end_with_dot && tmp1[tolen - 1] == '.')
231+ tolen--;
232+
233+ if (isc_buffer_length(buffer) < used_org + tolen)
234+ return (ISC_R_NOSPACE);
235+
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);
239+
240+ return (ISC_R_SUCCESS);
241+}
242+#endif /* WITH_LIBIDN*/
243
244 #ifdef DIG_SIGCHASE
245 void
246diff -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}
250 ${LWRESDEPLIBS}
251
252 LIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} ${ISCCFGLIBS} \
253- ${ISCLIBS} @IDNLIBS@ @LIBS@
254+ ${ISCLIBS} @IDNLIBS@ @LIBS@ -lidn
255
256 NOSYMLIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} ${ISCCFGLIBS} \
257- ${ISCNOSYMLIBS} @IDNLIBS@ @LIBS@
258+ ${ISCNOSYMLIBS} @IDNLIBS@ @LIBS@ -lidn
259
260 SUBDIRS =
261
262@@ -67,6 +67,8 @@ HTMLPAGES = dig.html host.html nslookup.
263
264 MANOBJS = ${MANPAGES} ${HTMLPAGES}
265
266+EXT_CFLAGS = -DWITH_LIBIDN
267+
268 @BIND9_MAKE_RULES@
269
270 dig@EXEEXT@: dig.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}