canohost.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
* Functions for returning the canonical host name of the remote site.
*
* As far as I am concerned, the code I have written for this software
* can be used freely for any purpose. Any derived versions of this
* software must be clearly marked as such, and if the derived work is
* incompatible with the protocol description in the RFC file, it must be
* called by a name other than "ssh" or "Secure Shell".
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "includes.h"
RCSID("$OpenBSD: canohost.c,v 1.34 2002/09/23 20:46:27 stevesk Exp $");
#pragma ident "%Z%%M% %I% %E% SMI"
#include "packet.h"
#include "xmalloc.h"
#include "log.h"
#include "canohost.h"
/*
* Return the canonical name of the host at the other end of the socket. The
* caller should free the returned string with xfree.
*/
static char *
{
struct sockaddr_storage from;
int i, res;
/* Get IP address of client. */
}
NULL, 0, NI_NUMERICHOST)) != 0)
#ifdef IPV4_IN_IPV6
}
#endif /* IPV4_IN_IPV6 */
/* Map the IP address to a host name. */
NULL, 0, NI_NAMEREQD) != 0) {
/* Host name not found. Use ip address. */
#if 0
#endif
}
/* Got host name. */
/*
* Convert it to all lowercase (which is expected by the rest
* of this software).
*/
for (i = 0; name[i]; i++)
if (!verify_reverse_mapping)
/*
* Map it back to an IP address and check that the given
* address actually is an address of this host. This is
* necessary because anyone with access to a name server can
* define arbitrary names for an IP address. Mapping from
* name to IP address can be trusted better (but can still be
* fooled if the intruder has access to the name server of
* the domain).
*/
log("reverse mapping checking getaddrinfo for %.700s "
"failed - POSSIBLE BREAKIN ATTEMPT!", name);
}
/* Look for the address from the list of addresses. */
break;
}
/* If we reached the end of the list, the address was not there. */
if (!ai) {
/* Address not found for the host name. */
log("Address %.100s maps to %.600s, but this does not "
"map back to the address - POSSIBLE BREAKIN ATTEMPT!",
}
}
/*
* Return the canonical name of the host in the other side of the current
* connection. The host name is cached, so it is efficient to call this
* several times.
*/
const char *
{
static char *canonical_host_name = NULL;
static int verify_reverse_mapping_done = 0;
/* Check if we have previously retrieved name with same option. */
if (canonical_host_name != NULL) {
else
return canonical_host_name;
}
/* Get the real hostname if socket; otherwise return UNKNOWN. */
else
return canonical_host_name;
}
/*
* Returns the remote IP-address of socket as a string. The returned
* string must be freed.
*/
char *
{
struct sockaddr_storage addr;
char ntop[NI_MAXHOST];
const char *result;
char abuf[INET6_ADDRSTRLEN];
/* Get IP address of client. */
if (remote) {
< 0) {
debug("get_socket_ipaddr: getpeername failed: %.100s",
return (NULL);
}
} else {
< 0) {
debug("get_socket_ipaddr: getsockname failed: %.100s",
return (NULL);
}
}
/* Get the address in ascii. */
return (NULL);
}
}
}
#if 0
static char *
{
struct sockaddr_storage addr;
char ntop[NI_MAXHOST];
/* Get IP address of client. */
if (remote) {
< 0)
return NULL;
} else {
< 0)
return NULL;
}
/* Get the address in ascii. */
return NULL;
}
}
#endif
char *
get_peer_ipaddr(int socket)
{
char *p;
return p;
return xstrdup("UNKNOWN");
}
char *
get_local_ipaddr(int socket)
{
char *p;
return p;
return xstrdup("UNKNOWN");
}
char *
get_local_name(int socket)
{
}
/*
* Returns the IP-address of the remote host as a string. The returned
* string must not be freed.
*/
const char *
get_remote_ipaddr(void)
{
static char *canonical_host_ip = NULL;
/* Check whether we have cached the ipaddr. */
if (canonical_host_ip == NULL) {
if (packet_connection_is_on_socket()) {
if (canonical_host_ip == NULL)
} else {
/* If not on socket, return UNKNOWN. */
}
}
return canonical_host_ip;
}
const char *
{
static const char *remote = "";
if (utmp_len > 0)
remote = get_remote_ipaddr();
return remote;
}
static int
{
struct sockaddr_storage from;
char strport[NI_MAXSERV];
/* Get IP address of client. */
if (local) {
return 0;
}
} else {
}
}
/* Return port number. */
fatal("get_sock_port: getnameinfo NI_NUMERICSERV failed");
}
static int
{
/*
* If the connection is not a socket, return 65535. This is
* intentionally chosen to be an unprivileged port number.
*/
if (!packet_connection_is_on_socket())
return 65535;
/* Get socket and return the port number. */
}
int
get_peer_port(int sock)
{
return get_sock_port(sock, 0);
}
int
get_remote_port(void)
{
return get_port(0);
}
int
get_local_port(void)
{
return get_port(1);
}
/*
* Taken from inetd.c
* This is a wrapper function for inet_ntop(). In case the af is AF_INET6
* and the address pointed by src is a IPv4-mapped IPv6 address, it
* returns printable IPv4 address, not IPv4-mapped IPv6 address. In other cases
* it behaves just like inet_ntop().
*/
static const char *
{
const char *result;
} else {
}
} else {
}
return (result);
}