From: Danilo Almeida Date: Mon, 9 Aug 1999 21:45:25 +0000 (+0000) Subject: Make sure we have FQDN in the case where we use gethostname X-Git-Tag: krb5-1.2-beta1~310 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=afe7621b62374f094ef5fffac41cf8e7e558d9bc;p=krb5.git 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 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 3c4d885a1..147d54f0c 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,5 +1,9 @@ 1999-08-06 Danilo Almeida + * 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 262b77922..5c054bd42 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 bda5e3706..3c05f5780 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);