From 62bfc36ee50b03a29e914c273186a3f12b1aafd1 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sun, 9 Jan 2000 09:18:32 +0000 Subject: [PATCH] (krb5_expand_hostname_realms): new variant of krb5_expand_hostname that tries until it expands into something that's digestable by krb5_get_host_realm, returning also the result from that function. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7779 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/expand_hostname.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/krb5/expand_hostname.c b/lib/krb5/expand_hostname.c index 4bce42eb0..5bf568aff 100644 --- a/lib/krb5/expand_hostname.c +++ b/lib/krb5/expand_hostname.c @@ -78,3 +78,40 @@ krb5_expand_hostname (krb5_context context, freeaddrinfo (ai); return copy_hostname (context, orig_hostname, new_hostname); } + +/* + * expand `hostname' to a name we believe to be a hostname in newly + * allocated space in `host' and return realms in `realms'. + */ + +krb5_error_code +krb5_expand_hostname_realms (krb5_context context, + const char *orig_hostname, + char **new_hostname, + char ***realms) +{ + struct addrinfo *ai, *a, hints; + int error; + + memset (&hints, 0, sizeof(hints)); + hints.ai_flags = AI_CANONNAME; + + error = getaddrinfo (orig_hostname, NULL, &hints, &ai); + if (error) + return copy_hostname (context, orig_hostname, new_hostname); + for (a = ai; a != NULL; a = a->ai_next) { + if (a->ai_canonname != NULL) { + krb5_error_code ret = krb5_get_host_realm (context, + a->ai_canonname, + realms); + + if (ret == 0) { + ret = copy_hostname (context, a->ai_canonname, new_hostname); + freeaddrinfo (ai); + return ret; + } + } + } + freeaddrinfo (ai); + return copy_hostname (context, orig_hostname, new_hostname); +}