From 2154b0078bbf359a64844339ac0cb5df03bf28d0 Mon Sep 17 00:00:00 2001 From: jbasney Date: Mon, 9 Sep 2002 22:01:52 +0000 Subject: [PATCH] use gethostbyaddr() to query the resolver for the official hostname of the target host --- openssh/gss-genr.c | 14 +++++++++++--- openssh/sshconnect1.c | 12 +++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/openssh/gss-genr.c b/openssh/gss-genr.c index 5dbd8b5..a21d697 100644 --- a/openssh/gss-genr.c +++ b/openssh/gss-genr.c @@ -425,7 +425,7 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host) { gss_buffer_desc gssbuf; OM_uint32 maj_status, min_status; struct hostent *hostinfo = NULL; - char *xhost; + char *xhost, *addr; /* Make a copy of the host name, in case it was returned by a * previous call to gethostbyname(). */ @@ -439,8 +439,16 @@ ssh_gssapi_import_name(Gssctxt *ctx, const char *host) { if ((hostinfo == NULL) || (hostinfo->h_name == NULL)) { debug("Unable to get FQDN for \"%s\"", xhost); } else { - xfree(xhost); - xhost = xstrdup(hostinfo->h_name); + addr = xmalloc(hostinfo->h_length); + memcpy(addr, hostinfo->h_addr, hostinfo->h_length); + hostinfo = gethostbyaddr(addr, hostinfo->h_length, AF_INET); + xfree(addr); + if ((hostinfo == NULL) || (hostinfo->h_name == NULL)) { + debug("Unable to get FQDN for \"%s\"", xhost); + } else { + xfree(xhost); + xhost = xstrdup(hostinfo->h_name); + } } gssbuf.length = sizeof("host@")+strlen(xhost); diff --git a/openssh/sshconnect1.c b/openssh/sshconnect1.c index f69a72c..6dd4cb7 100644 --- a/openssh/sshconnect1.c +++ b/openssh/sshconnect1.c @@ -1086,13 +1086,23 @@ int try_gssapi_authentication(char *host, Options *options) int type; char *gssapi_auth_type = NULL; struct hostent *hostinfo; - + char *addr; /* * host is not guarenteed to be a FQDN, so we need to make sure it is. */ hostinfo = gethostbyname(host); + if ((hostinfo == NULL) || (hostinfo->h_addr == NULL)) { + debug("GSSAPI authentication: Unable to get FQDN for \"%s\"", host); + goto cleanup; + } + + addr = xmalloc(hostinfo->h_length); + memcpy(addr, hostinfo->h_addr, hostinfo->h_length); + hostinfo = gethostbyaddr(addr, hostinfo->h_length, AF_INET); + xfree(addr); + if ((hostinfo == NULL) || (hostinfo->h_name == NULL)) { debug("GSSAPI authentication: Unable to get FQDN for \"%s\"", host); goto cleanup; -- 2.45.1