(krb5_expand_hostname): make sure that realms is filled in even when
getaddrinfo fails or does not return any canonical name git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7963 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -80,6 +80,31 @@ krb5_expand_hostname (krb5_context context,
|
|||||||
return copy_hostname (context, orig_hostname, new_hostname);
|
return copy_hostname (context, orig_hostname, new_hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handle the case of the hostname being unresolvable and thus identical
|
||||||
|
*/
|
||||||
|
|
||||||
|
static krb5_error_code
|
||||||
|
vanilla_hostname (krb5_context context,
|
||||||
|
const char *orig_hostname,
|
||||||
|
char **new_hostname,
|
||||||
|
char ***realms)
|
||||||
|
{
|
||||||
|
krb5_error_code ret;
|
||||||
|
|
||||||
|
ret = copy_hostname (context, orig_hostname, new_hostname);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
strlwr (*new_hostname);
|
||||||
|
|
||||||
|
ret = krb5_get_host_realm (context, *new_hostname, realms);
|
||||||
|
if (ret) {
|
||||||
|
free (*new_hostname);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* expand `hostname' to a name we believe to be a hostname in newly
|
* expand `hostname' to a name we believe to be a hostname in newly
|
||||||
* allocated space in `host' and return realms in `realms'.
|
* allocated space in `host' and return realms in `realms'.
|
||||||
@@ -100,21 +125,24 @@ krb5_expand_hostname_realms (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 vanilla_hostname (context, orig_hostname, new_hostname,
|
||||||
|
realms);
|
||||||
|
|
||||||
for (a = ai; a != NULL; a = a->ai_next) {
|
for (a = ai; a != NULL; a = a->ai_next) {
|
||||||
if (a->ai_canonname != NULL) {
|
if (a->ai_canonname != NULL) {
|
||||||
ret = copy_hostname (context, orig_hostname, new_hostname);
|
ret = copy_hostname (context, orig_hostname, new_hostname);
|
||||||
if (ret)
|
if (ret) {
|
||||||
goto out;
|
freeaddrinfo (ai);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
strlwr (*new_hostname);
|
strlwr (*new_hostname);
|
||||||
ret = krb5_get_host_realm (context, *new_hostname, realms);
|
ret = krb5_get_host_realm (context, *new_hostname, realms);
|
||||||
if (ret == 0)
|
if (ret == 0) {
|
||||||
goto out;
|
freeaddrinfo (ai);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
free (*new_hostname);
|
free (*new_hostname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = copy_hostname (context, orig_hostname, new_hostname);
|
return vanilla_hostname (context, orig_hostname, new_hostname, realms);
|
||||||
out:
|
|
||||||
freeaddrinfo (ai);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user