diff --git a/lib/krb5/sock_principal.c b/lib/krb5/sock_principal.c index 62cd3bcd4..4307330dc 100644 --- a/lib/krb5/sock_principal.c +++ b/lib/krb5/sock_principal.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -50,6 +50,7 @@ krb5_sock_to_principal (krb5_context context, struct hostent *hostent; int family; char hname[256]; + char *tmp; if (getsockname (sock, sa, &len) < 0) return errno; @@ -65,7 +66,18 @@ krb5_sock_to_principal (krb5_context context, if (hostent == NULL) return h_errno; - strlcpy(hname, hostent->h_name, sizeof(hname)); + tmp = hostent->h_name; + if (strchr(tmp, '.') == NULL) { + char **a; + + for (a = hostent->h_aliases; a != NULL && *a != NULL; ++a) + if (strchr(*a, '.') != NULL) { + tmp = *a; + break; + } + } + + strlcpy(hname, tmp, sizeof(hname)); return krb5_sname_to_principal (context, hname, sname,