]> git.ipfire.org Git - people/pmueller/ipfire-3.x.git/blob - bind/patches/bind-9.5-libidn2.patch
bind: Rework package.
[people/pmueller/ipfire-3.x.git] / bind / patches / bind-9.5-libidn2.patch
1 diff -up bind-9.5.0b1/bin/dig/dighost.c.libidn2 bind-9.5.0b1/bin/dig/dighost.c
2 --- bind-9.5.0b1/bin/dig/dighost.c.libidn2 2007-12-10 13:12:26.000000000 +0100
3 +++ bind-9.5.0b1/bin/dig/dighost.c 2007-12-10 14:21:09.000000000 +0100
4 @@ -153,7 +153,7 @@ int idnoptions = 0;
5 #endif
6
7 #ifdef WITH_LIBIDN
8 -static isc_result_t libidn_locale_to_utf8 (const char* from, char **to);
9 +static isc_result_t libidn_locale_to_utf8 (const char* from, char *to);
10 static isc_result_t libidn_utf8_to_ascii (const char* from, char *to);
11 static isc_result_t output_filter (isc_buffer_t *buffer,
12 unsigned int used_org,
13 @@ -1764,17 +1764,13 @@ setup_lookup(dig_lookup_t *lookup) {
14 char utf8_textname[MXNAME], utf8_origin[MXNAME], idn_textname[MXNAME];
15 #endif
16 #ifdef WITH_LIBIDN
17 - char *utf8_str = NULL, utf8_name[MXNAME], ascii_name[MXNAME];
18 + char utf8_str[MXNAME], utf8_name[MXNAME], ascii_name[MXNAME];
19 #endif
20
21 -#ifdef WITH_IDN
22 +#if defined (WITH_IDN) || defined (WITH_LIBIDN)
23 result = dns_name_settotextfilter(output_filter);
24 check_result(result, "dns_name_settotextfilter");
25 #endif
26 -#ifdef WITH_LIBIDN
27 - result = dns_name_settotextfilter (output_filter);
28 - check_result(result, "dns_name_settotextfilter");
29 -#endif
30 REQUIRE(lookup != NULL);
31 INSIST(!free_now);
32
33 @@ -1812,15 +1808,13 @@ setup_lookup(dig_lookup_t *lookup) {
34 utf8_textname, sizeof(utf8_textname));
35 idn_check_result(mr, "convert textname to UTF-8");
36 #elif defined (WITH_LIBIDN)
37 - result = libidn_locale_to_utf8 (lookup->textname, &utf8_str);
38 - check_result (result, "converting textname to UTF-8");
39 + result = libidn_locale_to_utf8 (lookup->textname, utf8_str);
40 + check_result (result, "convert textname to UTF-8");
41 len = strlen (utf8_str);
42 - if (len < MXNAME) {
43 + if (len < MXNAME)
44 (void) strcpy (utf8_name, utf8_str);
45 - } else {
46 + else
47 fatal ("Too long name");
48 - }
49 - isc_mem_free (mctx, utf8_str);
50 #endif
51
52 /*
53 @@ -1833,24 +1827,11 @@ setup_lookup(dig_lookup_t *lookup) {
54 if (lookup->new_search) {
55 #ifdef WITH_IDN
56 if ((count_dots(utf8_textname) >= ndots) || !usesearch) {
57 - lookup->origin = NULL; /* Force abs lookup */
58 - lookup->done_as_is = ISC_TRUE;
59 - lookup->need_search = usesearch;
60 - } else if (lookup->origin == NULL && usesearch) {
61 - lookup->origin = ISC_LIST_HEAD(search_list);
62 - lookup->need_search = ISC_FALSE;
63 - }
64 #elif defined (WITH_LIBIDN)
65 if ((count_dots(utf8_name) >= ndots) || !usesearch) {
66 - lookup->origin = NULL; /* Force abs lookup */
67 - lookup->done_as_is = ISC_TRUE;
68 - lookup->need_search = usesearch;
69 - } else if (lookup->origin == NULL && usesearch) {
70 - lookup->origin = ISC_LIST_HEAD(search_list);
71 - lookup->need_search = ISC_FALSE;
72 - }
73 #else
74 if ((count_dots(lookup->textname) >= ndots) || !usesearch) {
75 +#endif
76 lookup->origin = NULL; /* Force abs lookup */
77 lookup->done_as_is = ISC_TRUE;
78 lookup->need_search = usesearch;
79 @@ -1858,7 +1839,6 @@ setup_lookup(dig_lookup_t *lookup) {
80 lookup->origin = ISC_LIST_HEAD(search_list);
81 lookup->need_search = ISC_FALSE;
82 }
83 -#endif
84 }
85
86 #ifdef WITH_IDN
87 @@ -1877,15 +1857,12 @@ setup_lookup(dig_lookup_t *lookup) {
88 idn_check_result(mr, "convert UTF-8 textname to IDN encoding");
89 #elif defined (WITH_LIBIDN)
90 if (lookup->origin != NULL) {
91 - result = libidn_locale_to_utf8 (lookup->origin->origin, &utf8_str);
92 + result = libidn_locale_to_utf8 (lookup->origin->origin, utf8_str);
93 check_result (result, "convert origin to UTF-8");
94 - if (len + strlen (utf8_str) + 1 < MXNAME) {
95 - utf8_name[len++] = '.';
96 + if (len + strlen (utf8_str) < MXNAME)
97 (void) strcpy (utf8_name + len, utf8_str);
98 - } else {
99 + else
100 fatal ("Too long name + origin");
101 - }
102 - isc_mem_free (mctx, utf8_str);
103 }
104
105 result = libidn_utf8_to_ascii (utf8_name, ascii_name);
106 @@ -3600,76 +3577,85 @@ idn_check_result(idn_result_t r, const c
107 }
108 #endif /* WITH_IDN */
109 #ifdef WITH_LIBIDN
110 -/* If stringprep_locale_to_utf8 fails simple copy string */
111 static isc_result_t
112 -libidn_locale_to_utf8 (const char *from, char **to) {
113 +libidn_locale_to_utf8 (const char *from, char *to) {
114 char *utf8_str;
115
116 + debug ("libidn_locale_to_utf8");
117 utf8_str = stringprep_locale_to_utf8 (from);
118 - if (utf8_str == NULL) {
119 - *to = isc_mem_allocate (mctx, strlen (from) + 1);
120 - if (*to == NULL)
121 - return (ISC_R_NOMEMORY);
122 - (void) strcpy (*to, from);
123 - } else {
124 - *to = isc_mem_allocate (mctx, strlen (utf8_str) + 1);
125 - if (*to == NULL)
126 - return (ISC_R_NOMEMORY);
127 - (void) strcpy (*to, utf8_str);
128 + if (utf8_str != NULL) {
129 + (void) strcpy (to, utf8_str);
130 free (utf8_str);
131 + return ISC_R_SUCCESS;
132 }
133 - return (ISC_R_SUCCESS);
134 +
135 + debug ("libidn_locale_to_utf8: failure");
136 + return ISC_R_FAILURE;
137 }
138 static isc_result_t
139 libidn_utf8_to_ascii (const char *from, char *to) {
140 char *ascii;
141 + int iresult;
142
143 - if (idna_to_ascii_8z (from, &ascii, 0) != IDNA_SUCCESS)
144 - return (ISC_R_FAILURE);
145 + debug ("libidn_utf8_to_ascii");
146 + iresult = idna_to_ascii_8z (from, &ascii, 0);
147 + if (iresult != IDNA_SUCCESS) {
148 + debug ("idna_to_ascii_8z: %s", idna_strerror (iresult));
149 + return ISC_R_FAILURE;
150 + }
151
152 (void) strcpy (to, ascii);
153 free (ascii);
154 - return (ISC_R_SUCCESS);
155 + return ISC_R_SUCCESS;
156 }
157 -/* based on idnkit's code*/
158 +
159 static isc_result_t
160 output_filter (isc_buffer_t *buffer, unsigned int used_org,
161 isc_boolean_t absolute) {
162 +
163 char tmp1[MXNAME], *tmp2;
164 size_t fromlen, tolen;
165 isc_boolean_t end_with_dot;
166 + int iresult;
167 +
168 + debug ("output_filter");
169
170 - fromlen = isc_buffer_usedlength(buffer) - used_org;
171 + fromlen = isc_buffer_usedlength (buffer) - used_org;
172 if (fromlen >= MXNAME)
173 - return (ISC_R_SUCCESS);
174 - memcpy(tmp1, (char *)isc_buffer_base(buffer) + used_org, fromlen);
175 + return ISC_R_SUCCESS;
176 + memcpy (tmp1, (char *) isc_buffer_base (buffer) + used_org, fromlen);
177 end_with_dot = (tmp1[fromlen - 1] == '.') ? ISC_TRUE : ISC_FALSE;
178 if (absolute && !end_with_dot) {
179 fromlen++;
180 if (fromlen >= MXNAME)
181 - return (ISC_R_SUCCESS);
182 + return ISC_R_SUCCESS;
183 tmp1[fromlen - 1] = '.';
184 }
185 tmp1[fromlen] = '\0';
186
187 - if (idna_to_unicode_lzlz (tmp1, &tmp2, 0) != IDNA_SUCCESS)
188 - return (ISC_R_SUCCESS);
189 + iresult = idna_to_unicode_8z8z (tmp1, &tmp2, 0);
190 + if (iresult != IDNA_SUCCESS) {
191 + debug ("output_filter: %s", idna_strerror (iresult));
192 + return ISC_R_SUCCESS;
193 + }
194
195 (void) strcpy (tmp1, tmp2);
196 free (tmp2);
197
198 - tolen = strlen(tmp1);
199 + tolen = strlen (tmp1);
200 if (absolute && !end_with_dot && tmp1[tolen - 1] == '.')
201 tolen--;
202
203 - if (isc_buffer_length(buffer) < used_org + tolen)
204 - return (ISC_R_NOSPACE);
205 + if (isc_buffer_length (buffer) < used_org + tolen)
206 + return ISC_R_NOSPACE;
207 +
208 + debug ("%s", tmp1);
209
210 - isc_buffer_subtract(buffer, isc_buffer_usedlength(buffer) - used_org);
211 - memcpy(isc_buffer_used(buffer), tmp1, tolen);
212 - isc_buffer_add(buffer, tolen);
213 + isc_buffer_subtract (buffer, isc_buffer_usedlength (buffer) - used_org);
214 + memcpy (isc_buffer_used (buffer), tmp1, tolen);
215 + isc_buffer_add (buffer, tolen);
216
217 - return (ISC_R_SUCCESS);
218 + return ISC_R_SUCCESS;
219 }
220 #endif /* WITH_LIBIDN*/
221