From f23bd0709b862d76fffe3c7e2a8b6ce9d87cc051 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sat, 8 Jan 2000 08:07:18 +0000 Subject: [PATCH] (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 --- lib/krb5/expand_hostname.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/krb5/expand_hostname.c b/lib/krb5/expand_hostname.c index 2abd28780..4bce42eb0 100644 --- a/lib/krb5/expand_hostname.c +++ b/lib/krb5/expand_hostname.c @@ -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). * All rights reserved. * @@ -46,12 +46,17 @@ copy_hostname(krb5_context context, 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_expand_hostname (krb5_context context, const char *orig_hostname, char **new_hostname) { - struct addrinfo *ai, hints; + struct addrinfo *ai, *a, hints; int error; memset (&hints, 0, sizeof(hints)); @@ -60,13 +65,16 @@ krb5_expand_hostname (krb5_context context, error = getaddrinfo (orig_hostname, NULL, &hints, &ai); if (error) return copy_hostname (context, orig_hostname, new_hostname); - if (ai->ai_canonname == NULL) { - freeaddrinfo (ai); - return copy_hostname (context, orig_hostname, new_hostname); + for (a = ai; a != NULL; a = a->ai_next) { + if (a->ai_canonname != NULL) { + *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); - if (*new_hostname == NULL) - return ENOMEM; - return 0; + return copy_hostname (context, orig_hostname, new_hostname); }