|
|
900526 |
diff -up bind-9.5.0b1/bin/dig/dighost.c.libidn2 bind-9.5.0b1/bin/dig/dighost.c
|
|
|
900526 |
--- bind-9.5.0b1/bin/dig/dighost.c.libidn2 2007-12-10 13:12:26.000000000 +0100
|
|
|
900526 |
+++ bind-9.5.0b1/bin/dig/dighost.c 2007-12-10 14:21:09.000000000 +0100
|
|
|
900526 |
@@ -153,7 +153,7 @@ int idnoptions = 0;
|
|
|
900526 |
#endif
|
|
|
900526 |
|
|
|
900526 |
#ifdef WITH_LIBIDN
|
|
|
900526 |
-static isc_result_t libidn_locale_to_utf8 (const char* from, char **to);
|
|
|
900526 |
+static isc_result_t libidn_locale_to_utf8 (const char* from, char *to);
|
|
|
900526 |
static isc_result_t libidn_utf8_to_ascii (const char* from, char *to);
|
|
|
900526 |
static isc_result_t output_filter (isc_buffer_t *buffer,
|
|
|
900526 |
unsigned int used_org,
|
|
|
900526 |
@@ -1764,17 +1764,13 @@ setup_lookup(dig_lookup_t *lookup) {
|
|
|
900526 |
char utf8_textname[MXNAME], utf8_origin[MXNAME], idn_textname[MXNAME];
|
|
|
900526 |
#endif
|
|
|
900526 |
#ifdef WITH_LIBIDN
|
|
|
900526 |
- char *utf8_str = NULL, utf8_name[MXNAME], ascii_name[MXNAME];
|
|
|
900526 |
+ char utf8_str[MXNAME], utf8_name[MXNAME], ascii_name[MXNAME];
|
|
|
900526 |
#endif
|
|
|
900526 |
|
|
|
900526 |
-#ifdef WITH_IDN
|
|
|
900526 |
+#if defined (WITH_IDN) || defined (WITH_LIBIDN)
|
|
|
900526 |
result = dns_name_settotextfilter(output_filter);
|
|
|
900526 |
check_result(result, "dns_name_settotextfilter");
|
|
|
900526 |
#endif
|
|
|
900526 |
-#ifdef WITH_LIBIDN
|
|
|
900526 |
- result = dns_name_settotextfilter (output_filter);
|
|
|
900526 |
- check_result(result, "dns_name_settotextfilter");
|
|
|
900526 |
-#endif
|
|
|
900526 |
REQUIRE(lookup != NULL);
|
|
|
900526 |
INSIST(!free_now);
|
|
|
900526 |
|
|
|
900526 |
@@ -1812,15 +1808,13 @@ setup_lookup(dig_lookup_t *lookup) {
|
|
|
900526 |
utf8_textname, sizeof(utf8_textname));
|
|
|
900526 |
idn_check_result(mr, "convert textname to UTF-8");
|
|
|
900526 |
#elif defined (WITH_LIBIDN)
|
|
|
900526 |
- result = libidn_locale_to_utf8 (lookup->textname, &utf8_str);
|
|
|
900526 |
- check_result (result, "converting textname to UTF-8");
|
|
|
900526 |
+ result = libidn_locale_to_utf8 (lookup->textname, utf8_str);
|
|
|
900526 |
+ check_result (result, "convert textname to UTF-8");
|
|
|
900526 |
len = strlen (utf8_str);
|
|
|
900526 |
- if (len < MXNAME) {
|
|
|
900526 |
+ if (len < MXNAME)
|
|
|
900526 |
(void) strcpy (utf8_name, utf8_str);
|
|
|
900526 |
- } else {
|
|
|
900526 |
+ else
|
|
|
900526 |
fatal ("Too long name");
|
|
|
900526 |
- }
|
|
|
900526 |
- isc_mem_free (mctx, utf8_str);
|
|
|
900526 |
#endif
|
|
|
900526 |
|
|
|
900526 |
/*
|
|
|
900526 |
@@ -1833,24 +1827,11 @@ setup_lookup(dig_lookup_t *lookup) {
|
|
|
900526 |
if (lookup->new_search) {
|
|
|
900526 |
#ifdef WITH_IDN
|
|
|
900526 |
if ((count_dots(utf8_textname) >= ndots) || !usesearch) {
|
|
|
900526 |
- lookup->origin = NULL; /* Force abs lookup */
|
|
|
900526 |
- lookup->done_as_is = ISC_TRUE;
|
|
|
900526 |
- lookup->need_search = usesearch;
|
|
|
900526 |
- } else if (lookup->origin == NULL && usesearch) {
|
|
|
900526 |
- lookup->origin = ISC_LIST_HEAD(search_list);
|
|
|
900526 |
- lookup->need_search = ISC_FALSE;
|
|
|
900526 |
- }
|
|
|
900526 |
#elif defined (WITH_LIBIDN)
|
|
|
900526 |
if ((count_dots(utf8_name) >= ndots) || !usesearch) {
|
|
|
900526 |
- lookup->origin = NULL; /* Force abs lookup */
|
|
|
900526 |
- lookup->done_as_is = ISC_TRUE;
|
|
|
900526 |
- lookup->need_search = usesearch;
|
|
|
900526 |
- } else if (lookup->origin == NULL && usesearch) {
|
|
|
900526 |
- lookup->origin = ISC_LIST_HEAD(search_list);
|
|
|
900526 |
- lookup->need_search = ISC_FALSE;
|
|
|
900526 |
- }
|
|
|
900526 |
#else
|
|
|
900526 |
if ((count_dots(lookup->textname) >= ndots) || !usesearch) {
|
|
|
900526 |
+#endif
|
|
|
900526 |
lookup->origin = NULL; /* Force abs lookup */
|
|
|
900526 |
lookup->done_as_is = ISC_TRUE;
|
|
|
900526 |
lookup->need_search = usesearch;
|
|
|
900526 |
@@ -1858,7 +1839,6 @@ setup_lookup(dig_lookup_t *lookup) {
|
|
|
900526 |
lookup->origin = ISC_LIST_HEAD(search_list);
|
|
|
900526 |
lookup->need_search = ISC_FALSE;
|
|
|
900526 |
}
|
|
|
900526 |
-#endif
|
|
|
900526 |
}
|
|
|
900526 |
|
|
|
900526 |
#ifdef WITH_IDN
|
|
|
900526 |
@@ -1877,15 +1857,12 @@ setup_lookup(dig_lookup_t *lookup) {
|
|
|
900526 |
idn_check_result(mr, "convert UTF-8 textname to IDN encoding");
|
|
|
900526 |
#elif defined (WITH_LIBIDN)
|
|
|
900526 |
if (lookup->origin != NULL) {
|
|
|
900526 |
- result = libidn_locale_to_utf8 (lookup->origin->origin, &utf8_str);
|
|
|
900526 |
+ result = libidn_locale_to_utf8 (lookup->origin->origin, utf8_str);
|
|
|
900526 |
check_result (result, "convert origin to UTF-8");
|
|
|
900526 |
- if (len + strlen (utf8_str) + 1 < MXNAME) {
|
|
|
900526 |
- utf8_name[len++] = '.';
|
|
|
900526 |
+ if (len + strlen (utf8_str) < MXNAME)
|
|
|
900526 |
(void) strcpy (utf8_name + len, utf8_str);
|
|
|
900526 |
- } else {
|
|
|
900526 |
+ else
|
|
|
900526 |
fatal ("Too long name + origin");
|
|
|
900526 |
- }
|
|
|
900526 |
- isc_mem_free (mctx, utf8_str);
|
|
|
900526 |
}
|
|
|
900526 |
|
|
|
900526 |
result = libidn_utf8_to_ascii (utf8_name, ascii_name);
|
|
|
900526 |
@@ -3600,76 +3577,85 @@ idn_check_result(idn_result_t r, const c
|
|
|
900526 |
}
|
|
|
900526 |
#endif /* WITH_IDN */
|
|
|
900526 |
#ifdef WITH_LIBIDN
|
|
|
900526 |
-/* If stringprep_locale_to_utf8 fails simple copy string */
|
|
|
900526 |
static isc_result_t
|
|
|
900526 |
-libidn_locale_to_utf8 (const char *from, char **to) {
|
|
|
900526 |
+libidn_locale_to_utf8 (const char *from, char *to) {
|
|
|
900526 |
char *utf8_str;
|
|
|
900526 |
|
|
|
900526 |
+ debug ("libidn_locale_to_utf8");
|
|
|
900526 |
utf8_str = stringprep_locale_to_utf8 (from);
|
|
|
900526 |
- if (utf8_str == NULL) {
|
|
|
900526 |
- *to = isc_mem_allocate (mctx, strlen (from) + 1);
|
|
|
900526 |
- if (*to == NULL)
|
|
|
900526 |
- return (ISC_R_NOMEMORY);
|
|
|
900526 |
- (void) strcpy (*to, from);
|
|
|
900526 |
- } else {
|
|
|
900526 |
- *to = isc_mem_allocate (mctx, strlen (utf8_str) + 1);
|
|
|
900526 |
- if (*to == NULL)
|
|
|
900526 |
- return (ISC_R_NOMEMORY);
|
|
|
900526 |
- (void) strcpy (*to, utf8_str);
|
|
|
900526 |
+ if (utf8_str != NULL) {
|
|
|
900526 |
+ (void) strcpy (to, utf8_str);
|
|
|
900526 |
free (utf8_str);
|
|
|
900526 |
+ return ISC_R_SUCCESS;
|
|
|
900526 |
}
|
|
|
900526 |
- return (ISC_R_SUCCESS);
|
|
|
900526 |
+
|
|
|
900526 |
+ debug ("libidn_locale_to_utf8: failure");
|
|
|
900526 |
+ return ISC_R_FAILURE;
|
|
|
900526 |
}
|
|
|
900526 |
static isc_result_t
|
|
|
900526 |
libidn_utf8_to_ascii (const char *from, char *to) {
|
|
|
900526 |
char *ascii;
|
|
|
900526 |
+ int iresult;
|
|
|
900526 |
|
|
|
900526 |
- if (idna_to_ascii_8z (from, &ascii, 0) != IDNA_SUCCESS)
|
|
|
900526 |
- return (ISC_R_FAILURE);
|
|
|
900526 |
+ debug ("libidn_utf8_to_ascii");
|
|
|
900526 |
+ iresult = idna_to_ascii_8z (from, &ascii, 0);
|
|
|
900526 |
+ if (iresult != IDNA_SUCCESS) {
|
|
|
900526 |
+ debug ("idna_to_ascii_8z: %s", idna_strerror (iresult));
|
|
|
900526 |
+ return ISC_R_FAILURE;
|
|
|
900526 |
+ }
|
|
|
900526 |
|
|
|
900526 |
(void) strcpy (to, ascii);
|
|
|
900526 |
free (ascii);
|
|
|
900526 |
- return (ISC_R_SUCCESS);
|
|
|
900526 |
+ return ISC_R_SUCCESS;
|
|
|
900526 |
}
|
|
|
900526 |
-/* based on idnkit's code*/
|
|
|
900526 |
+
|
|
|
900526 |
static isc_result_t
|
|
|
900526 |
output_filter (isc_buffer_t *buffer, unsigned int used_org,
|
|
|
900526 |
isc_boolean_t absolute) {
|
|
|
900526 |
+
|
|
|
900526 |
char tmp1[MXNAME], *tmp2;
|
|
|
900526 |
size_t fromlen, tolen;
|
|
|
900526 |
isc_boolean_t end_with_dot;
|
|
|
900526 |
+ int iresult;
|
|
|
900526 |
+
|
|
|
900526 |
+ debug ("output_filter");
|
|
|
900526 |
|
|
|
900526 |
- fromlen = isc_buffer_usedlength(buffer) - used_org;
|
|
|
900526 |
+ fromlen = isc_buffer_usedlength (buffer) - used_org;
|
|
|
900526 |
if (fromlen >= MXNAME)
|
|
|
900526 |
- return (ISC_R_SUCCESS);
|
|
|
900526 |
- memcpy(tmp1, (char *)isc_buffer_base(buffer) + used_org, fromlen);
|
|
|
900526 |
+ return ISC_R_SUCCESS;
|
|
|
900526 |
+ memcpy (tmp1, (char *) isc_buffer_base (buffer) + used_org, fromlen);
|
|
|
900526 |
end_with_dot = (tmp1[fromlen - 1] == '.') ? ISC_TRUE : ISC_FALSE;
|
|
|
900526 |
if (absolute && !end_with_dot) {
|
|
|
900526 |
fromlen++;
|
|
|
900526 |
if (fromlen >= MXNAME)
|
|
|
900526 |
- return (ISC_R_SUCCESS);
|
|
|
900526 |
+ return ISC_R_SUCCESS;
|
|
|
900526 |
tmp1[fromlen - 1] = '.';
|
|
|
900526 |
}
|
|
|
900526 |
tmp1[fromlen] = '\0';
|
|
|
900526 |
|
|
|
900526 |
- if (idna_to_unicode_lzlz (tmp1, &tmp2, 0) != IDNA_SUCCESS)
|
|
|
900526 |
- return (ISC_R_SUCCESS);
|
|
|
900526 |
+ iresult = idna_to_unicode_8z8z (tmp1, &tmp2, 0);
|
|
|
900526 |
+ if (iresult != IDNA_SUCCESS) {
|
|
|
900526 |
+ debug ("output_filter: %s", idna_strerror (iresult));
|
|
|
900526 |
+ return ISC_R_SUCCESS;
|
|
|
900526 |
+ }
|
|
|
900526 |
|
|
|
900526 |
(void) strcpy (tmp1, tmp2);
|
|
|
900526 |
free (tmp2);
|
|
|
900526 |
|
|
|
900526 |
- tolen = strlen(tmp1);
|
|
|
900526 |
+ tolen = strlen (tmp1);
|
|
|
900526 |
if (absolute && !end_with_dot && tmp1[tolen - 1] == '.')
|
|
|
900526 |
tolen--;
|
|
|
900526 |
|
|
|
900526 |
- if (isc_buffer_length(buffer) < used_org + tolen)
|
|
|
900526 |
- return (ISC_R_NOSPACE);
|
|
|
900526 |
+ if (isc_buffer_length (buffer) < used_org + tolen)
|
|
|
900526 |
+ return ISC_R_NOSPACE;
|
|
|
900526 |
+
|
|
|
900526 |
+ debug ("%s", tmp1);
|
|
|
900526 |
|
|
|
900526 |
- isc_buffer_subtract(buffer, isc_buffer_usedlength(buffer) - used_org);
|
|
|
900526 |
- memcpy(isc_buffer_used(buffer), tmp1, tolen);
|
|
|
900526 |
- isc_buffer_add(buffer, tolen);
|
|
|
900526 |
+ isc_buffer_subtract (buffer, isc_buffer_usedlength (buffer) - used_org);
|
|
|
900526 |
+ memcpy (isc_buffer_used (buffer), tmp1, tolen);
|
|
|
900526 |
+ isc_buffer_add (buffer, tolen);
|
|
|
900526 |
|
|
|
900526 |
- return (ISC_R_SUCCESS);
|
|
|
900526 |
+ return ISC_R_SUCCESS;
|
|
|
900526 |
}
|
|
|
900526 |
#endif /* WITH_LIBIDN*/
|
|
|
900526 |
|