/[packages]/cauldron/bind/current/SOURCES/bind-9.5-libidn.patch
ViewVC logotype

Contents of /cauldron/bind/current/SOURCES/bind-9.5-libidn.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 621433 - (show annotations) (download)
Fri May 9 08:04:07 2014 UTC (9 years, 11 months ago) by oden
File size: 7857 byte(s)
- 9.10.0-P1
- rediff patches
- new named.cache

1 diff -Naurp bind-9.10.0-P1/bin/dig/dighost.c bind-9.10.0-P1.oden/bin/dig/dighost.c
2 --- bind-9.10.0-P1/bin/dig/dighost.c 2014-05-05 02:15:51.000000000 +0200
3 +++ bind-9.10.0-P1.oden/bin/dig/dighost.c 2014-05-09 08:13:40.000000000 +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/callbacks.h>
16 @@ -161,6 +166,14 @@ int idnoptions = 0;
17 isc_socket_t *keep = NULL;
18 isc_sockaddr_t keepaddr;
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 @@ -1353,8 +1366,15 @@ setup_system(void) {
32
33 #ifdef WITH_IDN
34 initialize_idn();
35 +
36 +#endif
37 +#ifdef WITH_LIBIDN
38 + result = dns_name_settotextfilter(output_filter);
39 + check_result(result, "dns_name_settotextfilter");
40 +#ifdef HAVE_SETLOCALE
41 + setlocale (LC_ALL, "");
42 +#endif
43 #endif
44 -
45 if (keyfile[0] != 0)
46 setup_file_key();
47 else if (keysecret[0] != 0)
48 @@ -2104,12 +2124,18 @@ setup_lookup(dig_lookup_t *lookup) {
49 idn_result_t mr;
50 char utf8_textname[MXNAME], utf8_origin[MXNAME], idn_textname[MXNAME];
51 #endif
52 +#ifdef WITH_LIBIDN
53 + char *utf8_str = NULL, utf8_name[MXNAME], ascii_name[MXNAME];
54 +#endif
55
56 #ifdef WITH_IDN
57 result = dns_name_settotextfilter(output_filter);
58 check_result(result, "dns_name_settotextfilter");
59 #endif
60 -
61 +#ifdef WITH_LIBIDN
62 + result = dns_name_settotextfilter (output_filter);
63 + check_result(result, "dns_name_settotextfilter");
64 +#endif
65 REQUIRE(lookup != NULL);
66 INSIST(!free_now);
67
68 @@ -2146,6 +2172,16 @@ setup_lookup(dig_lookup_t *lookup) {
69 mr = idn_encodename(IDN_LOCALCONV | IDN_DELIMMAP, lookup->textname,
70 utf8_textname, sizeof(utf8_textname));
71 idn_check_result(mr, "convert textname to UTF-8");
72 +#elif defined (WITH_LIBIDN)
73 + result = libidn_locale_to_utf8 (lookup->textname, &utf8_str);
74 + check_result (result, "converting textname to UTF-8");
75 + len = strlen (utf8_str);
76 + if (len < MXNAME) {
77 + (void) strcpy (utf8_name, utf8_str);
78 + } else {
79 + fatal ("Too long name");
80 + }
81 + isc_mem_free (mctx, utf8_str);
82 #endif
83
84 /*
85 @@ -2165,6 +2201,15 @@ setup_lookup(dig_lookup_t *lookup) {
86 lookup->origin = ISC_LIST_HEAD(search_list);
87 lookup->need_search = ISC_FALSE;
88 }
89 +#elif defined (WITH_LIBIDN)
90 + if ((count_dots(utf8_name) >= ndots) || !usesearch) {
91 + lookup->origin = NULL; /* Force abs lookup */
92 + lookup->done_as_is = ISC_TRUE;
93 + lookup->need_search = usesearch;
94 + } else if (lookup->origin == NULL && usesearch) {
95 + lookup->origin = ISC_LIST_HEAD(search_list);
96 + lookup->need_search = ISC_FALSE;
97 + }
98 #else
99 if ((count_dots(lookup->textname) >= ndots) || !usesearch) {
100 lookup->origin = NULL; /* Force abs lookup */
101 @@ -2191,6 +2236,20 @@ setup_lookup(dig_lookup_t *lookup) {
102 IDN_IDNCONV | IDN_LENCHECK, utf8_textname,
103 idn_textname, sizeof(idn_textname));
104 idn_check_result(mr, "convert UTF-8 textname to IDN encoding");
105 +#elif defined (WITH_LIBIDN)
106 + if (lookup->origin != NULL) {
107 + result = libidn_locale_to_utf8 (lookup->origin->origin, &utf8_str);
108 + check_result (result, "convert origin to UTF-8");
109 + if (len + strlen (utf8_str) + 1 < MXNAME) {
110 + utf8_name[len++] = '.';
111 + (void) strcpy (utf8_name + len, utf8_str);
112 + } else {
113 + fatal ("Too long name + origin");
114 + }
115 + isc_mem_free (mctx, utf8_str);
116 + }
117 +
118 + result = libidn_utf8_to_ascii (utf8_name, ascii_name);
119 #else
120 if (lookup->origin != NULL) {
121 debug("trying origin %s", lookup->origin->origin);
122 @@ -2246,6 +2305,13 @@ setup_lookup(dig_lookup_t *lookup) {
123 result = dns_name_fromtext(lookup->name, &b,
124 dns_rootname, 0,
125 &lookup->namebuf);
126 +#elif defined (WITH_LIBIDN)
127 + len = strlen (ascii_name);
128 + isc_buffer_init(&b, ascii_name, len);
129 + isc_buffer_add(&b, len);
130 + result = dns_name_fromtext(lookup->name, &b,
131 + dns_rootname, 0,
132 + &lookup->namebuf);
133 #else
134 len = strlen(lookup->textname);
135 isc_buffer_init(&b, lookup->textname, len);
136 @@ -4029,7 +4095,7 @@ destroy_libs(void) {
137 void * ptr;
138 dig_message_t *chase_msg;
139 #endif
140 -#ifdef WITH_IDN
141 +#if defined (WITH_IDN) || defined (WITH_LIBIDN)
142 isc_result_t result;
143 #endif
144
145 @@ -4070,6 +4136,10 @@ destroy_libs(void) {
146 result = dns_name_settotextfilter(NULL);
147 check_result(result, "dns_name_settotextfilter");
148 #endif
149 +#ifdef WITH_LIBIDN
150 + result = dns_name_settotextfilter (NULL);
151 + check_result(result, "clearing dns_name_settotextfilter");
152 +#endif
153 dns_name_destroy();
154
155 if (commctx != NULL) {
156 @@ -4249,6 +4319,79 @@ idn_check_result(idn_result_t r, const c
157 }
158 }
159 #endif /* WITH_IDN */
160 +#ifdef WITH_LIBIDN
161 +/* If stringprep_locale_to_utf8 fails simple copy string */
162 +static isc_result_t
163 +libidn_locale_to_utf8 (const char *from, char **to) {
164 + char *utf8_str;
165 +
166 + utf8_str = stringprep_locale_to_utf8 (from);
167 + if (utf8_str == NULL) {
168 + *to = isc_mem_allocate (mctx, strlen (from) + 1);
169 + if (*to == NULL)
170 + return (ISC_R_NOMEMORY);
171 + (void) strcpy (*to, from);
172 + } else {
173 + *to = isc_mem_allocate (mctx, strlen (utf8_str) + 1);
174 + if (*to == NULL)
175 + return (ISC_R_NOMEMORY);
176 + (void) strcpy (*to, utf8_str);
177 + free (utf8_str);
178 + }
179 + return (ISC_R_SUCCESS);
180 +}
181 +static isc_result_t
182 +libidn_utf8_to_ascii (const char *from, char *to) {
183 + char *ascii;
184 +
185 + if (idna_to_ascii_8z (from, &ascii, 0) != IDNA_SUCCESS)
186 + return (ISC_R_FAILURE);
187 +
188 + (void) strcpy (to, ascii);
189 + free (ascii);
190 + return (ISC_R_SUCCESS);
191 +}
192 +/* based on idnkit's code*/
193 +static isc_result_t
194 +output_filter (isc_buffer_t *buffer, unsigned int used_org,
195 + isc_boolean_t absolute) {
196 + char tmp1[MXNAME], *tmp2;
197 + size_t fromlen, tolen;
198 + isc_boolean_t end_with_dot;
199 +
200 + fromlen = isc_buffer_usedlength(buffer) - used_org;
201 + if (fromlen >= MXNAME)
202 + return (ISC_R_SUCCESS);
203 + memcpy(tmp1, (char *)isc_buffer_base(buffer) + used_org, fromlen);
204 + end_with_dot = (tmp1[fromlen - 1] == '.') ? ISC_TRUE : ISC_FALSE;
205 + if (absolute && !end_with_dot) {
206 + fromlen++;
207 + if (fromlen >= MXNAME)
208 + return (ISC_R_SUCCESS);
209 + tmp1[fromlen - 1] = '.';
210 + }
211 + tmp1[fromlen] = '\0';
212 +
213 + if (idna_to_unicode_lzlz (tmp1, &tmp2, 0) != IDNA_SUCCESS)
214 + return (ISC_R_SUCCESS);
215 +
216 + (void) strcpy (tmp1, tmp2);
217 + free (tmp2);
218 +
219 + tolen = strlen(tmp1);
220 + if (absolute && !end_with_dot && tmp1[tolen - 1] == '.')
221 + tolen--;
222 +
223 + if (isc_buffer_length(buffer) < used_org + tolen)
224 + return (ISC_R_NOSPACE);
225 +
226 + isc_buffer_subtract(buffer, isc_buffer_usedlength(buffer) - used_org);
227 + memcpy(isc_buffer_used(buffer), tmp1, tolen);
228 + isc_buffer_add(buffer, tolen);
229 +
230 + return (ISC_R_SUCCESS);
231 +}
232 +#endif /* WITH_LIBIDN*/
233
234 #ifdef DIG_SIGCHASE
235 void
236 diff -Naurp bind-9.10.0-P1/bin/dig/Makefile.in bind-9.10.0-P1.oden/bin/dig/Makefile.in
237 --- bind-9.10.0-P1/bin/dig/Makefile.in 2014-05-05 02:15:51.000000000 +0200
238 +++ bind-9.10.0-P1.oden/bin/dig/Makefile.in 2014-05-09 08:14:37.000000000 +0200
239 @@ -48,10 +48,10 @@ DEPLIBS = ${DNSDEPLIBS} ${BIND9DEPLIBS}
240 ${ISCCFGDEPLIBS} ${LWRESDEPLIBS}
241
242 LIBS = ${LWRESLIBS} ${BIND9LIBS} ${ISCCFGLIBS} \
243 - ${ISCLIBS} @IDNLIBS@ @LIBS@
244 + ${ISCLIBS} @IDNLIBS@ @LIBS@ -lidn
245
246 NOSYMLIBS = ${LWRESLIBS} ${BIND9LIBS} ${ISCCFGLIBS} \
247 - ${ISCNOSYMLIBS} @IDNLIBS@ @LIBS@
248 + ${ISCNOSYMLIBS} @IDNLIBS@ @LIBS@ -lidn
249
250 SUBDIRS =
251
252 @@ -69,6 +69,8 @@ HTMLPAGES = dig.html host.html nslookup.
253
254 MANOBJS = ${MANPAGES} ${HTMLPAGES}
255
256 +EXT_CFLAGS = -DWITH_LIBIDN
257 +
258 @BIND9_MAKE_RULES@
259
260 dig@EXEEXT@: dig.@O@ dighost.@O@ ${UOBJS} ${DEPLIBS}

  ViewVC Help
Powered by ViewVC 1.1.30