From f162bd7f2ea73d4225d2625e16be5346547abea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Tue, 17 Oct 2006 19:03:12 +0000 Subject: [PATCH] (krb5_get_host_realm): no components -> no dns. no mapping, try local realm and hope KDC knows better. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18539 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/get_host_realm.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/krb5/get_host_realm.c b/lib/krb5/get_host_realm.c index 5a38cd5ef..00b5524c8 100644 --- a/lib/krb5/get_host_realm.c +++ b/lib/krb5/get_host_realm.c @@ -211,7 +211,8 @@ _krb5_get_host_realm_int (krb5_context context, } /* - * Return the realm(s) of `host' as a NULL-terminated list in `realms'. + * Return the realm(s) of `host' as a NULL-terminated list in + * `realms'. Free `realms' with krb5_free_host_realm(). */ krb5_error_code KRB5_LIB_FUNCTION @@ -220,12 +221,36 @@ krb5_get_host_realm(krb5_context context, krb5_realm **realms) { char hostname[MAXHOSTNAMELEN]; + krb5_error_code ret; + int use_dns; if (host == NULL) { - if (gethostname (hostname, sizeof(hostname))) + if (gethostname (hostname, sizeof(hostname))) { + *realms = NULL; return errno; + } host = hostname; } - return _krb5_get_host_realm_int (context, host, 1, realms); + /* + * If our local hostname is without components, don't even try to dns. + */ + + use_dns = (strchr(host, '.') != NULL); + + ret = _krb5_get_host_realm_int (context, host, use_dns, realms); + if (ret) { + /* + * If there was no realm mapping for the host guess at the + * local realm, maybe our KDC knows better then we do and we + * get a referral back. + */ + ret = krb5_get_default_realms(context, realms); + if (ret) { + krb5_set_error_string(context, "Unable to find realm of host %s", + host); + return KRB5_ERR_HOST_REALM_UNKNOWN; + } + } + return 0; }