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).
*/
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,
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);