(krb5_expand_hostname): handle ai_canonname being set in any of the
addresses returnedby getaddrinfo. glibc apparently returns the reverse lookup of every address in ai_canonname. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7761 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999 Kungliga Tekniska H<>gskolan
|
* Copyright (c) 1999 - 2000 Kungliga Tekniska H<>gskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -46,12 +46,17 @@ copy_hostname(krb5_context context,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to make `orig_hostname' into a more canonical one in the newly
|
||||||
|
* allocated space returned in `new_hostname'.
|
||||||
|
*/
|
||||||
|
|
||||||
krb5_error_code
|
krb5_error_code
|
||||||
krb5_expand_hostname (krb5_context context,
|
krb5_expand_hostname (krb5_context context,
|
||||||
const char *orig_hostname,
|
const char *orig_hostname,
|
||||||
char **new_hostname)
|
char **new_hostname)
|
||||||
{
|
{
|
||||||
struct addrinfo *ai, hints;
|
struct addrinfo *ai, *a, hints;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
memset (&hints, 0, sizeof(hints));
|
memset (&hints, 0, sizeof(hints));
|
||||||
@@ -60,13 +65,16 @@ krb5_expand_hostname (krb5_context context,
|
|||||||
error = getaddrinfo (orig_hostname, NULL, &hints, &ai);
|
error = getaddrinfo (orig_hostname, NULL, &hints, &ai);
|
||||||
if (error)
|
if (error)
|
||||||
return copy_hostname (context, orig_hostname, new_hostname);
|
return copy_hostname (context, orig_hostname, new_hostname);
|
||||||
if (ai->ai_canonname == NULL) {
|
for (a = ai; a != NULL; a = a->ai_next) {
|
||||||
freeaddrinfo (ai);
|
if (a->ai_canonname != NULL) {
|
||||||
return copy_hostname (context, orig_hostname, new_hostname);
|
*new_hostname = strdup (a->ai_canonname);
|
||||||
|
freeaddrinfo (ai);
|
||||||
|
if (*new_hostname == NULL)
|
||||||
|
return ENOMEM;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*new_hostname = strdup(ai->ai_canonname);
|
|
||||||
freeaddrinfo (ai);
|
freeaddrinfo (ai);
|
||||||
if (*new_hostname == NULL)
|
return copy_hostname (context, orig_hostname, new_hostname);
|
||||||
return ENOMEM;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user