summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/krb5/os/ChangeLog4
-rw-r--r--src/lib/krb5/os/def_realm.c22
-rw-r--r--src/lib/krb5/os/hst_realm.c18
3 files changed, 38 insertions, 6 deletions
diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog
index 3c4d885a1b..147d54f0ce 100644
--- a/src/lib/krb5/os/ChangeLog
+++ b/src/lib/krb5/os/ChangeLog
@@ -1,5 +1,9 @@
1999-08-06 Danilo Almeida <dalmeida@mit.edu>
+ * def_realm.c (krb5_get_default_realm):
+ * hst_realm.c (krb5_get_host_realm): Make sure we have FQDN
+ in the case where we use gethostname.
+
* def_realm.c (krb5_get_default_realm): Check that we have
a realm before trying to copy it (since profile_get_string
may return no error but not get anything).
diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c
index 262b779226..5c054bd425 100644
--- a/src/lib/krb5/os/def_realm.c
+++ b/src/lib/krb5/os/def_realm.c
@@ -101,10 +101,26 @@ krb5_get_default_realm(context, lrealm)
*/
char localhost[MAX_DNS_NAMELEN+1];
char * p;
- localhost[0] = localhost[sizeof(localhost)-1] = 0;
- gethostname(localhost,MAX_DNS_NAMELEN);
-
+ struct hostent * h;
+
+ localhost[0] = 0;
+ gethostname(localhost, sizeof(localhost));
+ localhost[sizeof(localhost) - 1] = 0;
+
if ( localhost[0] ) {
+ /*
+ * Try to make sure that we have a fully qualified
+ * name if possible. We want to be able to handle
+ * the case where gethostname returns a partial
+ * name (i.e., it has a dot, but it is not a
+ * FQDN).
+ */
+ h = gethostbyname(localhost);
+ if (h) {
+ strncpy(localhost, h->h_name, sizeof(localhost));
+ localhost[sizeof(localhost) - 1] = '\0';
+ }
+
p = localhost;
do {
retval = krb5_try_realm_txt_rr("_kerberos", p,
diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c
index bda5e3706f..3c05f57804 100644
--- a/src/lib/krb5/os/hst_realm.c
+++ b/src/lib/krb5/os/hst_realm.c
@@ -234,14 +234,26 @@ krb5_get_host_realm(context, host, realmsp)
krb5_error_code retval;
int l;
char local_host[MAX_DNS_NAMELEN+1];
+ struct hostent *h;
+
if (host)
- strncpy(local_host, host, MAX_DNS_NAMELEN);
+ strncpy(local_host, host, sizeof(local_host));
else {
- if (gethostname(local_host, sizeof(local_host)-1) == -1)
+ if (gethostname(local_host, sizeof(local_host)) == -1)
return SOCKET_ERRNO;
+ /*
+ * Try to make sure that we have a fully qualified name if
+ * possible. We need to handle the case where the host has a
+ * dot but is not FQDN, so we call gethostbyname.
+ */
+ h = gethostbyname(local_host);
+ if (h) {
+ strncpy(local_host, h->h_name, sizeof(local_host));
+ }
}
- local_host[MAX_DNS_NAMELEN] = '\0';
+ local_host[sizeof(local_host) - 1] = '\0';
+
for (cp = local_host; *cp; cp++) {
if (isupper(*cp))
*cp = tolower(*cp);