hfaxd/InetFaxServer.c++
/*
 * Check host identity returned by getnameinfo to
 * weed out clients trying to spoof us (this is mostly
 * a sanity check; if they have full control of DNS
 * they can still spoof)
 * Look up the name and check that the peer's address
 * corresponds to the host name.
 */
Check host identity returned by getnameinfo to
weed out clients trying to spoof us (this is mostly
a sanity check; if they have full control of DNS
they can still spoof)
Look up the name and check that the peer's address
corresponds to the host name.
Check host identity returned by getnameinfo to weed out clients trying to spoof us ( this is mostly a sanity check ; if they have full control of DNS they can still spoof ) Look up the name and check that the peer ' s address corresponds to the host name .
bool
InetFaxServer::checkHostIdentity(const char*name)
{
    struct addrinfo hints, *ai;
    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = AI_CANONNAME;
    hints.ai_socktype = SOCK_STREAM;
    if (getaddrinfo(name, NULL, &hints, &ai) == 0) {
	for (struct addrinfo *aip = ai; aip != NULL; aip = aip->ai_next) {
	    Socket::Address *addr = (Socket::Address*)aip->ai_addr;
	    if (aip->ai_family != Socket::family(peer_addr))
		continue;
	    if ( (aip->ai_family == AF_INET6 &&
		     memcmp(&addr->in6.sin6_addr, &peer_addr.in6.sin6_addr, sizeof(struct in6_addr)) ==0)
		 ||(aip->ai_family == AF_INET &&
		     memcmp(&addr->in.sin_addr, &peer_addr.in.sin_addr, sizeof(struct in_addr)) ==0)
	       ) {
		freeaddrinfo(ai);
		return true;
	    }
	}
	reply(130, "Warning, client address \"%s\" is not listed for host name \"%s\".",
	    (const char*) remoteaddr, name);
	freeaddrinfo(ai);
    } else
	reply(130, "Warning, no inverse address mapping for client host name \"%s\".",
	    (const char*) name);
    return (false);
}
bool InetFaxServer :: checkHostIdentity ( const char * name ) { struct addrinfo hints , * ai ; memset ( & hints , 0 , sizeof ( hints ) ) ; hints . ai_flags = AI_CANONNAME ; hints . ai_socktype = SOCK_STREAM ; if ( getaddrinfo ( name , NULL , & hints , & ai ) == 0 ) { for ( struct addrinfo * aip = ai ; aip != NULL ; aip = aip -> ai_next ) { Socket :: Address * addr = ( Socket :: Address * ) aip -> ai_addr ; if ( aip -> ai_family != Socket :: family ( peer_addr ) ) continue ; if ( ( aip -> ai_family == AF_INET6 && memcmp ( & addr -> in6 . sin6_addr , & peer_addr . in6 . sin6_addr , sizeof ( struct in6_addr ) ) == 0 ) || ( aip -> ai_family == AF_INET && memcmp ( & addr -> in . sin_addr , & peer_addr . in . sin_addr , sizeof ( struct in_addr ) ) == 0 ) ) { freeaddrinfo ( ai ) ; return true ; } } reply ( 130 , " \" \" \" \" " , ( const char * ) remoteaddr , name ) ; freeaddrinfo ( ai ) ; } else reply ( 130 , " \" \" " , ( const char * ) name ) ; return ( false ) ; }
Check host identity returned by getnameinfo to
 weed out clients trying to spoof us (this is mostly
 a sanity check; if they have full control of DNS
 they can still spoof)
 Look up the name and check that the peer's address
 corresponds to the host name.
Check host identity returned by getnameinfo to weed out clients trying to spoof us ( this is mostly a sanity check ; if they have full control of DNS they can still spoof ) Look up the name and check that the peer ' s address corresponds to the host name .