Try doing a reverse address resolution to get the real hostname..
authorTheodore Tso <tytso@mit.edu>
Thu, 2 Jun 1994 17:01:03 +0000 (17:01 +0000)
committerTheodore Tso <tytso@mit.edu>
Thu, 2 Jun 1994 17:01:03 +0000 (17:01 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@3679 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/sn2princ.c

index 3dc491c1b2ad908326022e20ceed100f5e880d4d..3a486462c8722785a4e6ea032c8f17b314e34529 100644 (file)
@@ -75,9 +75,30 @@ OLDDECLARG(krb5_principal *,ret_princ)
        /* copy the hostname into non-volatile storage */
 
        if (type == KRB5_NT_SRV_HST) {
+           char *addr;
+           
            if (!(hp = gethostbyname(hostname)))
                return KRB5_ERR_BAD_HOSTNAME;
            remote_host = strdup(hp->h_name);
+           if (!remote_host)
+               return ENOMEM;
+           /*
+            * Do a reverse resolution to get the full name, just in
+            * case there's some funny business going on.  If there
+            * isn't an in-addr record, give up.
+            */
+           addr = malloc(hp->h_length);
+           if (!addr)
+               return ENOMEM;
+           memcpy(addr, hp->h_addr, hp->h_length);
+           hp = gethostbyaddr(addr, hp->h_length, hp->h_addrtype);
+           free(addr);
+           if (hp) {
+               free(remote_host);
+               remote_host = strdup(hp->h_name);
+               if (!remote_host)
+                   return ENOMEM;
+           }
        } else /* type == KRB5_NT_UNKNOWN */ {
            remote_host = strdup(hostname);
        }