summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/os/hst_realm.c
diff options
context:
space:
mode:
authorDanilo Almeida <dalmeida@mit.edu>1999-08-09 21:45:25 +0000
committerDanilo Almeida <dalmeida@mit.edu>1999-08-09 21:45:25 +0000
commitafe7621b62374f094ef5fffac41cf8e7e558d9bc (patch)
tree6e4d815197426969d4fcf855f1c2003025d9d890 /src/lib/krb5/os/hst_realm.c
parenta3445eac72f16653ac60bf65d9fa82d40a4b6674 (diff)
downloadkrb5-afe7621b62374f094ef5fffac41cf8e7e558d9bc.tar.gz
krb5-afe7621b62374f094ef5fffac41cf8e7e558d9bc.tar.xz
krb5-afe7621b62374f094ef5fffac41cf8e7e558d9bc.zip
Make sure we have FQDN in the case where we use gethostname
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11634 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/os/hst_realm.c')
-rw-r--r--src/lib/krb5/os/hst_realm.c18
1 files changed, 15 insertions, 3 deletions
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);