summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib/krb5/get_host_realm.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2006-11-07 06:59:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:25:03 -0500
commit3c1e780ec7e16dc6667402bbc65708bf9a5c062f (patch)
tree2102bb577ea9f00751b8c869b0a5c756fc2ae8e5 /source4/heimdal/lib/krb5/get_host_realm.c
parent8b91594e0936bbaedf5430406fcf8df3ea406c10 (diff)
downloadsamba-3c1e780ec7e16dc6667402bbc65708bf9a5c062f.tar.gz
samba-3c1e780ec7e16dc6667402bbc65708bf9a5c062f.tar.bz2
samba-3c1e780ec7e16dc6667402bbc65708bf9a5c062f.zip
r19604: This is a massive commit, and I appologise in advance for it's size.
This merges Samba4 with lorikeet-heimdal, which itself has been tracking Heimdal CVS for the past couple of weeks. This is such a big change because Heimdal reorganised it's internal structures, with the mechglue merge, and because many of our 'wishes' have been granted: we now have DCE_STYLE GSSAPI, send_to_kdc hooks and many other features merged into the mainline code. We have adapted to upstream's choice of API in these cases. In gensec_gssapi and gensec_krb5, we either expect a valid PAC, or NO PAC. This matches windows behavour. We also have an option to require the PAC to be present (which allows us to automate the testing of this code). This also includes a restructure of how the kerberos dependencies are handled, due to the fallout of the merge. Andrew Bartlett (This used to be commit 4826f1735197c2a471d771495e6d4c1051b4c471)
Diffstat (limited to 'source4/heimdal/lib/krb5/get_host_realm.c')
-rw-r--r--source4/heimdal/lib/krb5/get_host_realm.c74
1 files changed, 40 insertions, 34 deletions
diff --git a/source4/heimdal/lib/krb5/get_host_realm.c b/source4/heimdal/lib/krb5/get_host_realm.c
index 33a3438b12..ffc646d98b 100644
--- a/source4/heimdal/lib/krb5/get_host_realm.c
+++ b/source4/heimdal/lib/krb5/get_host_realm.c
@@ -34,7 +34,7 @@
#include "krb5_locl.h"
#include <resolve.h>
-RCSID("$Id: get_host_realm.c,v 1.35 2005/08/23 08:14:02 lha Exp $");
+RCSID("$Id: get_host_realm.c,v 1.37 2006/10/17 19:28:36 lha Exp $");
/* To automagically find the correct realm of a host (without
* [domain_realm] in krb5.conf) add a text record for your domain with
@@ -187,65 +187,71 @@ _krb5_get_host_realm_int (krb5_context context,
return 0;
}
}
-
- *realms = malloc(2 * sizeof(krb5_realm));
- if (*realms == NULL) {
- krb5_set_error_string(context, "malloc: out of memory");
- return ENOMEM;
- }
-
- (*realms)[1] = NULL;
-
p = strchr(host, '.');
if(p != NULL) {
p++;
- (*realms)[0] = strdup(p);
- if((*realms)[0] == NULL) {
- free(*realms);
+ *realms = malloc(2 * sizeof(krb5_realm));
+ if (*realms == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
- strupr((*realms)[0]);
- } else {
- krb5_error_code ret;
- ret = krb5_get_default_realm(context, &(*realms)[0]);
- if(ret) {
+
+ (*realms)[0] = strdup(p);
+ if((*realms)[0] == NULL) {
free(*realms);
krb5_set_error_string(context, "malloc: out of memory");
return ENOMEM;
}
- if((*realms)[0] == NULL) {
- free(*realms);
- krb5_set_error_string(context, "unable to find realm of host %s", host);
- return KRB5_ERR_HOST_REALM_UNKNOWN;
- }
+ strupr((*realms)[0]);
+ (*realms)[1] = NULL;
+ return 0;
}
- return 0;
+ krb5_set_error_string(context, "unable to find realm of host %s", host);
+ return KRB5_ERR_HOST_REALM_UNKNOWN;
}
/*
- * 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
krb5_get_host_realm(krb5_context context,
- const char *host,
+ const char *targethost,
krb5_realm **realms)
{
+ const char *host = targethost;
char hostname[MAXHOSTNAMELEN];
- krb5_boolean use_dns;
+ 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;
}
- if (strchr(host, '.') == NULL) {
- use_dns = FALSE;
- } else {
- use_dns = TRUE;
- }
+ /*
+ * If our local hostname is without components, don't even try to dns.
+ */
+
+ use_dns = (strchr(host, '.') != NULL);
- return _krb5_get_host_realm_int (context, host, use_dns, realms);
+ ret = _krb5_get_host_realm_int (context, host, use_dns, realms);
+ if (ret && targethost != NULL) {
+ /*
+ * If there was no realm mapping for the host (and we wasn't
+ * looking for ourself), 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 ret;
}