Make sure we have FQDN in the case where we use gethostname
authorDanilo Almeida <dalmeida@mit.edu>
Mon, 9 Aug 1999 21:45:25 +0000 (21:45 +0000)
committerDanilo Almeida <dalmeida@mit.edu>
Mon, 9 Aug 1999 21:45:25 +0000 (21:45 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11634 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/ChangeLog
src/lib/krb5/os/def_realm.c
src/lib/krb5/os/hst_realm.c

index 3c4d885a1b8b2c1685eaed1fd017487ca655ac20..147d54f0ceb13500f781ffb407109ddfd5b5ad5a 100644 (file)
@@ -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).
index 262b7792263021c0d80709bebda5eb42532c5b06..5c054bd4255880a27f7218511da0345bd839ecab 100644 (file)
@@ -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, 
index bda5e3706f71219042600625cf8cf8de7ea143e8..3c05f57804f67dfbd34f2085e7c7ac8fe512b468 100644 (file)
@@ -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);