mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Tell the truth about DNS lookups in the Event Log.
We've always had the back-end code unconditionally print 'Looking up host' before calling name_lookup. But name_lookup doesn't always do an actual lookup - in cases where the connection will be proxied and we're configured to let the proxy do the DNS for us, it just calls sk_nonamelookup to return a dummy SockAddr with the unresolved name still in it. It's better to print a message that varies depending on whether we're _really_ doing DNS or not, e.g. so that people can tell the difference between DNS failure and proxy misconfiguration. Hence, those log messages are now generated inside name_lookup(), which takes a couple of extra parameters for the purpose - a frontend pointer to pass to logevent(), and a reason string so that it can say what the hostname it's (optionally) looking up is going to be used for. (The latter is intended for possible use in logging subsidiary lookups for port forwarding, though the moment I haven't changed the current setup where those connection setups aren't logged in detail - we just pass NULL in that situation.)
This commit is contained in:
parent
42334b65b0
commit
37cdfdcd51
@ -100,7 +100,8 @@ Socket new_connection(SockAddr addr, const char *hostname,
|
||||
Socket new_listener(const char *srcaddr, int port, Plug plug,
|
||||
int local_host_only, Conf *conf, int addressfamily);
|
||||
SockAddr name_lookup(const char *host, int port, char **canonicalname,
|
||||
Conf *conf, int addressfamily);
|
||||
Conf *conf, int addressfamily, void *frontend_for_logging,
|
||||
const char *lookup_reason_for_logging);
|
||||
int proxy_for_destination (SockAddr addr, const char *hostname, int port,
|
||||
Conf *conf);
|
||||
|
||||
|
@ -443,7 +443,8 @@ char *pfd_connect(struct PortForwarding **pf_ret, char *hostname,int port,
|
||||
/*
|
||||
* Try to find host.
|
||||
*/
|
||||
addr = name_lookup(hostname, port, &dummy_realhost, conf, addressfamily);
|
||||
addr = name_lookup(hostname, port, &dummy_realhost, conf, addressfamily,
|
||||
NULL, NULL);
|
||||
if ((err = sk_addr_error(addr)) != NULL) {
|
||||
char *err_ret = dupstr(err);
|
||||
sk_addr_free(addr);
|
||||
|
25
proxy.c
25
proxy.c
@ -363,16 +363,35 @@ int proxy_for_destination (SockAddr addr, const char *hostname,
|
||||
}
|
||||
|
||||
SockAddr name_lookup(const char *host, int port, char **canonicalname,
|
||||
Conf *conf, int addressfamily)
|
||||
Conf *conf, int addressfamily, void *frontend,
|
||||
const char *reason)
|
||||
{
|
||||
char *logmsg;
|
||||
if (conf_get_int(conf, CONF_proxy_type) != PROXY_NONE &&
|
||||
do_proxy_dns(conf) &&
|
||||
proxy_for_destination(NULL, host, port, conf)) {
|
||||
|
||||
if (frontend) {
|
||||
logmsg = dupprintf("Leaving host lookup to proxy of \"%s\""
|
||||
" (for %s)", host, reason);
|
||||
logevent(frontend, logmsg);
|
||||
sfree(logmsg);
|
||||
}
|
||||
|
||||
*canonicalname = dupstr(host);
|
||||
return sk_nonamelookup(host);
|
||||
}
|
||||
} else {
|
||||
if (frontend) {
|
||||
logmsg = dupprintf("Looking up host \"%s\"%s for %s", host,
|
||||
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
||||
addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
|
||||
""), reason);
|
||||
logevent(frontend, logmsg);
|
||||
sfree(logmsg);
|
||||
}
|
||||
|
||||
return sk_namelookup(host, canonicalname, addressfamily);
|
||||
return sk_namelookup(host, canonicalname, addressfamily);
|
||||
}
|
||||
}
|
||||
|
||||
Socket new_connection(SockAddr addr, const char *hostname,
|
||||
|
12
raw.c
12
raw.c
@ -154,16 +154,8 @@ static const char *raw_init(void *frontend_handle, void **backend_handle,
|
||||
/*
|
||||
* Try to find host.
|
||||
*/
|
||||
{
|
||||
char *buf;
|
||||
buf = dupprintf("Looking up host \"%s\"%s", host,
|
||||
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
||||
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
|
||||
"")));
|
||||
logevent(raw->frontend, buf);
|
||||
sfree(buf);
|
||||
}
|
||||
addr = name_lookup(host, port, realhost, conf, addressfamily);
|
||||
addr = name_lookup(host, port, realhost, conf, addressfamily,
|
||||
raw->frontend, "main connection");
|
||||
if ((err = sk_addr_error(addr)) != NULL) {
|
||||
sk_addr_free(addr);
|
||||
return err;
|
||||
|
12
rlogin.c
12
rlogin.c
@ -194,16 +194,8 @@ static const char *rlogin_init(void *frontend_handle, void **backend_handle,
|
||||
/*
|
||||
* Try to find host.
|
||||
*/
|
||||
{
|
||||
char *buf;
|
||||
buf = dupprintf("Looking up host \"%s\"%s", host,
|
||||
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
||||
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
|
||||
"")));
|
||||
logevent(rlogin->frontend, buf);
|
||||
sfree(buf);
|
||||
}
|
||||
addr = name_lookup(host, port, realhost, conf, addressfamily);
|
||||
addr = name_lookup(host, port, realhost, conf, addressfamily,
|
||||
rlogin->frontend, "rlogin connection");
|
||||
if ((err = sk_addr_error(addr)) != NULL) {
|
||||
sk_addr_free(addr);
|
||||
return err;
|
||||
|
6
ssh.c
6
ssh.c
@ -3674,10 +3674,8 @@ static const char *connect_to_host(Ssh ssh, const char *host, int port,
|
||||
* Try to find host.
|
||||
*/
|
||||
addressfamily = conf_get_int(ssh->conf, CONF_addressfamily);
|
||||
logeventf(ssh, "Looking up host \"%s\"%s", host,
|
||||
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
||||
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" : "")));
|
||||
addr = name_lookup(host, port, realhost, ssh->conf, addressfamily);
|
||||
addr = name_lookup(host, port, realhost, ssh->conf, addressfamily,
|
||||
ssh->frontend, "SSH connection");
|
||||
if ((err = sk_addr_error(addr)) != NULL) {
|
||||
sk_addr_free(addr);
|
||||
return err;
|
||||
|
14
telnet.c
14
telnet.c
@ -751,17 +751,9 @@ static const char *telnet_init(void *frontend_handle, void **backend_handle,
|
||||
/*
|
||||
* Try to find host.
|
||||
*/
|
||||
{
|
||||
char *buf;
|
||||
addressfamily = conf_get_int(telnet->conf, CONF_addressfamily);
|
||||
buf = dupprintf("Looking up host \"%s\"%s", host,
|
||||
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
||||
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
|
||||
"")));
|
||||
logevent(telnet->frontend, buf);
|
||||
sfree(buf);
|
||||
}
|
||||
addr = name_lookup(host, port, realhost, telnet->conf, addressfamily);
|
||||
addressfamily = conf_get_int(telnet->conf, CONF_addressfamily);
|
||||
addr = name_lookup(host, port, realhost, telnet->conf, addressfamily,
|
||||
telnet->frontend, "Telnet connection");
|
||||
if ((err = sk_addr_error(addr)) != NULL) {
|
||||
sk_addr_free(addr);
|
||||
return err;
|
||||
|
3
x11fwd.c
3
x11fwd.c
@ -286,7 +286,8 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf)
|
||||
|
||||
disp->port = 6000 + disp->displaynum;
|
||||
disp->addr = name_lookup(disp->hostname, disp->port,
|
||||
&disp->realhost, conf, ADDRTYPE_UNSPEC);
|
||||
&disp->realhost, conf, ADDRTYPE_UNSPEC,
|
||||
NULL, NULL);
|
||||
|
||||
if ((err = sk_addr_error(disp->addr)) != NULL) {
|
||||
sk_addr_free(disp->addr);
|
||||
|
Loading…
Reference in New Issue
Block a user